2021-01-05 18:11:13 +08:00
|
|
|
|
import { InjectionKey } from 'vue'
|
|
|
|
|
import { createStore, useStore as baseUseStore, Store } from 'vuex'
|
2021-01-20 18:52:41 +08:00
|
|
|
|
import themeConfig from '/@/utils/themeConfig.ts'
|
2021-01-27 17:54:58 +08:00
|
|
|
|
import { getSession } from "/@/utils/storage.ts";
|
2021-01-05 18:11:13 +08:00
|
|
|
|
export interface RootStateTypes {
|
|
|
|
|
themeConfig: {
|
|
|
|
|
isDrawer: boolean,
|
|
|
|
|
primary: string,
|
|
|
|
|
success: string,
|
|
|
|
|
info: string,
|
|
|
|
|
warning: string,
|
|
|
|
|
danger: string,
|
|
|
|
|
topBar: string,
|
|
|
|
|
menuBar: string,
|
2021-01-10 23:59:43 +08:00
|
|
|
|
columnsMenuBar: string,
|
2021-01-05 18:11:13 +08:00
|
|
|
|
topBarColor: string,
|
|
|
|
|
menuBarColor: string,
|
2021-01-10 23:59:43 +08:00
|
|
|
|
columnsMenuBarColor: string,
|
2021-01-05 18:11:13 +08:00
|
|
|
|
isTopBarColorGradual: boolean,
|
|
|
|
|
isMenuBarColorGradual: boolean,
|
|
|
|
|
isMenuBarColorHighlight: boolean,
|
|
|
|
|
isCollapse: boolean,
|
|
|
|
|
isUniqueOpened: boolean,
|
|
|
|
|
isFixedHeader: boolean,
|
2021-01-06 13:30:53 +08:00
|
|
|
|
isFixedHeaderChange: boolean,
|
2021-01-17 21:14:26 +08:00
|
|
|
|
isClassicSplitMenu: boolean,
|
2021-01-12 22:48:55 +08:00
|
|
|
|
isLockScreen: boolean,
|
|
|
|
|
lockScreenTime: number,
|
2021-01-06 13:30:53 +08:00
|
|
|
|
isShowLogo: boolean,
|
2021-01-06 18:41:05 +08:00
|
|
|
|
isShowLogoChange: boolean,
|
|
|
|
|
isBreadcrumb: boolean,
|
|
|
|
|
isTagsview: boolean,
|
2021-01-18 11:49:04 +08:00
|
|
|
|
isBreadcrumbIcon: boolean,
|
2021-01-11 18:48:34 +08:00
|
|
|
|
isTagsviewIcon: boolean,
|
2021-01-22 12:59:44 +08:00
|
|
|
|
isCacheTagsView: boolean,
|
2021-01-29 18:33:32 +08:00
|
|
|
|
isSortableTagsView: boolean,
|
2021-01-06 21:46:22 +08:00
|
|
|
|
isFooter: boolean,
|
|
|
|
|
isGrayscale: boolean,
|
|
|
|
|
isInvert: boolean,
|
|
|
|
|
isWartermark: boolean,
|
2021-01-09 18:10:16 +08:00
|
|
|
|
wartermarkText: string,
|
|
|
|
|
tagsStyle: string,
|
2021-01-10 23:59:43 +08:00
|
|
|
|
animation: string,
|
2021-01-13 17:32:59 +08:00
|
|
|
|
columnsAsideStyle: string,
|
2021-02-22 21:56:45 +08:00
|
|
|
|
layout: string,
|
2021-02-26 18:39:44 +08:00
|
|
|
|
isRequestRoutes: boolean,
|
|
|
|
|
globalTitle: string,
|
|
|
|
|
globalViceTitle: string,
|
2021-01-20 18:52:41 +08:00
|
|
|
|
},
|
2021-01-21 18:59:16 +08:00
|
|
|
|
routes: Array<object>,
|
2021-02-05 01:15:37 +08:00
|
|
|
|
keepAliveNames: Array<string>,
|
2021-01-26 18:17:13 +08:00
|
|
|
|
tagsViewRoutes: Array<object>,
|
2021-02-25 00:42:24 +08:00
|
|
|
|
userInfos: object,
|
|
|
|
|
requestOldRoutes: Array<object>,
|
2021-01-05 18:11:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const key: InjectionKey<Store<RootStateTypes>> = Symbol()
|
|
|
|
|
|
|
|
|
|
export const store = createStore<RootStateTypes>({
|
|
|
|
|
state: {
|
2021-01-20 18:52:41 +08:00
|
|
|
|
themeConfig,
|
2021-01-21 18:59:16 +08:00
|
|
|
|
routes: [],
|
2021-02-05 01:15:37 +08:00
|
|
|
|
keepAliveNames: [],
|
2021-01-26 18:17:13 +08:00
|
|
|
|
tagsViewRoutes: [],
|
2021-02-25 00:42:24 +08:00
|
|
|
|
userInfos: {},
|
|
|
|
|
requestOldRoutes: []
|
2021-01-05 18:11:13 +08:00
|
|
|
|
},
|
|
|
|
|
mutations: {
|
2021-01-27 17:54:58 +08:00
|
|
|
|
// 设置布局配置
|
2021-01-05 18:11:13 +08:00
|
|
|
|
getThemeConfig(state: any, data: object) {
|
|
|
|
|
state.themeConfig = Object.assign({}, data)
|
2021-01-20 18:52:41 +08:00
|
|
|
|
},
|
2021-01-27 17:54:58 +08:00
|
|
|
|
// 设置路由,菜单中使用到
|
2021-01-20 18:52:41 +08:00
|
|
|
|
getRoutes(state: any, data: Array<object>) {
|
|
|
|
|
state.routes = data
|
2021-01-21 18:59:16 +08:00
|
|
|
|
},
|
2021-01-27 17:54:58 +08:00
|
|
|
|
// 设置缓存(name字段)
|
2021-01-21 18:59:16 +08:00
|
|
|
|
getCacheKeepAlive(state: any, data: Array<string>) {
|
2021-02-05 01:15:37 +08:00
|
|
|
|
state.keepAliveNames = data
|
2021-01-21 23:36:07 +08:00
|
|
|
|
},
|
2021-01-27 17:54:58 +08:00
|
|
|
|
// 设置 TagsView 路由
|
2021-01-21 23:36:07 +08:00
|
|
|
|
getTagsViewRoutes(state: any, data: Array<string>) {
|
|
|
|
|
state.tagsViewRoutes = data
|
2021-01-26 18:17:13 +08:00
|
|
|
|
},
|
2021-02-04 08:37:20 +08:00
|
|
|
|
// 设置用户信息
|
|
|
|
|
getUserInfos(state: any, data: object) {
|
|
|
|
|
state.userInfos = data
|
|
|
|
|
},
|
2021-02-25 00:42:24 +08:00
|
|
|
|
// 后端控制路由
|
|
|
|
|
getBackEndControlRoutes(state: any, data: object) {
|
|
|
|
|
state.requestOldRoutes = data
|
|
|
|
|
},
|
2021-01-05 18:11:13 +08:00
|
|
|
|
},
|
|
|
|
|
actions: {
|
2021-01-27 17:54:58 +08:00
|
|
|
|
// 设置布局配置
|
2021-01-05 18:11:13 +08:00
|
|
|
|
setThemeConfig({ commit }, data: object) {
|
|
|
|
|
commit('getThemeConfig', data)
|
2021-01-20 18:52:41 +08:00
|
|
|
|
},
|
2021-01-27 17:54:58 +08:00
|
|
|
|
// 设置路由,菜单中使用到
|
2021-01-21 18:59:16 +08:00
|
|
|
|
async setRoutes({ commit }, data: any) {
|
|
|
|
|
commit('getRoutes', data)
|
|
|
|
|
},
|
2021-01-27 17:54:58 +08:00
|
|
|
|
// 设置缓存(name字段)
|
2021-01-21 18:59:16 +08:00
|
|
|
|
async setCacheKeepAlive({ commit }, data: Array<string>) {
|
|
|
|
|
commit('getCacheKeepAlive', data)
|
|
|
|
|
},
|
2021-01-27 17:54:58 +08:00
|
|
|
|
// 设置 TagsView 路由
|
2021-01-21 23:36:07 +08:00
|
|
|
|
async setTagsViewRoutes({ commit }, data: Array<string>) {
|
|
|
|
|
commit('getTagsViewRoutes', data)
|
|
|
|
|
},
|
2021-02-04 08:37:20 +08:00
|
|
|
|
// 设置用户信息
|
|
|
|
|
async setUserInfos({ commit }, data: object) {
|
|
|
|
|
if (data) {
|
|
|
|
|
commit('getUserInfos', data)
|
2021-01-27 17:54:58 +08:00
|
|
|
|
} else {
|
2021-02-04 08:37:20 +08:00
|
|
|
|
if (getSession('userInfo')) commit('getUserInfos', getSession('userInfo'))
|
2021-01-27 17:54:58 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
2021-02-22 21:56:45 +08:00
|
|
|
|
// 后端控制路由
|
2021-02-25 00:42:24 +08:00
|
|
|
|
setBackEndControlRoutes({ commit }, routes: Array<string>) {
|
|
|
|
|
commit('getBackEndControlRoutes', routes)
|
2021-02-22 21:56:45 +08:00
|
|
|
|
}
|
2021-01-05 18:11:13 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export function useStore() {
|
|
|
|
|
return baseUseStore(key)
|
|
|
|
|
}
|