import { defineStore } from 'pinia' const initState = { nickname: '', avatar: '' } export const useUserStore = defineStore( 'user', () => { const userInfo = ref({ ...initState }) const setUserInfo = (val: IUserInfo) => { userInfo.value = val } const clearUserInfo = () => { userInfo.value = { ...initState } } // 一般没有reset需求,不需要的可以删除 const reset = () => { userInfo.value = { ...initState } } const isLogined = computed(() => !!userInfo.value.accessToken) const isMerchant = computed(() => userInfo.value.appLoginType === 4) const isAgent = computed(() => userInfo.value.appLoginType === 3) return { userInfo, setUserInfo, clearUserInfo, isLogined, isMerchant, isAgent, reset, } }, { persist: true, }, )