diff --git a/src/views/home/chatTest.vue b/src/views/home/chatTest.vue index 6ad5001b..e05d6397 100644 --- a/src/views/home/chatTest.vue +++ b/src/views/home/chatTest.vue @@ -3,28 +3,27 @@
-
新建聊天
+
新建聊天
-
-
{{ item.title }}
+
+
{{ item.title }}
+ +
-
+
- -
-
-
-
-
+ +
+
+
+ {{ item.chat_time }} +
{{ item.chat_text }}
+
-
- 前端有哪些性能优化? -
-
@@ -47,16 +46,44 @@ export default { data() { return { userName: "", - listData:[{id:1,title:'第一次聊天'}], - chatData: [{chat_text:'前端有哪些性能优化?',chat_time:'2022-08-18 10:00:00',chat_type:'myself'}], + listData:[{id:1,title:'前端有哪些性能优化?',}], + chatData: [ + {chat_text:'前端有哪些性能优化?',chat_time:'2022-08-18 10:00:00',chat_type:'myself'}, + {chat_text:'1. 图片优化使用适当格式(例如:JPEG, PNG, WebP)。压缩图片文件,减少文件大小。使用响应式图片(srcset)来适配不同分辨率的设备。2. 懒加载(Lazy Loading)对图片、视频和其他资源进行懒加载,仅在需要时才加载。使用 IntersectionObserver 或 loading="lazy" 属性来实现。3. 代码拆分(Code Splitting)将 JavaScript 拆分成更小的模块,按需加载,提高初始加载速度。使用 Webpack 或其他打包工具的代码分割功能。4. 资源缓存使用浏览器缓存(Cache-Control)来减少重复请求。使用 Service Workers 提供离线支持和缓存管理5. 减少 HTTP 请求合并 CSS 和 JavaScript 文件,减少请求次数。使用字体图标代替多个图片图标。',chat_time:'2022-08-18 10:00:00',chat_type:'serve'} + ], }; }, mounted() { var userInfo = this.$TOOL.data.get("USER_INFO"); this.userName = userInfo.username; + let items = document.querySelectorAll('.listItem'); + items.forEach(function(item) { + item.addEventListener('click', function() { + items.forEach(function(el) { + el.classList.remove('active'); + }); + item.classList.add('active'); + }); + }) }, methods: { - + createNewChat(){ + this.listData.unshift({title:'New Chat'}); + this.$nextTick(()=>{ + let items = document.querySelectorAll('.listItem'); + items.forEach(function(el) { + el.classList.remove('active'); + }); + items[0].classList.add('active') + }) + }, + listItemClick(id){ + this.listData.forEach((item)=>{ + if(item.id == id){ + this.chatData = item.data + } + }) + }, }, }; @@ -118,18 +145,30 @@ export default { z-index: auto; height: 45px; line-height: 45px; - width: 100%; display :flex; padding: 0 1rem; border-radius: 6px; box-sizing: border-box; color :rgb(51, 54, 57); + justify-content: space-between; + align-items: center; + cursor: pointer; border :1px solid rgb(229, 231, 235); } .listItem.active{ + color: rgb(75, 158, 95); + border-color: rgb(75, 158, 95); background-color :rgb(245, 245, 245) } +.listItemTitle{ + width: 160px; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + font-size: 14px; + font-weight: 500; +} .mainChat{ padding-left: 260px;height: 100%;box-sizing: border-box;position: relative;z-index: auto; } @@ -201,20 +240,41 @@ export default { padding:0.5rem 1rem; /* border:1px solid lightgray; */ } - .right_layout_myselfChat{ - width:200px; - position: absolute; - top:5px; - right:0; - display:flex; + .chatItemContainer{ + display: flex; + flex-direction: column; } - .myself_chat{ + .chatItem{ + display: flex; + justify-content: flex-end; /* 对齐到容器的右侧 */ + } + .chatItem.layout_left{ + flex-direction: row-reverse; /* 从右到左排列 */ + } + + .chatItem_text{ + display: flex; + flex-direction: column; + max-width: 80%; + } + .layout_right>.chat_img>.datatime{ position: absolute; - top:30px; - right:80px; + width: 170px; + right: 0; + } + .layout_right>.chatItem_text>.chat_text{ padding:10px 20px; border-radius: 10px; - background-color: #7ae1b6; + background-color: rgb(210, 249, 209); opacity: 0.8; } + .layout_left>.chatItem_text>.chat_text{ + padding:10px 20px; + border-radius: 10px; + background-color: rgb(244, 246, 248); + opacity: 0.8; + } + .user_icons{ + width:40px;height:40px; + } \ No newline at end of file