Commit b9501b2806ba8819086664431aa0f5d07df220f2

Authored by ww
1 parent d6c8cc59

perf: 物模型导入优化错误提示与导入loading

... ... @@ -34,7 +34,7 @@
34 34 </Authority>
35 35 <Button type="primary" @click="handleOpenTsl"> 物模型TSL </Button>
36 36 <Upload v-if="isShowBtn" :show-upload-list="false" :customRequest="handleImportModel">
37   - <Button type="primary"> 导入物模型 </Button>
  37 + <Button type="primary" :loading="importLoading"> 导入物模型 </Button>
38 38 </Upload>
39 39 </div>
40 40 <div class="flex gap-2">
... ... @@ -247,21 +247,34 @@
247 247 return { flag, data };
248 248 };
249 249
  250 + const importLoading = ref(false);
250 251 const handleImportModel = async (data: { file: File }) => {
251 252 const fileReader = new FileReader();
252 253
253 254 fileReader.onload = async () => {
254 255 const { flag, data } = paseJSON(fileReader.result as string);
255   - if (!flag) return;
256   - const result = await importModelOfMatter({
257   - tkDeviceProfileId: props.record.id,
258   - data: data!,
259   - functionType: 'all',
260   - });
  256 + if (!flag) {
  257 + createMessage.warning('JSON解析失败,请导入正确的JSON~');
  258 + return;
  259 + }
  260 + try {
  261 + importLoading.value = true;
  262 + const result = await importModelOfMatter({
  263 + tkDeviceProfileId: props.record.id,
  264 + data: data!,
  265 + functionType: 'all',
  266 + });
261 267
262   - result ? createMessage.success('导入成功~') : createMessage.error('导入失败~');
  268 + result
  269 + ? createMessage.success('导入成功~')
  270 + : createMessage.error('JSON解析失败,请导入正确的JSON~');
263 271
264   - result && reload();
  272 + result && reload();
  273 + } catch (error) {
  274 + throw error;
  275 + } finally {
  276 + importLoading.value = false;
  277 + }
265 278 };
266 279
267 280 fileReader.readAsText(data.file, 'utf-8');
... ...