routes.js 2.78 KB
/* eslint-disable node/prefer-global/process */
import layoutHeaderAside from "@/layout/header-aside";

// 由于懒加载页面太多的话会造成webpack热更新太慢,所以开发环境不使用懒加载,只有生产环境使用懒加载
const _import = require("@/libs/util.import." + process.env.NODE_ENV);

/**
 * 在主框架内显示(children 由后台返回资源点集合 从 resources 中动态过滤加载)
 */
const frameIn = [
	{
		path: "/",
		redirect: {
			name: "index",
		},
		component: layoutHeaderAside,
		children: [],
	},
];
/**
 * 首页
 * icon:element-ui
 */
export const home = {
	path: "/index",
	name: "index",
	// icon: 's-home',
	meta: {
		title: "总览",
		authId: "907",
		parentId: "1",
		cache: false,
		sideHidden: false,
	},
	auth: [
		{
			authId: "90701",
			parentId: "907",
			label: "报表模块",
		},
		{
			authId: "90702",
			parentId: "907",
			category: "Button",
			label: "查看企微推送对象",
			handle: "goCheck",
			addRoutePath: [
				{
					authId: "90703",
					name: "企微推送配置",
					parentId: "907",
				},
			],
		},
	],
	component: _import("index/simple"),
};
export const sys = [
	// 刷新页面 必须保留
	{
		path: "/refresh",
		name: "refresh",
		hidden: true,
		component: _import("system/function/refresh"),
	},
	// 页面重定向 必须保留
	{
		path: "redirect/:route*",
		name: "redirect",
		hidden: true,
		component: _import("system/function/redirect"),
	},
];

// 自带导入动态模块路径
const modulesFiles = require.context("./modules", true, /\.js$/);
// console.log("modulesFiles", modulesFiles)
const routerNameList = modulesFiles
	.keys()
	.reduce((routerNameList, modulePath) => {
		const value = modulesFiles(modulePath);
		// const moduleName = modulePath.replace(/^\.\/(.*)\.\w+$/, "$1")
		// console.log(modulesFiles(modulePath))
		// console.log(value.routerName)
		// routerNameList.push(...value.routerName)
		routerNameList = Object.assign(routerNameList, value.routerName);
		// modules[moduleName] = value.default
		return routerNameList;
	}, {});
// console.log("modules", routerNameList)

/**
 * 所有需动态过滤的资源点
 * 907 - 总览
 * 902 - 流量管理
 * 903 - 产品管理
 * 904 - 订单管理
 * 905 - 财务管理
 * 906 - 系统设置
 * 908 - 我的分账
 */
export const resources = {
	...routerNameList,
};

/**
 * 在主框架之外显示
 */
const frameOut = [
	// 登录
	{
		path: "/login",
		name: "login",
		component: _import("system/login"),
	},
];

/**
 * 错误页面
 */
export const errorPage = {
	path: "*",
	name: "404",
	component: _import("system/error/404"),
};

// 导出需要显示菜单的
export const frameInRoutes = frameIn;

export const localRoutes = {
	// [home.meta.authId]: home,
	...resources,
};

// 重新组织后导出
export default [...frameOut, errorPage];