feat: 处理数据导入,ID更新的可控功能

This commit is contained in:
奔跑的面条 2022-08-17 16:56:58 +08:00
parent 2236100e3d
commit 580f5b1a3f
2 changed files with 30 additions and 12 deletions

View File

@ -34,13 +34,13 @@ export const useFile = () => {
// 新增
onPositiveCallback: async () => {
fileData = JSON.parse(fileData)
await updateComponent(fileData)
await updateComponent(fileData, false, true)
window['$message'].success('导入成功!')
},
// 覆盖
onNegativeCallback: async () => {
fileData = JSON.parse(fileData)
await updateComponent(fileData, true)
await updateComponent(fileData, true, true)
window['$message'].success('导入成功!')
}
})

View File

@ -14,11 +14,11 @@ export const useSync = () => {
/**
* *
* @param projectData
* @param isSplace
* @param isReplace
* @returns
*/
const updateComponent = async (projectData: ChartEditStorage, isSplace = false) => {
if (isSplace) {
const updateComponent = async (projectData: ChartEditStorage, isReplace = false, changeId = false) => {
if (isReplace) {
// 清除列表
chartEditStore.componentList = []
// 清除历史记录
@ -47,22 +47,40 @@ export const useSync = () => {
// 组件
if (key === ChartEditStoreEnum.COMPONENT_LIST) {
for (const comItem of projectData[key]) {
// 重新创建是为了处理类种方法消失的问题
const create = async (e: CreateComponentType, callBack?: (e: CreateComponentType) => void) => {
const create = async (
_componentInstance: CreateComponentType,
callBack?: (componentInstance: CreateComponentType) => void
) => {
// 补充 class 上的方法
let newComponent: CreateComponentType = await createComponent(e.chartConfig)
let newComponent: CreateComponentType = await createComponent(_componentInstance.chartConfig)
if (callBack) {
callBack(Object.assign(newComponent, { ...e, id: getUUID() }))
if (changeId) {
callBack(Object.assign(newComponent, { ..._componentInstance, id: getUUID() }))
} else {
chartEditStore.addComponentList(Object.assign(newComponent, { ...e, id: getUUID() }), false, true)
callBack(Object.assign(newComponent))
}
} else {
if (changeId) {
chartEditStore.addComponentList(
Object.assign(newComponent, { ..._componentInstance, id: getUUID() }),
false,
true
)
} else {
chartEditStore.addComponentList(Object.assign(newComponent), false, true)
}
}
}
if (comItem.isGroup) {
// 创建分组
let groupClass = new PublicGroupConfigClass()
groupClass = Object.assign(groupClass, comItem)
if (changeId) {
groupClass = Object.assign(groupClass, { ...comItem, id: getUUID() })
} else {
groupClass = Object.assign(groupClass, { ...comItem })
}
// 注册子应用
const targetList: CreateComponentType[] = []