|
@@ -18,7 +18,7 @@ const IFrame = () => import("/@/layout/frameView.vue");
|
|
const modulesRoutes = import.meta.glob("/src/views/**/*.{vue,tsx}");
|
|
const modulesRoutes = import.meta.glob("/src/views/**/*.{vue,tsx}");
|
|
|
|
|
|
// 动态路由
|
|
// 动态路由
|
|
-// import { getAsyncRoutes } from "/@/api/routes";
|
|
|
|
|
|
+import { getAsyncRoutes } from "/@/api/routes";
|
|
|
|
|
|
// 按照路由中meta下的rank等级升序来排序路由
|
|
// 按照路由中meta下的rank等级升序来排序路由
|
|
function ascending(arr: any[]) {
|
|
function ascending(arr: any[]) {
|
|
@@ -113,80 +113,280 @@ function resetRouter(): void {
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// 添加不同按钮权限到/permission/button页面中
|
|
|
|
+function setDifAuthority(authority, routes) {
|
|
|
|
+ routes.children[1].meta.authority = [authority];
|
|
|
|
+ return routes;
|
|
|
|
+}
|
|
// 初始化路由
|
|
// 初始化路由
|
|
-function initRouter(arr: any[]) {
|
|
|
|
|
|
+function initRouter() {
|
|
return new Promise(resolve => {
|
|
return new Promise(resolve => {
|
|
- // getAsyncRoutes({ name }).then(({ info }) => {
|
|
|
|
- if (arr.length === 0) {
|
|
|
|
- usePermissionStoreHook().changeSetting(arr);
|
|
|
|
- } else {
|
|
|
|
- formatFlatteningRoutes(addAsyncRoutes(arr)).map((v: RouteRecordRaw) => {
|
|
|
|
- // 防止重复添加路由
|
|
|
|
- if (
|
|
|
|
- router.options.routes[0].children.findIndex(
|
|
|
|
- value => value.path === v.path
|
|
|
|
- ) !== -1
|
|
|
|
- ) {
|
|
|
|
- return;
|
|
|
|
- } else {
|
|
|
|
- // 切记将路由push到routes后还需要使用addRoute,这样路由才能正常跳转
|
|
|
|
- router.options.routes[0].children.push(v);
|
|
|
|
- // 最终路由进行升序
|
|
|
|
- ascending(router.options.routes[0].children);
|
|
|
|
- if (!router.hasRoute(v?.name)) router.addRoute(v);
|
|
|
|
- const flattenRouters = router.getRoutes().find(n => n.path === "/");
|
|
|
|
- router.addRoute(flattenRouters);
|
|
|
|
- }
|
|
|
|
- resolve(router);
|
|
|
|
|
|
+ getAsyncRoutes({}).then(({ code, data, message }) => {
|
|
|
|
+ // console.log(code, data, message);
|
|
|
|
+ // const systemRouter = {
|
|
|
|
+ // path: "/system",
|
|
|
|
+ // redirect: "/system/menuOperator/index",
|
|
|
|
+ // meta: {
|
|
|
|
+ // icon: "setting",
|
|
|
|
+ // title: "系统管理",
|
|
|
|
+ // rank: 11
|
|
|
|
+ // },
|
|
|
|
+ // children: [
|
|
|
|
+ // {
|
|
|
|
+ // path: "/system/menuOperator/index",
|
|
|
|
+ // name: "menuOperator",
|
|
|
|
+ // meta: {
|
|
|
|
+ // icon: "flUser",
|
|
|
|
+ // title: "用户管理"
|
|
|
|
+ // }
|
|
|
|
+ // },
|
|
|
|
+ // {
|
|
|
|
+ // path: "/system/oplog/index",
|
|
|
|
+ // name: "oplog",
|
|
|
|
+ // meta: {
|
|
|
|
+ // icon: "role",
|
|
|
|
+ // title: "角色管理"
|
|
|
|
+ // }
|
|
|
|
+ // },
|
|
|
|
+ // {
|
|
|
|
+ // path: "/system/updates/index",
|
|
|
|
+ // name: "updates",
|
|
|
|
+ // meta: {
|
|
|
|
+ // icon: "dept",
|
|
|
|
+ // title: "部门管理"
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // ]
|
|
|
|
+ // };
|
|
|
|
+ // const interestRouter = {
|
|
|
|
+ // path: "/interest",
|
|
|
|
+ // redirect: "/interest/account/index",
|
|
|
|
+ // meta: {
|
|
|
|
+ // icon: "setting",
|
|
|
|
+ // title: "权限管理",
|
|
|
|
+ // rank: 11
|
|
|
|
+ // },
|
|
|
|
+ // children: [
|
|
|
|
+ // {
|
|
|
|
+ // path: "/interest/account/index",
|
|
|
|
+ // name: "account",
|
|
|
|
+ // meta: {
|
|
|
|
+ // icon: "flUser",
|
|
|
|
+ // title: "用户管理"
|
|
|
|
+ // }
|
|
|
|
+ // },
|
|
|
|
+ // {
|
|
|
|
+ // path: "/interest/role/index",
|
|
|
|
+ // name: "role",
|
|
|
|
+ // meta: {
|
|
|
|
+ // icon: "role",
|
|
|
|
+ // title: "角色管理"
|
|
|
|
+ // }
|
|
|
|
+ // },
|
|
|
|
+ // {
|
|
|
|
+ // path: "/interest/action/index",
|
|
|
|
+ // name: "action",
|
|
|
|
+ // meta: {
|
|
|
|
+ // icon: "dept",
|
|
|
|
+ // title: "部门管理"
|
|
|
|
+ // }
|
|
|
|
+ // },
|
|
|
|
+ // {
|
|
|
|
+ // path: "/interest/dataShare/index",
|
|
|
|
+ // name: "dataShare",
|
|
|
|
+ // meta: {
|
|
|
|
+ // icon: "dict",
|
|
|
|
+ // title: "字典管理"
|
|
|
|
+ // }
|
|
|
|
+ // },
|
|
|
|
+ // {
|
|
|
|
+ // path: "/interest/group/index",
|
|
|
|
+ // name: "group",
|
|
|
|
+ // meta: {
|
|
|
|
+ // icon: "dict",
|
|
|
|
+ // title: "字典管理"
|
|
|
|
+ // }
|
|
|
|
+ // }
|
|
|
|
+ // ]
|
|
|
|
+ // };
|
|
|
|
+ const permissionRouter = {
|
|
|
|
+ path: "/permission",
|
|
|
|
+ redirect: "/permission/page/index",
|
|
|
|
+ meta: {
|
|
|
|
+ title: "menus.permission",
|
|
|
|
+ icon: "lollipop",
|
|
|
|
+ rank: 7
|
|
|
|
+ },
|
|
|
|
+ children: [
|
|
|
|
+ {
|
|
|
|
+ path: "/permission/page/index",
|
|
|
|
+ name: "PermissionPage",
|
|
|
|
+ meta: {
|
|
|
|
+ title: "menus.permissionPage"
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ path: "/permission/button/index",
|
|
|
|
+ name: "PermissionButton",
|
|
|
|
+ meta: {
|
|
|
|
+ title: "menus.permissionButton",
|
|
|
|
+ authority: []
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ };
|
|
|
|
+ const systemRouter = {
|
|
|
|
+ path: "/system",
|
|
|
|
+ redirect: "/system/user/index",
|
|
|
|
+ meta: {
|
|
|
|
+ icon: "setting",
|
|
|
|
+ title: "menus.hssysManagement",
|
|
|
|
+ rank: 11
|
|
|
|
+ },
|
|
|
|
+ children: [
|
|
|
|
+ {
|
|
|
|
+ path: "/system/user/index",
|
|
|
|
+ name: "User",
|
|
|
|
+ meta: {
|
|
|
|
+ icon: "flUser",
|
|
|
|
+ title: "menus.hsUser"
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ path: "/system/role/index",
|
|
|
|
+ name: "Role",
|
|
|
|
+ meta: {
|
|
|
|
+ icon: "role",
|
|
|
|
+ title: "menus.hsRole"
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ path: "/system/dept/index",
|
|
|
|
+ name: "Dept",
|
|
|
|
+ meta: {
|
|
|
|
+ icon: "dept",
|
|
|
|
+ title: "menus.hsDept"
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ path: "/system/dict",
|
|
|
|
+ component: "/system/dict/index",
|
|
|
|
+ name: "Dict",
|
|
|
|
+ meta: {
|
|
|
|
+ icon: "dict",
|
|
|
|
+ title: "menus.hsDict",
|
|
|
|
+ keepAlive: true
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const frameRouter = {
|
|
|
|
+ path: "/iframe",
|
|
|
|
+ redirect: "/iframe/pure",
|
|
|
|
+ meta: {
|
|
|
|
+ icon: "monitor",
|
|
|
|
+ title: "menus.hsExternalPage",
|
|
|
|
+ rank: 10
|
|
|
|
+ },
|
|
|
|
+ children: [
|
|
|
|
+ {
|
|
|
|
+ path: "/iframe/pure",
|
|
|
|
+ name: "FramePure",
|
|
|
|
+ meta: {
|
|
|
|
+ title: "menus.hsPureDocument",
|
|
|
|
+ frameSrc: "https://pure-admin-doc.vercel.app"
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ path: "/external",
|
|
|
|
+ name: "https://pure-admin-doc.vercel.app",
|
|
|
|
+ meta: {
|
|
|
|
+ title: "menus.externalLink"
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ path: "/iframe/ep",
|
|
|
|
+ name: "FrameEp",
|
|
|
|
+ meta: {
|
|
|
|
+ title: "menus.hsEpDocument",
|
|
|
|
+ frameSrc: "https://element-plus.org/zh-CN/"
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ const tabsRouter = {
|
|
|
|
+ path: "/tabs",
|
|
|
|
+ redirect: "/tabs/index",
|
|
|
|
+ meta: {
|
|
|
|
+ icon: "IF-team-icontabs",
|
|
|
|
+ title: "menus.hstabs",
|
|
|
|
+ rank: 13
|
|
|
|
+ },
|
|
|
|
+ children: [
|
|
|
|
+ {
|
|
|
|
+ path: "/tabs/index",
|
|
|
|
+ name: "Tabs",
|
|
|
|
+ meta: {
|
|
|
|
+ title: "menus.hstabs"
|
|
|
|
+ }
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ path: "/tabs/detail",
|
|
|
|
+ name: "TabDetail",
|
|
|
|
+ meta: {
|
|
|
|
+ title: "",
|
|
|
|
+ showLink: false,
|
|
|
|
+ dynamicLevel: 3,
|
|
|
|
+ refreshRedirect: "/tabs/index"
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ };
|
|
|
|
+ const arrag = [
|
|
|
|
+ tabsRouter,
|
|
|
|
+ frameRouter,
|
|
|
|
+ systemRouter,
|
|
|
|
+ setDifAuthority("v-admin", permissionRouter)
|
|
|
|
+ ];
|
|
|
|
+ console.log(arrag);
|
|
|
|
+ if (arrag.length === 0) {
|
|
|
|
+ usePermissionStoreHook().changeSetting(arrag);
|
|
|
|
+ } else {
|
|
|
|
+ formatFlatteningRoutes(addAsyncRoutes(arrag)).map(
|
|
|
|
+ (v: RouteRecordRaw) => {
|
|
|
|
+ // 防止重复添加路由
|
|
|
|
+ if (
|
|
|
|
+ router.options.routes[0].children.findIndex(
|
|
|
|
+ value => value.path === v.path
|
|
|
|
+ ) !== -1
|
|
|
|
+ ) {
|
|
|
|
+ return;
|
|
|
|
+ } else {
|
|
|
|
+ // 切记将路由push到routes后还需要使用addRoute,这样路由才能正常跳转
|
|
|
|
+ router.options.routes[0].children.push(v);
|
|
|
|
+ // 最终路由进行升序
|
|
|
|
+ ascending(router.options.routes[0].children);
|
|
|
|
+ if (!router.hasRoute(v?.name)) router.addRoute(v);
|
|
|
|
+ const flattenRouters = router
|
|
|
|
+ .getRoutes()
|
|
|
|
+ .find(n => n.path === "/");
|
|
|
|
+ router.addRoute(flattenRouters);
|
|
|
|
+ }
|
|
|
|
+ resolve(router);
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ usePermissionStoreHook().changeSetting(arrag);
|
|
|
|
+ }
|
|
|
|
+ router.addRoute({
|
|
|
|
+ path: "/:pathMatch(.*)",
|
|
|
|
+ redirect: "/error/404"
|
|
});
|
|
});
|
|
- usePermissionStoreHook().changeSetting(arr);
|
|
|
|
- }
|
|
|
|
- router.addRoute({
|
|
|
|
- path: "/:pathMatch(.*)",
|
|
|
|
- redirect: "/error/404"
|
|
|
|
|
|
+ resolve(code);
|
|
});
|
|
});
|
|
- // });
|
|
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-// // 初始化路由
|
|
|
|
-// function initRouter(name: string) {
|
|
|
|
-// return new Promise(resolve => {
|
|
|
|
-// getAsyncRoutes({ name }).then(({ info }) => {
|
|
|
|
-// if (info.length === 0) {
|
|
|
|
-// usePermissionStoreHook().changeSetting(info);
|
|
|
|
-// } else {
|
|
|
|
-// formatFlatteningRoutes(addAsyncRoutes(info)).map(
|
|
|
|
-// (v: RouteRecordRaw) => {
|
|
|
|
-// // 防止重复添加路由
|
|
|
|
-// if (
|
|
|
|
-// router.options.routes[0].children.findIndex(
|
|
|
|
-// value => value.path === v.path
|
|
|
|
-// ) !== -1
|
|
|
|
-// ) {
|
|
|
|
-// return;
|
|
|
|
-// } else {
|
|
|
|
-// // 切记将路由push到routes后还需要使用addRoute,这样路由才能正常跳转
|
|
|
|
-// router.options.routes[0].children.push(v);
|
|
|
|
-// // 最终路由进行升序
|
|
|
|
-// ascending(router.options.routes[0].children);
|
|
|
|
-// if (!router.hasRoute(v?.name)) router.addRoute(v);
|
|
|
|
-// const flattenRouters = router
|
|
|
|
-// .getRoutes()
|
|
|
|
-// .find(n => n.path === "/");
|
|
|
|
-// router.addRoute(flattenRouters);
|
|
|
|
-// }
|
|
|
|
-// resolve(router);
|
|
|
|
-// }
|
|
|
|
-// );
|
|
|
|
-// usePermissionStoreHook().changeSetting(info);
|
|
|
|
-// }
|
|
|
|
-// router.addRoute({
|
|
|
|
-// path: "/:pathMatch(.*)",
|
|
|
|
-// redirect: "/error/404"
|
|
|
|
-// });
|
|
|
|
-// });
|
|
|
|
-// });
|
|
|
|
-// }
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* 将多级嵌套路由处理成一维数组
|
|
* 将多级嵌套路由处理成一维数组
|