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 a65905b..a4a7ec7 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 = `/crm/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..97f92b0 100644 --- a/src/layout/components/Setting/src/Setting.vue +++ b/src/layout/components/Setting/src/Setting.vue @@ -2,8 +2,9 @@ // 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 cache from '@/plugins/cache' import { setCssVar, trim } from '@/utils' import { colorIsDark, hexToRGB, lighten } from '@/utils/color' @@ -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..27a7f7e 100644 --- a/src/layout/components/UserInfo/src/UserInfo.vue +++ b/src/layout/components/UserInfo/src/UserInfo.vue @@ -1,19 +1,18 @@