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: '',
|
2024-01-22 14:21:31 +08:00
|
|
|
jti: '',
|
|
|
|
|
loginName: ''
|
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-22 10:31:07 +08:00
|
|
|
if (type === 'auth') {
|
|
|
|
|
if (this.token_type && this.access_token) {
|
|
|
|
|
return this.token_type + ' ' + this.access_token
|
|
|
|
|
} else {
|
|
|
|
|
return ''
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return this.refresh_token
|
|
|
|
|
}
|
2023-12-21 16:42:39 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
persist: {
|
|
|
|
|
key: ADMIN_INFO
|
|
|
|
|
}
|
|
|
|
|
})
|