Skip to content

Commit

Permalink
feat(projects): 修复了路由跳转问题,增加了新页面
Browse files Browse the repository at this point in the history
  • Loading branch information
chansee97 committed Aug 15, 2022
1 parent 5b26d6c commit d45812b
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 16 deletions.
6 changes: 3 additions & 3 deletions mock/module/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ const userInfo = {
},
children: [
{
name: 'dashboard_console',
path: '/dashboard/console',
name: 'dashboard_workbench',
path: '/dashboard/workbench',
meta: {
title: '主控台',
title: '工作台',
requiresAuth: true,
icon: 'icon-park-outline:alarm',
},
Expand Down
22 changes: 20 additions & 2 deletions src/router/guard/dynamic.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { RouteRecordRaw } from 'vue-router';
import { router } from '@/router';
import { BasicLayout } from '@/layouts/index';
import { constantRoutes } from '../routes';

export async function setDynamicRoutes() {
const vueRoutes: RouteRecordRaw[] = [
Expand Down Expand Up @@ -41,7 +40,26 @@ export async function setDynamicRoutes() {
requiresAuth: true,
},
},
...constantRoutes,
{
path: '/dashboard/workbench',
name: 'workbench',
component: () => import('@/views/dashboard/workbench/index.vue'),
meta: {
title: '工作台',
icon: 'icon-park-outline:music-list',
requiresAuth: true,
},
},
{
path: '/dashboard/monitor',
name: 'monitor',
component: () => import('@/views/dashboard/monitor/index.vue'),
meta: {
title: '控制页',
icon: 'icon-park-outline:music-list',
requiresAuth: true,
},
},
],
},
];
Expand Down
4 changes: 2 additions & 2 deletions src/router/guard/permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ export async function createPermissionGuard(
}
return false;
}

// debugger;
// 有登录但是没有路由,初始化路由、侧边菜单等
await setDynamicRoutes();
// await setDynamicRoutes();
await routeStore.initAuthRoute();
// 动态路由加载完回到根路由
next({ name: 'root' });
Expand Down
3 changes: 2 additions & 1 deletion src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import type { App } from 'vue';
import { createRouter, createWebHistory, createWebHashHistory, RouteRecordRaw } from 'vue-router';
import { setupRouterGuard } from './guard';
import { BasicLayout } from '@/layouts/index';
import { constantRoutes } from './routes';

const routes: RouteRecordRaw[] = [
{
path: '/',
name: 'root',
redirect: '/test/test1',
component: BasicLayout,
children: [],
children: [...constantRoutes],
},
{
path: '/login',
Expand Down
12 changes: 7 additions & 5 deletions src/router/routes/index.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,30 @@
// import { BasicLayout } from '@/layouts/index';

/* 页面中的一些固定路由,错误页等 */
export const constantRoutes = [
{
path: '/no-found',
name: 'not-found',
component: () => import('@/views/inherit-page/not-found/index.vue'),
component: () => import('@/views/error/not-found/index.vue'),
meta: {
title: '找不到页面',
icon: 'icon-park-outline:ghost',
},
},
{
path: '/no-permission',
name: 'no-permission',
component: () => import('@/views/inherit-page/not-permission/index.vue'),
component: () => import('@/views/error/not-permission/index.vue'),
meta: {
title: '无权限',
icon: 'icon-park-outline:error',
},
},
{
path: '/service-error',
name: 'service-error',
component: () => import('@/views/inherit-page/service-error/index.vue'),
component: () => import('@/views/error/service-error/index.vue'),
meta: {
title: '服务器错误',
icon: 'icon-park-outline:close-wifi',
},
},
{
Expand Down
4 changes: 3 additions & 1 deletion src/store/modules/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ export const useAuthStore = defineStore('auth-store', {
resetAuthStore() {
const route = unref(router.currentRoute);
const { toLogin } = useAppRouter(false);
const { resetRouteStore } = useRouteStore();
// 清除本地缓存
clearAuthStorage();
// 清空pinia
// 清空路由、菜单等数据
resetRouteStore();
this.$reset();
if (route.meta.requiresAuth) {
toLogin();
Expand Down
13 changes: 11 additions & 2 deletions src/store/modules/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { defineStore } from 'pinia';
import { renderIcon, getUserInfo } from '@/utils';
import { MenuOption, radioGroupProps } from 'naive-ui';
// import { setDynamicRoutes } from '@/router/guard/dynamic';
import { setDynamicRoutes } from '@/router/guard/dynamic';
import { router } from '@/router';

interface RoutesStatus {
isInitAuthRoute: boolean;
Expand All @@ -17,6 +18,14 @@ export const useRouteStore = defineStore('route-store', {
};
},
actions: {
resetRouteStore() {
this.resetRoutes();
this.$reset();
},
resetRoutes() {
/* 删除后面添加的路由 */
router.removeRoute('test');
},
async setUserRoutes() {
this.userRoutes = getUserInfo().userRoutes;
},
Expand Down Expand Up @@ -61,7 +70,7 @@ export const useRouteStore = defineStore('route-store', {

async initAuthRoute() {
await this.setMenus();
// await setDynamicRoutes();
await setDynamicRoutes();
this.isInitAuthRoute = true;
},
},
Expand Down
7 changes: 7 additions & 0 deletions src/views/dashboard/monitor/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div>监控页</div>
</template>

<script setup lang="ts"></script>

<style scoped></style>
7 changes: 7 additions & 0 deletions src/views/dashboard/workbench/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<template>
<div>工作台</div>
</template>

<script setup lang="ts"></script>

<style scoped></style>
File renamed without changes.
File renamed without changes.
File renamed without changes.

1 comment on commit d45812b

@vercel
Copy link

@vercel vercel bot commented on d45812b Aug 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

ench-admin – ./

ench-admin.vercel.app
ench-admin-whyhenin.vercel.app
ench-admin-git-main-whyhenin.vercel.app

Please sign in to comment.