fix: 优化跳转初始化页面

This commit is contained in:
xieyonghong 2023-03-30 14:47:57 +08:00
parent ea4cb2492b
commit a1b67ce45c
3 changed files with 9 additions and 5 deletions

View File

@ -1,5 +1,5 @@
import { createRouter, createWebHashHistory } from 'vue-router'
import menus, { LoginPath } from './menu'
import menus, { AccountCenterBindPath, InitHomePath, LoginPath } from './menu'
import { cleanToken, getToken } from '@/utils/comm'
import { useUserInfo } from '@/store/userInfo'
import { useSystem } from '@/store/system'
@ -14,6 +14,8 @@ const router = createRouter({
}
})
const filterPath = [ InitHomePath, AccountCenterBindPath ]
router.beforeEach((to, from, next) => {
// TODO 切换路由取消请求
const token = getToken()
@ -24,7 +26,7 @@ router.beforeEach((to, from, next) => {
const userInfo = useUserInfo()
const system = useSystem()
const menu = useMenuStore()
if (!menu.siderMenus.length) {
if (!menu.siderMenus.length && !filterPath.includes(to.path)) {
userInfo.getUserInfo().then(() => {
system.getSystemVersion().then((menuData: any[]) => {
menuData.forEach(r => {

View File

@ -1,4 +1,6 @@
export const LoginPath = '/login'
export const InitHomePath = '/init-home'
export const AccountCenterBindPath = '/account/center/bind'
export const AccountMenu = {
path: '/account',
@ -55,11 +57,11 @@ export default [
component: () => import('@/views/user/Login/index.vue')
},
{
path: '/account/center/bind',
path: AccountCenterBindPath,
component: () => import('@/views/account/Center/bind/index.vue')
},
{
path: '/init-home', // 初始化
path: InitHomePath, // 初始化
component: () => import('@/views/init-home/index.vue')
},

View File

@ -237,7 +237,7 @@ const onFinish = async () => {
username: form.username,
});
LocalStore.set(TOKEN_KEY, res?.result.token);
if (res.result.username === 'admin') {
if (res.result.user?.username === 'admin') {
const resp: any = await getInitSet();
if (resp.status === 200 && !resp.result.length) {
window.location.href = '/#/init-home';