mirror of
https://github.com/Tencent/tdesign-vue-next-starter.git
synced 2024-09-20 02:34:24 +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) {
|
||||
return [];
|
||||
}
|
||||
// 如果meta中有orderNo则按照从小到大排序
|
||||
list.sort((a, b) => {
|
||||
return (a.meta?.orderNo || 0) - (b.meta?.orderNo || 0);
|
||||
});
|
||||
return list
|
||||
.map((item) => {
|
||||
const path = basePath ? `${basePath}/${item.path}` : item.path;
|
||||
|
|
|
@ -1,13 +1,21 @@
|
|||
import { useRoute, createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router';
|
||||
|
||||
import baseRouters from './modules/base';
|
||||
import componentsRouters from './modules/components';
|
||||
import othersRouters from './modules/others';
|
||||
// 自动导入modules文件夹下所有ts文件
|
||||
const modules = import.meta.globEager('./modules/**/*.ts');
|
||||
|
||||
// 路由暂存
|
||||
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 } 即可在侧边栏隐藏该路由
|
||||
|
||||
// 存放动态路由
|
||||
export const asyncRouterList: Array<RouteRecordRaw> = [...baseRouters, ...componentsRouters, ...othersRouters];
|
||||
export const asyncRouterList: Array<RouteRecordRaw> = [...routeModuleList];
|
||||
|
||||
// 存放固定的路由
|
||||
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 interface ImportMeta {
|
||||
env: {
|
||||
MODE: 'mock' | 'development' | 'test' | 'release';
|
||||
};
|
||||
glob: (url: string) => { url };
|
||||
}
|
||||
|
||||
declare module '*.svg' {
|
||||
const CONTENT: string;
|
||||
export default CONTENT;
|
||||
|
|
|
@ -7,7 +7,10 @@
|
|||
"sourceMap": true,
|
||||
"resolveJsonModule": true,
|
||||
"esModuleInterop": true,
|
||||
"skipLibCheck": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"lib": ["esnext", "dom"],
|
||||
"types": ["vite/client"],
|
||||
"noEmit": true,
|
||||
"baseUrl": "./",
|
||||
"paths": {
|
||||
|
|
Loading…
Reference in New Issue
Block a user