diff --git a/packages/canvas/DesignCanvas/src/importMap.js b/packages/canvas/DesignCanvas/src/importMap.js index e7f2daece..749333d4f 100644 --- a/packages/canvas/DesignCanvas/src/importMap.js +++ b/packages/canvas/DesignCanvas/src/importMap.js @@ -33,7 +33,9 @@ export function getImportMapData(overrideVersions = {}, canvasDeps = { scripts: } const materialsAndUtilsRequire = canvasDeps.scripts.reduce((imports, { package: pkg, script }) => { - imports[pkg] = script + if (pkg && script) { + imports[pkg] = script + } return imports }, {}) diff --git a/packages/canvas/common/src/utils.js b/packages/canvas/common/src/utils.js index 37fb14e63..600a2d66d 100644 --- a/packages/canvas/common/src/utils.js +++ b/packages/canvas/common/src/utils.js @@ -68,7 +68,7 @@ const getImportMapKeys = () => { } const importMaps = importMapElement.textContent - const importMapObject = JSON.parse(importMaps) + const importMapObject = JSON.parse(importMaps || '{}') || {} return Object.keys(importMapObject.imports) } catch (error) { diff --git a/packages/plugins/bridge/src/js/resource.js b/packages/plugins/bridge/src/js/resource.js index 822bfeccb..e99d670f2 100644 --- a/packages/plugins/bridge/src/js/resource.js +++ b/packages/plugins/bridge/src/js/resource.js @@ -178,41 +178,48 @@ const generateBridgeUtil = (...args) => { export const saveResource = async (data, callback, emit) => { const isEdit = getActionType() === ACTION_TYPE.Edit - if (isEdit) { - data.id = state.resource.id - const result = await requestUpdateReSource(data) + try { + if (isEdit) { + data.id = state.resource.id + const result = await requestUpdateReSource(data) - if (result) { - const index = useResource().appSchemaState[data.category].findIndex((item) => item.name === result.name) + if (result) { + const index = useResource().appSchemaState[data.category].findIndex((item) => item.name === result.name) - if (index === -1) { - useNotify({ - type: 'error', - message: '修改失败' - }) + if (index === -1) { + useNotify({ + type: 'error', + message: '修改失败' + }) - return + return + } + + useResource().appSchemaState[data.category][index] = result } + } else { + const result = await requestAddReSource(data) - useResource().appSchemaState[data.category][index] = result + if (result) { + useResource().appSchemaState[data.category].push(result) + } } - } else { - const result = await requestAddReSource(data) - if (result) { - useResource().appSchemaState[data.category].push(result) - } + // 更新画布工具函数环境,保证渲染最新工具类返回值, 并触发画布的强制刷新 + generateBridgeUtil(getAppId()) + useNotify({ + type: 'success', + message: `${isEdit ? '修改' : '创建'}成功` + }) + emit('refresh', state.type) + state.refresh = true + callback() + } catch (error) { + useNotify({ + type: 'error', + message: `工具类${isEdit ? '修改' : '创建'}失败:${error.message}` + }) } - - // 更新画布工具函数环境,保证渲染最新工具类返回值, 并触发画布的强制刷新 - generateBridgeUtil(getAppId()) - useNotify({ - type: 'success', - message: `${isEdit ? '修改' : '创建'}成功` - }) - emit('refresh', state.type) - state.refresh = true - callback() } export const deleteData = (name, callback, emit) => { diff --git a/packages/plugins/materials/src/composable/useMaterial.js b/packages/plugins/materials/src/composable/useMaterial.js index b4eca3931..9a416b3b3 100644 --- a/packages/plugins/materials/src/composable/useMaterial.js +++ b/packages/plugins/materials/src/composable/useMaterial.js @@ -327,7 +327,8 @@ const parseMaterialsDependencies = (materialBundle) => { scripts.forEach((item) => { const dep = scriptsDeps.find((dep) => dep.package === item.package) - if (dep) { + if (dep && item.components) { + // 合并组件 dep.components = { ...dep.components, ...item.components } } }) @@ -454,7 +455,9 @@ const getBlockDeps = (dependencies = {}) => { } }) - styles?.forEach((item) => materialState.componentsDepsMap.styles.add(item)) + if (Array.isArray(styles)) { + styles.forEach((item) => materialState.componentsDepsMap.styles.add(item)) + } } const initBuiltinMaterial = () => {