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-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-01-10 23:59:43 +08:00
|
|
|
|
layout: string
|
2021-01-20 18:52:41 +08:00
|
|
|
|
},
|
2021-01-21 18:59:16 +08:00
|
|
|
|
routes: Array<object>,
|
2021-01-21 23:36:07 +08:00
|
|
|
|
caches: Array<string>,
|
2021-01-26 18:17:13 +08:00
|
|
|
|
tagsViewRoutes: Array<object>,
|
|
|
|
|
auths: Array<string>
|
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-01-21 23:36:07 +08:00
|
|
|
|
caches: [],
|
2021-01-26 18:17:13 +08:00
|
|
|
|
tagsViewRoutes: [],
|
|
|
|
|
auths: []
|
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>) {
|
|
|
|
|
state.caches = 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-01-27 17:54:58 +08:00
|
|
|
|
// 设置权限
|
2021-01-26 18:17:13 +08:00
|
|
|
|
getAuths(state: any, data: Array<string>) {
|
|
|
|
|
state.auths = 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-01-27 17:54:58 +08:00
|
|
|
|
// 设置权限
|
|
|
|
|
async setAuths({ commit }, data: Array<string>) {
|
|
|
|
|
// 模拟权限,实际项目中,请通过直接走接口获取权限标识
|
2021-01-26 18:17:13 +08:00
|
|
|
|
let authList: Array<string> = []
|
2021-01-27 17:54:58 +08:00
|
|
|
|
if (getSession('defaultAuthList')) {
|
|
|
|
|
authList = getSession('defaultAuthList')
|
|
|
|
|
} else {
|
|
|
|
|
let defaultAuthList: Array<string> = ['admin', 'btn.add', 'btn.del', 'btn.edit']
|
|
|
|
|
if (data && data.length > 0) authList = data
|
|
|
|
|
else authList = defaultAuthList
|
|
|
|
|
}
|
2021-01-26 18:17:13 +08:00
|
|
|
|
commit('getAuths', authList)
|
2021-01-27 17:54:58 +08:00
|
|
|
|
},
|
2021-01-05 18:11:13 +08:00
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
export function useStore() {
|
|
|
|
|
return baseUseStore(key)
|
|
|
|
|
}
|