From 5939ec9131fdbfc1a76b917dba83bd97b99f36ad Mon Sep 17 00:00:00 2001 From: chenjiabin <80477286@163.com> Date: Wed, 14 May 2025 16:32:27 +0800 Subject: [PATCH] =?UTF-8?q?1.=E4=BF=AE=E5=A4=8D=E5=9B=A0permission.ts?= =?UTF-8?q?=E3=80=81usePageLoading.ts=E4=B8=8EuseTitle.ts=E5=9C=A8?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96Pinia=E4=B9=8B=E5=89=8D=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E5=AF=BC=E8=87=B4=E6=97=A0=E6=B3=95=E5=AD=98=E5=82=A8?= =?UTF-8?q?=E5=BA=94=E7=94=A8=E9=85=8D=E7=BD=AE=E9=97=AE=E9=A2=98(app.ts?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E9=85=8D=E7=BD=AE=E4=BB=A4=E7=89=8C)?= =?UTF-8?q?=EF=BC=8C=E5=B0=86permission.ts=E4=B8=AD=E8=B0=83=E7=94=A8useAp?= =?UTF-8?q?pStoreWithOut()=E7=9A=84=E4=BD=8D=E7=BD=AE=E6=94=B9=E4=B8=BA?= =?UTF-8?q?=E8=B7=AF=E7=94=B1=E5=AE=88=E5=8D=AB=E4=B8=AD=E8=B0=83=E7=94=A8?= =?UTF-8?q?=EF=BC=8C=E5=90=8C=E6=AD=A5=E4=BF=AE=E6=94=B9=E5=8F=A6=E5=A4=96?= =?UTF-8?q?=E4=B8=A4=E4=B8=AA=E6=96=87=E4=BB=B6=E7=9A=84=E8=B0=83=E7=94=A8?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E3=80=82=202.=E4=BF=AE=E5=A4=8D=E6=B0=B4?= =?UTF-8?q?=E5=8D=B0=E8=AE=BE=E7=BD=AE=E5=90=8E=E5=88=B7=E6=96=B0=E5=B0=B1?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E4=BA=86=E7=9A=84=E9=97=AE=E9=A2=98;?= =?UTF-8?q?=E6=B0=B4=E5=8D=B0=E8=AE=BE=E7=BD=AE=E8=BE=93=E5=85=A5=E6=A1=86?= =?UTF-8?q?=E6=94=B9=E4=B8=BA=E5=9B=BA=E5=AE=9A=E5=AE=BD=EF=BC=8C=E4=BB=A5?= =?UTF-8?q?=E9=98=B2=E6=AD=A2label=E8=A2=AB=E6=8C=A4=E5=8E=8B=E3=80=82=203?= =?UTF-8?q?.=E4=BF=AE=E6=94=B9app.ts=E4=B8=AD=E7=9A=84=E5=AD=98=E5=82=A8?= =?UTF-8?q?=EF=BC=8C=E5=B0=86useCache=E5=AD=98=E5=82=A8=E7=9A=84=E4=B8=AA?= =?UTF-8?q?=E5=88=AB=E9=85=8D=E7=BD=AE=E9=83=BD=E6=94=B9=E4=B8=BApinia?= =?UTF-8?q?=E5=AD=98=E5=82=A8=EF=BC=88pinia=E5=AD=98=E5=82=A8=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=BF=AE=E5=A4=8D=E5=90=8E=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 7 +++-- src/hooks/web/usePageLoading.ts | 3 +- src/hooks/web/useTitle.ts | 4 +-- src/hooks/web/useWatermark.ts | 25 ++++++----------- .../src/components/InterfaceDisplay.vue | 12 ++++---- src/permission.ts | 4 +-- src/store/modules/app.ts | 28 +++++++++---------- 7 files changed, 39 insertions(+), 44 deletions(-) diff --git a/src/App.vue b/src/App.vue index 7407d97ad..18058a5c0 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,8 +2,8 @@ import { isDark } from '@/utils/is' import { useAppStore } from '@/store/modules/app' import { useDesign } from '@/hooks/web/useDesign' -import { CACHE_KEY, useCache } from '@/hooks/web/useCache' import routerSearch from '@/components/RouterSearch/index.vue' +import { useWatermark } from '@/hooks/web/useWatermark' defineOptions({ name: 'APP' }) @@ -12,17 +12,18 @@ const prefixCls = getPrefixCls('app') const appStore = useAppStore() const currentSize = computed(() => appStore.getCurrentSize) const greyMode = computed(() => appStore.getGreyMode) -const { wsCache } = useCache() +const { setWatermark } = useWatermark() // 根据浏览器当前主题设置系统主题色 const setDefaultTheme = () => { - let isDarkTheme = wsCache.get(CACHE_KEY.IS_DARK) + let isDarkTheme = appStore.isDark if (isDarkTheme === null) { isDarkTheme = isDark() } appStore.setIsDark(isDarkTheme) } setDefaultTheme() +setWatermark(appStore.getWatermark) diff --git a/src/permission.ts b/src/permission.ts index b04bc3c13..e6cb31327 100644 --- a/src/permission.ts +++ b/src/permission.ts @@ -11,8 +11,6 @@ import { usePermissionStoreWithOut } from '@/store/modules/permission' const { start, done } = useNProgress() -const { loadStart, loadDone } = usePageLoading() - const parseURL = ( url: string | null | undefined ): { basePath: string; paramsObject: { [key: string]: string } } => { @@ -58,6 +56,7 @@ const whiteList = [ // 路由加载前 router.beforeEach(async (to, from, next) => { + const { loadStart } = usePageLoading() start() loadStart() if (getAccessToken()) { @@ -100,6 +99,7 @@ router.beforeEach(async (to, from, next) => { }) router.afterEach((to) => { + const { loadDone } = usePageLoading() useTitle(to?.meta?.title as string) done() // 结束Progress loadDone() diff --git a/src/store/modules/app.ts b/src/store/modules/app.ts index e3d6a56f3..c0c372e86 100644 --- a/src/store/modules/app.ts +++ b/src/store/modules/app.ts @@ -2,13 +2,10 @@ import { defineStore } from 'pinia' import { store } from '../index' import { humpToUnderline, setCssVar } from '@/utils' import { ElMessage } from 'element-plus' -import { CACHE_KEY, useCache } from '@/hooks/web/useCache' import { ElementPlusSize } from '@/types/elementPlus' import { LayoutType } from '@/types/layout' import { ThemeTypes } from '@/types/theme' -const { wsCache } = useCache() - interface AppState { breadcrumb: boolean breadcrumbIcon: boolean @@ -37,6 +34,7 @@ interface AppState { footer: boolean theme: ThemeTypes fixedMenu: boolean + watermark: string | null } export const useAppStore = defineStore('app', { @@ -65,12 +63,13 @@ export const useAppStore = defineStore('app', { fixedHeader: true, // 固定toolheader footer: true, // 显示页脚 greyMode: false, // 是否开始灰色模式,用于特殊悼念日 - fixedMenu: wsCache.get('fixedMenu') || false, // 是否固定菜单 + fixedMenu: false, // 是否固定菜单 + watermark: null, - layout: wsCache.get(CACHE_KEY.LAYOUT) || 'classic', // layout布局 - isDark: wsCache.get(CACHE_KEY.IS_DARK) || false, // 是否是暗黑模式 - currentSize: wsCache.get('default') || 'default', // 组件尺寸 - theme: wsCache.get(CACHE_KEY.THEME) || { + layout: 'classic', // layout布局 + isDark: false, // 是否是暗黑模式 + currentSize: 'default', // 组件尺寸 + theme: { // 主题色 elColorPrimary: '#409eff', // 左侧菜单边框颜色 @@ -180,6 +179,9 @@ export const useAppStore = defineStore('app', { }, getFooter(): boolean { return this.footer + }, + getWatermark(): string | null { + return this.watermark } }, actions: { @@ -229,7 +231,6 @@ export const useAppStore = defineStore('app', { this.greyMode = greyMode }, setFixedMenu(fixedMenu: boolean) { - wsCache.set('fixedMenu', fixedMenu) this.fixedMenu = fixedMenu }, setPageLoading(pageLoading: boolean) { @@ -241,7 +242,6 @@ export const useAppStore = defineStore('app', { return } this.layout = layout - wsCache.set(CACHE_KEY.LAYOUT, this.layout) }, setTitle(title: string) { this.title = title @@ -255,18 +255,15 @@ export const useAppStore = defineStore('app', { document.documentElement.classList.add('light') document.documentElement.classList.remove('dark') } - wsCache.set(CACHE_KEY.IS_DARK, this.isDark) }, setCurrentSize(currentSize: ElementPlusSize) { this.currentSize = currentSize - wsCache.set('currentSize', this.currentSize) }, setMobile(mobile: boolean) { this.mobile = mobile }, setTheme(theme: ThemeTypes) { this.theme = Object.assign(this.theme, theme) - wsCache.set(CACHE_KEY.THEME, this.theme) }, setCssVarTheme() { for (const key in this.theme) { @@ -275,9 +272,12 @@ export const useAppStore = defineStore('app', { }, setFooter(footer: boolean) { this.footer = footer + }, + setWatermark(watermark: string|null) { + this.watermark = watermark } }, - persist: false + persist: true }) export const useAppStoreWithOut = () => { -- Gitee