From a6873302f34c160170f605f0713bee24090c0c3c Mon Sep 17 00:00:00 2001 From: Pang Date: Fri, 15 Dec 2023 22:36:18 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=9A=E5=91=98=E5=A4=B4=E5=83=8F?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E9=94=99=E4=B9=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../assets/js/components/UserAvatar/index.vue | 18 +++++-- .../assets/js/components/UserAvatar/tip.vue | 47 ++++++++++++++++++- resources/assets/js/store/actions.js | 18 ++----- resources/assets/js/store/state.js | 1 - 4 files changed, 62 insertions(+), 22 deletions(-) diff --git a/resources/assets/js/components/UserAvatar/index.vue b/resources/assets/js/components/UserAvatar/index.vue index 2c2f357e8..ed0fea5c0 100755 --- a/resources/assets/js/components/UserAvatar/index.vue +++ b/resources/assets/js/components/UserAvatar/index.vue @@ -36,7 +36,7 @@ export default { mounted() { this.getData(); // - this.subscribe = Store.subscribe('cacheUserActive', (data) => { + this.subscribe = Store.subscribe('userActive', ({data}) => { if (data.userid == this.userid) { this.setUser(data) } @@ -136,15 +136,16 @@ export default { return value || 'D'; } }, + watch: { + userid() { + this.getData(); + } + }, methods: { getData() { if (!this.$store.state.userId) { return; } - if (this.userid == this.$store.state.userId) { - this.setUser(this.$store.state.userInfo); - return; - } const tempUser = this.$store.state.cacheUserBasic.find(({userid}) => userid == this.userid); if (tempUser) { this.setUser(tempUser); @@ -153,6 +154,13 @@ export default { }, setUser(info) { + try { + if (this.user && this.user.userimg != info.userimg && this.$refs.avatar) { + this.$refs.avatar.$data.isImageExist = true; + } + } catch (e) { + // + } this.user = info; if (typeof this.userResult === "function") { diff --git a/resources/assets/js/components/UserAvatar/tip.vue b/resources/assets/js/components/UserAvatar/tip.vue index e6249cfda..522fc9fec 100755 --- a/resources/assets/js/components/UserAvatar/tip.vue +++ b/resources/assets/js/components/UserAvatar/tip.vue @@ -62,9 +62,21 @@ export default { } }, + mounted() { + if (this.$listeners['update:online']) { + this.$watch('userid', () => { + this.updateOnline() + }) + this.$watch('user.online', () => { + this.updateOnline() + }) + this.updateOnline() + } + }, + computed: { showMenu() { - if (this.userId == this.userid) { + if (this.$store.state.userId == this.userid) { return false } if (this.user.delete_at || this.user.disable_at) { @@ -88,6 +100,39 @@ export default { this.userResult(info); } this.user = info; + }, + + updateOnline() { + if (!this.user) { + return + } + if (this.user.online || this.$store.state.userId === this.userid) { + this.$emit('update:online', true) + } else { + const now = $A.Time() + const line = $A.Time(this.user.line_at) + const seconds = now - line + let stats = '最后在线于很久以前'; + if (seconds < 60) { + stats = `最后在线于刚刚` + } else if (seconds < 3600) { + stats = `最后在线于 ${Math.floor(seconds / 60)} 分钟前` + } else if (seconds < 3600 * 6) { + stats = `最后在线于 ${Math.floor(seconds / 3600)} 小时前` + } else { + const nowYmd = $A.formatDate('Y-m-d', now) + const lineYmd = $A.formatDate('Y-m-d', line) + const lineHi = $A.formatDate('H:i', line) + if (nowYmd === lineYmd) { + stats = `最后在线于今天 ${lineHi}` + } else if ($A.formatDate('Y-m-d', now - 86400) === lineYmd) { + stats = `最后在线于昨天 ${lineHi}` + } else if (seconds < 3600 * 24 * 365) { + stats = `最后在线于 ${lineYmd}` + } + } + this.$emit('update:online', this.$L(stats)) + } } } } diff --git a/resources/assets/js/store/actions.js b/resources/assets/js/store/actions.js index 8ccc853b0..c1e213f56 100644 --- a/resources/assets/js/store/actions.js +++ b/resources/assets/js/store/actions.js @@ -662,18 +662,6 @@ export default { }); }, - /** - * 更新会员在线 - * @param state - * @param info {userid,online} - */ - saveUserOnlineStatus({state}, info) { - const {userid, online} = info; - if (state.userOnline[userid] !== online) { - state.userOnline = Object.assign({}, state.userOnline, {[userid]: online}); - } - }, - /** * 获取用户基础信息 * @param state @@ -700,7 +688,7 @@ export default { if (temp && time - temp._time <= 30) { setTimeout(() => { state.cacheUserActive = Object.assign(temp, {__:Math.random()}); - Store.set('cacheUserActive', temp); + Store.set('userActive', {type: 'cache', data: temp}); }, timeout += 5); return false; } @@ -752,7 +740,7 @@ export default { state.cacheUserBasic.push(data) } state.cacheUserActive = Object.assign(data, {__:Math.random()}); - Store.set('cacheUserActive', data); + Store.set('userActive', {type: 'cache', data}); // $A.IDBSave("cacheUserBasic", state.cacheUserBasic) }, @@ -3168,7 +3156,7 @@ export default { break case "line": - dispatch("saveUserOnlineStatus", msgDetail.data); + Store.set('userActive', {type: 'line', data: msgDetail.data}); break case "msgStream": diff --git a/resources/assets/js/store/state.js b/resources/assets/js/store/state.js index 3d61f88df..f10e65ddf 100644 --- a/resources/assets/js/store/state.js +++ b/resources/assets/js/store/state.js @@ -98,7 +98,6 @@ export default { userId: 0, userToken: '', userIsAdmin: false, - userOnline: {}, userAvatar: {}, // 会话聊天