njzscloud-dispose-web/src/common/app/app-user-store.ts

55 lines
1.2 KiB
TypeScript

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<string | null>(null)
const roles = ref<string[]>([])
const bizObj = ref<string | null>(null)
const nickname = ref<string | null>(null)
const avatar = ref<string | null>(null)
const token = ref<string | null>(null)
const tenantId = ref<string | null>(null)
const tenantName = ref<string | null>(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' ],
},
})