feat: 新增useStorage
This commit is contained in:
parent
57a5fa7b82
commit
dfea91c7e1
|
@ -7,7 +7,7 @@
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"i": "pnpm install",
|
"i": "pnpm install",
|
||||||
"dev": "vite --mode base",
|
"dev": "vite --mode base",
|
||||||
"ts:check": "vue-tsc --noEmit",
|
"ts:check": "vue-tsc --noEmit --skipLibCheck",
|
||||||
"build:pro": "vite build --mode pro",
|
"build:pro": "vite build --mode pro",
|
||||||
"build:gitee": "vite build --mode gitee",
|
"build:gitee": "vite build --mode gitee",
|
||||||
"build:dev": "vite build --mode dev",
|
"build:dev": "vite build --mode dev",
|
||||||
|
|
|
@ -4,7 +4,7 @@ import { useAppStore } from '@/store/modules/app'
|
||||||
import { ConfigGlobal } from '@/components/ConfigGlobal'
|
import { ConfigGlobal } from '@/components/ConfigGlobal'
|
||||||
import { isDark } from '@/utils/is'
|
import { isDark } from '@/utils/is'
|
||||||
import { useDesign } from '@/hooks/web/useDesign'
|
import { useDesign } from '@/hooks/web/useDesign'
|
||||||
import { useCache } from '@/hooks/web/useCache'
|
import { useStorage } from '@/hooks/web/useStorage'
|
||||||
|
|
||||||
const { getPrefixCls } = useDesign()
|
const { getPrefixCls } = useDesign()
|
||||||
|
|
||||||
|
@ -16,12 +16,12 @@ const currentSize = computed(() => appStore.getCurrentSize)
|
||||||
|
|
||||||
const greyMode = computed(() => appStore.getGreyMode)
|
const greyMode = computed(() => appStore.getGreyMode)
|
||||||
|
|
||||||
const { wsCache } = useCache()
|
const { getStorage } = useStorage()
|
||||||
|
|
||||||
// 根据浏览器当前主题设置系统主题色
|
// 根据浏览器当前主题设置系统主题色
|
||||||
const setDefaultTheme = () => {
|
const setDefaultTheme = () => {
|
||||||
if (wsCache.get('isDark') !== null) {
|
if (getStorage('isDark') !== null) {
|
||||||
appStore.setIsDark(wsCache.get('isDark'))
|
appStore.setIsDark(getStorage('isDark'))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const isDarkTheme = isDark()
|
const isDarkTheme = isDark()
|
||||||
|
|
|
@ -10,10 +10,12 @@ import { trim, setCssVar } from '@/utils'
|
||||||
import ColorRadioPicker from './components/ColorRadioPicker.vue'
|
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 { useCache } from '@/hooks/web/useCache'
|
import { useStorage } from '@/hooks/web/useStorage'
|
||||||
import { useClipboard } from '@vueuse/core'
|
import { useClipboard } from '@vueuse/core'
|
||||||
import { useDesign } from '@/hooks/web/useDesign'
|
import { useDesign } from '@/hooks/web/useDesign'
|
||||||
|
|
||||||
|
const { removeStorage } = useStorage()
|
||||||
|
|
||||||
const { getPrefixCls } = useDesign()
|
const { getPrefixCls } = useDesign()
|
||||||
|
|
||||||
const prefixCls = getPrefixCls('setting')
|
const prefixCls = getPrefixCls('setting')
|
||||||
|
@ -186,10 +188,9 @@ const copyConfig = async () => {
|
||||||
|
|
||||||
// 清空缓存
|
// 清空缓存
|
||||||
const clear = () => {
|
const clear = () => {
|
||||||
const { wsCache } = useCache()
|
removeStorage('layout')
|
||||||
wsCache.delete('layout')
|
removeStorage('theme')
|
||||||
wsCache.delete('theme')
|
removeStorage('isDark')
|
||||||
wsCache.delete('isDark')
|
|
||||||
window.location.reload()
|
window.location.reload()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ElDropdown, ElDropdownMenu, ElDropdownItem, ElMessageBox } from 'element-plus'
|
import { ElDropdown, ElDropdownMenu, ElDropdownItem, ElMessageBox } from 'element-plus'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useCache } from '@/hooks/web/useCache'
|
import { useStorage } from '@/hooks/web/useStorage'
|
||||||
import { resetRouter } from '@/router'
|
import { resetRouter } from '@/router'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { loginOutApi } from '@/api/login'
|
import { loginOutApi } from '@/api/login'
|
||||||
|
@ -24,7 +24,7 @@ const prefixCls = getPrefixCls('user-info')
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
const { wsCache } = useCache()
|
const { clear } = useStorage()
|
||||||
|
|
||||||
const { replace } = useRouter()
|
const { replace } = useRouter()
|
||||||
|
|
||||||
|
@ -37,7 +37,7 @@ const loginOut = () => {
|
||||||
.then(async () => {
|
.then(async () => {
|
||||||
const res = await loginOutApi().catch(() => {})
|
const res = await loginOutApi().catch(() => {})
|
||||||
if (res) {
|
if (res) {
|
||||||
wsCache.clear()
|
clear()
|
||||||
tagsViewStore.delAllViews()
|
tagsViewStore.delAllViews()
|
||||||
resetRouter() // 重置静态路由表
|
resetRouter() // 重置静态路由表
|
||||||
replace('/login')
|
replace('/login')
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { ref } from 'vue'
|
||||||
import { ElInput, ElButton } from 'element-plus'
|
import { ElInput, ElButton } from 'element-plus'
|
||||||
import { resetRouter } from '@/router'
|
import { resetRouter } from '@/router'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { useCache } from '@/hooks/web/useCache'
|
import { useStorage } from '@/hooks/web/useStorage'
|
||||||
import { useLockStore } from '@/store/modules/lock'
|
import { useLockStore } from '@/store/modules/lock'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useNow } from '@/hooks/web/useNow'
|
import { useNow } from '@/hooks/web/useNow'
|
||||||
|
@ -14,7 +14,7 @@ import { useTagsViewStore } from '@/store/modules/tagsView'
|
||||||
|
|
||||||
const tagsViewStore = useTagsViewStore()
|
const tagsViewStore = useTagsViewStore()
|
||||||
|
|
||||||
const { wsCache } = useCache()
|
const { clear } = useStorage()
|
||||||
|
|
||||||
const { replace } = useRouter()
|
const { replace } = useRouter()
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ async function unLock() {
|
||||||
async function goLogin() {
|
async function goLogin() {
|
||||||
const res = await loginOutApi().catch(() => {})
|
const res = await loginOutApi().catch(() => {})
|
||||||
if (res) {
|
if (res) {
|
||||||
wsCache.clear()
|
clear()
|
||||||
tagsViewStore.delAllViews()
|
tagsViewStore.delAllViews()
|
||||||
resetRouter() // 重置静态路由表
|
resetRouter() // 重置静态路由表
|
||||||
lockStore.resetLockInfo()
|
lockStore.resetLockInfo()
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
import type { App, Directive, DirectiveBinding } from 'vue'
|
import type { App, Directive, DirectiveBinding } from 'vue'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useCache } from '@/hooks/web/useCache'
|
import { useStorage } from '@/hooks/web/useStorage'
|
||||||
import { intersection } from 'lodash-es'
|
import { intersection } from 'lodash-es'
|
||||||
import { isArray } from '@/utils/is'
|
import { isArray } from '@/utils/is'
|
||||||
import { useAppStoreWithOut } from '@/store/modules/app'
|
import { useAppStoreWithOut } from '@/store/modules/app'
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const { wsCache } = useCache()
|
const { getStorage } = useStorage()
|
||||||
const appStore = useAppStoreWithOut()
|
const appStore = useAppStoreWithOut()
|
||||||
|
|
||||||
// 全部权限
|
// 全部权限
|
||||||
const all_permission = ['*.*.*']
|
const all_permission = ['*.*.*']
|
||||||
const hasPermission = (value: string | string[]): boolean => {
|
const hasPermission = (value: string | string[]): boolean => {
|
||||||
const permissions = wsCache.get(appStore.getUserInfo).permissions as string[]
|
const permissions = getStorage(appStore.getUserInfo).permissions as string[]
|
||||||
if (!value) {
|
if (!value) {
|
||||||
throw new Error(t('permission.hasPermission'))
|
throw new Error(t('permission.hasPermission'))
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
/**
|
|
||||||
* 配置浏览器本地存储的方式,可直接存储对象数组。
|
|
||||||
*/
|
|
||||||
|
|
||||||
import WebStorageCache from 'web-storage-cache'
|
|
||||||
|
|
||||||
type CacheType = 'sessionStorage' | 'localStorage'
|
|
||||||
|
|
||||||
export const useCache = (type: CacheType = 'sessionStorage') => {
|
|
||||||
const wsCache: WebStorageCache = new WebStorageCache({
|
|
||||||
storage: type
|
|
||||||
})
|
|
||||||
|
|
||||||
return {
|
|
||||||
wsCache
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
import { isArray, isObject } from '@/utils/is'
|
||||||
|
|
||||||
|
export const useStorage = (type: 'sessionStorage' | 'localStorage' = 'sessionStorage') => {
|
||||||
|
const setStorage = (key: string, value: any) => {
|
||||||
|
window[type].setItem(key, isArray(value) || isObject(value) ? JSON.stringify(value) : value)
|
||||||
|
}
|
||||||
|
|
||||||
|
const getStorage = (key: string) => {
|
||||||
|
const value = window[type].getItem(key)
|
||||||
|
try {
|
||||||
|
return JSON.parse(value || '')
|
||||||
|
} catch (error) {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeStorage = (key: string) => {
|
||||||
|
window[type].removeItem(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
const clear = () => {
|
||||||
|
window[type].clear()
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
setStorage,
|
||||||
|
getStorage,
|
||||||
|
removeStorage,
|
||||||
|
clear
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
import router from './router'
|
import router from './router'
|
||||||
import { useAppStoreWithOut } from '@/store/modules/app'
|
import { useAppStoreWithOut } from '@/store/modules/app'
|
||||||
import { useCache } from '@/hooks/web/useCache'
|
import { useStorage } from '@/hooks/web/useStorage'
|
||||||
import type { RouteRecordRaw } from 'vue-router'
|
import type { RouteRecordRaw } from 'vue-router'
|
||||||
import { useTitle } from '@/hooks/web/useTitle'
|
import { useTitle } from '@/hooks/web/useTitle'
|
||||||
import { useNProgress } from '@/hooks/web/useNProgress'
|
import { useNProgress } from '@/hooks/web/useNProgress'
|
||||||
|
@ -15,7 +15,7 @@ const appStore = useAppStoreWithOut()
|
||||||
|
|
||||||
const dictStore = useDictStoreWithOut()
|
const dictStore = useDictStoreWithOut()
|
||||||
|
|
||||||
const { wsCache } = useCache()
|
const { getStorage } = useStorage()
|
||||||
|
|
||||||
const { start, done } = useNProgress()
|
const { start, done } = useNProgress()
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ const whiteList = ['/login'] // 不重定向白名单
|
||||||
router.beforeEach(async (to, from, next) => {
|
router.beforeEach(async (to, from, next) => {
|
||||||
start()
|
start()
|
||||||
loadStart()
|
loadStart()
|
||||||
if (wsCache.get(appStore.getUserInfo)) {
|
if (getStorage(appStore.getUserInfo)) {
|
||||||
if (to.path === '/login') {
|
if (to.path === '/login') {
|
||||||
next({ path: '/' })
|
next({ path: '/' })
|
||||||
} else {
|
} else {
|
||||||
|
@ -44,8 +44,8 @@ router.beforeEach(async (to, from, next) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 开发者可根据实际情况进行修改
|
// 开发者可根据实际情况进行修改
|
||||||
const roleRouters = wsCache.get('roleRouters') || []
|
const roleRouters = getStorage('roleRouters') || []
|
||||||
const userInfo = wsCache.get(appStore.getUserInfo)
|
const userInfo = getStorage(appStore.getUserInfo)
|
||||||
|
|
||||||
// 是否使用动态路由
|
// 是否使用动态路由
|
||||||
if (appStore.getDynamicRouter) {
|
if (appStore.getDynamicRouter) {
|
||||||
|
|
|
@ -2,9 +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, ComponentSize } from 'element-plus'
|
import { ElMessage, ComponentSize } from 'element-plus'
|
||||||
import { useCache } from '@/hooks/web/useCache'
|
import { useStorage } from '@/hooks/web/useStorage'
|
||||||
|
|
||||||
const { wsCache } = useCache()
|
const { getStorage, setStorage } = useStorage()
|
||||||
|
|
||||||
interface AppState {
|
interface AppState {
|
||||||
breadcrumb: boolean
|
breadcrumb: boolean
|
||||||
|
@ -57,13 +57,13 @@ export const useAppStore = defineStore('app', {
|
||||||
fixedHeader: true, // 固定toolheader
|
fixedHeader: true, // 固定toolheader
|
||||||
footer: true, // 显示页脚
|
footer: true, // 显示页脚
|
||||||
greyMode: false, // 是否开始灰色模式,用于特殊悼念日
|
greyMode: false, // 是否开始灰色模式,用于特殊悼念日
|
||||||
dynamicRouter: wsCache.get('dynamicRouter') || false, // 是否动态路由
|
dynamicRouter: getStorage('dynamicRouter') || false, // 是否动态路由
|
||||||
fixedMenu: wsCache.get('fixedMenu') || false, // 是否固定菜单
|
fixedMenu: getStorage('fixedMenu') || false, // 是否固定菜单
|
||||||
|
|
||||||
layout: wsCache.get('layout') || 'classic', // layout布局
|
layout: getStorage('layout') || 'classic', // layout布局
|
||||||
isDark: wsCache.get('isDark') || false, // 是否是暗黑模式
|
isDark: getStorage('isDark') || false, // 是否是暗黑模式
|
||||||
currentSize: wsCache.get('default') || 'default', // 组件尺寸
|
currentSize: getStorage('default') || 'default', // 组件尺寸
|
||||||
theme: wsCache.get('theme') || {
|
theme: getStorage('theme') || {
|
||||||
// 主题色
|
// 主题色
|
||||||
elColorPrimary: '#409eff',
|
elColorPrimary: '#409eff',
|
||||||
// 左侧菜单边框颜色
|
// 左侧菜单边框颜色
|
||||||
|
@ -213,11 +213,11 @@ export const useAppStore = defineStore('app', {
|
||||||
this.greyMode = greyMode
|
this.greyMode = greyMode
|
||||||
},
|
},
|
||||||
setDynamicRouter(dynamicRouter: boolean) {
|
setDynamicRouter(dynamicRouter: boolean) {
|
||||||
wsCache.set('dynamicRouter', dynamicRouter)
|
setStorage('dynamicRouter', dynamicRouter)
|
||||||
this.dynamicRouter = dynamicRouter
|
this.dynamicRouter = dynamicRouter
|
||||||
},
|
},
|
||||||
setFixedMenu(fixedMenu: boolean) {
|
setFixedMenu(fixedMenu: boolean) {
|
||||||
wsCache.set('fixedMenu', fixedMenu)
|
setStorage('fixedMenu', fixedMenu)
|
||||||
this.fixedMenu = fixedMenu
|
this.fixedMenu = fixedMenu
|
||||||
},
|
},
|
||||||
setPageLoading(pageLoading: boolean) {
|
setPageLoading(pageLoading: boolean) {
|
||||||
|
@ -229,7 +229,7 @@ export const useAppStore = defineStore('app', {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.layout = layout
|
this.layout = layout
|
||||||
wsCache.set('layout', this.layout)
|
setStorage('layout', this.layout)
|
||||||
},
|
},
|
||||||
setTitle(title: string) {
|
setTitle(title: string) {
|
||||||
this.title = title
|
this.title = title
|
||||||
|
@ -243,18 +243,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)
|
setStorage('isDark', this.isDark)
|
||||||
},
|
},
|
||||||
setCurrentSize(currentSize: ComponentSize) {
|
setCurrentSize(currentSize: ComponentSize) {
|
||||||
this.currentSize = currentSize
|
this.currentSize = currentSize
|
||||||
wsCache.set('currentSize', this.currentSize)
|
setStorage('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)
|
setStorage('theme', this.theme)
|
||||||
},
|
},
|
||||||
setCssVarTheme() {
|
setCssVarTheme() {
|
||||||
for (const key in this.theme) {
|
for (const key in this.theme) {
|
||||||
|
|
|
@ -2,10 +2,10 @@ 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'
|
import { useStorage } from '@/hooks/web/useStorage'
|
||||||
import { LocaleDropdownType } from '@/components/LocaleDropdown'
|
import { LocaleDropdownType } from '@/components/LocaleDropdown'
|
||||||
|
|
||||||
const { wsCache } = useCache()
|
const { getStorage, setStorage } = useStorage()
|
||||||
|
|
||||||
const elLocaleMap = {
|
const elLocaleMap = {
|
||||||
'zh-CN': zhCn,
|
'zh-CN': zhCn,
|
||||||
|
@ -20,8 +20,8 @@ export const useLocaleStore = defineStore('locales', {
|
||||||
state: (): LocaleState => {
|
state: (): LocaleState => {
|
||||||
return {
|
return {
|
||||||
currentLocale: {
|
currentLocale: {
|
||||||
lang: wsCache.get('lang') || 'zh-CN',
|
lang: getStorage('lang') || 'zh-CN',
|
||||||
elLocale: elLocaleMap[wsCache.get('lang') || 'zh-CN']
|
elLocale: elLocaleMap[getStorage('lang') || 'zh-CN']
|
||||||
},
|
},
|
||||||
// 多语言
|
// 多语言
|
||||||
localeMap: [
|
localeMap: [
|
||||||
|
@ -49,7 +49,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)
|
setStorage('lang', localeMap?.lang)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { ElButton } from 'element-plus'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { saveTableApi } from '@/api/table'
|
import { saveTableApi } from '@/api/table'
|
||||||
import { useEmitt } from '@/hooks/web/useEmitt'
|
import { useEmitt } from '@/hooks/event/useEmitt'
|
||||||
|
|
||||||
const { emitter } = useEmitt()
|
const { emitter } = useEmitt()
|
||||||
|
|
||||||
|
@ -50,3 +50,4 @@ const save = async () => {
|
||||||
</template>
|
</template>
|
||||||
</ContentDetailWrap>
|
</ContentDetailWrap>
|
||||||
</template>
|
</template>
|
||||||
|
@/hooks/event/useEmitt
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter, useRoute } from 'vue-router'
|
||||||
import { saveTableApi, getTableDetApi } from '@/api/table'
|
import { saveTableApi, getTableDetApi } from '@/api/table'
|
||||||
import { TableData } from '@/api/table/types'
|
import { TableData } from '@/api/table/types'
|
||||||
import { useEmitt } from '@/hooks/web/useEmitt'
|
import { useEmitt } from '@/hooks/event/useEmitt'
|
||||||
|
|
||||||
const { emitter } = useEmitt()
|
const { emitter } = useEmitt()
|
||||||
|
|
||||||
|
@ -64,3 +64,4 @@ const save = async () => {
|
||||||
</template>
|
</template>
|
||||||
</ContentDetailWrap>
|
</ContentDetailWrap>
|
||||||
</template>
|
</template>
|
||||||
|
@/hooks/event/useEmitt
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { useTable } from '@/hooks/web/useTable'
|
||||||
import { TableData } from '@/api/table/types'
|
import { TableData } from '@/api/table/types'
|
||||||
import { h, reactive, ref, unref } from 'vue'
|
import { h, reactive, ref, unref } from 'vue'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
import { useEmitt } from '@/hooks/web/useEmitt'
|
import { useEmitt } from '@/hooks/event/useEmitt'
|
||||||
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
|
import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas'
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
|
@ -265,3 +265,4 @@ const action = (row: TableData, type: string) => {
|
||||||
/>
|
/>
|
||||||
</ContentWrap>
|
</ContentWrap>
|
||||||
</template>
|
</template>
|
||||||
|
@/hooks/event/useEmitt
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { useI18n } from '@/hooks/web/useI18n'
|
||||||
import { ElButton, ElCheckbox, ElLink } from 'element-plus'
|
import { ElButton, ElCheckbox, ElLink } from 'element-plus'
|
||||||
import { useForm } from '@/hooks/web/useForm'
|
import { useForm } from '@/hooks/web/useForm'
|
||||||
import { loginApi, getTestRoleApi, getAdminRoleApi } from '@/api/login'
|
import { loginApi, getTestRoleApi, getAdminRoleApi } from '@/api/login'
|
||||||
import { useCache } from '@/hooks/web/useCache'
|
import { useStorage } from '@/hooks/web/useStorage'
|
||||||
import { useAppStore } from '@/store/modules/app'
|
import { useAppStore } from '@/store/modules/app'
|
||||||
import { usePermissionStore } from '@/store/modules/permission'
|
import { usePermissionStore } from '@/store/modules/permission'
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
|
@ -24,7 +24,7 @@ const permissionStore = usePermissionStore()
|
||||||
|
|
||||||
const { currentRoute, addRoute, push } = useRouter()
|
const { currentRoute, addRoute, push } = useRouter()
|
||||||
|
|
||||||
const { wsCache } = useCache()
|
const { setStorage } = useStorage()
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
@ -222,7 +222,7 @@ const signIn = async () => {
|
||||||
const res = await loginApi(formData)
|
const res = await loginApi(formData)
|
||||||
|
|
||||||
if (res) {
|
if (res) {
|
||||||
wsCache.set(appStore.getUserInfo, res.data)
|
setStorage(appStore.getUserInfo, res.data)
|
||||||
// 是否使用动态路由
|
// 是否使用动态路由
|
||||||
if (appStore.getDynamicRouter) {
|
if (appStore.getDynamicRouter) {
|
||||||
getRole()
|
getRole()
|
||||||
|
@ -253,9 +253,8 @@ const getRole = async () => {
|
||||||
const res =
|
const res =
|
||||||
formData.username === 'admin' ? await getAdminRoleApi(params) : await getTestRoleApi(params)
|
formData.username === 'admin' ? await getAdminRoleApi(params) : await getTestRoleApi(params)
|
||||||
if (res) {
|
if (res) {
|
||||||
const { wsCache } = useCache()
|
|
||||||
const routers = res.data || []
|
const routers = res.data || []
|
||||||
wsCache.set('roleRouters', routers)
|
setStorage('roleRouters', routers)
|
||||||
|
|
||||||
formData.username === 'admin'
|
formData.username === 'admin'
|
||||||
? await permissionStore.generateRoutes('admin', routers).catch(() => {})
|
? await permissionStore.generateRoutes('admin', routers).catch(() => {})
|
||||||
|
|
|
@ -16,6 +16,7 @@ module.exports = {
|
||||||
ignoreAtRules: ['function', 'if', 'each', 'include', 'mixin']
|
ignoreAtRules: ['function', 'if', 'each', 'include', 'mixin']
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
'media-query-no-invalid': null,
|
||||||
'no-empty-source': null,
|
'no-empty-source': null,
|
||||||
'named-grid-areas-no-invalid': null,
|
'named-grid-areas-no-invalid': null,
|
||||||
'unicode-bom': 'never',
|
'unicode-bom': 'never',
|
||||||
|
|
Loading…
Reference in New Issue