Commit 5596d0436ac52dbd4ce755132893f10dc4afd762
Merge branch 'cherry-pick-e704e9bf' into 'main'
Merge branch 'feat-import-model-of-matter' into 'main_dev' See merge request yunteng/thingskit-front!602
Showing
1 changed file
with
22 additions
and
9 deletions
| ... | ... | @@ -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'); | ... | ... |