| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- import { staticRoutes } from "@/router/constantRoutes"
- import { dynamicRoutes } from "@/router/dynamicRoutes"
- import { useUserStore } from "@/store/user.js"
- import Layout from "@/layout/index.vue"
- import ParentView from "@/components/ParentView/index.vue"
- const modules = import.meta.glob("./../views/**/*.vue")
- export const usePermissionStore = defineStore(
- "permission",
- {
- state: () => ({
- routes: [],
- addRoutes: [],
- sidebarRouters: [],
- defaultRoutes: []
- }),
- actions: {
- setRoutes(routes) {
- this.addRoutes = routes
- this.routes = staticRoutes.concat(routes)
- },
- setSidebarRouters(routes) {
- this.sidebarRouters = routes
- },
- setDefaultRoutes(routes) {
- this.defaultRoutes = staticRoutes.concat(routes)
- },
- generateRoutes() {
- return new Promise(resolve => {
- const sidebarRoutes = filterAsyncRouter(useUserStore().menuList[0].children[0].children)
- this.setSidebarRouters(staticRoutes.concat(sidebarRoutes))
- const rewriteRoutes = filterAsyncRouter(useUserStore().menuList[0].children[0].children, false)
- this.setRoutes(rewriteRoutes)
- resolve(rewriteRoutes)
- })
- }
- }
- }
- )
- function filterAsyncRouter(asyncRouterMap, httpSave = true) {
- const blackList = ["/system/dataList"]
- const hideList = ["/publicDomain",
- // "/workflow"
- ]
- let arr = []
- asyncRouterMap.filter(route => {
- if (!blackList.includes(route.path)) {
- if (route.children != null && route.children && route.children.length && route.children[0].type != 2 && route.parentId == "1762659463383281665") {
- let info = {
- alwaysShow: true,
- children: [],
- component: Layout,
- hidden: hideList.includes(route.path),
- meta: {
- icon: route.icon,
- link: "",
- cache: false,
- title: route.name
- },
- name: route.name,
- path: route.path,
- redirect: false
- }
- info.children = filterAsyncRouter(route.children)
- if (info.children.length > 0) {
- info.redirect = info.children[0].path
- }
- arr.push(info)
- } else if (route.children != null && route.children && route.children.length && route.children[0].type != 2 && route.parentId != "1762659463383281665") {
- let info = {
- alwaysShow: true,
- children: [],
- component: ParentView,
- hidden: hideList.includes(route.path),
- meta: {
- icon: route.icon,
- link: "",
- cache: false,
- title: route.name
- },
- name: route.name,
- path: route.path,
- redirect: false
- }
- info.children = filterAsyncRouter(route.children)
- if (info.children.length > 0) {
- info.redirect = info.children[0].path
- }
- arr.push(info)
- } else if (route.children.length == 0 && route.parentId == "1762659463383281665") {
- let info = {
- path: "",
- component: Layout,
- redirect: route.path,
- alwaysShow: false,
- hidden: hideList.includes(route.path),
- meta: {
- icon: route.icon,
- title: route.name
- },
- children: [{
- // alwaysShow: false, //菜单不支持设置
- children: [],
- component: loadView(route.path),
- hidden: hideList.includes(route.path),
- meta: {
- icon: route.icon,
- link: "",
- cache: false,
- title: route.name
- },
- name: route.name,
- path: route.path,
- redirect: false
- }]
- }
- if (route.path.startsWith("http") || route.path.startsWith("/tjmchild") || route.path.includes("queryParams")) {
- if (httpSave) {
- // const prefix = "/tjmchild"
- // if (route.path.startsWith(prefix)) {
- // info.redirect = route.path.slice(prefix.length)
- // info.children[0].path = route.path.slice(prefix.length)
- // }
- arr.push(info)
- }
- } else {
- arr.push(info)
- }
- } else if (route.type == 1) {
- let info = {
- // alwaysShow: false, //菜单不支持设置
- children: [],
- component: loadView(route.path),
- hidden: hideList.includes(route.path),
- meta: {
- icon: route.icon,
- link: "",
- cache: false,
- title: route.name
- },
- name: route.name,
- path: route.path,
- redirect: false
- }
- if (route.path.startsWith("http") || route.path.startsWith("/tjmchild") || route.path.includes("queryParams")) {
- if (httpSave) {
- // const prefix = "/tjmchild"
- // if (route.path.startsWith(prefix)) {
- // info.redirect = route.path.slice(prefix.length)
- // info.path = route.path.slice(prefix.length)
- // }
- arr.push(info)
- }
- } else {
- arr.push(info)
- }
- }
- }
- })
- return arr
- }
- function loadView(view) {
- for (const path in modules) {
- const dir = "/" + path.split("views/")[1].split(".vue")[0];
- if (dir === view || dir == view + "/index") {
- return modules[path]
- }
- }
- }
|