fix: 解决导入时顺序不对的问题

This commit is contained in:
奔跑的面条 2022-10-14 14:33:14 +08:00
parent a5bf0e9f6a
commit d835a904c9

View File

@ -18,7 +18,7 @@ const componentMerge = (object: any, sources: any, notComponent = false) => {
if (notComponent) return merge(object, sources) if (notComponent) return merge(object, sources)
// 组件排除 options // 组件排除 options
const option = sources.option const option = sources.option
if(!option) return merge(object, sources) if (!option) return merge(object, sources)
// 为 undefined 的 sources 来源对象属性将被跳过详见 https://www.lodashjs.com/docs/lodash.merge // 为 undefined 的 sources 来源对象属性将被跳过详见 https://www.lodashjs.com/docs/lodash.merge
sources.option = undefined sources.option = undefined
@ -66,12 +66,8 @@ export const useSync = () => {
intComponent(e as CreateComponentType) intComponent(e as CreateComponentType)
} }
}) })
// 数据赋值
for (const key in projectData) { // 创建函数-重新创建是为了处理类种方法消失的问题
// 组件
if (key === ChartEditStoreEnum.COMPONENT_LIST) {
for (const comItem of projectData[key]) {
// 重新创建是为了处理类种方法消失的问题
const create = async ( const create = async (
_componentInstance: CreateComponentType, _componentInstance: CreateComponentType,
callBack?: (componentInstance: CreateComponentType) => void callBack?: (componentInstance: CreateComponentType) => void
@ -97,6 +93,11 @@ export const useSync = () => {
} }
} }
// 数据赋值
for (const key in projectData) {
// 组件
if (key === ChartEditStoreEnum.COMPONENT_LIST) {
for (const comItem of projectData[key]) {
if (comItem.isGroup) { if (comItem.isGroup) {
// 创建分组 // 创建分组
let groupClass = new PublicGroupConfigClass() let groupClass = new PublicGroupConfigClass()
@ -106,19 +107,19 @@ export const useSync = () => {
groupClass = componentMerge(groupClass, comItem) groupClass = componentMerge(groupClass, comItem)
} }
// 注册子应用 // 异步注册子应用
const targetList: CreateComponentType[] = [] const targetList: CreateComponentType[] = []
;(comItem as CreateComponentGroupType).groupList.forEach(groupItem => { for (const groupItem of (comItem as CreateComponentGroupType).groupList) {
create(groupItem, e => { await create(groupItem, e => {
targetList.push(e) targetList.push(e)
}) })
}) }
groupClass.groupList = targetList groupClass.groupList = targetList
// 分组插入到列表 // 分组插入到列表
chartEditStore.addComponentList(groupClass, false, true) chartEditStore.addComponentList(groupClass, false, true)
} else { } else {
create(comItem as CreateComponentType) await create(comItem as CreateComponentType)
} }
} }
} else { } else {