import { defineStore } from 'pinia' import { computed, ref, } from 'vue' import Strings from '@/common/utils/strings.ts' import Evt from '@/common/utils/evt.ts' export const useAppUserStore = defineStore('AppUser', () => { const userId = ref(null) const roles = ref([]) const bizObj = ref(null) const nickname = ref(null) const avatar = ref(null) const token = ref(null) const tenantId = ref(null) const tenantName = ref(null) const isAuthenticated = computed(() => !Strings.isEmpty(token.value)) const isXiaoNa = computed(() => { return false }) function $reset() { userId.value = null avatar.value = null nickname.value = null token.value = null tenantId.value = null tenantName.value = null bizObj.value = null roles.value = [] } Evt.on('logout', $reset) return { userId, avatar, nickname, token, tenantId, tenantName, bizObj, isAuthenticated, roles, isXiaoNa, $reset, } }, { persist: { pick: [ 'userId', 'avatar', 'nickname', 'token', 'tenantId', 'tenantName', 'bizObj' ], }, })