perf: perf store

This commit is contained in:
kailong321200875 2022-10-08 11:28:50 +08:00
parent e757c54fb6
commit d416178d69
7 changed files with 25 additions and 38 deletions

View File

@ -42,7 +42,6 @@
"mockjs": "^1.1.0", "mockjs": "^1.1.0",
"nprogress": "^0.2.0", "nprogress": "^0.2.0",
"pinia": "^2.0.22", "pinia": "^2.0.22",
"pinia-plugin-persistedstate": "^2.2.0",
"qrcode": "^1.5.1", "qrcode": "^1.5.1",
"qs": "^6.11.0", "qs": "^6.11.0",
"url": "^0.11.0", "url": "^0.11.0",

View File

@ -4,13 +4,11 @@ import '@/plugins/windi.css'
// 导入全局的svg图标 // 导入全局的svg图标
import '@/plugins/svgIcon' import '@/plugins/svgIcon'
import './store'
// 初始化多语言 // 初始化多语言
import { setupI18n } from '@/plugins/vueI18n' import { setupI18n } from '@/plugins/vueI18n'
// 引入状态管理 // 引入状态管理
// import { setupStore } from '@/store' import { setupStore } from '@/store'
// 全局组件 // 全局组件
import { setupGlobCom } from '@/components' import { setupGlobCom } from '@/components'
@ -42,7 +40,7 @@ const setupAll = async () => {
await setupI18n(app) await setupI18n(app)
// setupStore(app) setupStore(app)
setupGlobCom(app) setupGlobCom(app)

View File

@ -1,22 +1,10 @@
// TODO: 感觉这样是有问题的,但目前还没想到更好的办法 import type { App } from 'vue'
import { createPinia } from 'pinia' import { createPinia } from 'pinia'
import { createApp } from 'vue'
import App from '../App.vue'
import { createPersistedState } from 'pinia-plugin-persistedstate'
const app = createApp(App)
const store = createPinia() const store = createPinia()
store.use( export const setupStore = (app: App<Element>) => {
createPersistedState({
storage: sessionStorage
})
)
app.use(store) app.use(store)
}
export { store } export { store }

View File

@ -2,6 +2,9 @@ import { defineStore } from 'pinia'
import { store } from '../index' import { store } from '../index'
import { setCssVar, humpToUnderline } from '@/utils' import { setCssVar, humpToUnderline } from '@/utils'
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { useCache } from '@/hooks/web/useCache'
const { wsCache } = useCache()
type LayoutType = 'classic' | 'topLeft' | 'top' | 'cutMenu' type LayoutType = 'classic' | 'topLeft' | 'top' | 'cutMenu'
@ -71,12 +74,12 @@ export const useAppStore = defineStore('app', {
fixedHeader: true, // 固定toolheader fixedHeader: true, // 固定toolheader
footer: true, // 显示页脚 footer: true, // 显示页脚
greyMode: false, // 是否开始灰色模式,用于特殊悼念日 greyMode: false, // 是否开始灰色模式,用于特殊悼念日
dynamicRouter: false, // 是否动态路由 dynamicRouter: wsCache.get('dynamicRouter') || false, // 是否动态路由
layout: 'classic', // layout布局 layout: wsCache.get('layout') || 'classic', // layout布局
isDark: false, // 是否是暗黑模式 isDark: wsCache.get('isDark') || false, // 是否是暗黑模式
currentSize: 'default', // 组件尺寸 currentSize: wsCache.get('default') || 'default', // 组件尺寸
theme: { theme: wsCache.get('theme') || {
// 主题色 // 主题色
elColorPrimary: '#409eff', elColorPrimary: '#409eff',
// 左侧菜单边框颜色 // 左侧菜单边框颜色
@ -108,7 +111,6 @@ export const useAppStore = defineStore('app', {
} }
} }
}, },
persist: true,
getters: { getters: {
getBreadcrumb(): boolean { getBreadcrumb(): boolean {
return this.breadcrumb return this.breadcrumb
@ -224,7 +226,7 @@ export const useAppStore = defineStore('app', {
this.greyMode = greyMode this.greyMode = greyMode
}, },
setDynamicRouter(dynamicRouter: boolean) { setDynamicRouter(dynamicRouter: boolean) {
// wsCache.set('dynamicRouter', dynamicRouter) wsCache.set('dynamicRouter', dynamicRouter)
this.dynamicRouter = dynamicRouter this.dynamicRouter = dynamicRouter
}, },
setPageLoading(pageLoading: boolean) { setPageLoading(pageLoading: boolean) {
@ -236,7 +238,7 @@ export const useAppStore = defineStore('app', {
return return
} }
this.layout = layout this.layout = layout
// wsCache.set('layout', this.layout) wsCache.set('layout', this.layout)
}, },
setTitle(title: string) { setTitle(title: string) {
this.title = title this.title = title
@ -250,18 +252,18 @@ export const useAppStore = defineStore('app', {
document.documentElement.classList.add('light') document.documentElement.classList.add('light')
document.documentElement.classList.remove('dark') document.documentElement.classList.remove('dark')
} }
// wsCache.set('isDark', this.isDark) wsCache.set('isDark', this.isDark)
}, },
setCurrentSize(currentSize: ElememtPlusSize) { setCurrentSize(currentSize: ElememtPlusSize) {
this.currentSize = currentSize this.currentSize = currentSize
// wsCache.set('currentSize', this.currentSize) wsCache.set('currentSize', this.currentSize)
}, },
setMobile(mobile: boolean) { setMobile(mobile: boolean) {
this.mobile = mobile this.mobile = mobile
}, },
setTheme(theme: ThemeTypes) { setTheme(theme: ThemeTypes) {
this.theme = Object.assign(this.theme, theme) this.theme = Object.assign(this.theme, theme)
// wsCache.set('theme', this.theme) wsCache.set('theme', this.theme)
}, },
setCssVarTheme() { setCssVarTheme() {
for (const key in this.theme) { for (const key in this.theme) {

View File

@ -11,7 +11,6 @@ export const useDictStore = defineStore('dict', {
isSetDict: false, isSetDict: false,
dictObj: {} dictObj: {}
}), }),
persist: true,
getters: { getters: {
getDictObj(): Recordable { getDictObj(): Recordable {
return this.dictObj return this.dictObj

View File

@ -2,6 +2,9 @@ import { defineStore } from 'pinia'
import { store } from '../index' import { store } from '../index'
import zhCn from 'element-plus/es/locale/lang/zh-cn' import zhCn from 'element-plus/es/locale/lang/zh-cn'
import en from 'element-plus/es/locale/lang/en' import en from 'element-plus/es/locale/lang/en'
import { useCache } from '@/hooks/web/useCache'
const { wsCache } = useCache()
const elLocaleMap = { const elLocaleMap = {
'zh-CN': zhCn, 'zh-CN': zhCn,
@ -16,8 +19,8 @@ export const useLocaleStore = defineStore('locales', {
state: (): LocaleState => { state: (): LocaleState => {
return { return {
currentLocale: { currentLocale: {
lang: 'zh-CN', lang: wsCache.get('lang') || 'zh-CN',
elLocale: elLocaleMap['zh-CN'] elLocale: elLocaleMap[wsCache.get('lang') || 'zh-CN']
}, },
// 多语言 // 多语言
localeMap: [ localeMap: [
@ -32,7 +35,6 @@ export const useLocaleStore = defineStore('locales', {
] ]
} }
}, },
persist: true,
getters: { getters: {
getCurrentLocale(): LocaleDropdownType { getCurrentLocale(): LocaleDropdownType {
return this.currentLocale return this.currentLocale
@ -46,7 +48,7 @@ export const useLocaleStore = defineStore('locales', {
// this.locale = Object.assign(this.locale, localeMap) // this.locale = Object.assign(this.locale, localeMap)
this.currentLocale.lang = localeMap?.lang this.currentLocale.lang = localeMap?.lang
this.currentLocale.elLocale = elLocaleMap[localeMap?.lang] this.currentLocale.elLocale = elLocaleMap[localeMap?.lang]
// wsCache.set('lang', localeMap?.lang) wsCache.set('lang', localeMap?.lang)
} }
} }
}) })

View File

@ -18,7 +18,6 @@ export const usePermissionStore = defineStore('permission', {
isAddRouters: false, isAddRouters: false,
menuTabRouters: [] menuTabRouters: []
}), }),
persist: true,
getters: { getters: {
getRouters(): AppRouteRecordRaw[] { getRouters(): AppRouteRecordRaw[] {
return this.routers return this.routers