mirror of
https://github.com/kuaifan/dootask.git
synced 2025-12-12 19:24:17 +00:00
fix: 会员头像显示错乱
This commit is contained in:
parent
c4b49b34b8
commit
a6873302f3
@ -36,7 +36,7 @@ export default {
|
|||||||
mounted() {
|
mounted() {
|
||||||
this.getData();
|
this.getData();
|
||||||
//
|
//
|
||||||
this.subscribe = Store.subscribe('cacheUserActive', (data) => {
|
this.subscribe = Store.subscribe('userActive', ({data}) => {
|
||||||
if (data.userid == this.userid) {
|
if (data.userid == this.userid) {
|
||||||
this.setUser(data)
|
this.setUser(data)
|
||||||
}
|
}
|
||||||
@ -136,15 +136,16 @@ export default {
|
|||||||
return value || 'D';
|
return value || 'D';
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
watch: {
|
||||||
|
userid() {
|
||||||
|
this.getData();
|
||||||
|
}
|
||||||
|
},
|
||||||
methods: {
|
methods: {
|
||||||
getData() {
|
getData() {
|
||||||
if (!this.$store.state.userId) {
|
if (!this.$store.state.userId) {
|
||||||
return;
|
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);
|
const tempUser = this.$store.state.cacheUserBasic.find(({userid}) => userid == this.userid);
|
||||||
if (tempUser) {
|
if (tempUser) {
|
||||||
this.setUser(tempUser);
|
this.setUser(tempUser);
|
||||||
@ -153,6 +154,13 @@ export default {
|
|||||||
},
|
},
|
||||||
|
|
||||||
setUser(info) {
|
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;
|
this.user = info;
|
||||||
|
|
||||||
if (typeof this.userResult === "function") {
|
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: {
|
computed: {
|
||||||
showMenu() {
|
showMenu() {
|
||||||
if (this.userId == this.userid) {
|
if (this.$store.state.userId == this.userid) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if (this.user.delete_at || this.user.disable_at) {
|
if (this.user.delete_at || this.user.disable_at) {
|
||||||
@ -88,6 +100,39 @@ export default {
|
|||||||
this.userResult(info);
|
this.userResult(info);
|
||||||
}
|
}
|
||||||
this.user = 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
|
* @param state
|
||||||
@ -700,7 +688,7 @@ export default {
|
|||||||
if (temp && time - temp._time <= 30) {
|
if (temp && time - temp._time <= 30) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
state.cacheUserActive = Object.assign(temp, {__:Math.random()});
|
state.cacheUserActive = Object.assign(temp, {__:Math.random()});
|
||||||
Store.set('cacheUserActive', temp);
|
Store.set('userActive', {type: 'cache', data: temp});
|
||||||
}, timeout += 5);
|
}, timeout += 5);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -752,7 +740,7 @@ export default {
|
|||||||
state.cacheUserBasic.push(data)
|
state.cacheUserBasic.push(data)
|
||||||
}
|
}
|
||||||
state.cacheUserActive = Object.assign(data, {__:Math.random()});
|
state.cacheUserActive = Object.assign(data, {__:Math.random()});
|
||||||
Store.set('cacheUserActive', data);
|
Store.set('userActive', {type: 'cache', data});
|
||||||
//
|
//
|
||||||
$A.IDBSave("cacheUserBasic", state.cacheUserBasic)
|
$A.IDBSave("cacheUserBasic", state.cacheUserBasic)
|
||||||
},
|
},
|
||||||
@ -3168,7 +3156,7 @@ export default {
|
|||||||
break
|
break
|
||||||
|
|
||||||
case "line":
|
case "line":
|
||||||
dispatch("saveUserOnlineStatus", msgDetail.data);
|
Store.set('userActive', {type: 'line', data: msgDetail.data});
|
||||||
break
|
break
|
||||||
|
|
||||||
case "msgStream":
|
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,
|
userId: 0,
|
||||||
userToken: '',
|
userToken: '',
|
||||||
userIsAdmin: false,
|
userIsAdmin: false,
|
||||||
userOnline: {},
|
|
||||||
userAvatar: {},
|
userAvatar: {},
|
||||||
|
|
||||||
// 会话聊天
|
// 会话聊天
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user