soybean-admin/src/views/index.ts

32 lines
946 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import type { Component } from 'vue';
type ViewComponent = Record<string, () => Promise<Component>>;
const importViews = import.meta.glob('./**/index.vue') as ViewComponent;
const COMPONENTS_KEY = 'components';
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));
function getViewComponent() {
const components: ViewComponent = {};
viewKeys.forEach(key => {
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;
}
export const views = getViewComponent();