ruoyi-plus-soybean/src/views/index.ts

34 lines
922 B
TypeScript
Raw Normal View History

import type { Component } from 'vue';
type ViewComponent = Record<string, () => Promise<Component>>;
const importViews = import.meta.glob('./**/index.vue');
const COMPONENTS_KEY = 'components';
2022-03-05 23:20:00 +08:00
/**
*
* 1 './' => ''
* 2 '/index.vue' => ''
* 3 'system-view_' => '' (RouteKey)
*/
const KEY_REGEXP = /\.\/|\/index\.vue|system-view_/g;
const PATH_SPLIT_MARK = '/';
const ROUTE_KEY_SPLIT_MARK = '_';
/** 过滤掉组件文件 */
const viewKeys = Object.keys(importViews).filter(key => !key.includes(COMPONENTS_KEY));
function getViewComponent() {
const components: ViewComponent = {};
viewKeys.forEach(key => {
2022-03-05 23:20:00 +08:00
const routeKey = key.replace(KEY_REGEXP, '').replace(new RegExp(PATH_SPLIT_MARK, 'g'), ROUTE_KEY_SPLIT_MARK);
components[routeKey] = importViews[key];
});
return components;
}
export const views = getViewComponent();