Skip to content

Commit

Permalink
fix: review
Browse files Browse the repository at this point in the history
  • Loading branch information
yy-wow committed Jan 13, 2025
1 parent b26bbf4 commit 330c3a1
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 31 deletions.
4 changes: 3 additions & 1 deletion packages/canvas/DesignCanvas/src/importMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}, {})
Expand Down
2 changes: 1 addition & 1 deletion packages/canvas/common/src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
61 changes: 34 additions & 27 deletions packages/plugins/bridge/src/js/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
7 changes: 5 additions & 2 deletions packages/plugins/materials/src/composable/useMaterial.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
})
Expand Down Expand Up @@ -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 = () => {
Expand Down

0 comments on commit 330c3a1

Please sign in to comment.