diff --git a/im-uniapp/App.vue b/im-uniapp/App.vue index 363b9e0..a30cd85 100644 --- a/im-uniapp/App.vue +++ b/im-uniapp/App.vue @@ -5,7 +5,7 @@ import * as enums from './common/enums'; import * as wsApi from './common/wssocket'; import UNI_APP from '@/.env.js' - import { getCurrentInstance } from 'vue' + export default { data() { return { @@ -66,10 +66,10 @@ console.log("ws断开", res); // 重新连接 this.reconnectWs(); - + }) }, - loadStore(){ + loadStore() { return this.userStore.loadUser().then(() => { const promises = []; promises.push(this.friendStore.loadFriend()); @@ -112,7 +112,7 @@ } // 消息已读处理,清空已读数量 if (msg.type == enums.MESSAGE_TYPE.READED) { - this.chatStore.resetUnreadCount( { + this.chatStore.resetUnreadCount({ type: 'PRIVATE', targetId: msg.recvId }) @@ -120,7 +120,7 @@ } // 消息回执处理,改消息状态为已读 if (msg.type == enums.MESSAGE_TYPE.RECEIPT) { - this.chatStore.readedMessage( { + this.chatStore.readedMessage({ friendId: msg.sendId }) return; @@ -129,10 +129,9 @@ msg.selfSend = msg.sendId == this.userStore.userInfo.id; // 好友id let friendId = msg.selfSend ? msg.recvId : msg.sendId; - this.loadFriendInfo(friendId).then((friend) => { + this.loadFriendInfo(friendId, (friend) => { this.insertPrivateMessage(friend, msg); }) - }, insertPrivateMessage(friend, msg) { // 单人视频信令 @@ -205,7 +204,7 @@ } // 标记这条消息是不是自己发的 msg.selfSend = msg.sendId == this.userStore.userInfo.id; - this.loadGroupInfo(msg.groupId).then((group) => { + this.loadGroupInfo(msg.groupId, (group) => { // 插入群聊消息 this.insertGroupMessage(group, msg); }) @@ -260,41 +259,37 @@ // 打开会话 this.chatStore.openChat(chatInfo); // 插入消息 - this.chatStore.insertMessage( msg); + this.chatStore.insertMessage(msg); // 播放提示音 this.playAudioTip(); }, - loadFriendInfo(id) { - return new Promise((resolve, reject) => { - let friend = this.friendStore.findFriend(id); - if (friend) { - resolve(friend); - } else { - http({ - url: `/friend/find/${id}`, - method: 'GET' - }).then((friend) => { - this.friendStore.addFriend(friend); - resolve(friend) - }) - } - }); + loadFriendInfo(id, callback) { + let friend = this.friendStore.findFriend(id); + if (friend) { + callback(friend); + } else { + http({ + url: `/friend/find/${id}`, + method: 'GET' + }).then((friend) => { + this.friendStore.addFriend(friend); + callback(friend) + }) + } }, - loadGroupInfo(id) { - return new Promise((resolve, reject) => { - let group = this.groupStore.groups.find((g) => g.id == id); - if (group) { - resolve(group); - } else { - http({ - url: `/group/find/${id}`, - method: 'GET' - }).then((group) => { - this.groupStore.addGroup(group); - resolve(group) - }) - } - }); + loadGroupInfo(id, callback) { + let group = this.groupStore.findGroup(id); + if (group) { + callback(group); + } else { + http({ + url: `/group/find/${id}`, + method: 'GET' + }).then((group) => { + this.groupStore.addGroup(group); + callback(group) + }) + } }, exit() { console.log("exit"); @@ -384,7 +379,7 @@ .tab-page { // #ifdef H5 - height: calc(100vh - 50px); // h5平台100vh是包含了底部高度,需要减去 + height: calc(100vh - 50px); // h5平台100vh是包含了底部高度,需要减去 // #endif // #ifndef H5 height: calc(100vh); diff --git a/im-uniapp/common/request.js b/im-uniapp/common/request.js index 481c6be..4bdef2e 100644 --- a/im-uniapp/common/request.js +++ b/im-uniapp/common/request.js @@ -21,7 +21,7 @@ const request = (options) => { if (res.data.code == 200) { return resolve(res.data.data) } else if (res.data.code == 400) { - getApp().exit(); + getApp().$vm.exit(); } else if (res.data.code == 401) { console.log("token失效,尝试重新获取") if (isRefreshToken) { @@ -38,7 +38,7 @@ const request = (options) => { requestList = []; isRefreshToken = false; console.log("刷新token失败") - getApp().exit(); + getApp().$vm.exit(); return; } let newInfo = res.data.data; diff --git a/im-uniapp/pages/chat/chat-box.vue b/im-uniapp/pages/chat/chat-box.vue index 64c943f..d646714 100644 --- a/im-uniapp/pages/chat/chat-box.vue +++ b/im-uniapp/pages/chat/chat-box.vue @@ -838,7 +838,7 @@ margin-bottom: 10rpx; border: #dddddd solid 1px; background-color: #f7f8fd; - + height: 80rpx; .iconfont { font-size: 68rpx; margin: 6rpx; diff --git a/im-uniapp/pages/common/user-info.vue b/im-uniapp/pages/common/user-info.vue index fb54bd2..366a034 100644 --- a/im-uniapp/pages/common/user-info.vue +++ b/im-uniapp/pages/common/user-info.vue @@ -1,7 +1,7 @@