Commit c3f5e84416ba5c3f8e63a169a9a2c413a072a2a3
Merge branch 'fix/object-model-import' into 'main_dev'
fix: 修复物模型导入空对象时报错 See merge request yunteng/thingskit-front!713
Showing
2 changed files
with
18 additions
and
1 deletions
... | ... | @@ -247,6 +247,8 @@ |
247 | 247 | return { flag, data }; |
248 | 248 | }; |
249 | 249 | |
250 | + const isEmptyObject = (value: any) => isObject(value) && !Object.keys(value).length; | |
251 | + | |
250 | 252 | const importLoading = ref(false); |
251 | 253 | const handleImportModel = async (data: { file: File }) => { |
252 | 254 | const fileReader = new FileReader(); |
... | ... | @@ -259,6 +261,14 @@ |
259 | 261 | } |
260 | 262 | try { |
261 | 263 | importLoading.value = true; |
264 | + | |
265 | + Object.keys(data || {}).forEach((key) => { | |
266 | + const value = (data || {})[key]; | |
267 | + if (value && isEmptyObject(value)) { | |
268 | + (data || {})[key] = []; | |
269 | + } | |
270 | + }); | |
271 | + | |
262 | 272 | const result = await importModelOfMatter({ |
263 | 273 | tkDeviceProfileId: props.record.id, |
264 | 274 | data: data!, | ... | ... |
... | ... | @@ -25,6 +25,7 @@ |
25 | 25 | import { Button } from 'ant-design-vue'; |
26 | 26 | import { getModelTsl } from '/@/api/device/modelOfMatter'; |
27 | 27 | import { FunctionType } from './cpns/config'; |
28 | + import { isObject } from '/@/utils/is'; | |
28 | 29 | |
29 | 30 | defineEmits(['register']); |
30 | 31 | |
... | ... | @@ -78,11 +79,17 @@ |
78 | 79 | ]); |
79 | 80 | }; |
80 | 81 | |
82 | + const isEmptyObject = (value: any) => isObject(value) && !Object.keys(value).length; | |
83 | + | |
81 | 84 | const handleExportAll = async () => { |
82 | 85 | loading.value = true; |
83 | 86 | try { |
84 | 87 | const [events, properties, services] = await getAllModel(); |
85 | - const value = { properties, services, events }; | |
88 | + const value = { | |
89 | + properties: isEmptyObject(properties) ? [] : properties, | |
90 | + services: isEmptyObject(services) ? [] : services, | |
91 | + events: isEmptyObject(events) ? [] : events, | |
92 | + }; | |
86 | 93 | exportJSONFile(value); |
87 | 94 | } catch (error) { |
88 | 95 | throw error; | ... | ... |