first commit
This commit is contained in:
37
src/stores/adminInfo.ts
Normal file
37
src/stores/adminInfo.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
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: '',
|
||||
token: '',
|
||||
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
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user