diff --git a/README.md b/README.md index 7df8fde..87f6af2 100644 --- a/README.md +++ b/README.md @@ -13,14 +13,13 @@ #### 近期更新 -发布2.0版本,本次更新主要是加入了uniapp版本: +发布2.0版本,本次更新加入了uniapp版本: - 支持移动端和web端同时在线,多端消息同步 - 目前仅兼容h5和微信小程序,后续会继续兼容更多终端类型 -- 页面风格优化:表情包更新、自动生成文字头像等 - -感兴趣的小伙伴,可在下方扫码体验 - +- 聊天窗口加入已读未读显示 +- 群聊加入@功能 +- 界面风格升级,表情包更新、生成文字头像等 #### 在线体验 diff --git a/im-ui/src/components/chat/ChatBox.vue b/im-ui/src/components/chat/ChatBox.vue index 346d039..82744db 100644 --- a/im-ui/src/components/chat/ChatBox.vue +++ b/im-ui/src/components/chat/ChatBox.vue @@ -219,7 +219,6 @@ }, createSendText() { let sendText = "" - console.log(this.$refs.editBox.childNodes); this.$refs.editBox.childNodes.forEach((node) => { if (node.nodeName == "#text") { sendText += node.textContent; @@ -233,10 +232,8 @@ }, createAtUserIds() { let ids = []; - console.log(this.$refs.editBox.childNodes); this.$refs.editBox.childNodes.forEach((node) => { if (node.nodeName == "SPAN") { - console.log(node); ids.push(node.dataset.id); } }) diff --git a/im-ui/src/view/Login.vue b/im-ui/src/view/Login.vue index 9ae9728..dc80110 100644 --- a/im-ui/src/view/Login.vue +++ b/im-ui/src/view/Login.vue @@ -17,6 +17,13 @@
  • 修改拉取离线消息机制:用户登录后,自动从服务器同步最近1个月的消息
  • +
    +

    最近更新(2023-11-12):

    + +

    项目依旧完全开源,可内网部署。如果项目对您有帮助,请帮忙点个star:

    diff --git a/im-uniapp/common/wssocket.js b/im-uniapp/common/wssocket.js index 1f3a04a..deedfae 100644 --- a/im-uniapp/common/wssocket.js +++ b/im-uniapp/common/wssocket.js @@ -4,9 +4,14 @@ let messageCallBack = null; let closeCallBack = null; let isConnect = false; //连接标识 避免重复连接 let rec = null; +let isInit = false; let init = () => { - + // 防止重复初始化 + if (isInit) { + return; + } + isInit = true; uni.onSocketOpen((res) => { console.log("WebSocket连接已打开"); isConnect = true; @@ -21,7 +26,7 @@ let init = () => { data: JSON.stringify(loginInfo) }); }) - + uni.onSocketMessage((res) => { let sendInfo = JSON.parse(res.data) if (sendInfo.cmd == 0) { @@ -32,17 +37,17 @@ let init = () => { heartCheck.reset(); } else { // 其他消息转发出去 - console.log("接收到消息",sendInfo); + console.log("接收到消息", sendInfo); messageCallBack && messageCallBack(sendInfo.cmd, sendInfo.data) } }) - + uni.onSocketClose((res) => { console.log('WebSocket连接关闭') isConnect = false; //断开后修改标识 closeCallBack && closeCallBack(res); }) - + uni.onSocketError((e) => { console.log(e) isConnect = false; //连接断开修改标识 @@ -53,7 +58,7 @@ let init = () => { }) }; -let connect = (url, token)=>{ +let connect = (url, token) => { wsurl = url; accessToken = token; if (isConnect) { @@ -67,23 +72,23 @@ let connect = (url, token)=>{ fail: (e) => { console.log(e); console.log("websocket连接失败,10s后重连"); - setTimeout(()=>{ + setTimeout(() => { connect(); - },10000) + }, 10000) } }); } //定义重连函数 -let reconnect = (wsurl,accessToken) => { +let reconnect = (wsurl, accessToken) => { console.log("尝试重新连接"); - if (isConnect){ + if (isConnect) { //如果已经连上就不在重连了 - return; + return; } rec && clearTimeout(rec); rec = setTimeout(function() { // 延迟15秒重连 避免过多次过频繁请求重连 - connect(wsurl,accessToken); + connect(wsurl, accessToken); }, 15000); }; @@ -98,8 +103,8 @@ let close = () => { console.log("关闭websocket连接"); isConnect = false; }, - fail:(e)=>{ - console.log("关闭websocket连接失败",e); + fail: (e) => { + console.log("关闭websocket连接失败", e); } }); }; diff --git a/im-uniapp/components/chat-at-box/chat-at-box.vue b/im-uniapp/components/chat-at-box/chat-at-box.vue new file mode 100644 index 0000000..51ad5b2 --- /dev/null +++ b/im-uniapp/components/chat-at-box/chat-at-box.vue @@ -0,0 +1,176 @@ + + + + + + \ No newline at end of file diff --git a/im-uniapp/components/chat-message-item/chat-message-item.vue b/im-uniapp/components/chat-message-item/chat-message-item.vue index c627bc6..8085022 100644 --- a/im-uniapp/components/chat-message-item/chat-message-item.vue +++ b/im-uniapp/components/chat-message-item/chat-message-item.vue @@ -7,7 +7,7 @@ - + {{showName}} diff --git a/im-uniapp/components/head-image/head-image.vue b/im-uniapp/components/head-image/head-image.vue index b3dd3d1..cdb3248 100644 --- a/im-uniapp/components/head-image/head-image.vue +++ b/im-uniapp/components/head-image/head-image.vue @@ -1,5 +1,5 @@