mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 11:19:56 +00:00
fix: 会员头像显示错乱
This commit is contained in:
parent
c4b49b34b8
commit
a6873302f3
@ -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") {
|
||||
|
||||
@ -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))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
18
resources/assets/js/store/actions.js
vendored
18
resources/assets/js/store/actions.js
vendored
@ -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":
|
||||
|
||||
1
resources/assets/js/store/state.js
vendored
1
resources/assets/js/store/state.js
vendored
@ -98,7 +98,6 @@ export default {
|
||||
userId: 0,
|
||||
userToken: '',
|
||||
userIsAdmin: false,
|
||||
userOnline: {},
|
||||
userAvatar: {},
|
||||
|
||||
// 会话聊天
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user