Skip to content

Commit

Permalink
fix: add error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
chilingling committed Dec 11, 2024
1 parent c777b18 commit 7886450
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 12 deletions.
6 changes: 4 additions & 2 deletions packages/canvas/DesignCanvas/src/DesignCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import {
getOptions,
getMetaApi,
META_SERVICE,
useMessage
useMessage,
useNotify
} from '@opentiny/tiny-engine-meta-register'
import { constants } from '@opentiny/tiny-engine-utils'
import * as ast from '@opentiny/tiny-engine-common/js/ast'
Expand Down Expand Up @@ -188,7 +189,8 @@ export default {
request: getMetaApi(META_SERVICE.Http).getHttp(),
ast,
useModal,
useMessage
useMessage,
useNotify
},
CanvasLayout,
canvasRef,
Expand Down
6 changes: 5 additions & 1 deletion packages/canvas/DesignCanvas/src/api/useCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,14 @@ const operationTypeMap = {
node = pageState.pageSchema
}

if (!node.props) {
node.props = {}
}

if (overwrite) {
node.props = value.props
} else {
Object.assign(node, value || {})
Object.assign(node.props, value?.props || {})
}

return {
Expand Down
8 changes: 8 additions & 0 deletions packages/canvas/render/src/RenderMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ const getDeletedKeys = (objA, objB) => {
const getUtils = () => utils

const setUtils = (data) => {
if (!Array.isArray(data)) {
return
}

// 筛选出来已经被删除的 key
const newKeys = new Set(data.map(({ name }) => name))
const currentKeys = Object.keys(utils)
Expand Down Expand Up @@ -150,6 +154,10 @@ const generateStateAccessors = (type, accessor, key) => {
}

const setState = (data) => {
if (typeof data !== 'object' || data === null) {
return
}

const deletedKeys = getDeletedKeys(state, data)

// 同步删除的 key
Expand Down
19 changes: 13 additions & 6 deletions packages/canvas/render/src/builtin/CanvasCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,12 +119,19 @@ const askShouldImportData = ({ node, sourceRef, updateKey }) => {
.confirm({
message: '检测到表格存在配置的数据,是否需要引入?',
exec() {
const sourceColumns = sourceRef.value?.data?.columns?.map(({ title, field }) => ({ title, field })) || []
// 这里需要找到对应列,然后进行列合并
node.props.columns = generateAssignColumns(sourceColumns, node.props.columns)

publish({ topic: 'schemaChange', data: {} })
updateKey.value++
try {
const sourceColumns = sourceRef.value?.data?.columns?.map(({ title, field }) => ({ title, field })) || []
// 这里需要找到对应列,然后进行列合并
node.props.columns = generateAssignColumns(sourceColumns, node.props.columns)

publish({ topic: 'schemaChange', data: {} })
updateKey.value++
} catch (error) {
getController().useNotify({
type: 'error',
message: '引入配置数据失败'
})
}
},
cancel() {
node.props.columns = [...(sourceRef.value.data?.columns || [])]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ export default {
const { operateNode } = useCanvas()
const id = value.id
operateNode({ type: 'changeProps', id, value: value.props })
operateNode({ type: 'changeProps', id, value: { props: value.props } })
}
return { children, addChildren, delChildren, dragEnd, onTitleUpdate }
Expand Down
20 changes: 20 additions & 0 deletions packages/plugins/bridge/src/js/resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,16 @@ export const saveResource = (data, callback, emit) => {
requestUpdateReSource(data).then((result) => {
if (result) {
const index = useResource().appSchemaState[data.category].findIndex((item) => item.name === result.name)

if (index === -1) {
useNotify({
type: 'error',
message: '修改失败'
})

return
}

useResource().appSchemaState[data.category][index] = result

// 更新画布工具函数环境,保证渲染最新工具类返回值, 并触发画布的强制刷新
Expand Down Expand Up @@ -222,6 +232,16 @@ export const deleteData = (name, callback, emit) => {
requestDeleteReSource(params).then((data) => {
if (data) {
const index = useResource().appSchemaState[state.type].findIndex((item) => item.name === data.name)

if (index === -1) {
useNotify({
type: 'error',
message: '删除失败'
})

return
}

useResource().appSchemaState[state.type].splice(index, 1)

generateBridgeUtil(getAppId())
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/i18n/src/composable/useTranslate.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ const getI18n = async ({ init, local }) => {

return { locales, messages }
} else {
const i18n = init ? appSchemaState.langs : await getI18nData
const i18n = init ? appSchemaState.langs : await getI18nData()

return i18n
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/state/src/Main.vue
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ export default {
} else {
const pageSchema = getSchema() || {}
state.dataSource = pageSchema.state
state.dataSource = pageSchema.state || {}
}
}
Expand Down

0 comments on commit 7886450

Please sign in to comment.