chat-app/src/store/modules/user.js

71 lines
1.9 KiB
JavaScript
Raw Normal View History

2024-11-20 01:17:47 +00:00
import { defineStore } from 'pinia'
2024-11-22 01:06:37 +00:00
import { ServeGetUserSetting } from '@/api/user/index.js'
2024-11-20 01:17:47 +00:00
// import { ServeFindFriendApplyNum } from '@/api/contact'
import { ServeGroupApplyUnread } from '@/api/group'
// import { delAccessToken } from '@/utils/auth'
// import { storage } from '@/utils/storage'
2024-11-22 09:00:03 +00:00
export const useUserStore = defineStore('chatUser', {
2024-11-20 01:17:47 +00:00
persist: true,
state: () => {
return {
uid: 0, // 用户ID
mobile: '',
email: '',
nickname: '', // 用户昵称
gender: 0, // 性别
motto: '', // 个性签名
avatar: '',
banner: '', // 名片背景
online: false, // 在线状态
isQiye: false,
isContactApply: false,
isGroupApply: false
}
},
getters: {},
actions: {
// 设置用户登录状态
updateSocketStatus(status) {
this.online = status
},
// logoutLogin() {
// this.$reset()
// storage.remove('user_info')
// delAccessToken()
// location.reload()
// },
loadSetting() {
2024-11-22 01:06:37 +00:00
ServeGetUserSetting().then(({ code, data }) => {
if (code == 200) {
this.nickname = data.user_info.nickname
this.uid = data.user_info.uid
this.avatar = data.user_info.avatar
2024-11-20 01:17:47 +00:00
2024-11-22 01:06:37 +00:00
this.gender = data.user_info.gender
this.mobile = data.user_info.mobile || ''
this.email = data.user_info.email || ''
this.motto = data.user_info.motto
this.isQiye = data.user_info.is_qiye || false
2024-11-20 01:17:47 +00:00
2024-11-22 01:06:37 +00:00
// storage.set('user_info', data)
}
})
2024-11-20 01:17:47 +00:00
// ServeFindFriendApplyNum().then(({ code, data }) => {
// if (code == 200) {
// this.isContactApply = data.unread_num > 0
// }
// })
ServeGroupApplyUnread().then(({ code, data }) => {
if (code == 200) {
this.isGroupApply = data.unread_num > 0
}
})
}
}
})