acdr/acdr-ui/src/store/user.js

56 lines
962 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { defineStore } from 'pinia'
import { ref, computed } from 'vue'
const initState = {
nickname: '',
avatar: '',
id: null,
name: '',
mobile: '',
cardId: '',
createTime: '',
updateTime: '',
token: '',
sex: '',
isRealName: false,
isPetNursery: false,
expiresTime: '',
refreshToken: '',
}
export const useUserStore = defineStore(
'user',
() => {
const userInfo = ref({ ...initState })
const setUserInfo = (val) => {
userInfo.value = {
...userInfo.value,
...val,
}
}
const clearUserInfo = () => {
userInfo.value = { ...initState }
}
// 一般没有reset需求不需要的可以删除
const reset = () => {
userInfo.value = { ...initState }
}
const isLogined = computed(() => userInfo.value.token != '')
return {
userInfo,
setUserInfo,
clearUserInfo,
isLogined,
reset,
}
},
{
persist: true,
},
)