import { defineStore } from 'pinia' import { ADMIN_INFO } from '@/stores/constant/cacheKey' import type { AdminInfo } from '@/stores/interface' export const useAdminInfo = defineStore('adminInfo', { state: (): AdminInfo => { return { access_token: '', token_type: '', refresh_token: '', expires_in: 0, scope: '', nickname: '', userType: 1, deptIndex: '', userIndex: '', client_id: '', headSculpture: '', jti: '' } }, actions: { dataFill(state: AdminInfo) { this.$state = { ...this.$state, ...state } }, removeToken() { this.access_token = '' this.refresh_token = '' }, setToken(token: string, type: 'auth' | 'refresh') { const field = type == 'auth' ? 'token' : 'refresh_token' this[field] = token }, getToken(type: 'auth' | 'refresh' = 'auth') { return type === 'auth' ? this.token_type + ' ' + this.access_token : this.refresh_token } }, persist: { key: ADMIN_INFO } })