Browse Source

一些兼容性优化

master
xsx 2 years ago
parent
commit
ef3f8f0b34
  1. 33
      im-uniapp/App.vue
  2. 4
      im-uniapp/common/request.js
  3. 2
      im-uniapp/pages/chat/chat-box.vue
  4. 2
      im-uniapp/pages/common/user-info.vue
  5. 8
      im-uniapp/pages/group/group-edit.vue
  6. 4
      im-uniapp/pages/login/login.vue
  7. 3
      im-uniapp/pages/mine/mine.vue
  8. 14
      im-uniapp/store/friendStore.js
  9. 13
      im-uniapp/store/groupStore.js

33
im-uniapp/App.vue

@ -5,7 +5,7 @@
import * as enums from './common/enums'; import * as enums from './common/enums';
import * as wsApi from './common/wssocket'; import * as wsApi from './common/wssocket';
import UNI_APP from '@/.env.js' import UNI_APP from '@/.env.js'
import { getCurrentInstance } from 'vue'
export default { export default {
data() { data() {
return { return {
@ -69,7 +69,7 @@
}) })
}, },
loadStore(){ loadStore() {
return this.userStore.loadUser().then(() => { return this.userStore.loadUser().then(() => {
const promises = []; const promises = [];
promises.push(this.friendStore.loadFriend()); promises.push(this.friendStore.loadFriend());
@ -112,7 +112,7 @@
} }
// //
if (msg.type == enums.MESSAGE_TYPE.READED) { if (msg.type == enums.MESSAGE_TYPE.READED) {
this.chatStore.resetUnreadCount( { this.chatStore.resetUnreadCount({
type: 'PRIVATE', type: 'PRIVATE',
targetId: msg.recvId targetId: msg.recvId
}) })
@ -120,7 +120,7 @@
} }
// , // ,
if (msg.type == enums.MESSAGE_TYPE.RECEIPT) { if (msg.type == enums.MESSAGE_TYPE.RECEIPT) {
this.chatStore.readedMessage( { this.chatStore.readedMessage({
friendId: msg.sendId friendId: msg.sendId
}) })
return; return;
@ -129,10 +129,9 @@
msg.selfSend = msg.sendId == this.userStore.userInfo.id; msg.selfSend = msg.sendId == this.userStore.userInfo.id;
// id // id
let friendId = msg.selfSend ? msg.recvId : msg.sendId; let friendId = msg.selfSend ? msg.recvId : msg.sendId;
this.loadFriendInfo(friendId).then((friend) => { this.loadFriendInfo(friendId, (friend) => {
this.insertPrivateMessage(friend, msg); this.insertPrivateMessage(friend, msg);
}) })
}, },
insertPrivateMessage(friend, msg) { insertPrivateMessage(friend, msg) {
// //
@ -205,7 +204,7 @@
} }
// //
msg.selfSend = msg.sendId == this.userStore.userInfo.id; msg.selfSend = msg.sendId == this.userStore.userInfo.id;
this.loadGroupInfo(msg.groupId).then((group) => { this.loadGroupInfo(msg.groupId, (group) => {
// //
this.insertGroupMessage(group, msg); this.insertGroupMessage(group, msg);
}) })
@ -260,41 +259,37 @@
// //
this.chatStore.openChat(chatInfo); this.chatStore.openChat(chatInfo);
// //
this.chatStore.insertMessage( msg); this.chatStore.insertMessage(msg);
// //
this.playAudioTip(); this.playAudioTip();
}, },
loadFriendInfo(id) { loadFriendInfo(id, callback) {
return new Promise((resolve, reject) => {
let friend = this.friendStore.findFriend(id); let friend = this.friendStore.findFriend(id);
if (friend) { if (friend) {
resolve(friend); callback(friend);
} else { } else {
http({ http({
url: `/friend/find/${id}`, url: `/friend/find/${id}`,
method: 'GET' method: 'GET'
}).then((friend) => { }).then((friend) => {
this.friendStore.addFriend(friend); this.friendStore.addFriend(friend);
resolve(friend) callback(friend)
}) })
} }
});
}, },
loadGroupInfo(id) { loadGroupInfo(id, callback) {
return new Promise((resolve, reject) => { let group = this.groupStore.findGroup(id);
let group = this.groupStore.groups.find((g) => g.id == id);
if (group) { if (group) {
resolve(group); callback(group);
} else { } else {
http({ http({
url: `/group/find/${id}`, url: `/group/find/${id}`,
method: 'GET' method: 'GET'
}).then((group) => { }).then((group) => {
this.groupStore.addGroup(group); this.groupStore.addGroup(group);
resolve(group) callback(group)
}) })
} }
});
}, },
exit() { exit() {
console.log("exit"); console.log("exit");

4
im-uniapp/common/request.js

@ -21,7 +21,7 @@ const request = (options) => {
if (res.data.code == 200) { if (res.data.code == 200) {
return resolve(res.data.data) return resolve(res.data.data)
} else if (res.data.code == 400) { } else if (res.data.code == 400) {
getApp().exit(); getApp().$vm.exit();
} else if (res.data.code == 401) { } else if (res.data.code == 401) {
console.log("token失效,尝试重新获取") console.log("token失效,尝试重新获取")
if (isRefreshToken) { if (isRefreshToken) {
@ -38,7 +38,7 @@ const request = (options) => {
requestList = []; requestList = [];
isRefreshToken = false; isRefreshToken = false;
console.log("刷新token失败") console.log("刷新token失败")
getApp().exit(); getApp().$vm.exit();
return; return;
} }
let newInfo = res.data.data; let newInfo = res.data.data;

2
im-uniapp/pages/chat/chat-box.vue

@ -838,7 +838,7 @@
margin-bottom: 10rpx; margin-bottom: 10rpx;
border: #dddddd solid 1px; border: #dddddd solid 1px;
background-color: #f7f8fd; background-color: #f7f8fd;
height: 80rpx;
.iconfont { .iconfont {
font-size: 68rpx; font-size: 68rpx;
margin: 6rpx; margin: 6rpx;

2
im-uniapp/pages/common/user-info.vue

@ -1,7 +1,7 @@
<template> <template>
<view class="page user-info"> <view class="page user-info">
<view class="content"> <view class="content">
<head-image :name="userInfo.nickName" :url="userInfo.headImage" <head-image :name="userInfo.nickName" :url="userInfo.headImageThumb"
:size="160" @click="onShowFullImage()"></head-image> :size="160" @click="onShowFullImage()"></head-image>
<view class="info-item"> <view class="info-item">

8
im-uniapp/pages/group/group-edit.vue

@ -3,11 +3,11 @@
<uni-forms ref="form" :modelValue="group" :rules="rules" validate-trigger="bind" label-position="top" <uni-forms ref="form" :modelValue="group" :rules="rules" validate-trigger="bind" label-position="top"
label-width="100%"> label-width="100%">
<uni-forms-item label="群聊头像:" name="headImage"> <uni-forms-item label="群聊头像:" name="headImage">
<image-upload v-show="isOwner" :onSuccess="onUnloadImageSuccess"> <image-upload v-if="isOwner" :onSuccess="onUnloadImageSuccess">
<image :src="group.headImage" class="group-image"></image> <image :src="group.headImageThumb" class="group-image"></image>
</image-upload> </image-upload>
<head-image v-show="!isOwner" :name="group.showGroupName" <head-image v-if="!isOwner" :name="group.showGroupName"
:url="group.headImage" :size="200"></head-image> :url="group.headImageThumb" :size="200"></head-image>
</uni-forms-item> </uni-forms-item>
<uni-forms-item label="群聊名称:" name="name" :required="true"> <uni-forms-item label="群聊名称:" name="name" :required="true">
<uni-easyinput type="text" v-model="group.name" :disabled="!isOwner" placeholder="请输入群聊名称" /> <uni-easyinput type="text" v-model="group.name" :disabled="!isOwner" placeholder="请输入群聊名称" />

4
im-uniapp/pages/login/login.vue

@ -54,7 +54,7 @@
loginInfo.expireTime = new Date().getTime() + loginInfo.refreshTokenExpiresIn * 1000; loginInfo.expireTime = new Date().getTime() + loginInfo.refreshTokenExpiresIn * 1000;
uni.setStorageSync("loginInfo", loginInfo); uni.setStorageSync("loginInfo", loginInfo);
// App.vue // App.vue
getApp().init() getApp().$vm.init()
// //
uni.switchTab({ uni.switchTab({
url: "/pages/chat/chat" url: "/pages/chat/chat"
@ -72,8 +72,6 @@
<style lang="scss" scoped> <style lang="scss" scoped>
.login { .login {
.title { .title {
padding-top: 150rpx; padding-top: 150rpx;
padding-bottom: 50rpx; padding-bottom: 50rpx;

3
im-uniapp/pages/mine/mine.vue

@ -52,7 +52,8 @@
title: '确认退出?', title: '确认退出?',
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
getApp().exit() console.log(getApp())
getApp().$vm.exit()
} }
} }
}); });

14
im-uniapp/store/friendStore.js

@ -19,14 +19,12 @@ export default defineStore('friendStore', {
this.friends = friends; this.friends = friends;
}, },
updateFriend(friend) { updateFriend(friend) {
this.friends.forEach((f, index) => { let f = this.findFriend(friend.id);
if (f.id == friend.id) { let copy = JSON.parse(JSON.stringify(f));
// 拷贝属性 Object.assign(f, friend);
let online = this.friends[index].online; f.online = copy.online;
Object.assign(this.friends[index], friend); f.onlineWeb = copy.onlineWeb;
this.friends[index].online = online; f.onlineApp = copy.onlineApp;
}
})
}, },
removeFriend(id) { removeFriend(id) {
this.friends.forEach((f, idx) => { this.friends.forEach((f, idx) => {

13
im-uniapp/store/groupStore.js

@ -29,12 +29,8 @@ export default defineStore('groupStore', {
}) })
}, },
updateGroup(group) { updateGroup(group) {
this.groups.forEach((g, idx) => { let g = this.findGroup(group.id);
if (g.id == group.id) { Object.assign(g, group);
// 拷贝属性
Object.assign(this.groups[idx], group);
}
})
}, },
clear() { clear() {
this.groups = []; this.groups = [];
@ -53,5 +49,10 @@ export default defineStore('groupStore', {
}) })
}); });
} }
},
getters: {
findGroup: (state) => (id) => {
return state.groups.find((g) => g.id == id);
}
} }
}) })
Loading…
Cancel
Save