Files
admin-govern/src/stores/adminInfo.ts

38 lines
1.0 KiB
TypeScript
Raw Normal View History

2023-12-21 16:42:39 +08:00
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 {
id: 0,
username: '',
nickname: '',
avatar: '',
last_login_time: '',
2024-01-03 14:04:56 +08:00
token: '',
2023-12-21 16:42:39 +08:00
refresh_token: '',
super: false
}
},
actions: {
dataFill(state: AdminInfo) {
this.$state = { ...this.$state, ...state }
},
removeToken() {
this.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 : this.refresh_token
}
},
persist: {
key: ADMIN_INFO
}
})