Commit d011484fa8f29064215fa45507a83d581f8f0342
Merge branch 'dev-fix-ww' into 'main_dev'
feat: 产品详情物模型新增导出全部物模型 See merge request yunteng/thingskit-front!567
Showing
2 changed files
with
40 additions
and
11 deletions
... | ... | @@ -179,12 +179,7 @@ |
179 | 179 | ); |
180 | 180 | |
181 | 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 | 185 | const handleViewDetail = (record: ModelOfMatterParams) => { | ... | ... |
... | ... | @@ -5,12 +5,16 @@ |
5 | 5 | destroyOnClose |
6 | 6 | v-bind="$attrs" |
7 | 7 | width="55rem" |
8 | + :okButtonProps="{ loading }" | |
8 | 9 | @register="register" |
9 | 10 | @ok="handleSubmit" |
10 | 11 | okText="导出物模型" |
11 | 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 | 18 | </BasicModal> |
15 | 19 | </template> |
16 | 20 | <script lang="ts" setup> |
... | ... | @@ -18,6 +22,9 @@ |
18 | 22 | import { BasicModal, useModalInner } from '/@/components/Modal'; |
19 | 23 | import TslContent from './cpns/TslContent.vue'; |
20 | 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 | 29 | defineEmits(['register']); |
23 | 30 | |
... | ... | @@ -28,6 +35,8 @@ |
28 | 35 | const TslConRef = ref<InstanceType<typeof TslContent>>(); |
29 | 36 | const isUpdate = ref(false); |
30 | 37 | |
38 | + const loading = ref(false); | |
39 | + | |
31 | 40 | const [register, { closeModal, setModalProps }] = useModalInner(async (data) => { |
32 | 41 | setModalProps({ confirmLoading: true }); |
33 | 42 | isUpdate.value = data.isUpdate; |
... | ... | @@ -41,10 +50,7 @@ |
41 | 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 | 54 | const blob = new Blob([JSON.stringify(value, null, 2)], { type: 'text/json' }); |
49 | 55 | const objectURL = URL.createObjectURL(blob); |
50 | 56 | const element = document.createElement('a'); |
... | ... | @@ -56,6 +62,34 @@ |
56 | 62 | element.remove(); |
57 | 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 | 93 | </script> |
60 | 94 | |
61 | 95 | <style lang="less" scope> | ... | ... |