mirror of
				https://github.com/pure-admin/vue-pure-admin.git
				synced 2025-11-03 13:44:47 +08:00 
			
		
		
		
	perf: router
This commit is contained in:
		
							parent
							
								
									07794d000c
								
							
						
					
					
						commit
						079a455181
					
				@ -5,7 +5,7 @@ import { MockMethod } from "vite-plugin-mock";
 | 
				
			|||||||
const systemRouter = {
 | 
					const systemRouter = {
 | 
				
			||||||
  path: "/system",
 | 
					  path: "/system",
 | 
				
			||||||
  name: "system",
 | 
					  name: "system",
 | 
				
			||||||
  redirect: "/system/user",
 | 
					  redirect: "/system/user/index",
 | 
				
			||||||
  meta: {
 | 
					  meta: {
 | 
				
			||||||
    icon: "Setting",
 | 
					    icon: "Setting",
 | 
				
			||||||
    title: "menus.hssysManagement",
 | 
					    title: "menus.hssysManagement",
 | 
				
			||||||
@ -15,7 +15,7 @@ const systemRouter = {
 | 
				
			|||||||
  },
 | 
					  },
 | 
				
			||||||
  children: [
 | 
					  children: [
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      path: "/system/user",
 | 
					      path: "/system/user/index",
 | 
				
			||||||
      name: "user",
 | 
					      name: "user",
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "menus.hsBaseinfo",
 | 
					        title: "menus.hsBaseinfo",
 | 
				
			||||||
@ -24,7 +24,7 @@ const systemRouter = {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      path: "/system/dict",
 | 
					      path: "/system/dict/index",
 | 
				
			||||||
      name: "dict",
 | 
					      name: "dict",
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "menus.hsDict",
 | 
					        title: "menus.hsDict",
 | 
				
			||||||
@ -39,7 +39,7 @@ const systemRouter = {
 | 
				
			|||||||
const permissionRouter = {
 | 
					const permissionRouter = {
 | 
				
			||||||
  path: "/permission",
 | 
					  path: "/permission",
 | 
				
			||||||
  name: "permission",
 | 
					  name: "permission",
 | 
				
			||||||
  redirect: "/permission/page",
 | 
					  redirect: "/permission/page/index",
 | 
				
			||||||
  meta: {
 | 
					  meta: {
 | 
				
			||||||
    title: "menus.permission",
 | 
					    title: "menus.permission",
 | 
				
			||||||
    icon: "Lollipop",
 | 
					    icon: "Lollipop",
 | 
				
			||||||
@ -49,7 +49,7 @@ const permissionRouter = {
 | 
				
			|||||||
  },
 | 
					  },
 | 
				
			||||||
  children: [
 | 
					  children: [
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      path: "/permission/page",
 | 
					      path: "/permission/page/index",
 | 
				
			||||||
      name: "permissionPage",
 | 
					      name: "permissionPage",
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "menus.permissionPage",
 | 
					        title: "menus.permissionPage",
 | 
				
			||||||
@ -58,7 +58,7 @@ const permissionRouter = {
 | 
				
			|||||||
      }
 | 
					      }
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
      path: "/permission/button",
 | 
					      path: "/permission/button/index",
 | 
				
			||||||
      name: "permissionButton",
 | 
					      name: "permissionButton",
 | 
				
			||||||
      meta: {
 | 
					      meta: {
 | 
				
			||||||
        title: "menus.permissionButton",
 | 
					        title: "menus.permissionButton",
 | 
				
			||||||
 | 
				
			|||||||
@ -18,7 +18,7 @@ import closeLeft from "/@/assets/svg/close_left.svg";
 | 
				
			|||||||
import closeOther from "/@/assets/svg/close_other.svg";
 | 
					import closeOther from "/@/assets/svg/close_other.svg";
 | 
				
			||||||
import closeRight from "/@/assets/svg/close_right.svg";
 | 
					import closeRight from "/@/assets/svg/close_right.svg";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import { $t } from "/@/plugins/i18n";
 | 
					import { $t as t } from "/@/plugins/i18n";
 | 
				
			||||||
import { emitter } from "/@/utils/mitt";
 | 
					import { emitter } from "/@/utils/mitt";
 | 
				
			||||||
import { isEqual, isEmpty } from "lodash-es";
 | 
					import { isEqual, isEmpty } from "lodash-es";
 | 
				
			||||||
import { transformI18n } from "/@/plugins/i18n";
 | 
					import { transformI18n } from "/@/plugins/i18n";
 | 
				
			||||||
@ -189,42 +189,42 @@ const handleScroll = (offset: number): void => {
 | 
				
			|||||||
const tagsViews = ref<Array<tagsViewsType>>([
 | 
					const tagsViews = ref<Array<tagsViewsType>>([
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    icon: refresh,
 | 
					    icon: refresh,
 | 
				
			||||||
    text: $t("buttons.hsreload"),
 | 
					    text: t("buttons.hsreload"),
 | 
				
			||||||
    divided: false,
 | 
					    divided: false,
 | 
				
			||||||
    disabled: false,
 | 
					    disabled: false,
 | 
				
			||||||
    show: true
 | 
					    show: true
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    icon: close,
 | 
					    icon: close,
 | 
				
			||||||
    text: $t("buttons.hscloseCurrentTab"),
 | 
					    text: t("buttons.hscloseCurrentTab"),
 | 
				
			||||||
    divided: false,
 | 
					    divided: false,
 | 
				
			||||||
    disabled: multiTags.value.length > 1 ? false : true,
 | 
					    disabled: multiTags.value.length > 1 ? false : true,
 | 
				
			||||||
    show: true
 | 
					    show: true
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    icon: closeLeft,
 | 
					    icon: closeLeft,
 | 
				
			||||||
    text: $t("buttons.hscloseLeftTabs"),
 | 
					    text: t("buttons.hscloseLeftTabs"),
 | 
				
			||||||
    divided: true,
 | 
					    divided: true,
 | 
				
			||||||
    disabled: multiTags.value.length > 1 ? false : true,
 | 
					    disabled: multiTags.value.length > 1 ? false : true,
 | 
				
			||||||
    show: true
 | 
					    show: true
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    icon: closeRight,
 | 
					    icon: closeRight,
 | 
				
			||||||
    text: $t("buttons.hscloseRightTabs"),
 | 
					    text: t("buttons.hscloseRightTabs"),
 | 
				
			||||||
    divided: false,
 | 
					    divided: false,
 | 
				
			||||||
    disabled: multiTags.value.length > 1 ? false : true,
 | 
					    disabled: multiTags.value.length > 1 ? false : true,
 | 
				
			||||||
    show: true
 | 
					    show: true
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    icon: closeOther,
 | 
					    icon: closeOther,
 | 
				
			||||||
    text: $t("buttons.hscloseOtherTabs"),
 | 
					    text: t("buttons.hscloseOtherTabs"),
 | 
				
			||||||
    divided: true,
 | 
					    divided: true,
 | 
				
			||||||
    disabled: multiTags.value.length > 2 ? false : true,
 | 
					    disabled: multiTags.value.length > 2 ? false : true,
 | 
				
			||||||
    show: true
 | 
					    show: true
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  {
 | 
					  {
 | 
				
			||||||
    icon: closeAll,
 | 
					    icon: closeAll,
 | 
				
			||||||
    text: $t("buttons.hscloseAllTabs"),
 | 
					    text: t("buttons.hscloseAllTabs"),
 | 
				
			||||||
    divided: false,
 | 
					    divided: false,
 | 
				
			||||||
    disabled: multiTags.value.length > 1 ? false : true,
 | 
					    disabled: multiTags.value.length > 1 ? false : true,
 | 
				
			||||||
    show: true
 | 
					    show: true
 | 
				
			||||||
 | 
				
			|||||||
@ -117,8 +117,9 @@ router.beforeEach((to: toRouteType, _from, next) => {
 | 
				
			|||||||
                route?.meta?.rank !== 0 &&
 | 
					                route?.meta?.rank !== 0 &&
 | 
				
			||||||
                routePartent.length === 0
 | 
					                routePartent.length === 0
 | 
				
			||||||
              ) {
 | 
					              ) {
 | 
				
			||||||
 | 
					                if (!route?.meta?.refreshRedirect) return;
 | 
				
			||||||
                const { name, meta } = findRouteByPath(
 | 
					                const { name, meta } = findRouteByPath(
 | 
				
			||||||
                  route?.meta?.refreshRedirect,
 | 
					                  route.meta.refreshRedirect,
 | 
				
			||||||
                  routes
 | 
					                  routes
 | 
				
			||||||
                );
 | 
					                );
 | 
				
			||||||
                handTag(
 | 
					                handTag(
 | 
				
			||||||
 | 
				
			|||||||
@ -13,7 +13,7 @@ import { useTimeoutFn } from "@vueuse/core";
 | 
				
			|||||||
import { RouteConfigs } from "/@/layout/types";
 | 
					import { RouteConfigs } from "/@/layout/types";
 | 
				
			||||||
import { usePermissionStoreHook } from "/@/store/modules/permission";
 | 
					import { usePermissionStoreHook } from "/@/store/modules/permission";
 | 
				
			||||||
// https://cn.vitejs.dev/guide/features.html#glob-import
 | 
					// https://cn.vitejs.dev/guide/features.html#glob-import
 | 
				
			||||||
const modulesRoutes = import.meta.glob("/src/views/*/*/*.vue");
 | 
					const modulesRoutes = import.meta.glob("/src/views/**/*.{vue,tsx}");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// 动态路由
 | 
					// 动态路由
 | 
				
			||||||
import { getAsyncRoutes } from "/@/api/routes";
 | 
					import { getAsyncRoutes } from "/@/api/routes";
 | 
				
			||||||
@ -212,11 +212,13 @@ const handleAliveRoute = (matched: RouteRecordNormalized[], mode?: string) => {
 | 
				
			|||||||
// 过滤后端传来的动态路由 重新生成规范路由
 | 
					// 过滤后端传来的动态路由 重新生成规范路由
 | 
				
			||||||
const addAsyncRoutes = (arrRoutes: Array<RouteRecordRaw>) => {
 | 
					const addAsyncRoutes = (arrRoutes: Array<RouteRecordRaw>) => {
 | 
				
			||||||
  if (!arrRoutes || !arrRoutes.length) return;
 | 
					  if (!arrRoutes || !arrRoutes.length) return;
 | 
				
			||||||
 | 
					  const modulesRoutesKeys = Object.keys(modulesRoutes);
 | 
				
			||||||
  arrRoutes.forEach((v: RouteRecordRaw) => {
 | 
					  arrRoutes.forEach((v: RouteRecordRaw) => {
 | 
				
			||||||
    if (v.redirect) {
 | 
					    if (v.redirect) {
 | 
				
			||||||
      v.component = Layout;
 | 
					      v.component = Layout;
 | 
				
			||||||
    } else {
 | 
					    } else {
 | 
				
			||||||
      v.component = modulesRoutes[`/src/views${v.path}/index.vue`];
 | 
					      const index = modulesRoutesKeys.findIndex(ev => ev.includes(v.path));
 | 
				
			||||||
 | 
					      v.component = modulesRoutes[modulesRoutesKeys[index]];
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    if (v.children) {
 | 
					    if (v.children) {
 | 
				
			||||||
      addAsyncRoutes(v.children);
 | 
					      addAsyncRoutes(v.children);
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user