mirror of
https://github.com/chansee97/nova-admin.git
synced 2025-04-06 03:57:54 +08:00
fix(projects): 修改路由错误
This commit is contained in:
parent
12114706ca
commit
8e1008d004
@ -1,8 +1,16 @@
|
|||||||
import type { App } from 'vue';
|
import type { App } from 'vue';
|
||||||
import { createRouter, createWebHistory, createWebHashHistory, RouteRecordRaw } from 'vue-router';
|
import { createRouter, createWebHistory, createWebHashHistory, RouteRecordRaw } from 'vue-router';
|
||||||
import { setupRouterGuard } from './guard';
|
import { setupRouterGuard } from './guard';
|
||||||
|
import { BasicLayout } from '@/layouts/index';
|
||||||
|
|
||||||
const routes: RouteRecordRaw[] = [
|
const routes: RouteRecordRaw[] = [
|
||||||
|
{
|
||||||
|
path: '/',
|
||||||
|
name: 'root',
|
||||||
|
redirect: '/test/test1',
|
||||||
|
component: BasicLayout,
|
||||||
|
children: [],
|
||||||
|
},
|
||||||
{
|
{
|
||||||
path: '/login',
|
path: '/login',
|
||||||
name: 'login',
|
name: 'login',
|
||||||
|
@ -50,8 +50,10 @@ export const useAuthStore = defineStore('auth-store', {
|
|||||||
// 等待数据写入完成
|
// 等待数据写入完成
|
||||||
const catchSuccess = await this.catchUserInfo(data);
|
const catchSuccess = await this.catchUserInfo(data);
|
||||||
// 初始化侧边菜单
|
// 初始化侧边菜单
|
||||||
const { setMenus } = useRouteStore();
|
const { setMenus, setUserRoutes } = useRouteStore();
|
||||||
|
await setUserRoutes(data.userRoutes);
|
||||||
await setMenus();
|
await setMenus();
|
||||||
|
|
||||||
// 登录写入信息成功
|
// 登录写入信息成功
|
||||||
if (catchSuccess) {
|
if (catchSuccess) {
|
||||||
// 进行重定向跳转
|
// 进行重定向跳转
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { renderIcon, getUserInfo } from '@/utils';
|
import { renderIcon, getUserInfo } from '@/utils';
|
||||||
import type { MenuOption } from 'naive-ui';
|
import { MenuOption, radioGroupProps } from 'naive-ui';
|
||||||
|
import { setDynamicRoutes } from '@/router/guard/dynamic';
|
||||||
|
|
||||||
interface RoutesStatus {
|
interface RoutesStatus {
|
||||||
isInitAuthRoute: boolean;
|
isInitAuthRoute: boolean;
|
||||||
@ -10,7 +11,7 @@ interface RoutesStatus {
|
|||||||
export const useRouteStore = defineStore('route-store', {
|
export const useRouteStore = defineStore('route-store', {
|
||||||
state: (): RoutesStatus => {
|
state: (): RoutesStatus => {
|
||||||
return {
|
return {
|
||||||
userRoutes: getUserInfo().userRoutes,
|
userRoutes: [],
|
||||||
isInitAuthRoute: false,
|
isInitAuthRoute: false,
|
||||||
menus: [],
|
menus: [],
|
||||||
};
|
};
|
||||||
@ -19,7 +20,9 @@ export const useRouteStore = defineStore('route-store', {
|
|||||||
async setMenus() {
|
async setMenus() {
|
||||||
this.menus = this.transformAuthRoutesToMenus(this.userRoutes);
|
this.menus = this.transformAuthRoutesToMenus(this.userRoutes);
|
||||||
},
|
},
|
||||||
|
async setUserRoutes(routes: any) {
|
||||||
|
this.userRoutes = routes;
|
||||||
|
},
|
||||||
// 将返回的路由表渲染成侧边栏
|
// 将返回的路由表渲染成侧边栏
|
||||||
transformAuthRoutesToMenus(userRoutes: Auth.UserInfoPermissions[]): MenuOption[] {
|
transformAuthRoutesToMenus(userRoutes: Auth.UserInfoPermissions[]): MenuOption[] {
|
||||||
return userRoutes.map((item) => {
|
return userRoutes.map((item) => {
|
||||||
@ -57,6 +60,7 @@ export const useRouteStore = defineStore('route-store', {
|
|||||||
|
|
||||||
async initAuthRoute() {
|
async initAuthRoute() {
|
||||||
await this.setMenus();
|
await this.setMenus();
|
||||||
|
await setDynamicRoutes();
|
||||||
this.isInitAuthRoute = true;
|
this.isInitAuthRoute = true;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user