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

42 lines
1.2 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 {
2024-01-19 14:08:07 +08:00
access_token: '',
token_type: '',
2023-12-21 16:42:39 +08:00
refresh_token: '',
2024-01-19 14:08:07 +08:00
expires_in: 0,
scope: '',
nickname: '',
userType: 1,
deptIndex: '',
userIndex: '',
client_id: '',
headSculpture: '',
jti: ''
2023-12-21 16:42:39 +08:00
}
},
actions: {
dataFill(state: AdminInfo) {
this.$state = { ...this.$state, ...state }
},
removeToken() {
2024-01-19 14:08:07 +08:00
this.access_token = ''
2023-12-21 16:42:39 +08:00
this.refresh_token = ''
},
setToken(token: string, type: 'auth' | 'refresh') {
const field = type == 'auth' ? 'token' : 'refresh_token'
this[field] = token
},
getToken(type: 'auth' | 'refresh' = 'auth') {
2024-01-19 14:08:07 +08:00
return type === 'auth' ? this.token_type + ' ' + this.access_token : this.refresh_token
2023-12-21 16:42:39 +08:00
}
},
persist: {
key: ADMIN_INFO
}
})