mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-12-27 09:56:02 +08:00
v3.9.0【优化】typescript版本;【优化】App端消息;【优化】弹出层z-index;
This commit is contained in:
165
smart-admin-web-javascript/src/router/index.js
Normal file
165
smart-admin-web-javascript/src/router/index.js
Normal file
@@ -0,0 +1,165 @@
|
||||
/*
|
||||
* 路由
|
||||
*
|
||||
* @Author: 1024创新实验室-主任:卓大
|
||||
* @Date: 2022-09-06 20:52:04
|
||||
* @Wechat: zhuda1024
|
||||
* @Email: lab1024@163.com
|
||||
* @Copyright 1024创新实验室 ( https://1024lab.net ),Since 2012
|
||||
*/
|
||||
import nProgress from 'nprogress';
|
||||
import 'nprogress/nprogress.css';
|
||||
import { nextTick } from 'vue';
|
||||
import { createRouter, createWebHashHistory } from 'vue-router';
|
||||
import { routerArray } from './routers';
|
||||
import { PAGE_PATH_404, PAGE_PATH_LOGIN, HOME_PAGE_PATH } from '/@/constants/common-const';
|
||||
import { HOME_PAGE_NAME } from '/@/constants/system/home-const';
|
||||
import SmartLayout from '../layout/index.vue';
|
||||
import { useUserStore } from '/@/store/modules/system/user';
|
||||
import { localClear, localRead } from '/@/utils/local-util';
|
||||
import _ from 'lodash';
|
||||
import LocalStorageKeyConst from '/@/constants/local-storage-key-const.js';
|
||||
|
||||
export const router = createRouter({
|
||||
history: createWebHashHistory(),
|
||||
routes: routerArray,
|
||||
strict: true,
|
||||
scrollBehavior: () => ({ left: 0, top: 0 }),
|
||||
});
|
||||
|
||||
// ----------------------- 路由加载前 -----------------------
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
// 进度条开启
|
||||
nProgress.start();
|
||||
|
||||
// 公共页面,任何时候都可以跳转
|
||||
if (to.path === PAGE_PATH_404) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
// 验证登录
|
||||
const token = localRead(LocalStorageKeyConst.USER_TOKEN);
|
||||
if (!token) {
|
||||
useUserStore().logout();
|
||||
if (to.path === PAGE_PATH_LOGIN) {
|
||||
next();
|
||||
} else {
|
||||
next({ path: PAGE_PATH_LOGIN });
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 登录页,则跳转到首页
|
||||
if (to.path === PAGE_PATH_LOGIN) {
|
||||
next({ path: HOME_PAGE_PATH });
|
||||
return;
|
||||
}
|
||||
|
||||
// 首页( 需要登录 ,但不需要验证权限)
|
||||
if (to.path === HOME_PAGE_NAME) {
|
||||
next();
|
||||
return;
|
||||
}
|
||||
|
||||
// 下载路由对应的 页面组件,并修改组件的Name,如果修改过,则不需要修改
|
||||
let toRouterInfo = routerMap.get(to.name);
|
||||
if (toRouterInfo && _.isFunction(toRouterInfo.component) && toRouterInfo.meta.renameComponentFlag === false) {
|
||||
// 因为组件component 为 lazy load是个方法,所以可以直接执行 component()方法
|
||||
toRouterInfo.component().then((val) => {
|
||||
// 修改组件的name
|
||||
val.default.name = to.meta.componentName;
|
||||
// 记录已经修改过 组件的name
|
||||
toRouterInfo.meta.renameComponentFlag = true;
|
||||
});
|
||||
}
|
||||
|
||||
// 设置tagNav
|
||||
useUserStore().setTagNav(to, from);
|
||||
|
||||
// 设置keepAlive
|
||||
if (to.meta.keepAlive) {
|
||||
nextTick(() => {
|
||||
useUserStore().pushKeepAliveIncludes(to.meta.componentName);
|
||||
});
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
// ----------------------- 路由加载后 -----------------------
|
||||
router.afterEach(() => {
|
||||
nProgress.done();
|
||||
});
|
||||
|
||||
// ----------------------- 构建router对象 -----------------------
|
||||
const routerMap = new Map();
|
||||
|
||||
export function buildRoutes(menuRouterList) {
|
||||
let menuList = menuRouterList ? menuRouterList : useUserStore().getMenuRouterList || [];
|
||||
/**
|
||||
* 1、构建整个路由信息
|
||||
* 2、添加到路由里
|
||||
*/
|
||||
const routerList = [];
|
||||
// 获取所有vue组件引用地址 用于构建路由
|
||||
const modules = import.meta.glob('../views/**/**.vue');
|
||||
// 获取所有vue组件 用于注入name属性 name属性用于keep-alive
|
||||
|
||||
//1、构建整个路由信息
|
||||
for (const e of menuList) {
|
||||
if (!e.menuId) {
|
||||
continue;
|
||||
}
|
||||
if (!e.path) {
|
||||
continue;
|
||||
}
|
||||
if (e.deletedFlag && e.deletedFlag === true) {
|
||||
continue;
|
||||
}
|
||||
let route = {
|
||||
path: e.path.startsWith('/') ? e.path : `/${e.path}`,
|
||||
// 使用【menuId】作为name唯一标识
|
||||
name: e.menuId.toString(),
|
||||
meta: {
|
||||
// 数据库菜单(页面)id
|
||||
id: e.menuId.toString(),
|
||||
// 组件名称
|
||||
componentName: e.menuId.toString(),
|
||||
// 菜单展示
|
||||
title: e.menuName,
|
||||
// 菜单图标展示
|
||||
icon: e.icon,
|
||||
// 是否在菜单隐藏
|
||||
hideInMenu: !e.visibleFlag,
|
||||
// 页面是否keep-alive缓存
|
||||
keepAlive: e.cacheFlag,
|
||||
// 是否为外链
|
||||
frameFlag: e.frameFlag,
|
||||
// 外链地址
|
||||
frameUrl: e.frameUrl,
|
||||
// 是否 rename了组件的名字
|
||||
renameComponentFlag: false,
|
||||
},
|
||||
};
|
||||
|
||||
if (e.frameFlag) {
|
||||
route.component = () => import('../components/framework/iframe/iframe-index.vue');
|
||||
} else {
|
||||
let componentPath = e.component && e.component.startsWith('/') ? e.component : '/' + e.component;
|
||||
let relativePath = `../views${componentPath}`;
|
||||
// // eslint-disable-next-line no-prototype-builtins
|
||||
route.component = modules[relativePath];
|
||||
}
|
||||
routerList.push(route);
|
||||
routerMap.set(e.menuId.toString(), route);
|
||||
}
|
||||
|
||||
//2、添加到路由里
|
||||
router.addRoute({
|
||||
path: '/',
|
||||
meta: {},
|
||||
component: SmartLayout,
|
||||
children: routerList,
|
||||
});
|
||||
}
|
||||
22
smart-admin-web-javascript/src/router/routers.js
Normal file
22
smart-admin-web-javascript/src/router/routers.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 所有路由入口
|
||||
*
|
||||
* @Author: 1024创新实验室-主任:卓大
|
||||
* @Date: 2022-09-06 20:52:26
|
||||
* @Wechat: zhuda1024
|
||||
* @Email: lab1024@163.com
|
||||
* @Copyright 1024创新实验室 ( https://1024lab.net ),Since 2012
|
||||
*/
|
||||
import { homeRouters } from './system/home';
|
||||
import { loginRouters } from './system/login';
|
||||
import { helpDocRouters } from './support/help-doc';
|
||||
import NotFound from '/@/views/system/40X/404.vue';
|
||||
import NoPrivilege from '/@/views/system/40X/403.vue';
|
||||
|
||||
export const routerArray = [
|
||||
...loginRouters,
|
||||
...homeRouters,
|
||||
...helpDocRouters,
|
||||
{ path: '/:pathMatch(.*)*', name: '404', component: NotFound },
|
||||
{ path: '/403', name: '403', component: NoPrivilege }
|
||||
];
|
||||
28
smart-admin-web-javascript/src/router/support/help-doc.js
Normal file
28
smart-admin-web-javascript/src/router/support/help-doc.js
Normal file
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* 帮助文档
|
||||
*
|
||||
* @Author: 1024创新实验室-主任:卓大
|
||||
* @Date: 2022-09-06 20:53:19
|
||||
* @Wechat: zhuda1024
|
||||
* @Email: lab1024@163.com
|
||||
* @Copyright 1024创新实验室 ( https://1024lab.net ),Since 2012
|
||||
*/
|
||||
import HelpDocLayout from '/@/layout/help-doc-layout.vue';
|
||||
|
||||
export const helpDocRouters = [
|
||||
{
|
||||
path: '/help-doc',
|
||||
name: 'HelpDoc',
|
||||
component: HelpDocLayout,
|
||||
meta: {
|
||||
title: '帮助文档',
|
||||
hideInMenu: true,
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '/help-doc/detail',
|
||||
component: () => import('/@/views/support/help-doc/user-view/help-doc-user-view.vue'),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
48
smart-admin-web-javascript/src/router/system/home.js
Normal file
48
smart-admin-web-javascript/src/router/system/home.js
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* 首页路由
|
||||
*
|
||||
* @Author: 1024创新实验室-主任:卓大
|
||||
* @Date: 2022-09-06 20:51:41
|
||||
* @Wechat: zhuda1024
|
||||
* @Email: lab1024@163.com
|
||||
* @Copyright 1024创新实验室 ( https://1024lab.net ),Since 2012
|
||||
*/
|
||||
import { HOME_PAGE_NAME } from '/@/constants/system/home-const';
|
||||
import { MENU_TYPE_ENUM } from '/@/constants/system/menu-const';
|
||||
import SmartLayout from '/@/layout/index.vue';
|
||||
|
||||
export const homeRouters = [
|
||||
{
|
||||
path: '/',
|
||||
name: '_home',
|
||||
redirect: { name: HOME_PAGE_NAME },
|
||||
component: SmartLayout,
|
||||
meta: {
|
||||
title: '首页',
|
||||
menuType: MENU_TYPE_ENUM.CATALOG.value,
|
||||
icon: 'HomeOutlined',
|
||||
},
|
||||
children: [
|
||||
{
|
||||
path: '/home',
|
||||
name: HOME_PAGE_NAME,
|
||||
meta: {
|
||||
title: '首页',
|
||||
menuType: MENU_TYPE_ENUM.MENU.value,
|
||||
icon: 'HomeOutlined',
|
||||
parentMenuList: [{ name: '_home', title: '首页' }],
|
||||
},
|
||||
component: () => import('/@/views/system/home/index.vue'),
|
||||
},
|
||||
{
|
||||
path: '/account',
|
||||
name: 'Account',
|
||||
component: () => import('/@/views/system/account/index.vue'),
|
||||
meta: {
|
||||
title: '个人中心',
|
||||
hideInMenu: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
21
smart-admin-web-javascript/src/router/system/login.js
Normal file
21
smart-admin-web-javascript/src/router/system/login.js
Normal file
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* 登录页面
|
||||
*
|
||||
* @Author: 1024创新实验室-主任:卓大
|
||||
* @Date: 2022-09-06 20:51:50
|
||||
* @Wechat: zhuda1024
|
||||
* @Email: lab1024@163.com
|
||||
* @Copyright 1024创新实验室 ( https://1024lab.net ),Since 2012
|
||||
*/
|
||||
|
||||
export const loginRouters = [
|
||||
{
|
||||
path: '/login',
|
||||
name: 'Login',
|
||||
component: () => import('/@/views/system/login3/login.vue'),
|
||||
meta: {
|
||||
title: '登录',
|
||||
hideInMenu: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
Reference in New Issue
Block a user