使用html 和javascript 实现微信界面功能2

打印 上一主题 下一主题

主题 923|帖子 923|积分 2769

1.功能分析:

对上一篇的基础上进行了稍稍改造
主要修改点:
搜刮功能:
在搜刮框后面增加了搜刮按钮。
搜刮按钮调用performSearch函数来实行搜刮操作。
表单情势的功能:
上传文件: 修改为表单情势,允许用户通过文件输入控件选择文件并上传。
发布朋侪圈: 修改为表单情势,允许用户输入朋侪圈内容并发布。
展示视频: 修改为表单情势,允许用户输入视频URL并展示。
2.代码展示

  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <title>简易版微信</title>
  7.     <style>
  8.         body {
  9.             font-family: Arial, sans-serif;
  10.             display: flex;
  11.             justify-content: center;
  12.             align-items: center;
  13.             height: 100vh;
  14.             margin: 0;
  15.             background-color: #f5f5f5;
  16.         }
  17.         .container {
  18.             width: 80%;
  19.             max-width: 1200px;
  20.             background: white;
  21.             border-radius: 10px;
  22.             box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
  23.             overflow: hidden;
  24.             display: flex;
  25.         }
  26.         .sidebar {
  27.             width: 25%;
  28.             background: #e9ecef;
  29.             padding: 20px;
  30.             box-sizing: border-box;
  31.         }
  32.         .main-content {
  33.             width: 75%;
  34.             padding: 20px;
  35.             box-sizing: border-box;
  36.         }
  37.         .search-area {
  38.             margin-bottom: 20px;
  39.             display: flex;
  40.             align-items: center;
  41.         }
  42.         .search-area input {
  43.             width: calc(100% - 80px);
  44.             padding: 10px;
  45.             border: 1px solid #ddd;
  46.             border-radius: 5px;
  47.             outline: none;
  48.         }
  49.         .search-area button {
  50.             padding: 10px 20px;
  51.             border: none;
  52.             background: #07c160;
  53.             color: white;
  54.             cursor: pointer;
  55.             border-radius: 5px;
  56.             margin-left: 10px;
  57.         }
  58.         .search-area button:hover {
  59.             background: #06a352;
  60.         }
  61.         .friends-list, .favorites-list, .files-list, .moments-list, .videos-list {
  62.             margin-top: 20px;
  63.         }
  64.         .item {
  65.             padding: 10px;
  66.             border-bottom: 1px solid #ddd;
  67.             cursor: pointer;
  68.         }
  69.         .item:last-child {
  70.             border-bottom: none;
  71.         }
  72.         .item:hover {
  73.             background: #f1f1f1;
  74.         }
  75.         .video-item video {
  76.             width: 100%;
  77.             border-radius: 10px;
  78.         }
  79.         .disabled {
  80.             opacity: 0.5;
  81.             pointer-events: none;
  82.         }
  83.         .messages {
  84.             max-height: 300px;
  85.             overflow-y: auto;
  86.             border-bottom: 1px solid #ddd;
  87.             padding-bottom: 10px;
  88.         }
  89.         .message {
  90.             margin-bottom: 10px;
  91.         }
  92.         .message.user {
  93.             text-align: right;
  94.         }
  95.         .message.bot {
  96.             text-align: left;
  97.         }
  98.         .input-area {
  99.             display: flex;
  100.             border-top: 1px solid #ddd;
  101.         }
  102.         .input-area input {
  103.             flex-grow: 1;
  104.             padding: 10px;
  105.             border: none;
  106.             outline: none;
  107.         }
  108.         .input-area button {
  109.             padding: 10px;
  110.             border: none;
  111.             background: #07c160;
  112.             color: white;
  113.             cursor: pointer;
  114.         }
  115.         .input-area button:hover {
  116.             background: #06a352;
  117.         }
  118.         .confirmation-message {
  119.             margin-top: 20px;
  120.             padding: 10px;
  121.             background: #ffcccc;
  122.             border: 1px solid #ff4d4d;
  123.             border-radius: 5px;
  124.         }
  125.         .confirmation-message p {
  126.             margin: 0;
  127.         }
  128.         .confirmation-buttons button {
  129.             margin-right: 10px;
  130.         }
  131.         .friend-details img {
  132.             width: 50px;
  133.             height: 50px;
  134.             border-radius: 50%;
  135.             object-fit: cover;
  136.             margin-right: 10px;
  137.         }
  138.         .form-group {
  139.             margin-bottom: 15px;
  140.         }
  141.         .form-group label {
  142.             display: block;
  143.             margin-bottom: 5px;
  144.         }
  145.         .form-group input,
  146.         .form-group textarea,
  147.         .form-group select {
  148.             width: 100%;
  149.             padding: 10px;
  150.             border: 1px solid #ddd;
  151.             border-radius: 5px;
  152.             outline: none;
  153.         }
  154.         .form-group button {
  155.             padding: 10px 20px;
  156.             border: none;
  157.             background: #07c160;
  158.             color: white;
  159.             cursor: pointer;
  160.             border-radius: 5px;
  161.         }
  162.         .form-group button:hover {
  163.             background: #06a352;
  164.         }
  165.         .preview-image {
  166.             width: 100px;
  167.             height: 100px;
  168.             border-radius: 50%;
  169.             object-fit: cover;
  170.             margin-top: 10px;
  171.         }
  172.     </style>
  173. </head>
  174. <body>
  175.     <div class="container">
  176.         <div class="sidebar">
  177.             <h3>搜索</h3>
  178.             <div class="search-area">
  179.                 <input type="text" id="searchInput" placeholder="搜索...">
  180.                 <button onclick="performSearch()">搜索</button>
  181.             </div>
  182.             <h3>好友</h3>
  183.             <div class="friends-list" id="friendsList">
  184.                 <div class="item" onclick="showFriends()">查看好友</div>
  185.             </div>
  186.             <h3>收藏</h3>
  187.             <div class="favorites-list" id="favoritesList">
  188.                 <div class="item" onclick="showFavorites()">查看收藏</div>
  189.             </div>
  190.             <h3>文件</h3>
  191.             <div class="files-list" id="filesList">
  192.                 <div class="item" onclick="showFiles()">查看文件</div>
  193.             </div>
  194.             <h3>朋友圈</h3>
  195.             <div class="moments-list" id="momentsList">
  196.                 <div class="item" onclick="showMoments()">查看朋友圈</div>
  197.             </div>
  198.             <h3>视频号</h3>
  199.             <div class="videos-list" id="videosList">
  200.                 <div class="item" onclick="showVideos()">查看视频</div>
  201.             </div>
  202.         </div>
  203.         <div class="main-content">
  204.             <h2 id="contentTitle">主界面</h2>
  205.             <div id="contentArea"></div>
  206.         </div>
  207.     </div>
  208.     <script>
  209.         let friends = [];
  210.         let favorites = [];
  211.         let files = [];
  212.         let moments = [];
  213.         let videos = [];
  214.         let confirmationCallback = null;
  215.         function generateUniqueId() {
  216.             return Math.random().toString(36).substr(2, 9);
  217.         }
  218.         function addFriendForm() {
  219.             const contentArea = document.getElementById('contentArea');
  220.             contentArea.innerHTML = `
  221.                 <h3>添加好友</h3>
  222.                 <form id="addFriendForm">
  223.                     <div class="form-group">
  224.                         <label for="friendNickname">网名:</label>
  225.                         <input type="text" id="friendNickname" required>
  226.                     </div>
  227.                     <div class="form-group">
  228.                         <label for="friendAge">年龄:</label>
  229.                         <input type="number" id="friendAge" min="1" required>
  230.                     </div>
  231.                     <div class="form-group">
  232.                         <label for="friendGender">性别:</label>
  233.                         <select id="friendGender" required>
  234.                             <option value="">请选择...</option>
  235.                             <option value="male">男</option>
  236.                             <option value="female">女</option>
  237.                             <option value="other">其他</option>
  238.                         </select>
  239.                     </div>
  240.                     <div class="form-group">
  241.                         <label for="friendAddress">地址:</label>
  242.                         <input type="text" id="friendAddress" required>
  243.                     </div>
  244.                     <div class="form-group">
  245.                         <label for="friendAvatar">头像:</label>
  246.                         <input type="file" id="friendAvatar" accept="image/*" required>
  247.                         <img id="avatarPreview" class="preview-image" src="" alt="Avatar Preview" style="display:none;">
  248.                     </div>
  249.                     <button type="submit">添加好友</button>
  250.                 </form>
  251.             `;
  252.             document.getElementById('friendAvatar').addEventListener('change', function(event) {
  253.                 const file = event.target.files[0];
  254.                 if (file) {
  255.                     const reader = new FileReader();
  256.                     reader.onload = function(e) {
  257.                         const previewImage = document.getElementById('avatarPreview');
  258.                         previewImage.src = e.target.result;
  259.                         previewImage.style.display = 'block';
  260.                     };
  261.                     reader.readAsDataURL(file);
  262.                 }
  263.             });
  264.             document.getElementById('addFriendForm').onsubmit = (event) => {
  265.                 event.preventDefault();
  266.                 const nickname = document.getElementById('friendNickname').value;
  267.                 const age = parseInt(document.getElementById('friendAge').value);
  268.                 const gender = document.getElementById('friendGender').value;
  269.                 const address = document.getElementById('friendAddress').value;
  270.                 const avatarFile = document.getElementById('friendAvatar').files[0];
  271.                 if (!avatarFile) {
  272.                     showMessage('请上传头像');
  273.                     return;
  274.                 }
  275.                 const friendId = generateUniqueId();
  276.                 const reader = new FileReader();
  277.                 reader.onloadend = () => {
  278.                     const avatarUrl = reader.result;
  279.                     friends.push({ id: friendId, nickname, age, gender, address, avatar: avatarUrl, blocked: false });
  280.                     showMessage(`已添加好友 ${nickname}`);
  281.                     showFriends();
  282.                 };
  283.                 reader.readAsDataURL(avatarFile);
  284.             };
  285.         }
  286.         function deleteFriend(index) {
  287.             confirmationCallback = () => {
  288.                 friends.splice(index, 1);
  289.                 showFriends();
  290.             };
  291.             showConfirmation(`确定要删除 ${friends[index].nickname} 吗?`);
  292.         }
  293.         function blockFriend(index) {
  294.             friends[index].blocked = !friends[index].blocked;
  295.             showMessage(`已将 ${friends[index].nickname} ${friends[index].blocked ? '拉黑' : '取消拉黑'}`);
  296.             showFriends();
  297.         }
  298.         function addToFavoritesForm() {
  299.             const contentArea = document.getElementById('contentArea');
  300.             contentArea.innerHTML = `
  301.                 <h3>添加收藏</h3>
  302.                 <form id="addFavoriteForm">
  303.                     <div class="form-group">
  304.                         <label for="favoriteContent">收藏内容:</label>
  305.                         <textarea id="favoriteContent" rows="4" required></textarea>
  306.                     </div>
  307.                     <button type="submit">添加收藏</button>
  308.                 </form>
  309.             `;
  310.             document.getElementById('addFavoriteForm').onsubmit = (event) => {
  311.                 event.preventDefault();
  312.                 const content = document.getElementById('favoriteContent').value;
  313.                 if (content) {
  314.                     favorites.push({ content, likes: 0 });
  315.                     showMessage(`已添加收藏`);
  316.                     showFavorites();
  317.                 }
  318.             };
  319.         }
  320.         function deleteFavorite(index) {
  321.             confirmationCallback = () => {
  322.                 favorites.splice(index, 1);
  323.                 showFavorites();
  324.             };
  325.             showConfirmation(`确定要删除此收藏吗?`);
  326.         }
  327.         function likeFavorite(index) {
  328.             favorites[index].likes++;
  329.             showFavorites();
  330.         }
  331.         function uploadFileForm() {
  332.             const contentArea = document.getElementById('contentArea');
  333.             contentArea.innerHTML = `
  334.                 <h3>上传文件</h3>
  335.                 <form id="uploadFileForm">
  336.                     <div class="form-group">
  337.                         <label for="fileUpload">选择文件:</label>
  338.                         <input type="file" id="fileUpload" required>
  339.                     </div>
  340.                     <button type="submit">上传文件</button>
  341.                 </form>
  342.             `;
  343.             document.getElementById('uploadFileForm').onsubmit = (event) => {
  344.                 event.preventDefault();
  345.                 const fileInput = document.getElementById('fileUpload');
  346.                 const file = fileInput.files[0];
  347.                 if (file) {
  348.                     files.push(file);
  349.                     showMessage(`${file.name} 已上传`);
  350.                     showFiles();
  351.                 }
  352.             };
  353.         }
  354.         function downloadFile(index) {
  355.             const file = files[index];
  356.             const url = URL.createObjectURL(file);
  357.             const a = document.createElement('a');
  358.             a.href = url;
  359.             a.download = file.name;
  360.             document.body.appendChild(a);
  361.             a.click();
  362.             a.remove();
  363.         }
  364.         function deleteFile(index) {
  365.             confirmationCallback = () => {
  366.                 files.splice(index, 1);
  367.                 showFiles();
  368.             };
  369.             showConfirmation(`确定要删除此文件吗?`);
  370.         }
  371.         function postMomentForm() {
  372.             const contentArea = document.getElementById('contentArea');
  373.             contentArea.innerHTML = `
  374.                 <h3>发布朋友圈</h3>
  375.                 <form id="postMomentForm">
  376.                     <div class="form-group">
  377.                         <label for="momentContent">朋友圈内容:</label>
  378.                         <textarea id="momentContent" rows="4" required></textarea>
  379.                     </div>
  380.                     <button type="submit">发布朋友圈</button>
  381.                 </form>
  382.             `;
  383.             document.getElementById('postMomentForm').onsubmit = (event) => {
  384.                 event.preventDefault();
  385.                 const content = document.getElementById('momentContent').value;
  386.                 if (content) {
  387.                     moments.push({ content, likes: 0 });
  388.                     showMessage(`已发布朋友圈`);
  389.                     showMoments();
  390.                 }
  391.             };
  392.         }
  393.         function deleteMoment(index) {
  394.             confirmationCallback = () => {
  395.                 moments.splice(index, 1);
  396.                 showMoments();
  397.             };
  398.             showConfirmation(`确定要删除此朋友圈吗?`);
  399.         }
  400.         function likeMoment(index) {
  401.             moments[index].likes++;
  402.             showMoments();
  403.         }
  404.         function showVideoForm() {
  405.             const contentArea = document.getElementById('contentArea');
  406.             contentArea.innerHTML = `
  407.                 <h3>展示视频</h3>
  408.                 <form id="showVideoForm">
  409.                     <div class="form-group">
  410.                         <label for="videoUrl">视频URL:</label>
  411.                         <input type="url" id="videoUrl" required>
  412.                     </div>
  413.                     <button type="submit">展示视频</button>
  414.                 </form>
  415.             `;
  416.             document.getElementById('showVideoForm').onsubmit = (event) => {
  417.                 event.preventDefault();
  418.                 const videoUrl = document.getElementById('videoUrl').value;
  419.                 if (videoUrl) {
  420.                     videos.push({ url: videoUrl, likes: 0 });
  421.                     showMessage(`已添加视频`);
  422.                     showVideos();
  423.                 }
  424.             };
  425.         }
  426.         function deleteVideo(index) {
  427.             confirmationCallback = () => {
  428.                 videos.splice(index, 1);
  429.                 showVideos();
  430.             };
  431.             showConfirmation(`确定要删除此视频吗?`);
  432.         }
  433.         function likeVideo(index) {
  434.             videos[index].likes++;
  435.             showVideos();
  436.         }
  437.         function updateFriendsList() {
  438.             const friendsList = document.getElementById('friendsList');
  439.             friendsList.innerHTML = `
  440.                 <div class="item" οnclick="showFriends()">查看好友</div>
  441.             `;
  442.             if (friends.length > 0) {
  443.                 friends.forEach((friend, index) => {
  444.                     const item = document.createElement('div');
  445.                     item.className = 'item';
  446.                     item.textContent = `${friend.nickname} (${friend.age}) ${friend.blocked ? '(已拉黑)' : ''}`;
  447.                     item.onclick = () => showFriendDetails(index);
  448.                     friendsList.appendChild(item);
  449.                 });
  450.             }
  451.         }
  452.         function updateFavoritesList() {
  453.             const favoritesList = document.getElementById('favoritesList');
  454.             favoritesList.innerHTML = `
  455.                 <div class="item" οnclick="showFavorites()">查看收藏</div>
  456.             `;
  457.             if (favorites.length > 0) {
  458.                 favorites.forEach((favorite, index) => {
  459.                     const item = document.createElement('div');
  460.                     item.className = 'item';
  461.                     item.textContent = `${favorite.content.substring(0, 50)}... (${favorite.likes} 点赞)`;
  462.                     item.onclick = () => showFavoriteDetails(index);
  463.                     favoritesList.appendChild(item);
  464.                 });
  465.             }
  466.         }
  467.         function updateFilesList() {
  468.             const filesList = document.getElementById('filesList');
  469.             filesList.innerHTML = `
  470.                 <div class="item" οnclick="showFiles()">查看文件</div>
  471.             `;
  472.             if (files.length > 0) {
  473.                 files.forEach((file, index) => {
  474.                     const item = document.createElement('div');
  475.                     item.className = 'item';
  476.                     item.textContent = `${file.name}`;
  477.                     item.onclick = () => showFileDetails(index);
  478.                     filesList.appendChild(item);
  479.                 });
  480.             }
  481.         }
  482.         function updateMomentsList() {
  483.             const momentsList = document.getElementById('momentsList');
  484.             momentsList.innerHTML = `
  485.                 <div class="item" οnclick="showMoments()">查看朋友圈</div>
  486.             `;
  487.             if (moments.length > 0) {
  488.                 moments.forEach((moment, index) => {
  489.                     const item = document.createElement('div');
  490.                     item.className = 'item';
  491.                     item.textContent = `${moment.content.substring(0, 50)}... (${moment.likes} 点赞)`;
  492.                     item.onclick = () => showMomentDetails(index);
  493.                     momentsList.appendChild(item);
  494.                 });
  495.             }
  496.         }
  497.         function updateVideosList() {
  498.             const videosList = document.getElementById('videosList');
  499.             videosList.innerHTML = `
  500.                 <div class="item" οnclick="showVideos()">查看视频</div>
  501.             `;
  502.             if (videos.length > 0) {
  503.                 videos.forEach((video, index) => {
  504.                     const item = document.createElement('div');
  505.                     item.className = 'item';
  506.                     item.innerHTML = `<video src="${video.url}" controls></video> (${video.likes} 点赞)`;
  507.                     item.onclick = () => showVideoDetails(index);
  508.                     videosList.appendChild(item);
  509.                 });
  510.             }
  511.         }
  512.         function showFriends() {
  513.             const contentArea = document.getElementById('contentArea');
  514.             contentArea.innerHTML = `
  515.                 <h3>好友列表</h3>
  516.                 <button οnclick="addFriendForm()">添加好友</button>
  517.                 <div id="friendsContent"></div>
  518.             `;
  519.             const friendsContent = document.getElementById('friendsContent');
  520.             friends.forEach((friend, index) => {
  521.                 const item = document.createElement('div');
  522.                 item.className = 'item';
  523.                 item.textContent = `${friend.nickname} (${friend.age}) ${genderMap[friend.gender]} ${friend.blocked ? '(已拉黑)' : ''}`;
  524.                 item.onclick = () => showFriendDetails(index);
  525.                 friendsContent.appendChild(item);
  526.             });
  527.         }
  528.         function showFriendDetails(index) {
  529.             const friend = friends[index];
  530.             const contentArea = document.getElementById('contentArea');
  531.             contentArea.innerHTML = `
  532.                 <h3>${friend.nickname}</h3>
  533.                 <div class="friend-details">
  534.                     <img src="${friend.avatar}" alt="${friend.nickname}'s Avatar">
  535.                     <p>年龄: ${friend.age}</p>
  536.                     <p>性别: ${genderMap[friend.gender]}</p>
  537.                     <p>地址: ${friend.address}</p>
  538.                     <p>状态: ${friend.blocked ? '已拉黑' : '正常'}</p>
  539.                     <button οnclick="chatWithFriend(${index})" ${friend.blocked ? 'class="disabled"' : ''}>聊天</button>
  540.                     <button οnclick="deleteFriend(${index})">删除好友</button>
  541.                     <button οnclick="blockFriend(${index})">${friend.blocked ? '取消拉黑' : '拉黑好友'}</button>
  542.                 </div>
  543.             `;
  544.         }
  545.         function chatWithFriend(index) {
  546.             const friend = friends[index];
  547.             if (friend.blocked) {
  548.                 showMessage('无法与已拉黑的好友聊天');
  549.                 return;
  550.             }
  551.             const contentArea = document.getElementById('contentArea');
  552.             contentArea.innerHTML = `
  553.                 <h3>与 ${friend.nickname} 聊天</h3>
  554.                 <div class="messages" id="friendMessages"></div>
  555.                 <div class="input-area">
  556.                     <input type="text" id="friendMessageInput" placeholder="输入消息...">
  557.                     <button οnclick="sendFriendMessage(${index})">发送</button>
  558.                 </div>
  559.             `;
  560.         }
  561.         function sendFriendMessage(index) {
  562.             const friendMessageInput = document.getElementById('friendMessageInput');
  563.             const friendMessagesContainer = document.getElementById('friendMessages');
  564.             const userMessage = friendMessageInput.value.trim();
  565.             if (userMessage === '') return;
  566.             // 创建用户消息元素
  567.             const userMessageElement = document.createElement('div');
  568.             userMessageElement.className = 'message user';
  569.             userMessageElement.textContent = userMessage;
  570.             friendMessagesContainer.appendChild(userMessageElement);
  571.             // 添加撤回按钮
  572.             const revokeButton = document.createElement('button');
  573.             revokeButton.textContent = '撤回';
  574.             revokeButton.onclick = () => {
  575.                 friendMessagesContainer.removeChild(userMessageElement);
  576.             };
  577.             userMessageElement.appendChild(revokeButton);
  578.             // 清空输入框
  579.             friendMessageInput.value = '';
  580.             // 模拟好友回复
  581.             setTimeout(() => {
  582.                 const friendReply = `收到:${userMessage}`;
  583.                 const friendMessageElement = document.createElement('div');
  584.                 friendMessageElement.className = 'message bot';
  585.                 friendMessageElement.textContent = friendReply;
  586.                 friendMessagesContainer.appendChild(friendMessageElement);
  587.                 // 自动滚动到底部
  588.                 friendMessagesContainer.scrollTop = friendMessagesContainer.scrollHeight;
  589.             }, 1000);
  590.         }
  591.         function showFavoriteDetails(index) {
  592.             const favorite = favorites[index];
  593.             const contentArea = document.getElementById('contentArea');
  594.             contentArea.innerHTML = `
  595.                 <h3>收藏内容</h3>
  596.                 <p>${favorite.content}</p>
  597.                 <p>点赞数: ${favorite.likes}</p>
  598.                 <button οnclick="likeFavorite(${index})">点赞</button>
  599.                 <button οnclick="deleteFavorite(${index})">删除收藏</button>
  600.             `;
  601.         }
  602.         function showFileDetails(index) {
  603.             const contentArea = document.getElementById('contentArea');
  604.             contentArea.innerHTML = `
  605.                 <h3>文件详情</h3>
  606.                 <p>文件名: ${files[index].name}</p>
  607.                 <button οnclick="downloadFile(${index})">下载文件</button>
  608.                 <button οnclick="deleteFile(${index})">删除文件</button>
  609.             `;
  610.         }
  611.         function showMomentDetails(index) {
  612.             const contentArea = document.getElementById('contentArea');
  613.             contentArea.innerHTML = `
  614.                 <h3>朋友圈内容</h3>
  615.                 <p>${moments[index].content}</p>
  616.                 <p>点赞数: ${moments[index].likes}</p>
  617.                 <button οnclick="likeMoment(${index})">点赞</button>
  618.                 <button οnclick="deleteMoment(${index})">删除朋友圈</button>
  619.             `;
  620.         }
  621.         function showVideoDetails(index) {
  622.             const contentArea = document.getElementById('contentArea');
  623.             contentArea.innerHTML = `
  624.                 <h3>视频详情</h3>
  625.                 <video src="${videos[index].url}" controls></video>
  626.                 <p>点赞数: ${videos[index].likes}</p>
  627.                 <button οnclick="likeVideo(${index})">点赞</button>
  628.                 <button οnclick="deleteVideo(${index})">删除视频</button>
  629.             `;
  630.         }
  631.         function showFavorites() {
  632.             const contentArea = document.getElementById('contentArea');
  633.             contentArea.innerHTML = `
  634.                 <h3>收藏内容列表</h3>
  635.                 <button οnclick="addToFavoritesForm()">新增收藏内容</button>
  636.                 <div id="favoritesContent"></div>
  637.             `;
  638.             const favoritesContent = document.getElementById('favoritesContent');
  639.             favorites.forEach((favorite, index) => {
  640.                 const item = document.createElement('div');
  641.                 item.className = 'item';
  642.                 item.textContent = `${favorite.content.substring(0, 50)}... (${favorite.likes} 点赞)`;
  643.                 item.onclick = () => showFavoriteDetails(index);
  644.                 favoritesContent.appendChild(item);
  645.             });
  646.         }
  647.         function showFiles() {
  648.             const contentArea = document.getElementById('contentArea');
  649.             contentArea.innerHTML = `
  650.                 <h3>文件列表</h3>
  651.                 <button οnclick="uploadFileForm()">上传文件</button>
  652.                 <div id="filesContent"></div>
  653.             `;
  654.             const filesContent = document.getElementById('filesContent');
  655.             files.forEach((file, index) => {
  656.                 const item = document.createElement('div');
  657.                 item.className = 'item';
  658.                 item.textContent = `${file.name}`;
  659.                 item.onclick = () => showFileDetails(index);
  660.                 filesContent.appendChild(item);
  661.             });
  662.         }
  663.         function showMoments() {
  664.             const contentArea = document.getElementById('contentArea');
  665.             contentArea.innerHTML = `
  666.                 <h3>朋友圈列表</h3>
  667.                 <button οnclick="postMomentForm()">发布朋友圈</button>
  668.                 <div id="momentsContent"></div>
  669.             `;
  670.             const momentsContent = document.getElementById('momentsContent');
  671.             moments.forEach((moment, index) => {
  672.                 const item = document.createElement('div');
  673.                 item.className = 'item';
  674.                 item.textContent = `${moment.content.substring(0, 50)}... (${moment.likes} 点赞)`;
  675.                 item.onclick = () => showMomentDetails(index);
  676.                 momentsContent.appendChild(item);
  677.             });
  678.         }
  679.         function showVideos() {
  680.             const contentArea = document.getElementById('contentArea');
  681.             contentArea.innerHTML = `
  682.                 <h3>视频列表</h3>
  683.                 <button οnclick="showVideoForm()">展示视频</button>
  684.                 <div id="videosContent"></div>
  685.             `;
  686.             const videosContent = document.getElementById('videosContent');
  687.             videos.forEach((video, index) => {
  688.                 const item = document.createElement('div');
  689.                 item.className = 'item';
  690.                 item.innerHTML = `<video src="${video.url}" controls></video> (${video.likes} 点赞)`;
  691.                 item.onclick = () => showVideoDetails(index);
  692.                 videosContent.appendChild(item);
  693.             });
  694.         }
  695.         function showConfirmation(message) {
  696.             const contentArea = document.getElementById('contentArea');
  697.             contentArea.innerHTML += `
  698.                 <div class="confirmation-message" id="confirmationMessage">
  699.                     <p>${message}</p>
  700.                     <div class="confirmation-buttons">
  701.                         <button οnclick="confirmAction()">确认</button>
  702.                         <button οnclick="cancelAction()">取消</button>
  703.                     </div>
  704.                 </div>
  705.             `;
  706.         }
  707.         function confirmAction() {
  708.             if (confirmationCallback) {
  709.                 confirmationCallback();
  710.                 confirmationCallback = null;
  711.             }
  712.             hideConfirmation();
  713.         }
  714.         function cancelAction() {
  715.             confirmationCallback = null;
  716.             hideConfirmation();
  717.         }
  718.         function hideConfirmation() {
  719.             const confirmationMessage = document.getElementById('confirmationMessage');
  720.             if (confirmationMessage) {
  721.                 confirmationMessage.remove();
  722.             }
  723.         }
  724.         function showMessage(message) {
  725.             const contentArea = document.getElementById('contentArea');
  726.             contentArea.innerHTML += `
  727.                 <div class="confirmation-message" id="confirmationMessage">
  728.                     <p>${message}</p>
  729.                 </div>
  730.             `;
  731.             setTimeout(hideConfirmation, 3000); // Hide after 3 seconds
  732.         }
  733.         function searchFriends(query) {
  734.             const filteredFriends = friends.filter(friend =>
  735.                 friend.nickname.toLowerCase().includes(query.toLowerCase())
  736.             );
  737.             const contentArea = document.getElementById('contentArea');
  738.             contentArea.innerHTML = `
  739.                 <h3>搜索结果</h3>
  740.                 <div id="searchResults"></div>
  741.             `;
  742.             const searchResults = document.getElementById('searchResults');
  743.             if (filteredFriends.length > 0) {
  744.                 filteredFriends.forEach((friend, index) => {
  745.                     const item = document.createElement('div');
  746.                     item.className = 'item';
  747.                     item.textContent = `${friend.nickname} (${friend.age}) ${genderMap[friend.gender]} ${friend.blocked ? '(已拉黑)' : ''}`;
  748.                     item.onclick = () => showSearchFriendDetails(filteredFriends, index);
  749.                     searchResults.appendChild(item);
  750.                 });
  751.             } else {
  752.                 searchResults.innerHTML = '<p>没有找到匹配的好友</p>';
  753.             }
  754.         }
  755.         function performSearch() {
  756.             const query = document.getElementById('searchInput').value;
  757.             if (query.trim()) {
  758.                 searchFriends(query);
  759.             } else {
  760.                 showFriends(); // Reset to full list if search is cleared
  761.             }
  762.         }
  763.         function showSearchFriendDetails(filteredFriends, index) {
  764.             const friend = filteredFriends[index];
  765.             const contentArea = document.getElementById('contentArea');
  766.             contentArea.innerHTML = `
  767.                 <h3>${friend.nickname}</h3>
  768.                 <div class="friend-details">
  769.                     <img src="${friend.avatar}" alt="${friend.nickname}'s Avatar">
  770.                     <p>年龄: ${friend.age}</p>
  771.                     <p>性别: ${genderMap[friend.gender]}</p>
  772.                     <p>地址: ${friend.address}</p>
  773.                     <p>状态: ${friend.blocked ? '已拉黑' : '正常'}</p>
  774.                     <button οnclick="chatWithFriend(${friends.indexOf(friend)})" ${friend.blocked ? 'class="disabled"' : ''}>聊天</button>
  775.                     <button οnclick="deleteFriend(${friends.indexOf(friend)})">删除好友</button>
  776.                     <button οnclick="blockFriend(${friends.indexOf(friend)})">${friend.blocked ? '取消拉黑' : '拉黑好友'}</button>
  777.                 </div>
  778.             `;
  779.         }
  780.         // Gender mapping
  781.         const genderMap = {
  782.             male: '男',
  783.             female: '女',
  784.             other: '其他'
  785.         };
  786.         // 初始化列表
  787.         updateFriendsList();
  788.         updateFavoritesList();
  789.         updateFilesList();
  790.         updateMomentsList();
  791.         updateVideosList();
  792.     </script>
  793. </body>
  794. </html>
复制代码
3.效果展示



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

汕尾海湾

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表