登录页面init
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
/**
|
||||
* 本地缓存Key
|
||||
*/
|
||||
|
||||
// 用户信息
|
||||
export const USER_INFO = 'userInfo'
|
||||
|
||||
// WEB端布局配置
|
||||
export const STORE_CONFIG = 'storeConfig'
|
||||
|
||||
// 后台标签页
|
||||
export const STORE_TAB_VIEW_CONFIG = 'storeTabViewConfig'
|
||||
// 字典
|
||||
export const DICT_DATA = 'dictData'
|
||||
@@ -1,95 +0,0 @@
|
||||
// 变量名对应含义请在 /stores/* 里边找
|
||||
import type { RouteRecordRaw, RouteLocationNormalized } from 'vue-router'
|
||||
|
||||
export interface Layout {
|
||||
showDrawer: boolean
|
||||
shrink: boolean
|
||||
layoutMode: string
|
||||
mainAnimation: string
|
||||
isDark: boolean
|
||||
menuWidth: number
|
||||
menuDefaultIcon: string
|
||||
menuCollapse: boolean
|
||||
menuUniqueOpened: boolean
|
||||
menuShowTopBar: boolean
|
||||
elementUiPrimary: string[]
|
||||
tableHeaderBackground: string[]
|
||||
tableHeaderColor: string[]
|
||||
tableCurrent: string[]
|
||||
menuBackground: string[]
|
||||
menuColor: string[]
|
||||
menuActiveBackground: string[]
|
||||
menuActiveColor: string[]
|
||||
menuTopBarBackground: string[]
|
||||
headerBarTabColor: string[]
|
||||
headerBarBackground: string[]
|
||||
headerBarHoverBackground: string[]
|
||||
headerBarTabActiveBackground: string[]
|
||||
headerBarTabActiveColor: string[]
|
||||
}
|
||||
|
||||
export interface NavTabs {
|
||||
activeIndex: number
|
||||
activeRoute: RouteLocationNormalized | null
|
||||
tabsView: RouteLocationNormalized[]
|
||||
tabFullScreen: boolean
|
||||
tabsViewRoutes: RouteRecordRaw[]
|
||||
authNode: Map<string, string[]>
|
||||
}
|
||||
|
||||
// 用户信息
|
||||
export interface UserInfo {
|
||||
access_token: string
|
||||
token_type: string
|
||||
refresh_token: string
|
||||
expires_in: number
|
||||
scope: string
|
||||
nickname: string
|
||||
userType: number
|
||||
deptIndex: string
|
||||
userIndex: string
|
||||
client_id: string
|
||||
headSculpture: any
|
||||
jti: string
|
||||
name: string
|
||||
deptId: string
|
||||
phone: string
|
||||
email: string
|
||||
limitIpStart: string
|
||||
limitIpEnd: string
|
||||
limitTime: string
|
||||
casualUser: number
|
||||
type: number
|
||||
smsNotice: number
|
||||
emailNotice: number
|
||||
role: string[]
|
||||
devCode: any
|
||||
id: string
|
||||
loginName: string
|
||||
state: number
|
||||
registerTime: string
|
||||
loginTime: string
|
||||
deptName: string
|
||||
areaId: string
|
||||
areaName: string
|
||||
deptLevel: number
|
||||
roleList: string[]
|
||||
roleCode: string[]
|
||||
}
|
||||
|
||||
// 字典数据
|
||||
export interface DictData {
|
||||
basic: BasicDictData[]
|
||||
area: BasicDictData[]
|
||||
areaTree: BasicDictData[]
|
||||
userList: string[]
|
||||
}
|
||||
|
||||
export interface BasicDictData {
|
||||
name: string
|
||||
id: string
|
||||
code: string
|
||||
value: null
|
||||
sort: number | null
|
||||
children?: BasicDictData[]
|
||||
}
|
||||
@@ -1,6 +1,9 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { USER_INFO } from '@/stores/constant/cacheKey'
|
||||
import type { UserInfo } from '@/stores/interface'
|
||||
import { USER_INFO } from '@/constants/storeKey'
|
||||
import { TOKEN_PREFIX } from '@/constants/user'
|
||||
import type { UserInfo } from '@/types/user'
|
||||
import { getUserById } from '@/api/user'
|
||||
import { createPersistedState } from 'pinia-plugin-persistedstate'
|
||||
|
||||
export const useUserInfoStore = defineStore('userInfo', {
|
||||
// 行为
|
||||
@@ -8,6 +11,9 @@ export const useUserInfoStore = defineStore('userInfo', {
|
||||
dataFill(state: UserInfo) {
|
||||
this.$state = { ...this.$state, ...state }
|
||||
},
|
||||
async initUserInfo() {
|
||||
this.dataFill(await getUserById())
|
||||
},
|
||||
removeToken() {
|
||||
this.access_token = ''
|
||||
this.refresh_token = ''
|
||||
@@ -18,8 +24,8 @@ export const useUserInfoStore = defineStore('userInfo', {
|
||||
},
|
||||
getToken(type: 'auth' | 'refresh' = 'auth') {
|
||||
if (type === 'auth') {
|
||||
if (this.token_type && this.access_token) {
|
||||
return this.token_type + ' ' + this.access_token
|
||||
if (this.access_token) {
|
||||
return `${TOKEN_PREFIX}${this.access_token}`
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
@@ -32,7 +38,6 @@ export const useUserInfoStore = defineStore('userInfo', {
|
||||
state: (): UserInfo => {
|
||||
return {
|
||||
access_token: '',
|
||||
token_type: '',
|
||||
refresh_token: '',
|
||||
expires_in: 0,
|
||||
scope: '',
|
||||
@@ -69,7 +74,10 @@ export const useUserInfoStore = defineStore('userInfo', {
|
||||
roleCode: [],
|
||||
}
|
||||
},
|
||||
persist: {
|
||||
key: USER_INFO,
|
||||
},
|
||||
plugins: [
|
||||
createPersistedState({
|
||||
key: USER_INFO,
|
||||
storage: window.localStorage
|
||||
}),
|
||||
],
|
||||
})
|
||||
Reference in New Issue
Block a user