docs(projects): update README.md

This commit is contained in:
Soybean
2022-03-06 01:03:34 +08:00
parent 4e31abd446
commit a0dfa3d30d
2 changed files with 23 additions and 77 deletions

View File

@ -5,17 +5,12 @@ type ViewComponent = Record<string, () => Promise<Component>>;
const importViews = import.meta.glob('./**/index.vue');
const COMPONENTS_KEY = 'components';
/**
* 路径正则匹配
* 1 './' => ''
* 2 '/index.vue' => ''
* 3 'system-view_' => '' (系统的内置路由该文件夹名称不作为RouteKey)
*/
const KEY_REGEXP = /\.\/|\/index\.vue|system-view_/g;
const PREFIX = './';
const SUFFIX = '/index.vue';
const PATH_SPLIT_MARK = '/';
const ROUTE_KEY_SPLIT_MARK = '_';
/** 系统的内置路由该文件夹名称不作为RouteKey */
const SYSTEM_VIEW = 'system-view_';
/** 过滤掉组件文件 */
const viewKeys = Object.keys(importViews).filter(key => !key.includes(COMPONENTS_KEY));
@ -23,8 +18,11 @@ const viewKeys = Object.keys(importViews).filter(key => !key.includes(COMPONENTS
function getViewComponent() {
const components: ViewComponent = {};
viewKeys.forEach(key => {
const routeKey = key.replace(KEY_REGEXP, '').replace(new RegExp(PATH_SPLIT_MARK, 'g'), ROUTE_KEY_SPLIT_MARK);
const routeKey = key
.replace(PREFIX, '')
.replace(SUFFIX, '')
.replace(new RegExp(PATH_SPLIT_MARK, 'g'), ROUTE_KEY_SPLIT_MARK)
.replace(SYSTEM_VIEW, '');
components[routeKey] = importViews[key];
});
return components;