61 lines
1.7 KiB
TypeScript
61 lines
1.7 KiB
TypeScript
import { computed, ref } from 'vue'
|
|
// import { get } from 'lodash'
|
|
import { defineStore } from 'pinia'
|
|
import { getMe } from '@/api/me'
|
|
import type { User } from '@/models/login'
|
|
import { useWalletStore } from '@/store/walletStore'
|
|
import { setFingerPrint } from '@/utils'
|
|
import type { PWallet } from '@/models/wallet'
|
|
|
|
|
|
export const useUserStore = defineStore('user', () => {
|
|
const userInfo = ref<User | undefined>(undefined)
|
|
const walletStore = useWalletStore()
|
|
const productWallet = ref<PWallet[] | undefined>(undefined)
|
|
let isFirst = true
|
|
|
|
async function getMyInfo() {
|
|
try {
|
|
userInfo.value = await getMe()
|
|
setFingerPrint(userInfo.value.finger_print.toString())
|
|
productWallet.value = userInfo.value.pwallet
|
|
// return userInfo.value
|
|
walletStore.walletInfo = userInfo.value.wallet
|
|
} catch (e) {
|
|
console.log(e)
|
|
}
|
|
}
|
|
|
|
function removeInformation() {
|
|
userInfo.value = undefined
|
|
}
|
|
|
|
const isSingle = computed(() => userInfo.value?.type === 2)
|
|
|
|
/* const permissions: ComputedRef<string[]> = computed(() => {
|
|
const permissions: string[] = get(userInfo.value, 'permission', [])
|
|
const excludes: string[] = get(userInfo.value, 'exclude', [])
|
|
return permissions.filter((item) => !excludes.includes(item))
|
|
})*/
|
|
|
|
/*
|
|
function canAccess(permissionKey: string) {
|
|
if (isAdmin.value) return true
|
|
return permissions.value.includes(permissionKey)
|
|
}
|
|
*/
|
|
/*
|
|
const isAdmin = computed(() => {
|
|
return userInfo.value?.is_admin
|
|
})*/
|
|
|
|
return {
|
|
userInfo,
|
|
getMyInfo,
|
|
removeInformation,
|
|
isSingle,
|
|
isFirst,
|
|
productWallet/* permissions, canAccess, isAdmin*/
|
|
}
|
|
})
|