-
@@ -27,9 +24,7 @@
-
@@ -41,17 +36,20 @@
{{ userInfo.sex==0?"男":"女" }}
{{ userInfo.signature }}
-
+
- 发送消息
- 加为好友
- 删除好友
+ 发消息
+ 加为好友
+ 删除好友
-
+
@@ -106,7 +104,7 @@
})
})
},
- onAddFriend(user){
+ onAddFriend(user) {
this.$http({
url: "/friend/add",
method: "post",
@@ -116,12 +114,12 @@
}).then((data) => {
this.$message.success("添加成功,对方已成为您的好友");
let friend = {
- id:user.id,
+ id: user.id,
nickName: user.nickName,
headImage: user.headImage,
online: user.online
}
- this.$store.commit("addFriend",friend);
+ this.$store.commit("addFriend", friend);
})
},
onSendMessage(user) {
@@ -172,14 +170,14 @@
friendStore() {
return this.$store.state.friendStore;
},
- isFriend(){
- return this.friendStore.friends.find((f)=>f.id==this.userInfo.id);
+ isFriend() {
+ return this.friendStore.friends.find((f) => f.id == this.userInfo.id);
}
}
}
-
\ No newline at end of file
diff --git a/im-ui/src/view/Login.vue b/im-ui/src/view/Login.vue
index c64b6d4..5e14eda 100644
--- a/im-ui/src/view/Login.vue
+++ b/im-ui/src/view/Login.vue
@@ -30,6 +30,13 @@
uniapp移动端支持发送语音消息
+
+
最近更新(2024-04-27):
+
+ - uniapp端加载离线消息慢以及卡顿问题优化
+ - web端样式风格调整
+
+
如果本项目对您有帮助,请在gitee上帮忙点个star
@@ -178,7 +185,7 @@
.login-view {
width: 100%;
height: 100%;
- background: rgb(232, 242, 255);
+ background: #E8F2FF;
background-size: cover;
box-sizing: border-box;
diff --git a/im-uniapp/App.vue b/im-uniapp/App.vue
index ab6121d..8e8fdc7 100644
--- a/im-uniapp/App.vue
+++ b/im-uniapp/App.vue
@@ -243,18 +243,32 @@
// this.audioTip = uni.createInnerAudioContext();
// this.audioTip.src = "/static/audio/tip.wav";
// this.audioTip.play();
- }
+ },
+ isExpired(loginInfo){
+ if(!loginInfo || !loginInfo.expireTime){
+ return true;
+ }
+ return loginInfo.expireTime < new Date().getTime();
+ },
},
onLaunch() {
// 登录状态校验
- if (uni.getStorageSync("loginInfo")) {
+ let loginInfo = uni.getStorageSync("loginInfo")
+ if (!this.isExpired(loginInfo)) {
+ console.log("初始化")
// 初始化
- this.init()
- } else {
- // 跳转到登录页
- uni.navigateTo({
- url: "/pages/login/login"
+ this.init();
+ // 跳转到聊天页面
+ uni.switchTab({
+ url: "/pages/chat/chat"
})
+ } else{
+ // 跳转到登录页
+ // #ifdef H5
+ uni.navigateTo({
+ url: "/pages/login/login"
+ })
+ // #endif
}
}
}
diff --git a/im-uniapp/common/request.js b/im-uniapp/common/request.js
index 461ff6b..ea9ed94 100644
--- a/im-uniapp/common/request.js
+++ b/im-uniapp/common/request.js
@@ -41,7 +41,9 @@ const request = (options) => {
getApp().exit();
return;
}
- uni.setStorageSync("loginInfo", res.data.data);
+ let newInfo = res.data.data;
+ newInfo.expireTime = new Date().getTime() + newInfo.refreshTokenExpiresIn*1000;
+ uni.setStorageSync("loginInfo", newInfo);
requestList.forEach(cb => cb());
requestList = [];
isRefreshToken = false;
diff --git a/im-uniapp/components/chat-item/chat-item.vue b/im-uniapp/components/chat-item/chat-item.vue
index aade43c..d328e51 100644
--- a/im-uniapp/components/chat-item/chat-item.vue
+++ b/im-uniapp/components/chat-item/chat-item.vue
@@ -1,5 +1,7 @@
-
+
+
+
{{chat.unreadCount}}
@@ -12,7 +14,7 @@
{{atText}}
{{chat.sendNickName+': '}}
-
+
@@ -75,7 +77,13 @@
&.active {
background-color: #eeeeee;
}
-
+
+
+ .mask {
+ position: absolute;
+ width: 100%;
+ height: 100%;
+ }
.left {
position: relative;
display: flex;
diff --git a/im-uniapp/pages/login/login.vue b/im-uniapp/pages/login/login.vue
index b0b996f..e3146b0 100644
--- a/im-uniapp/pages/login/login.vue
+++ b/im-uniapp/pages/login/login.vue
@@ -3,7 +3,7 @@
欢迎登录
-
+
@@ -45,11 +45,12 @@
url: '/login',
data: this.loginForm,
method: 'POST'
- }).then(data => {
+ }).then(loginInfo => {
console.log("登录成功,自动跳转到聊天页面...")
uni.setStorageSync("userName", this.loginForm.userName);
uni.setStorageSync("password", this.loginForm.password);
- uni.setStorageSync("loginInfo", data);
+ loginInfo.expireTime = new Date().getTime() + loginInfo.refreshTokenExpiresIn*1000;
+ uni.setStorageSync("loginInfo", loginInfo);
// 调用App.vue的初始化方法
getApp().init()
// 跳转到聊天页面
@@ -59,17 +60,10 @@
})
}
},
+
onLoad() {
this.loginForm.userName = uni.getStorageSync("userName");
this.loginForm.password = uni.getStorageSync("password");
- let loginInfo = uni.getStorageSync("loginInfo");
- if (loginInfo) {
- // 跳转到聊天页面
- uni.switchTab({
- url: "/pages/chat/chat"
- })
-
- }
}
}
diff --git a/im-uniapp/store/chatStore.js b/im-uniapp/store/chatStore.js
index b1cdfc9..75950af 100644
--- a/im-uniapp/store/chatStore.js
+++ b/im-uniapp/store/chatStore.js
@@ -27,6 +27,7 @@ export default {
mutations: {
initChats(state, chatsData) {
cacheChats = [];
+ state.chats = [];
for (let chat of chatsData.chats) {
// 已删除的会话直接丢弃
if (chat.delete) {
@@ -50,7 +51,7 @@ export default {
}
})
})
-
+ console.log(cacheChats.length)
},
openChat(state, chatInfo) {
let chats = this.getters.findChats();
@@ -294,6 +295,7 @@ export default {
});
// 将消息一次性装载回来
state.chats = cacheChats;
+ console.log(cacheChats.length)
this.commit("saveToStorage");
},
saveToStorage(state) {
@@ -302,7 +304,7 @@ export default {
return;
}
let userId = userStore.state.userInfo.id;
- let key = "chats-" + userId;
+ let key = "chats-app-" + userId;
let chatsData = {
privateMsgMaxId: state.privateMsgMaxId,
groupMsgMaxId: state.groupMsgMaxId,
@@ -327,7 +329,7 @@ export default {
return new Promise((resolve, reject) => {
let userId = userStore.state.userInfo.id;
uni.getStorage({
- key: "chats-" + userId,
+ key: "chats-app-" + userId,
success(res) {
context.commit("initChats", res.data);
resolve()