Browse Source

一些兼容性优化

master
xsx 2 years ago
parent
commit
ef3f8f0b34
  1. 75
      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

75
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); // h5100vh
height: calc(100vh - 50px); // h5100vh
// #endif
// #ifndef H5
height: calc(100vh);

4
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;

2
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;

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

@ -1,7 +1,7 @@
<template>
<view class="page user-info">
<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>
<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"
label-width="100%">
<uni-forms-item label="群聊头像:" name="headImage">
<image-upload v-show="isOwner" :onSuccess="onUnloadImageSuccess">
<image :src="group.headImage" class="group-image"></image>
<image-upload v-if="isOwner" :onSuccess="onUnloadImageSuccess">
<image :src="group.headImageThumb" class="group-image"></image>
</image-upload>
<head-image v-show="!isOwner" :name="group.showGroupName"
:url="group.headImage" :size="200"></head-image>
<head-image v-if="!isOwner" :name="group.showGroupName"
:url="group.headImageThumb" :size="200"></head-image>
</uni-forms-item>
<uni-forms-item label="群聊名称:" name="name" :required="true">
<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;
uni.setStorageSync("loginInfo", loginInfo);
// App.vue
getApp().init()
getApp().$vm.init()
//
uni.switchTab({
url: "/pages/chat/chat"
@ -72,8 +72,6 @@
<style lang="scss" scoped>
.login {
.title {
padding-top: 150rpx;
padding-bottom: 50rpx;

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

@ -52,7 +52,8 @@
title: '确认退出?',
success: (res) => {
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;
},
updateFriend(friend) {
this.friends.forEach((f, index) => {
if (f.id == friend.id) {
// 拷贝属性
let online = this.friends[index].online;
Object.assign(this.friends[index], friend);
this.friends[index].online = online;
}
})
let f = this.findFriend(friend.id);
let copy = JSON.parse(JSON.stringify(f));
Object.assign(f, friend);
f.online = copy.online;
f.onlineWeb = copy.onlineWeb;
f.onlineApp = copy.onlineApp;
},
removeFriend(id) {
this.friends.forEach((f, idx) => {

13
im-uniapp/store/groupStore.js

@ -29,12 +29,8 @@ export default defineStore('groupStore', {
})
},
updateGroup(group) {
this.groups.forEach((g, idx) => {
if (g.id == group.id) {
// 拷贝属性
Object.assign(this.groups[idx], group);
}
})
let g = this.findGroup(group.id);
Object.assign(g, group);
},
clear() {
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