mirror of
https://github.com/Tencent/tdesign-vue-next-starter.git
synced 2024-11-10 07:08:23 +08:00
feat: router修改为自动导入 (#223)
* feat: router修改为自动导入 * fix: 修复CI编译错误并移除多余声明 * feat: 添加orderNo令自动导入的路由可以排序
This commit is contained in:
parent
3afb38d1d1
commit
4067e7ca30
|
@ -7,6 +7,10 @@ const getMenuList = (list: MenuRoute[], basePath?: string): MenuRoute[] => {
|
||||||
if (!list) {
|
if (!list) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
// 如果meta中有orderNo则按照从小到大排序
|
||||||
|
list.sort((a, b) => {
|
||||||
|
return (a.meta?.orderNo || 0) - (b.meta?.orderNo || 0);
|
||||||
|
});
|
||||||
return list
|
return list
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
const path = basePath ? `${basePath}/${item.path}` : item.path;
|
const path = basePath ? `${basePath}/${item.path}` : item.path;
|
||||||
|
|
|
@ -1,13 +1,21 @@
|
||||||
import { useRoute, createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
|
import { useRoute, createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
|
||||||
|
|
||||||
import baseRouters from './modules/base';
|
// 自动导入modules文件夹下所有ts文件
|
||||||
import componentsRouters from './modules/components';
|
const modules = import.meta.globEager('./modules/**/*.ts');
|
||||||
import othersRouters from './modules/others';
|
|
||||||
|
// 路由暂存
|
||||||
|
const routeModuleList: Array<RouteRecordRaw> = [];
|
||||||
|
|
||||||
|
Object.keys(modules).forEach((key) => {
|
||||||
|
const mod = modules[key].default || {};
|
||||||
|
const modList = Array.isArray(mod) ? [...mod] : [mod];
|
||||||
|
routeModuleList.push(...modList);
|
||||||
|
});
|
||||||
|
|
||||||
// 关于单层路由,meta 中设置 { single: true } 即可为单层路由,{ hidden: true } 即可在侧边栏隐藏该路由
|
// 关于单层路由,meta 中设置 { single: true } 即可为单层路由,{ hidden: true } 即可在侧边栏隐藏该路由
|
||||||
|
|
||||||
// 存放动态路由
|
// 存放动态路由
|
||||||
export const asyncRouterList: Array<RouteRecordRaw> = [...baseRouters, ...componentsRouters, ...othersRouters];
|
export const asyncRouterList: Array<RouteRecordRaw> = [...routeModuleList];
|
||||||
|
|
||||||
// 存放固定的路由
|
// 存放固定的路由
|
||||||
const defaultRouterList: Array<RouteRecordRaw> = [
|
const defaultRouterList: Array<RouteRecordRaw> = [
|
||||||
|
|
7
src/types/globals.d.ts
vendored
7
src/types/globals.d.ts
vendored
|
@ -10,13 +10,6 @@ declare module '*.vue' {
|
||||||
|
|
||||||
declare type ClassName = { [className: string]: any } | ClassName[] | string;
|
declare type ClassName = { [className: string]: any } | ClassName[] | string;
|
||||||
|
|
||||||
declare interface ImportMeta {
|
|
||||||
env: {
|
|
||||||
MODE: 'mock' | 'development' | 'test' | 'release';
|
|
||||||
};
|
|
||||||
glob: (url: string) => { url };
|
|
||||||
}
|
|
||||||
|
|
||||||
declare module '*.svg' {
|
declare module '*.svg' {
|
||||||
const CONTENT: string;
|
const CONTENT: string;
|
||||||
export default CONTENT;
|
export default CONTENT;
|
||||||
|
|
|
@ -7,7 +7,10 @@
|
||||||
"sourceMap": true,
|
"sourceMap": true,
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"allowSyntheticDefaultImports": true,
|
||||||
"lib": ["esnext", "dom"],
|
"lib": ["esnext", "dom"],
|
||||||
|
"types": ["vite/client"],
|
||||||
"noEmit": true,
|
"noEmit": true,
|
||||||
"baseUrl": "./",
|
"baseUrl": "./",
|
||||||
"paths": {
|
"paths": {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user