import { defineStore } from 'pinia' import { StaticUrl } from '@/config' interface userStroe { token: string /** * 重定向路由名称 */ redirectName: string /** * 用户登录信息 */ userInfo: Api.userInfo } export const useUserStore = defineStore('user', { state: (): userStroe => ({ token: '', redirectName: '', userInfo: { id: 0, }, }), getters: { getUserAvatar(): string { if (this.userInfo.avatarUrl) { return this.userInfo.avatarUrl } return `${StaticUrl}/avator.png` }, }, actions: { async getUserInfo() { if (this.token) { const res = await api.sys.userInfo({}) this.userInfo = res } }, async updataUserInfo(data: Api.userInfo) { uni.showLoading({ mask: true }) await Apis.sys.updateUserInfo({ pathParams: { memberId: data.id }, data }) uni.hideLoading() useGlobalToast().show({ msg: '修改成功' }) this.getUserInfo() }, }, })