perf: store

pull/2/head
xingyu 2022-08-03 12:55:27 +08:00
parent e081fb2700
commit 55b26f87ee
3 changed files with 9 additions and 6 deletions

View File

@ -6,6 +6,7 @@ import { useRouter } from 'vue-router'
import { useDesign } from '@/hooks/web/useDesign'
import avatarImg from '@/assets/imgs/avatar.gif'
import { useUserStore } from '@/store/modules/user'
import { useTagsViewStore } from '@/store/modules/tagsView'
const { t } = useI18n()
@ -15,6 +16,8 @@ const { push, replace } = useRouter()
const userStore = useUserStore()
const tagsViewStore = useTagsViewStore()
const { getPrefixCls } = useDesign()
const prefixCls = getPrefixCls('user-info')
@ -33,6 +36,7 @@ const loginOut = () => {
})
.then(async () => {
userStore.loginOut()
tagsViewStore.delAllViews
replace('/login')
})
.catch(() => {})

View File

@ -48,14 +48,14 @@ router.beforeEach(async (to, from, next) => {
if (to.path === '/login') {
next({ path: '/' })
} else {
console.info(3)
// 获取所有字典
const res = await listSimpleDictDataApi()
dictStore.setDictMap(res)
if (!dictStore.getHasDictData) {
const res = await listSimpleDictDataApi()
dictStore.setDictMap(res)
}
if (userStore.getRoles.length === 0) {
isRelogin.show = true
isRelogin.show = false
console.info(2)
// 后端过滤菜单
await permissionStore.generateRoutes()
permissionStore.getAddRouters.forEach((route) => {
@ -66,7 +66,6 @@ router.beforeEach(async (to, from, next) => {
const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect }
next(nextData)
} else {
console.info(3)
next()
}
}

View File

@ -28,7 +28,7 @@ export const useDictStore = defineStore({
getDictMap(): Recordable {
return this.dictMap
},
getHasDictData(): Boolean {
getHasDictData(): boolean {
if (this.dictMap.length > 0) {
return true
} else {