From e59ba74c1269ebf393d1cf1f38d4f777a0ded5e8 Mon Sep 17 00:00:00 2001 From: qsh <> Date: Thu, 1 Aug 2024 18:55:41 +0800 Subject: [PATCH] tj --- src/App.vue | 6 +- src/config/axios/service.ts | 15 ++-- src/directives/permission/hasPermi.ts | 6 +- src/directives/permission/hasRole.ts | 6 +- src/layout/components/Setting/src/Setting.vue | 10 +-- .../components/UserInfo/src/UserInfo.vue | 7 +- src/permission.js | 78 +++++++++++-------- src/store/modules/app.ts | 29 ++++--- src/store/modules/dict.ts | 14 ++-- src/store/modules/permission.ts | 8 +- src/store/modules/user.ts | 14 ++-- src/utils/auth.ts | 47 +++++------ src/utils/permission.ts | 9 +-- src/views/Basic/Menu/MenuForm.vue | 6 +- src/views/Basic/Menu/index.vue | 6 +- src/views/Pers/Setting/Comp/DialogPlan.vue | 1 + 16 files changed, 134 insertions(+), 128 deletions(-) diff --git a/src/App.vue b/src/App.vue index f75478c..97cdad3 100644 --- a/src/App.vue +++ b/src/App.vue @@ -2,19 +2,19 @@ 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 { CACHE_KEY } from '@/hooks/web/useCache' import routerSearch from '@/components/RouterSearch/index.vue' +import cache from '@/plugins/cache' const { getPrefixCls } = useDesign() const prefixCls = getPrefixCls('app') const appStore = useAppStore() const currentSize = computed(() => appStore.getCurrentSize) const greyMode = computed(() => appStore.getGreyMode) -const { wsCache } = useCache() // 根据浏览器当前主题设置系统主题色 const setDefaultTheme = () => { - let isDarkTheme = wsCache.get(CACHE_KEY.IS_DARK) + let isDarkTheme = cache.local.get(CACHE_KEY.IS_DARK) if (isDarkTheme === null) { isDarkTheme = isDark() } diff --git a/src/config/axios/service.ts b/src/config/axios/service.ts index f4749bc..3009121 100644 --- a/src/config/axios/service.ts +++ b/src/config/axios/service.ts @@ -20,7 +20,6 @@ import { import errorCode from './errorCode' import { resetRouter } from '@/router' -import { useCache } from '@/hooks/web/useCache' import cache from '@/plugins/cache' const { result_code, base_url, request_timeout } = config @@ -213,11 +212,10 @@ service.interceptors.response.use( type: 'warning' }).then(() => { // 无访问权限,退出登录 - const { wsCache } = useCache() - const tenantId = wsCache.get('TENANT_ID') - const appId = wsCache.get('App_ID') + const tenantId = cache.local.get('TENANT_ID') + const appId = cache.local.get('App_ID') resetRouter() // 重置静态路由表 - wsCache.clear() + cache.local.clear() removeToken() window.location.href = `/oa/login?tenantId=${tenantId}&appId=${appId}` }) @@ -259,11 +257,10 @@ const handleAuthorized = () => { confirmButtonText: t('login.relogin'), type: 'warning' }).then(() => { - const { wsCache } = useCache() - const tenantId = wsCache.get('TENANT_ID') - const appId = wsCache.get('App_ID') + const tenantId = cache.local.get('TENANT_ID') + const appId = cache.local.get('App_ID') resetRouter() // 重置静态路由表 - wsCache.clear() + cache.local.clear() removeToken() isRelogin.show = false // 干掉token后再走一次路由让它过router.beforeEach的校验 diff --git a/src/directives/permission/hasPermi.ts b/src/directives/permission/hasPermi.ts index 1207464..82fe8d9 100644 --- a/src/directives/permission/hasPermi.ts +++ b/src/directives/permission/hasPermi.ts @@ -1,14 +1,14 @@ import type { App } from 'vue' -import { CACHE_KEY, useCache } from '@/hooks/web/useCache' +import { CACHE_KEY } from '@/hooks/web/useCache' +import cache from '@/plugins/cache' const { t } = useI18n() // 国际化 export function hasPermi(app: App) { app.directive('hasPermi', (el, binding) => { - const { wsCache } = useCache() const { value } = binding const all_permission = '*:*:*' - const permissions = wsCache.get(CACHE_KEY.USER)?.permissions || [] + const permissions = cache.local.get(CACHE_KEY.USER)?.permissions || [] if (value && value instanceof Array && value.length > 0) { const permissionFlag = value diff --git a/src/directives/permission/hasRole.ts b/src/directives/permission/hasRole.ts index 31a352a..99e80b7 100644 --- a/src/directives/permission/hasRole.ts +++ b/src/directives/permission/hasRole.ts @@ -1,14 +1,14 @@ import type { App } from 'vue' -import { CACHE_KEY, useCache } from '@/hooks/web/useCache' +import { CACHE_KEY } from '@/hooks/web/useCache' +import cache from '@/plugins/cache' const { t } = useI18n() // 国际化 export function hasRole(app: App) { app.directive('hasRole', (el, binding) => { - const { wsCache } = useCache() const { value } = binding const super_admin = 'admin' - const roles = wsCache.get(CACHE_KEY.USER).roles + const roles = cache.local.get(CACHE_KEY.USER).roles if (value && value instanceof Array && value.length > 0) { const roleFlag = value diff --git a/src/layout/components/Setting/src/Setting.vue b/src/layout/components/Setting/src/Setting.vue index 908ed99..90a7000 100644 --- a/src/layout/components/Setting/src/Setting.vue +++ b/src/layout/components/Setting/src/Setting.vue @@ -2,7 +2,7 @@ // import { ElMessage } from 'element-plus' // import { useClipboard, useCssVar } from '@vueuse/core' import { useCssVar } from '@vueuse/core' -import { CACHE_KEY, useCache } from '@/hooks/web/useCache' +import { CACHE_KEY } from '@/hooks/web/useCache' import { useDesign } from '@/hooks/web/useDesign' import { setCssVar, trim } from '@/utils' @@ -13,6 +13,7 @@ import ColorRadioPicker from './components/ColorRadioPicker.vue' // import InterfaceDisplay from './components/InterfaceDisplay.vue' // import LayoutRadioPicker from './components/LayoutRadioPicker.vue' import { useWatermark } from '@/hooks/web/useWatermark' +import cache from '@/plugins/cache' const { setWatermark } = useWatermark() @@ -195,10 +196,9 @@ watch( // 清空缓存 const clear = () => { - const { wsCache } = useCache() - wsCache.delete(CACHE_KEY.LAYOUT) - wsCache.delete(CACHE_KEY.THEME) - wsCache.delete(CACHE_KEY.IS_DARK) + cache.local.delete(CACHE_KEY.LAYOUT) + cache.local.delete(CACHE_KEY.THEME) + cache.local.delete(CACHE_KEY.IS_DARK) window.location.reload() } diff --git a/src/layout/components/UserInfo/src/UserInfo.vue b/src/layout/components/UserInfo/src/UserInfo.vue index d305009..a6f049b 100644 --- a/src/layout/components/UserInfo/src/UserInfo.vue +++ b/src/layout/components/UserInfo/src/UserInfo.vue @@ -1,7 +1,7 @@