tj
This commit is contained in:
@@ -2,19 +2,19 @@
|
|||||||
import { isDark } from '@/utils/is'
|
import { isDark } from '@/utils/is'
|
||||||
import { useAppStore } from '@/store/modules/app'
|
import { useAppStore } from '@/store/modules/app'
|
||||||
import { useDesign } from '@/hooks/web/useDesign'
|
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 routerSearch from '@/components/RouterSearch/index.vue'
|
||||||
|
import cache from '@/plugins/cache'
|
||||||
|
|
||||||
const { getPrefixCls } = useDesign()
|
const { getPrefixCls } = useDesign()
|
||||||
const prefixCls = getPrefixCls('app')
|
const prefixCls = getPrefixCls('app')
|
||||||
const appStore = useAppStore()
|
const appStore = useAppStore()
|
||||||
const currentSize = computed(() => appStore.getCurrentSize)
|
const currentSize = computed(() => appStore.getCurrentSize)
|
||||||
const greyMode = computed(() => appStore.getGreyMode)
|
const greyMode = computed(() => appStore.getGreyMode)
|
||||||
const { wsCache } = useCache()
|
|
||||||
|
|
||||||
// 根据浏览器当前主题设置系统主题色
|
// 根据浏览器当前主题设置系统主题色
|
||||||
const setDefaultTheme = () => {
|
const setDefaultTheme = () => {
|
||||||
let isDarkTheme = wsCache.get(CACHE_KEY.IS_DARK)
|
let isDarkTheme = cache.local.get(CACHE_KEY.IS_DARK)
|
||||||
if (isDarkTheme === null) {
|
if (isDarkTheme === null) {
|
||||||
isDarkTheme = isDark()
|
isDarkTheme = isDark()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ import {
|
|||||||
import errorCode from './errorCode'
|
import errorCode from './errorCode'
|
||||||
|
|
||||||
import { resetRouter } from '@/router'
|
import { resetRouter } from '@/router'
|
||||||
import { useCache } from '@/hooks/web/useCache'
|
|
||||||
import cache from '@/plugins/cache'
|
import cache from '@/plugins/cache'
|
||||||
|
|
||||||
const { result_code, base_url, request_timeout } = config
|
const { result_code, base_url, request_timeout } = config
|
||||||
@@ -213,11 +212,10 @@ service.interceptors.response.use(
|
|||||||
type: 'warning'
|
type: 'warning'
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
// 无访问权限,退出登录
|
// 无访问权限,退出登录
|
||||||
const { wsCache } = useCache()
|
const tenantId = cache.local.get('TENANT_ID')
|
||||||
const tenantId = wsCache.get('TENANT_ID')
|
const appId = cache.local.get('App_ID')
|
||||||
const appId = wsCache.get('App_ID')
|
|
||||||
resetRouter() // 重置静态路由表
|
resetRouter() // 重置静态路由表
|
||||||
wsCache.clear()
|
cache.local.clear()
|
||||||
removeToken()
|
removeToken()
|
||||||
window.location.href = `/oa/login?tenantId=${tenantId}&appId=${appId}`
|
window.location.href = `/oa/login?tenantId=${tenantId}&appId=${appId}`
|
||||||
})
|
})
|
||||||
@@ -259,11 +257,10 @@ const handleAuthorized = () => {
|
|||||||
confirmButtonText: t('login.relogin'),
|
confirmButtonText: t('login.relogin'),
|
||||||
type: 'warning'
|
type: 'warning'
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
const { wsCache } = useCache()
|
const tenantId = cache.local.get('TENANT_ID')
|
||||||
const tenantId = wsCache.get('TENANT_ID')
|
const appId = cache.local.get('App_ID')
|
||||||
const appId = wsCache.get('App_ID')
|
|
||||||
resetRouter() // 重置静态路由表
|
resetRouter() // 重置静态路由表
|
||||||
wsCache.clear()
|
cache.local.clear()
|
||||||
removeToken()
|
removeToken()
|
||||||
isRelogin.show = false
|
isRelogin.show = false
|
||||||
// 干掉token后再走一次路由让它过router.beforeEach的校验
|
// 干掉token后再走一次路由让它过router.beforeEach的校验
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import type { App } from 'vue'
|
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() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
|
|
||||||
export function hasPermi(app: App<Element>) {
|
export function hasPermi(app: App<Element>) {
|
||||||
app.directive('hasPermi', (el, binding) => {
|
app.directive('hasPermi', (el, binding) => {
|
||||||
const { wsCache } = useCache()
|
|
||||||
const { value } = binding
|
const { value } = binding
|
||||||
const all_permission = '*:*:*'
|
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) {
|
if (value && value instanceof Array && value.length > 0) {
|
||||||
const permissionFlag = value
|
const permissionFlag = value
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import type { App } from 'vue'
|
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() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
|
|
||||||
export function hasRole(app: App<Element>) {
|
export function hasRole(app: App<Element>) {
|
||||||
app.directive('hasRole', (el, binding) => {
|
app.directive('hasRole', (el, binding) => {
|
||||||
const { wsCache } = useCache()
|
|
||||||
const { value } = binding
|
const { value } = binding
|
||||||
const super_admin = 'admin'
|
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) {
|
if (value && value instanceof Array && value.length > 0) {
|
||||||
const roleFlag = value
|
const roleFlag = value
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// import { ElMessage } from 'element-plus'
|
// import { ElMessage } from 'element-plus'
|
||||||
// import { useClipboard, useCssVar } from '@vueuse/core'
|
// import { useClipboard, useCssVar } from '@vueuse/core'
|
||||||
import { 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 { useDesign } from '@/hooks/web/useDesign'
|
||||||
|
|
||||||
import { setCssVar, trim } from '@/utils'
|
import { setCssVar, trim } from '@/utils'
|
||||||
@@ -13,6 +13,7 @@ import ColorRadioPicker from './components/ColorRadioPicker.vue'
|
|||||||
// import InterfaceDisplay from './components/InterfaceDisplay.vue'
|
// import InterfaceDisplay from './components/InterfaceDisplay.vue'
|
||||||
// import LayoutRadioPicker from './components/LayoutRadioPicker.vue'
|
// import LayoutRadioPicker from './components/LayoutRadioPicker.vue'
|
||||||
import { useWatermark } from '@/hooks/web/useWatermark'
|
import { useWatermark } from '@/hooks/web/useWatermark'
|
||||||
|
import cache from '@/plugins/cache'
|
||||||
|
|
||||||
const { setWatermark } = useWatermark()
|
const { setWatermark } = useWatermark()
|
||||||
|
|
||||||
@@ -195,10 +196,9 @@ watch(
|
|||||||
|
|
||||||
// 清空缓存
|
// 清空缓存
|
||||||
const clear = () => {
|
const clear = () => {
|
||||||
const { wsCache } = useCache()
|
cache.local.delete(CACHE_KEY.LAYOUT)
|
||||||
wsCache.delete(CACHE_KEY.LAYOUT)
|
cache.local.delete(CACHE_KEY.THEME)
|
||||||
wsCache.delete(CACHE_KEY.THEME)
|
cache.local.delete(CACHE_KEY.IS_DARK)
|
||||||
wsCache.delete(CACHE_KEY.IS_DARK)
|
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
<script lang="ts" name="UserInfo" setup>
|
<script lang="ts" name="UserInfo" setup>
|
||||||
import { ElMessageBox } from 'element-plus'
|
import { ElMessageBox } from 'element-plus'
|
||||||
|
|
||||||
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
import { CACHE_KEY } from '@/hooks/web/useCache'
|
||||||
import { useDesign } from '@/hooks/web/useDesign'
|
import { useDesign } from '@/hooks/web/useDesign'
|
||||||
import avatarImg from '@/assets/imgs/avatar.gif'
|
import avatarImg from '@/assets/imgs/avatar.gif'
|
||||||
import { useUserStore } from '@/store/modules/user'
|
import { useUserStore } from '@/store/modules/user'
|
||||||
@@ -9,11 +9,10 @@ import { useTagsViewStore } from '@/store/modules/tagsView'
|
|||||||
import { getTenantId, getAppId } from '@/utils/auth'
|
import { getTenantId, getAppId } from '@/utils/auth'
|
||||||
|
|
||||||
import { Setting } from '@/layout/components/Setting'
|
import { Setting } from '@/layout/components/Setting'
|
||||||
|
import cache from '@/plugins/cache'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
const { wsCache } = useCache()
|
|
||||||
|
|
||||||
const { push, replace } = useRouter()
|
const { push, replace } = useRouter()
|
||||||
|
|
||||||
const userStore = useUserStore()
|
const userStore = useUserStore()
|
||||||
@@ -24,7 +23,7 @@ const { getPrefixCls } = useDesign()
|
|||||||
|
|
||||||
const prefixCls = getPrefixCls('user-info')
|
const prefixCls = getPrefixCls('user-info')
|
||||||
|
|
||||||
const user = wsCache.get(CACHE_KEY.USER)
|
const user = cache.local.get(CACHE_KEY.USER)
|
||||||
|
|
||||||
const avatar = user.user.avatar ? user.user.avatar : avatarImg
|
const avatar = user.user.avatar ? user.user.avatar : avatarImg
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { useDictStoreWithOut } from '@/store/modules/dict'
|
|||||||
import { useUserStoreWithOut } from '@/store/modules/user'
|
import { useUserStoreWithOut } from '@/store/modules/user'
|
||||||
import { usePermissionStoreWithOut } from '@/store/modules/permission'
|
import { usePermissionStoreWithOut } from '@/store/modules/permission'
|
||||||
import { getTenantId, getAppId } from '@/utils/auth'
|
import { getTenantId, getAppId } from '@/utils/auth'
|
||||||
|
import cache from '@/plugins/cache'
|
||||||
|
|
||||||
const { start, done } = useNProgress()
|
const { start, done } = useNProgress()
|
||||||
|
|
||||||
@@ -19,6 +20,14 @@ const whiteList = ['/login', '/social-login', '/auth-redirect', '/bind', '/regis
|
|||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
start()
|
start()
|
||||||
loadStart()
|
loadStart()
|
||||||
|
if (getAppId() && to.query?.appId && getAppId() != to.query?.appId) {
|
||||||
|
removeToken()
|
||||||
|
cache?.local?.delete('appInfo')
|
||||||
|
cache?.local?.delete('roleRouters')
|
||||||
|
cache?.local?.delete('user')
|
||||||
|
cache?.local?.delete('App_ID')
|
||||||
|
next(`/login?tenantId=${to.query?.tenantId}&appId=${to.query?.appId}`)
|
||||||
|
} else {
|
||||||
if (getAccessToken()) {
|
if (getAccessToken()) {
|
||||||
if (to.path === '/login') {
|
if (to.path === '/login') {
|
||||||
next({ path: '/' })
|
next({ path: '/' })
|
||||||
@@ -60,6 +69,7 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
router.afterEach((to) => {
|
router.afterEach((to) => {
|
||||||
|
|||||||
@@ -2,14 +2,13 @@ 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 { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
import { CACHE_KEY } from '@/hooks/web/useCache'
|
||||||
import { ElementPlusSize } from '@/types/elementPlus'
|
import { ElementPlusSize } from '@/types/elementPlus'
|
||||||
import { LayoutType } from '@/types/layout'
|
import { LayoutType } from '@/types/layout'
|
||||||
import { ThemeTypes } from '@/types/theme'
|
import { ThemeTypes } from '@/types/theme'
|
||||||
import { getAppInfo } from '@/api/login'
|
import { getAppInfo } from '@/api/login'
|
||||||
|
|
||||||
const { wsCache } = useCache()
|
import cache from '@/plugins/cache'
|
||||||
|
|
||||||
interface AppState {
|
interface AppState {
|
||||||
breadcrumb: boolean
|
breadcrumb: boolean
|
||||||
breadcrumbIcon: boolean
|
breadcrumbIcon: boolean
|
||||||
@@ -46,7 +45,7 @@ export const useAppStore = defineStore('app', {
|
|||||||
sizeMap: ['default', 'large', 'small'],
|
sizeMap: ['default', 'large', 'small'],
|
||||||
mobile: false, // 是否是移动端
|
mobile: false, // 是否是移动端
|
||||||
title: import.meta.env.VITE_APP_TITLE, // 标题
|
title: import.meta.env.VITE_APP_TITLE, // 标题
|
||||||
appInfo: wsCache.get('appInfo'),
|
appInfo: cache.local.get('appInfo'),
|
||||||
pageLoading: false, // 路由跳转loading
|
pageLoading: false, // 路由跳转loading
|
||||||
|
|
||||||
breadcrumb: true, // 面包屑
|
breadcrumb: true, // 面包屑
|
||||||
@@ -64,12 +63,12 @@ export const useAppStore = defineStore('app', {
|
|||||||
fixedHeader: true, // 固定toolheader
|
fixedHeader: true, // 固定toolheader
|
||||||
footer: false, // 显示页脚
|
footer: false, // 显示页脚
|
||||||
greyMode: false, // 是否开始灰色模式,用于特殊悼念日
|
greyMode: false, // 是否开始灰色模式,用于特殊悼念日
|
||||||
fixedMenu: wsCache.get('fixedMenu') || false, // 是否固定菜单
|
fixedMenu: cache.local.get('fixedMenu') || false, // 是否固定菜单
|
||||||
|
|
||||||
layout: wsCache.get(CACHE_KEY.LAYOUT) || 'classic', // layout布局
|
layout: cache.local.get(CACHE_KEY.LAYOUT) || 'classic', // layout布局
|
||||||
isDark: wsCache.get(CACHE_KEY.IS_DARK) || false, // 是否是暗黑模式
|
isDark: cache.local.get(CACHE_KEY.IS_DARK) || false, // 是否是暗黑模式
|
||||||
currentSize: wsCache.get('default') || 'default', // 组件尺寸
|
currentSize: cache.local.get('default') || 'default', // 组件尺寸
|
||||||
theme: wsCache.get(CACHE_KEY.THEME) || {
|
theme: cache.local.get(CACHE_KEY.THEME) || {
|
||||||
// 主题色
|
// 主题色
|
||||||
elColorPrimary: '#409eff',
|
elColorPrimary: '#409eff',
|
||||||
// 左侧菜单边框颜色
|
// 左侧菜单边框颜色
|
||||||
@@ -225,7 +224,7 @@ export const useAppStore = defineStore('app', {
|
|||||||
this.greyMode = greyMode
|
this.greyMode = greyMode
|
||||||
},
|
},
|
||||||
setFixedMenu(fixedMenu: boolean) {
|
setFixedMenu(fixedMenu: boolean) {
|
||||||
wsCache.set('fixedMenu', fixedMenu)
|
cache.local.set('fixedMenu', fixedMenu)
|
||||||
this.fixedMenu = fixedMenu
|
this.fixedMenu = fixedMenu
|
||||||
},
|
},
|
||||||
setPageLoading(pageLoading: boolean) {
|
setPageLoading(pageLoading: boolean) {
|
||||||
@@ -237,7 +236,7 @@ export const useAppStore = defineStore('app', {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.layout = layout
|
this.layout = layout
|
||||||
wsCache.set(CACHE_KEY.LAYOUT, this.layout)
|
cache.local.set(CACHE_KEY.LAYOUT, this.layout)
|
||||||
},
|
},
|
||||||
setTitle(title: string) {
|
setTitle(title: string) {
|
||||||
this.title = title
|
this.title = title
|
||||||
@@ -251,18 +250,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(CACHE_KEY.IS_DARK, this.isDark)
|
cache.local.set(CACHE_KEY.IS_DARK, this.isDark)
|
||||||
},
|
},
|
||||||
setCurrentSize(currentSize: ElementPlusSize) {
|
setCurrentSize(currentSize: ElementPlusSize) {
|
||||||
this.currentSize = currentSize
|
this.currentSize = currentSize
|
||||||
wsCache.set('currentSize', this.currentSize)
|
cache.local.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(CACHE_KEY.THEME, this.theme)
|
cache.local.set(CACHE_KEY.THEME, this.theme)
|
||||||
},
|
},
|
||||||
setCssVarTheme() {
|
setCssVarTheme() {
|
||||||
for (const key in this.theme) {
|
for (const key in this.theme) {
|
||||||
@@ -274,7 +273,7 @@ export const useAppStore = defineStore('app', {
|
|||||||
},
|
},
|
||||||
async setAppInfo(appId: number) {
|
async setAppInfo(appId: number) {
|
||||||
const appInfo = await getAppInfo(appId)
|
const appInfo = await getAppInfo(appId)
|
||||||
wsCache.set('appInfo', appInfo)
|
cache.local.set('appInfo', appInfo)
|
||||||
this.appInfo = appInfo
|
this.appInfo = appInfo
|
||||||
return appInfo
|
return appInfo
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,9 @@ import { defineStore } from 'pinia'
|
|||||||
import { store } from '../index'
|
import { store } from '../index'
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
import { DictDataVO } from '@/api/system/dict/types'
|
import { DictDataVO } from '@/api/system/dict/types'
|
||||||
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
import { CACHE_KEY } from '@/hooks/web/useCache'
|
||||||
const { wsCache } = useCache('sessionStorage')
|
|
||||||
import { listSimpleDictData } from '@/api/system/dict/dict.data'
|
import { listSimpleDictData } from '@/api/system/dict/dict.data'
|
||||||
|
import cache from '@/plugins/cache'
|
||||||
|
|
||||||
export interface DictValueType {
|
export interface DictValueType {
|
||||||
value: any
|
value: any
|
||||||
@@ -28,7 +28,7 @@ export const useDictStore = defineStore('dict', {
|
|||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
getDictMap(): Recordable {
|
getDictMap(): Recordable {
|
||||||
const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE)
|
const dictMap = cache.session.get(CACHE_KEY.DICT_CACHE)
|
||||||
if (dictMap) {
|
if (dictMap) {
|
||||||
this.dictMap = dictMap
|
this.dictMap = dictMap
|
||||||
}
|
}
|
||||||
@@ -40,7 +40,7 @@ export const useDictStore = defineStore('dict', {
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
async setDictMap() {
|
async setDictMap() {
|
||||||
const dictMap = wsCache.get(CACHE_KEY.DICT_CACHE)
|
const dictMap = cache.session.get(CACHE_KEY.DICT_CACHE)
|
||||||
if (dictMap) {
|
if (dictMap) {
|
||||||
this.dictMap = dictMap
|
this.dictMap = dictMap
|
||||||
this.isSetDict = true
|
this.isSetDict = true
|
||||||
@@ -64,7 +64,7 @@ export const useDictStore = defineStore('dict', {
|
|||||||
})
|
})
|
||||||
this.dictMap = dictDataMap
|
this.dictMap = dictDataMap
|
||||||
this.isSetDict = true
|
this.isSetDict = true
|
||||||
wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期
|
cache.session.set(CACHE_KEY.DICT_CACHE, dictDataMap) // 60 秒 过期
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
getDictByType(type: string) {
|
getDictByType(type: string) {
|
||||||
@@ -74,7 +74,7 @@ export const useDictStore = defineStore('dict', {
|
|||||||
return this.dictMap[type]
|
return this.dictMap[type]
|
||||||
},
|
},
|
||||||
async resetDict() {
|
async resetDict() {
|
||||||
wsCache.delete(CACHE_KEY.DICT_CACHE)
|
cache.session.delete(CACHE_KEY.DICT_CACHE)
|
||||||
const res = await listSimpleDictData()
|
const res = await listSimpleDictData()
|
||||||
// 设置数据
|
// 设置数据
|
||||||
const dictDataMap = new Map<string, any>()
|
const dictDataMap = new Map<string, any>()
|
||||||
@@ -94,7 +94,7 @@ export const useDictStore = defineStore('dict', {
|
|||||||
})
|
})
|
||||||
this.dictMap = dictDataMap
|
this.dictMap = dictDataMap
|
||||||
this.isSetDict = true
|
this.isSetDict = true
|
||||||
wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期
|
cache.session.set(CACHE_KEY.DICT_CACHE, dictDataMap) // 60 秒 过期
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ import { store } from '../index'
|
|||||||
import { cloneDeep } from 'lodash-es'
|
import { cloneDeep } from 'lodash-es'
|
||||||
import remainingRouter from '@/router/modules/remaining'
|
import remainingRouter from '@/router/modules/remaining'
|
||||||
import { generateRoute, flatMultiLevelRoutes } from '@/utils/routerHelper'
|
import { generateRoute, flatMultiLevelRoutes } from '@/utils/routerHelper'
|
||||||
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
import { CACHE_KEY } from '@/hooks/web/useCache'
|
||||||
|
|
||||||
const { wsCache } = useCache()
|
import cache from '@/plugins/cache'
|
||||||
|
|
||||||
export interface PermissionState {
|
export interface PermissionState {
|
||||||
routers: AppRouteRecordRaw[]
|
routers: AppRouteRecordRaw[]
|
||||||
@@ -34,8 +34,8 @@ export const usePermissionStore = defineStore('permission', {
|
|||||||
async generateRoutes(): Promise<unknown> {
|
async generateRoutes(): Promise<unknown> {
|
||||||
return new Promise<void>(async (resolve) => {
|
return new Promise<void>(async (resolve) => {
|
||||||
let res: AppCustomRouteRecordRaw[] = []
|
let res: AppCustomRouteRecordRaw[] = []
|
||||||
if (wsCache.get(CACHE_KEY.ROLE_ROUTERS)) {
|
if (cache.local.get(CACHE_KEY.ROLE_ROUTERS)) {
|
||||||
res = wsCache.get(CACHE_KEY.ROLE_ROUTERS) as AppCustomRouteRecordRaw[]
|
res = cache.local.get(CACHE_KEY.ROLE_ROUTERS) as AppCustomRouteRecordRaw[]
|
||||||
}
|
}
|
||||||
const routerMap: AppRouteRecordRaw[] = generateRoute(res)
|
const routerMap: AppRouteRecordRaw[] = generateRoute(res)
|
||||||
// 动态路由,404一定要放到最后面
|
// 动态路由,404一定要放到最后面
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import { store } from '../index'
|
import { store } from '../index'
|
||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import { getAccessToken, removeToken } from '@/utils/auth'
|
import { getAccessToken, removeToken } from '@/utils/auth'
|
||||||
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
import { CACHE_KEY } from '@/hooks/web/useCache'
|
||||||
import { getInfo, loginOut } from '@/api/login'
|
import { getInfo, loginOut } from '@/api/login'
|
||||||
|
|
||||||
const { wsCache } = useCache()
|
import cache from '@/plugins/cache'
|
||||||
|
|
||||||
interface UserVO {
|
interface UserVO {
|
||||||
id: number
|
id: number
|
||||||
@@ -49,7 +49,7 @@ export const useUserStore = defineStore('admin-user', {
|
|||||||
this.resetState()
|
this.resetState()
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
let userInfo = wsCache.get(CACHE_KEY.USER)
|
let userInfo = cache.local.get(CACHE_KEY.USER)
|
||||||
if (!userInfo) {
|
if (!userInfo) {
|
||||||
userInfo = await getInfo({})
|
userInfo = await getInfo({})
|
||||||
}
|
}
|
||||||
@@ -57,13 +57,13 @@ export const useUserStore = defineStore('admin-user', {
|
|||||||
this.roles = userInfo.roles
|
this.roles = userInfo.roles
|
||||||
this.user = userInfo.user
|
this.user = userInfo.user
|
||||||
this.isSetUser = true
|
this.isSetUser = true
|
||||||
wsCache.set(CACHE_KEY.USER, userInfo)
|
cache.local.set(CACHE_KEY.USER, userInfo)
|
||||||
wsCache.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus)
|
cache.local.set(CACHE_KEY.ROLE_ROUTERS, userInfo.menus)
|
||||||
},
|
},
|
||||||
async loginOut() {
|
async loginOut() {
|
||||||
await loginOut()
|
await loginOut()
|
||||||
removeToken()
|
removeToken()
|
||||||
wsCache.clear()
|
cache.local.clear()
|
||||||
this.resetState()
|
this.resetState()
|
||||||
},
|
},
|
||||||
resetState() {
|
resetState() {
|
||||||
@@ -77,7 +77,7 @@ export const useUserStore = defineStore('admin-user', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
refresh() {
|
refresh() {
|
||||||
wsCache.delete(CACHE_KEY.USER)
|
cache.local.delete(CACHE_KEY.USER)
|
||||||
this.resetState()
|
this.resetState()
|
||||||
window.location.href = ''
|
window.location.href = ''
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
import { useCache } from '@/hooks/web/useCache'
|
|
||||||
import { TokenType } from '@/api/login/types'
|
import { TokenType } from '@/api/login/types'
|
||||||
import { decrypt, encrypt } from '@/utils/jsencrypt'
|
import { decrypt, encrypt } from '@/utils/jsencrypt'
|
||||||
|
|
||||||
const { wsCache } = useCache()
|
import cache from '@/plugins/cache'
|
||||||
|
|
||||||
const AccessTokenKey = 'ACCESS_TOKEN'
|
const AccessTokenKey = 'ACCESS_TOKEN'
|
||||||
const RefreshTokenKey = 'REFRESH_TOKEN'
|
const RefreshTokenKey = 'REFRESH_TOKEN'
|
||||||
@@ -10,24 +9,26 @@ const RefreshTokenKey = 'REFRESH_TOKEN'
|
|||||||
// 获取token
|
// 获取token
|
||||||
export const getAccessToken = () => {
|
export const getAccessToken = () => {
|
||||||
// 此处与TokenKey相同,此写法解决初始化时Cookies中不存在TokenKey报错
|
// 此处与TokenKey相同,此写法解决初始化时Cookies中不存在TokenKey报错
|
||||||
return wsCache.get(AccessTokenKey) ? wsCache.get(AccessTokenKey) : wsCache.get('ACCESS_TOKEN')
|
return cache.local.get(AccessTokenKey)
|
||||||
|
? cache.local.get(AccessTokenKey)
|
||||||
|
: cache.local.get('ACCESS_TOKEN')
|
||||||
}
|
}
|
||||||
|
|
||||||
// 刷新token
|
// 刷新token
|
||||||
export const getRefreshToken = () => {
|
export const getRefreshToken = () => {
|
||||||
return wsCache.get(RefreshTokenKey)
|
return cache.local.get(RefreshTokenKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置token
|
// 设置token
|
||||||
export const setToken = (token: TokenType) => {
|
export const setToken = (token: TokenType) => {
|
||||||
wsCache.set(RefreshTokenKey, token.refreshToken, { exp: token.expiresTime })
|
cache.local.set(RefreshTokenKey, token.refreshToken)
|
||||||
wsCache.set(AccessTokenKey, token.accessToken)
|
cache.local.set(AccessTokenKey, token.accessToken)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 删除token
|
// 删除token
|
||||||
export const removeToken = () => {
|
export const removeToken = () => {
|
||||||
wsCache.delete(AccessTokenKey)
|
cache.local.delete(AccessTokenKey)
|
||||||
wsCache.delete(RefreshTokenKey)
|
cache.local.delete(RefreshTokenKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** 格式化token(jwt格式) */
|
/** 格式化token(jwt格式) */
|
||||||
@@ -47,7 +48,7 @@ export type LoginFormType = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const getLoginForm = () => {
|
export const getLoginForm = () => {
|
||||||
const loginForm: LoginFormType = wsCache.get(LoginFormKey)
|
const loginForm: LoginFormType = cache.local.get(LoginFormKey)
|
||||||
if (loginForm) {
|
if (loginForm) {
|
||||||
loginForm.password = decrypt(loginForm.password) as string
|
loginForm.password = decrypt(loginForm.password) as string
|
||||||
}
|
}
|
||||||
@@ -56,11 +57,11 @@ export const getLoginForm = () => {
|
|||||||
|
|
||||||
export const setLoginForm = (loginForm: LoginFormType) => {
|
export const setLoginForm = (loginForm: LoginFormType) => {
|
||||||
loginForm.password = encrypt(loginForm.password) as string
|
loginForm.password = encrypt(loginForm.password) as string
|
||||||
wsCache.set(LoginFormKey, loginForm, { exp: 30 * 24 * 60 * 60 })
|
cache.local.set(LoginFormKey, loginForm)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const removeLoginForm = () => {
|
export const removeLoginForm = () => {
|
||||||
wsCache.delete(LoginFormKey)
|
cache.local.delete(LoginFormKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ========== 租户相关 ==========
|
// ========== 租户相关 ==========
|
||||||
@@ -69,52 +70,52 @@ const TenantIdKey = 'TENANT_ID'
|
|||||||
const TenantNameKey = 'TENANT_NAME'
|
const TenantNameKey = 'TENANT_NAME'
|
||||||
|
|
||||||
export const getTenantName = () => {
|
export const getTenantName = () => {
|
||||||
return wsCache.get(TenantNameKey)
|
return cache.local.get(TenantNameKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setTenantName = (username: string) => {
|
export const setTenantName = (username: string) => {
|
||||||
wsCache.set(TenantNameKey, username, { exp: 30 * 24 * 60 * 60 })
|
cache.local.set(TenantNameKey, username)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const removeTenantName = () => {
|
export const removeTenantName = () => {
|
||||||
wsCache.delete(TenantNameKey)
|
cache.local.delete(TenantNameKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getTenantId = () => {
|
export const getTenantId = () => {
|
||||||
return wsCache.get(TenantIdKey)
|
return cache.local.get(TenantIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setTenantId = (username: string) => {
|
export const setTenantId = (username: string) => {
|
||||||
wsCache.set(TenantIdKey, username)
|
cache.local.set(TenantIdKey, username)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const removeTenantId = () => {
|
export const removeTenantId = () => {
|
||||||
wsCache.delete(TenantIdKey)
|
cache.local.delete(TenantIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
const AppIdKey = 'App_ID'
|
const AppIdKey = 'App_ID'
|
||||||
const AppNameKey = 'App_NAME'
|
const AppNameKey = 'App_NAME'
|
||||||
|
|
||||||
export const getAPPName = () => {
|
export const getAPPName = () => {
|
||||||
return wsCache.get(AppNameKey)
|
return cache.local.get(AppNameKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setAppName = (name: string) => {
|
export const setAppName = (name: string) => {
|
||||||
wsCache.set(AppNameKey, name, { exp: 30 * 24 * 60 * 60 })
|
cache.local.set(AppNameKey, name)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const removeAppName = () => {
|
export const removeAppName = () => {
|
||||||
wsCache.delete(AppNameKey)
|
cache.local.delete(AppNameKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getAppId = () => {
|
export const getAppId = () => {
|
||||||
return wsCache.get(AppIdKey)
|
return cache.local.get(AppIdKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setAppId = (id: number) => {
|
export const setAppId = (id: number) => {
|
||||||
wsCache.set(AppIdKey, id)
|
cache.local.set(AppIdKey, id)
|
||||||
}
|
}
|
||||||
|
|
||||||
export const removeAppId = () => {
|
export const removeAppId = () => {
|
||||||
wsCache.delete(AppIdKey)
|
cache.local.delete(AppIdKey)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
import { CACHE_KEY } from '@/hooks/web/useCache'
|
||||||
|
import cache from '@/plugins/cache'
|
||||||
|
|
||||||
const { t } = useI18n() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
|
|
||||||
@@ -9,10 +10,9 @@ const { t } = useI18n() // 国际化
|
|||||||
*/
|
*/
|
||||||
export function checkPermi(value: string[]) {
|
export function checkPermi(value: string[]) {
|
||||||
if (value && value instanceof Array && value.length > 0) {
|
if (value && value instanceof Array && value.length > 0) {
|
||||||
const { wsCache } = useCache()
|
|
||||||
const permissionDatas = value
|
const permissionDatas = value
|
||||||
const all_permission = '*:*:*'
|
const all_permission = '*:*:*'
|
||||||
const permissions = wsCache.get(CACHE_KEY.USER).permissions
|
const permissions = cache.local.get(CACHE_KEY.USER).permissions
|
||||||
const hasPermission = permissions.some((permission) => {
|
const hasPermission = permissions.some((permission) => {
|
||||||
return all_permission === permission || permissionDatas.includes(permission)
|
return all_permission === permission || permissionDatas.includes(permission)
|
||||||
})
|
})
|
||||||
@@ -30,10 +30,9 @@ export function checkPermi(value: string[]) {
|
|||||||
*/
|
*/
|
||||||
export function checkRole(value: string[]) {
|
export function checkRole(value: string[]) {
|
||||||
if (value && value instanceof Array && value.length > 0) {
|
if (value && value instanceof Array && value.length > 0) {
|
||||||
const { wsCache } = useCache()
|
|
||||||
const permissionRoles = value
|
const permissionRoles = value
|
||||||
const super_admin = 'admin'
|
const super_admin = 'admin'
|
||||||
const roles = wsCache.get(CACHE_KEY.USER).roles
|
const roles = cache.local.get(CACHE_KEY.USER).roles
|
||||||
const hasRole = roles.some((role) => {
|
const hasRole = roles.some((role) => {
|
||||||
return super_admin === role || permissionRoles.includes(role)
|
return super_admin === role || permissionRoles.includes(role)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -116,11 +116,11 @@
|
|||||||
<script lang="ts" name="SystemMenuForm" setup>
|
<script lang="ts" name="SystemMenuForm" setup>
|
||||||
// import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
// import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
|
||||||
import * as MenuApi from '@/api/system/menu'
|
import * as MenuApi from '@/api/system/menu'
|
||||||
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
import { CACHE_KEY } from '@/hooks/web/useCache'
|
||||||
import { CommonStatusEnum, SystemMenuTypeEnum } from '@/utils/constants'
|
import { CommonStatusEnum, SystemMenuTypeEnum } from '@/utils/constants'
|
||||||
import { defaultProps, handleTree } from '@/utils/tree'
|
import { defaultProps, handleTree } from '@/utils/tree'
|
||||||
|
import cache from '@/plugins/cache'
|
||||||
|
|
||||||
const { wsCache } = useCache()
|
|
||||||
const { t } = useI18n() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
const message = useMessage() // 消息弹窗
|
const message = useMessage() // 消息弹窗
|
||||||
|
|
||||||
@@ -218,7 +218,7 @@ const submitForm = async () => {
|
|||||||
} finally {
|
} finally {
|
||||||
formLoading.value = false
|
formLoading.value = false
|
||||||
// 清空,从而触发刷新
|
// 清空,从而触发刷新
|
||||||
wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
|
cache.local.delete(CACHE_KEY.ROLE_ROUTERS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,8 +88,8 @@
|
|||||||
import { handleTree } from '@/utils/tree'
|
import { handleTree } from '@/utils/tree'
|
||||||
import * as MenuApi from '@/api/system/menu'
|
import * as MenuApi from '@/api/system/menu'
|
||||||
import MenuForm from './MenuForm.vue'
|
import MenuForm from './MenuForm.vue'
|
||||||
import { CACHE_KEY, useCache } from '@/hooks/web/useCache'
|
import { CACHE_KEY } from '@/hooks/web/useCache'
|
||||||
const { wsCache } = useCache()
|
import cache from '@/plugins/cache'
|
||||||
const { t } = useI18n() // 国际化
|
const { t } = useI18n() // 国际化
|
||||||
const message = useMessage() // 消息弹窗
|
const message = useMessage() // 消息弹窗
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ const refreshMenu = async () => {
|
|||||||
try {
|
try {
|
||||||
await message.confirm('即将更新缓存刷新浏览器!', '刷新菜单缓存')
|
await message.confirm('即将更新缓存刷新浏览器!', '刷新菜单缓存')
|
||||||
// 清空,从而触发刷新
|
// 清空,从而触发刷新
|
||||||
wsCache.delete(CACHE_KEY.ROLE_ROUTERS)
|
cache.local.delete(CACHE_KEY.ROLE_ROUTERS)
|
||||||
// 刷新浏览器
|
// 刷新浏览器
|
||||||
location.reload()
|
location.reload()
|
||||||
} catch {}
|
} catch {}
|
||||||
|
|||||||
@@ -73,6 +73,7 @@
|
|||||||
import * as PlanApi from '@/api/pers/attendancePlan'
|
import * as PlanApi from '@/api/pers/attendancePlan'
|
||||||
|
|
||||||
const message = useMessage() // 消息弹窗
|
const message = useMessage() // 消息弹窗
|
||||||
|
const { t } = useI18n() // 国际化
|
||||||
|
|
||||||
const dialogVisible = ref(false) // 弹窗的是否展示
|
const dialogVisible = ref(false) // 弹窗的是否展示
|
||||||
const dialogTitle = ref('考勤方案设置')
|
const dialogTitle = ref('考勤方案设置')
|
||||||
|
|||||||
Reference in New Issue
Block a user