override.ts
2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { ConfigType } from "../index.d"
import { compatibleConfig } from "./compatibleConfig"
import { matchExternalPrefixReg } from "./useWidgetKey"
const getAllConfigFile = async () => {
return import.meta.glob('../components/**/config.ts', )
}
const getChartConfigFile = async (path: string) => {
const fileList = await getAllConfigFile()
if (path.includes('group')) return // 分组则终止
return fileList[path]() as any
}
export const createComponent = async (configType: ConfigType) => {
// eslint-disable-next-line prefer-const
// eslint-disable-next-line prefer-const
let { key, chartKey, category, package: packageName, redirectComponent, categoryName , conKey, isThreeModel} = configType
// redirectComponent 是给图片组件库和图标组件库使用的
if (!isThreeModel && redirectComponent) {
const [packageName, categoryName, keyName] = redirectComponent.split('/')
const filePath = `../components/${packageName}/${categoryName}/${keyName}/config.ts`
const redirectChart = await getChartConfigFile(filePath)
return new redirectChart.default()
}
// isThreeModel是给3D模型使用的
if(isThreeModel && redirectComponent) {
const [packageName, categoryName, keyName] = (redirectComponent as string).split('/')
const hasExternalPrefix = matchExternalPrefixReg.test(chartKey)
const filePath = `../components${hasExternalPrefix ? '/external' : ''}/${packageName}/${categoryName}/${keyName}/config.ts`
const redirectChart = await getChartConfigFile(filePath)
return new redirectChart.default()
}
/**
* 兼容之前导入错误的补丁
*/
const includeOldTitleKeys=['LeftCenterRightHead','LeftCenterRightHeadAnimat','Title1','Title2','Title3']
compatibleConfig?.forEach(item => {
if (item?.key === key) {
key = includeOldTitleKeys.includes(item?.key)?item?.newKey:item?.key as any
packageName = item?.newPackage as string
category = item?.newCategory as string
// eslint-disable-next-line @typescript-eslint/no-unused-vars
categoryName = item?.newCategoryName as string
chartKey = includeOldTitleKeys.includes(item?.key)?item?.newChartKey:chartKey as any
// eslint-disable-next-line @typescript-eslint/no-unused-vars
conKey = includeOldTitleKeys.includes(item?.key)?item?.newConKey:conKey as any
}
})
//
const hasExternalPrefix = matchExternalPrefixReg.test(chartKey)
const filePath = `../components${hasExternalPrefix ? '/external' : ''}/${packageName}/${category}/${key}/config.ts`
if (filePath.includes('group')) return // 分组则终止
const chart = await getChartConfigFile(filePath)
return new chart.default()
}