Commit 44f1ceb7e2f7a2524baeed320ebf53cc6ece26d4

Authored by ww
1 parent 2876552a

fix: 修复物模型导入空对象时报错

@@ -247,6 +247,8 @@ @@ -247,6 +247,8 @@
247 return { flag, data }; 247 return { flag, data };
248 }; 248 };
249 249
  250 + const isEmptyObject = (value: any) => isObject(value) && !Object.keys(value).length;
  251 +
250 const importLoading = ref(false); 252 const importLoading = ref(false);
251 const handleImportModel = async (data: { file: File }) => { 253 const handleImportModel = async (data: { file: File }) => {
252 const fileReader = new FileReader(); 254 const fileReader = new FileReader();
@@ -259,6 +261,14 @@ @@ -259,6 +261,14 @@
259 } 261 }
260 try { 262 try {
261 importLoading.value = true; 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 const result = await importModelOfMatter({ 272 const result = await importModelOfMatter({
263 tkDeviceProfileId: props.record.id, 273 tkDeviceProfileId: props.record.id,
264 data: data!, 274 data: data!,
@@ -25,6 +25,7 @@ @@ -25,6 +25,7 @@
25 import { Button } from 'ant-design-vue'; 25 import { Button } from 'ant-design-vue';
26 import { getModelTsl } from '/@/api/device/modelOfMatter'; 26 import { getModelTsl } from '/@/api/device/modelOfMatter';
27 import { FunctionType } from './cpns/config'; 27 import { FunctionType } from './cpns/config';
  28 + import { isObject } from '/@/utils/is';
28 29
29 defineEmits(['register']); 30 defineEmits(['register']);
30 31
@@ -78,11 +79,17 @@ @@ -78,11 +79,17 @@
78 ]); 79 ]);
79 }; 80 };
80 81
  82 + const isEmptyObject = (value: any) => isObject(value) && !Object.keys(value).length;
  83 +
81 const handleExportAll = async () => { 84 const handleExportAll = async () => {
82 loading.value = true; 85 loading.value = true;
83 try { 86 try {
84 const [events, properties, services] = await getAllModel(); 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 exportJSONFile(value); 93 exportJSONFile(value);
87 } catch (error) { 94 } catch (error) {
88 throw error; 95 throw error;