From de6e5a9ac77a2df82786767451777c440fd5f93e Mon Sep 17 00:00:00 2001 From: xsx <825657193@qq.com> Date: Sat, 28 Oct 2023 02:35:44 +0800 Subject: [PATCH] =?UTF-8?q?ui=E7=BE=8E=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- im-ui/src/api/date.js | 66 +++++++ im-ui/src/api/wssocket.js | 10 +- im-ui/src/components/chat/ChatItem.vue | 177 +++++++++--------- im-ui/src/components/chat/ChatMessageItem.vue | 20 +- im-ui/src/components/chat/ChatTime.vue | 43 ----- im-ui/src/components/common/HeadImage.vue | 2 +- im-ui/src/components/common/RightMenu.vue | 42 +++-- im-ui/src/components/friend/FriendItem.vue | 108 ++++++----- im-ui/src/components/group/GroupItem.vue | 31 ++- im-ui/src/main.js | 3 +- im-ui/src/store/chatStore.js | 6 + im-ui/src/view/Chat.vue | 12 +- im-ui/src/view/Friend.vue | 62 +++--- im-ui/src/view/Group.vue | 50 ++--- im-uniapp/common/date.js | 66 +++++++ im-uniapp/components/chat-item/chat-item.vue | 53 +++++- .../chat-message-item/chat-message-item.vue | 12 +- im-uniapp/components/chat-time/chat-time.vue | 45 ----- .../components/friend-item/friend-item.vue | 39 ++-- .../components/group-item/group-item.vue | 21 +-- im-uniapp/components/pop-menu/pop-menu.vue | 14 +- im-uniapp/main.js | 2 + im-uniapp/pages/group/group-info.vue | 33 ++-- 23 files changed, 520 insertions(+), 397 deletions(-) create mode 100644 im-ui/src/api/date.js delete mode 100644 im-ui/src/components/chat/ChatTime.vue create mode 100644 im-uniapp/common/date.js delete mode 100644 im-uniapp/components/chat-time/chat-time.vue diff --git a/im-ui/src/api/date.js b/im-ui/src/api/date.js new file mode 100644 index 0000000..705f1b7 --- /dev/null +++ b/im-ui/src/api/date.js @@ -0,0 +1,66 @@ +let toTimeText = (timeStamp, simple) => { + var dateTime = new Date(timeStamp) + var currentTime = Date.parse(new Date()); //当前时间 + var timeDiff = currentTime - dateTime; //与当前时间误差 + var timeText = ''; + if (timeDiff <= 60000) { //一分钟内 + timeText = '刚刚'; + } else if (timeDiff > 60000 && timeDiff < 3600000) { + //1小时内 + timeText = Math.floor(timeDiff / 60000) + '分钟前'; + } else if (timeDiff >= 3600000 && timeDiff < 86400000 && !isYestday(dateTime)) { + //今日 + timeText = formatDateTime(dateTime).substr(11, 5); + } else if (isYestday(dateTime)) { + //昨天 + timeText = '昨天' + formatDateTime(dateTime).substr(11, 5); + } else if (isYear(dateTime)) { + //今年 + timeText = formatDateTime(dateTime).substr(5, simple ? 5 : 14); + } else { + //不属于今年 + timeText = formatDateTime(dateTime); + if(simple){ + timeText = timeText.substring(2,5); + } + } + return timeText; +} + +let isYestday = (date) => { + var yesterday = new Date(new Date() - 1000 * 60 * 60 * 24); + return yesterday.getYear() === date.getYear() && + yesterday.getMonth() === date.getMonth() && + yesterday.getDate() === date.getDate(); +} + +let isYear = (date) => { + return date.getYear() === new Date().getYear(); +} + +let formatDateTime = (date) => { + if (date === '' || !date) { + return '' + } + var dateObject = new Date(date) + var y = dateObject.getFullYear() + var m = dateObject.getMonth() + 1 + m = m < 10 ? ('0' + m) : m + var d = dateObject.getDate() + d = d < 10 ? ('0' + d) : d + var h = dateObject.getHours() + h = h < 10 ? ('0' + h) : h + var minute = dateObject.getMinutes() + minute = minute < 10 ? ('0' + minute) : minute + var second = dateObject.getSeconds() + second = second < 10 ? ('0' + second) : second + return y + '/' + m + '/' + d + ' ' + h + ':' + minute + ':' + second +} + + +export{ + toTimeText, + isYestday, + isYear, + formatDateTime +} \ No newline at end of file diff --git a/im-ui/src/api/wssocket.js b/im-ui/src/api/wssocket.js index b54801f..e014edd 100644 --- a/im-ui/src/api/wssocket.js +++ b/im-ui/src/api/wssocket.js @@ -86,7 +86,7 @@ let close = () => { //心跳设置 -var heartCheck = { +let heartCheck = { timeout: 5000, //每段时间发送一次心跳包 这里设置为20s timeoutObj: null, //延时发送消息对象(启动心跳新建这个对象,收到消息后重置对象) start: function() { @@ -112,7 +112,7 @@ var heartCheck = { // 实际调用的方法 -function sendMessage(agentData) { +let sendMessage = (agentData) => { // console.log(globalCallback) if (websock.readyState === websock.OPEN) { // 若是ws开启状态 @@ -131,16 +131,16 @@ function sendMessage(agentData) { } -function onMessage(callback) { +let onMessage = (callback) => { messageCallBack = callback; } -function onOpen(callback) { +let onOpen = (callback) => { openCallBack = callback; } -function onClose(callback) { +let onClose = (callback) => { closeCallBack = callback; } // 将方法暴露出去 diff --git a/im-ui/src/components/chat/ChatItem.vue b/im-ui/src/components/chat/ChatItem.vue index 12dffd0..de0bc26 100644 --- a/im-ui/src/components/chat/ChatItem.vue +++ b/im-ui/src/components/chat/ChatItem.vue @@ -1,36 +1,53 @@ - + \ No newline at end of file diff --git a/im-ui/src/components/chat/ChatMessageItem.vue b/im-ui/src/components/chat/ChatMessageItem.vue index 21fd465..6f5166f 100644 --- a/im-ui/src/components/chat/ChatMessageItem.vue +++ b/im-ui/src/components/chat/ChatMessageItem.vue @@ -8,7 +8,7 @@
{{showName}} - + {{$date.toTimeText(msgInfo.sendTime)}}
- - diff --git a/im-ui/src/components/common/HeadImage.vue b/im-ui/src/components/common/HeadImage.vue index 71e0827..edece98 100644 --- a/im-ui/src/components/common/HeadImage.vue +++ b/im-ui/src/components/common/HeadImage.vue @@ -46,7 +46,7 @@ img { position: relative; overflow: hidden; - border-radius: 5%; + border-radius: 10%; } img:before { diff --git a/im-ui/src/components/common/RightMenu.vue b/im-ui/src/components/common/RightMenu.vue index cf70666..f71f8ea 100644 --- a/im-ui/src/components/common/RightMenu.vue +++ b/im-ui/src/components/common/RightMenu.vue @@ -1,10 +1,12 @@