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

114 lines
3.1 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: '',
2024-01-26 16:15:40 +08:00
userType: 0,
2024-01-19 14:08:07 +08:00
deptIndex: '',
userIndex: '',
client_id: '',
headSculpture: '',
2024-01-22 14:21:31 +08:00
jti: '',
2024-01-26 16:15:40 +08:00
name: '',
deptId: '',
phone: '',
email: '',
limitIpStart: '',
limitIpEnd: '',
limitTime: '',
casualUser: 0,
type: 0,
smsNotice: 0,
emailNotice: 0,
role: [],
devCode: '',
id: '',
loginName: '',
state: 0,
registerTime: '',
loginTime: '',
deptName: '',
areaId: '',
areaName: '',
deptLevel: 0,
roleList: [],
roleCode: []
2023-12-21 16:42:39 +08:00
}
},
actions: {
dataFill(state: AdminInfo) {
this.$state = { ...this.$state, ...state }
},
2024-08-16 14:28:57 +08:00
reset() {
this.$state = {
access_token: '',
token_type: '',
refresh_token: '',
expires_in: 0,
scope: '',
nickname: '',
userType: 0,
deptIndex: '',
userIndex: '',
client_id: '',
headSculpture: '',
jti: '',
name: '',
deptId: '',
phone: '',
email: '',
limitIpStart: '',
limitIpEnd: '',
limitTime: '',
casualUser: 0,
type: 0,
smsNotice: 0,
emailNotice: 0,
role: [],
devCode: '',
id: '',
loginName: '',
state: 0,
registerTime: '',
loginTime: '',
deptName: '',
areaId: '',
areaName: '',
deptLevel: 0,
roleList: [],
roleCode: []
}
},
2023-12-21 16:42:39 +08:00
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' ? 'access_token' : 'refresh_token'
2023-12-21 16:42:39 +08:00
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
}
})