|
@@ -14,12 +14,10 @@ import { buildHierarchyTree } from "@pureadmin/utils";
|
|
|
import { usePermissionStoreHook } from "/@/store/modules/permission";
|
|
|
const Layout = () => import("/@/layout/index.vue");
|
|
|
const IFrame = () => import("/@/layout/frameView.vue");
|
|
|
+import { useUserStoreHook } from "/@/store/modules/user";
|
|
|
// https://cn.vitejs.dev/guide/features.html#glob-import
|
|
|
const modulesRoutes = import.meta.glob("/src/views/**/*.{vue,tsx}");
|
|
|
|
|
|
-// 动态路由
|
|
|
-import { getAsyncRoutes } from "/@/api/user";
|
|
|
-
|
|
|
// 按照路由中meta下的rank等级升序来排序路由
|
|
|
function ascending(arr: any[]) {
|
|
|
arr.forEach(v => {
|
|
@@ -121,90 +119,87 @@ function setDifAuthority(authority, routes) {
|
|
|
// 初始化路由
|
|
|
function initRouter() {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
- getAsyncRoutes({}).then(({ code, data }) => {
|
|
|
- if (code === 0) {
|
|
|
- const arrag: Array<any> = [];
|
|
|
- const actionList: Array<any> = [];
|
|
|
- data.forEach(e => {
|
|
|
- // const arr = e.menu_img.split("ep:");
|
|
|
- const eitem = {
|
|
|
- path: `/${e.menu_route}`,
|
|
|
- component: Layout,
|
|
|
- redirect: `${e.menu_route}`,
|
|
|
- meta: {
|
|
|
- // icon: arr.length === 2 ? arr[1] : "",
|
|
|
- // icon: `${e.menu_img}`,
|
|
|
- title: `${e.menu_name}`,
|
|
|
- showLink: e.is_private + "" === "1"
|
|
|
- },
|
|
|
- children: []
|
|
|
- };
|
|
|
+ useUserStoreHook()
|
|
|
+ .postMenuList({})
|
|
|
+ .then(({ code, data }) => {
|
|
|
+ if (code === 0) {
|
|
|
+ const arrag: Array<any> = [];
|
|
|
|
|
|
- e.child.forEach((s, si) => {
|
|
|
- // const arr2 = s.menu_img.split("ep:");
|
|
|
- const sitem = {
|
|
|
- path: `/${e.menu_route}/${s.menu_route}`,
|
|
|
- component: `${s.menu_url}`,
|
|
|
- //本地能使用,上生产直接GG
|
|
|
+ data.forEach(e => {
|
|
|
+ // const arr = e.menu_img.split("ep:");
|
|
|
+ const eitem = {
|
|
|
+ path: `/${e.menu_route}`,
|
|
|
+ component: Layout,
|
|
|
+ redirect: `${e.menu_route}`,
|
|
|
meta: {
|
|
|
- // icon: arr2.length === 2 ? arr2[1] : "",
|
|
|
- showLink: s.is_private + "" === "1",
|
|
|
- title: `${s.menu_name}`
|
|
|
- }
|
|
|
+ // icon: arr.length === 2 ? arr[1] : "",
|
|
|
+ // icon: `${e.menu_img}`,
|
|
|
+ title: `${e.menu_name}`,
|
|
|
+ showLink: e.is_private + "" === "1"
|
|
|
+ },
|
|
|
+ children: []
|
|
|
};
|
|
|
- // console.log(sitem);
|
|
|
- eitem.children.push(sitem);
|
|
|
- if (si === 0) {
|
|
|
- eitem.redirect += `/${s.menu_route}`;
|
|
|
- }
|
|
|
- const asitem = {
|
|
|
- menu_route: s.menu_route,
|
|
|
- action: s.action
|
|
|
- };
|
|
|
- actionList.push(asitem);
|
|
|
+
|
|
|
+ e.child.forEach((s, si) => {
|
|
|
+ // const arr2 = s.menu_img.split("ep:");
|
|
|
+ const sitem = {
|
|
|
+ path: `/${e.menu_route}/${s.menu_route}`,
|
|
|
+ component: `${s.menu_url}`,
|
|
|
+ //本地能使用,上生产直接GG
|
|
|
+ meta: {
|
|
|
+ // icon: arr2.length === 2 ? arr2[1] : "",
|
|
|
+ showLink: s.is_private + "" === "1",
|
|
|
+ title: `${s.menu_name}`
|
|
|
+ }
|
|
|
+ };
|
|
|
+ // console.log(sitem);
|
|
|
+ eitem.children.push(sitem);
|
|
|
+ if (si === 0) {
|
|
|
+ eitem.redirect += `/${s.menu_route}`;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // console.log(eitem);
|
|
|
+ arrag.push(eitem);
|
|
|
});
|
|
|
- // console.log(eitem);
|
|
|
- arrag.push(eitem);
|
|
|
- });
|
|
|
- // console.log(arrag);
|
|
|
- if (arrag.length === 0) {
|
|
|
- usePermissionStoreHook().changeSetting(arrag);
|
|
|
- resolve(code);
|
|
|
- } 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);
|
|
|
+ // console.log(arrag);
|
|
|
+ if (arrag.length === 0) {
|
|
|
+ usePermissionStoreHook().changeSetting(arrag);
|
|
|
+ resolve(code);
|
|
|
+ } 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);
|
|
|
}
|
|
|
- resolve(router);
|
|
|
- }
|
|
|
- );
|
|
|
- usePermissionStoreHook().changeSetting(arrag);
|
|
|
+ );
|
|
|
+ usePermissionStoreHook().changeSetting(arrag);
|
|
|
+ }
|
|
|
+ router.addRoute({
|
|
|
+ path: "/:pathMatch(.*)",
|
|
|
+ redirect: "/error/404"
|
|
|
+ });
|
|
|
+ resolve(router);
|
|
|
+ } else {
|
|
|
+ reject(false);
|
|
|
}
|
|
|
- router.addRoute({
|
|
|
- path: "/:pathMatch(.*)",
|
|
|
- redirect: "/error/404"
|
|
|
- });
|
|
|
- resolve(router);
|
|
|
- } else {
|
|
|
- reject(false);
|
|
|
- }
|
|
|
- });
|
|
|
+ });
|
|
|
});
|
|
|
}
|
|
|
|