Commit 4331f4fc3b77763cd99812039bfb2b68813e5f6f

Authored by ww
1 parent 4c00183f

feat: 产品详情物模型新增导出全部物模型

@@ -179,12 +179,7 @@ @@ -179,12 +179,7 @@
179 ); 179 );
180 180
181 selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => { 181 selectionOptions.rowSelection.getCheckboxProps = (record: Recordable) => {
182 - // Demo:status为1的选择框禁用  
183 - if (record.status === 1) {  
184 - return { disabled: true };  
185 - } else {  
186 - return { disabled: false };  
187 - } 182 + return { disabled: record.status === 1 };
188 }; 183 };
189 184
190 const handleViewDetail = (record: ModelOfMatterParams) => { 185 const handleViewDetail = (record: ModelOfMatterParams) => {
@@ -5,12 +5,16 @@ @@ -5,12 +5,16 @@
5 destroyOnClose 5 destroyOnClose
6 v-bind="$attrs" 6 v-bind="$attrs"
7 width="55rem" 7 width="55rem"
  8 + :okButtonProps="{ loading }"
8 @register="register" 9 @register="register"
9 @ok="handleSubmit" 10 @ok="handleSubmit"
10 okText="导出物模型" 11 okText="导出物模型"
11 @cancel="handleCancel" 12 @cancel="handleCancel"
12 > 13 >
13 - <TslContent :record="$props.record" ref="TslConRef" /> 14 + <TslContent :record="record" ref="TslConRef" />
  15 + <template #centerFooter>
  16 + <Button type="primary" :loading="loading" @click="handleExportAll">导出全部</Button>
  17 + </template>
14 </BasicModal> 18 </BasicModal>
15 </template> 19 </template>
16 <script lang="ts" setup> 20 <script lang="ts" setup>
@@ -18,6 +22,9 @@ @@ -18,6 +22,9 @@
18 import { BasicModal, useModalInner } from '/@/components/Modal'; 22 import { BasicModal, useModalInner } from '/@/components/Modal';
19 import TslContent from './cpns/TslContent.vue'; 23 import TslContent from './cpns/TslContent.vue';
20 import { DeviceRecord } from '/@/api/device/model/deviceModel'; 24 import { DeviceRecord } from '/@/api/device/model/deviceModel';
  25 + import { Button } from 'ant-design-vue';
  26 + import { getModelTsl } from '/@/api/device/modelOfMatter';
  27 + import { FunctionType } from './cpns/config';
21 28
22 defineEmits(['register']); 29 defineEmits(['register']);
23 30
@@ -28,6 +35,8 @@ @@ -28,6 +35,8 @@
28 const TslConRef = ref<InstanceType<typeof TslContent>>(); 35 const TslConRef = ref<InstanceType<typeof TslContent>>();
29 const isUpdate = ref(false); 36 const isUpdate = ref(false);
30 37
  38 + const loading = ref(false);
  39 +
31 const [register, { closeModal, setModalProps }] = useModalInner(async (data) => { 40 const [register, { closeModal, setModalProps }] = useModalInner(async (data) => {
32 setModalProps({ confirmLoading: true }); 41 setModalProps({ confirmLoading: true });
33 isUpdate.value = data.isUpdate; 42 isUpdate.value = data.isUpdate;
@@ -41,10 +50,7 @@ @@ -41,10 +50,7 @@
41 closeModal(); 50 closeModal();
42 }; 51 };
43 52
44 - const handleSubmit = () => {  
45 - const value = TslConRef.value?.getFormData();  
46 - if (!value) return;  
47 - 53 + const exportJSONFile = (value: Recordable) => {
48 const blob = new Blob([JSON.stringify(value, null, 2)], { type: 'text/json' }); 54 const blob = new Blob([JSON.stringify(value, null, 2)], { type: 'text/json' });
49 const objectURL = URL.createObjectURL(blob); 55 const objectURL = URL.createObjectURL(blob);
50 const element = document.createElement('a'); 56 const element = document.createElement('a');
@@ -56,6 +62,34 @@ @@ -56,6 +62,34 @@
56 element.remove(); 62 element.remove();
57 URL.revokeObjectURL(objectURL); 63 URL.revokeObjectURL(objectURL);
58 }; 64 };
  65 +
  66 + const handleSubmit = () => {
  67 + const value = TslConRef.value?.getFormData();
  68 + if (!value) return;
  69 + exportJSONFile(value);
  70 + };
  71 +
  72 + const getAllModel = () => {
  73 + const { id: deviceProfileId } = props.record;
  74 + return Promise.all([
  75 + getModelTsl({ deviceProfileId, functionType: FunctionType.EVENTS }),
  76 + getModelTsl({ deviceProfileId, functionType: FunctionType.PROPERTIES }),
  77 + getModelTsl({ deviceProfileId, functionType: FunctionType.SERVICE }),
  78 + ]);
  79 + };
  80 +
  81 + const handleExportAll = async () => {
  82 + loading.value = true;
  83 + try {
  84 + const [events, properties, service] = await getAllModel();
  85 + const value = { properties, service, events };
  86 + exportJSONFile(value);
  87 + } catch (error) {
  88 + throw error;
  89 + } finally {
  90 + loading.value = false;
  91 + }
  92 + };
59 </script> 93 </script>
60 94
61 <style lang="less" scope> 95 <style lang="less" scope>