Commit aef89d0dce5075c46954d3e2491c629cd66e7159
Merge branch 'ft_local_dev' into 'main'
pref:优化物模型重复代码 See merge request huang/yun-teng-iot-front!388
Showing
8 changed files
with
56 additions
and
79 deletions
... | ... | @@ -186,7 +186,7 @@ export const getGATEWAYdevice = async (params: { organization: string }) => { |
186 | 186 | params, |
187 | 187 | }); |
188 | 188 | return Promise.resolve<{ label: string; value: string }[]>( |
189 | - res.map((item) => ({ label: item.name, value: item.id })) | |
189 | + res.map((item) => ({ label: item.name, value: item.tbDeviceId })) | |
190 | 190 | ); |
191 | 191 | }; |
192 | 192 | ... | ... |
... | ... | @@ -304,7 +304,7 @@ |
304 | 304 | async function handleEdit(record: Recordable) { |
305 | 305 | if (record.deviceType === 'SENSOR') { |
306 | 306 | const res = await getGATEWAY(record.tbDeviceId); |
307 | - Reflect.set(record, 'gatewayId', res.id); | |
307 | + Reflect.set(record, 'gatewayId', res.tbDeviceId); | |
308 | 308 | } |
309 | 309 | openModal(true, { |
310 | 310 | isUpdate: true, | ... | ... |
... | ... | @@ -56,7 +56,7 @@ |
56 | 56 | const serveiceDisable = ref(false); |
57 | 57 | const eventDisable = ref(false); |
58 | 58 | const blockContent = `属性一般是设备的运行状态,如当前温度等;服务是设备可被调用的方法,支持定义参数,如执行某项任务;事件则是设备上报的 |
59 | -通知,如告警,需要被及时处理。`; | |
59 | + 通知,如告警,需要被及时处理。`; | |
60 | 60 | const activeKey = ref('1'); |
61 | 61 | const size = ref('small'); |
62 | 62 | const AttrRef = ref<InstanceType<typeof Attribute>>(); |
... | ... | @@ -86,28 +86,28 @@ |
86 | 86 | let F = enums[val]; |
87 | 87 | F(data); |
88 | 88 | } |
89 | + function dynamicDisable(a, s, e) { | |
90 | + attrDisable.value = a; | |
91 | + serveiceDisable.value = s; | |
92 | + eventDisable.value = e; | |
93 | + } | |
94 | + function dynamicActive(n, callback) { | |
95 | + activeKey.value = n; | |
96 | + callback; | |
97 | + } | |
89 | 98 | const dynamicData = (t, a, s, e) => { |
90 | 99 | switch (t) { |
91 | 100 | case 'attr': |
92 | - activeKey.value = '1'; | |
93 | - action(t, a); | |
94 | - attrDisable.value = false; | |
95 | - serveiceDisable.value = true; | |
96 | - eventDisable.value = true; | |
101 | + dynamicActive('1', action(t, a)); | |
102 | + dynamicDisable(false, true, true); | |
97 | 103 | break; |
98 | 104 | case 'service': |
99 | - activeKey.value = '2'; | |
100 | - action(t, s); | |
101 | - attrDisable.value = true; | |
102 | - serveiceDisable.value = false; | |
103 | - eventDisable.value = true; | |
105 | + dynamicActive('2', action(t, s)); | |
106 | + dynamicDisable(true, false, true); | |
104 | 107 | break; |
105 | 108 | case 'events': |
106 | - activeKey.value = '3'; | |
107 | - action(t, e); | |
108 | - attrDisable.value = true; | |
109 | - serveiceDisable.value = true; | |
110 | - eventDisable.value = false; | |
109 | + dynamicActive('3', action(t, e)); | |
110 | + dynamicDisable(true, true, false); | |
111 | 111 | break; |
112 | 112 | } |
113 | 113 | }; | ... | ... |
... | ... | @@ -22,8 +22,7 @@ |
22 | 22 | import { attrSchemas } from './config'; |
23 | 23 | import { useModal } from '/@/components/Modal'; |
24 | 24 | import { validateValueStruct } from '../hook/useValidateParital'; |
25 | - import { useChangeTypeGetTypeForm } from '../hook/useTypeGetForm'; | |
26 | - import { buildUUID } from '/@/utils/uuid'; | |
25 | + import { useChangeTypeGetTypeForm, useGetInOrOutData } from '../hook/useTypeGetForm'; | |
27 | 26 | import AddParamsModal from './components/AddParamsModal.vue'; |
28 | 27 | import CommomParam from './components/CommomParam.vue'; |
29 | 28 | |
... | ... | @@ -44,16 +43,7 @@ |
44 | 43 | showActionButtonGroup: false, |
45 | 44 | }); |
46 | 45 | |
47 | - const getData = (d, f) => { | |
48 | - if (f == 'input') { | |
49 | - if (d.id !== null) { | |
50 | - const findIndex = unref(inputParamData).findIndex((f) => f.id == d.id); | |
51 | - if (findIndex !== -1) unref(inputParamData).splice(findIndex, 1, d); | |
52 | - } else { | |
53 | - unref(inputParamData).push({ ...d, id: buildUUID() }); | |
54 | - } | |
55 | - } | |
56 | - }; | |
46 | + const getData = (d, f) => useGetInOrOutData(d, f, unref(inputParamData), []); | |
57 | 47 | |
58 | 48 | const handleAddInParam = (b, o) => openModal(b, o); |
59 | 49 | |
... | ... | @@ -83,8 +73,7 @@ |
83 | 73 | //回显结构体数据 |
84 | 74 | const { dataSpecsList } = v[0]; |
85 | 75 | if (dataSpecsList !== undefined) { |
86 | - inputParamData.value = [...new Array(dataSpecsList.length).keys()]; | |
87 | - inputParamData.value = dataSpecsList; | |
76 | + inputParamData.value = [...new Array(dataSpecsList.length).keys()] && dataSpecsList; | |
88 | 77 | } |
89 | 78 | } catch (e) { |
90 | 79 | console.log('Attribute error info', e); | ... | ... |
... | ... | @@ -21,9 +21,9 @@ |
21 | 21 | import { BasicForm, useForm } from '/@/components/Form'; |
22 | 22 | import { eventSchemas } from './config'; |
23 | 23 | import { useModal } from '/@/components/Modal'; |
24 | - import { buildUUID } from '/@/utils/uuid'; | |
25 | 24 | import AddParamsModal from './components/AddParamsModal.vue'; |
26 | 25 | import CommomParam from './components/CommomParam.vue'; |
26 | + import { useGetInOrOutData } from '../hook/useTypeGetForm'; | |
27 | 27 | |
28 | 28 | const inputParamData: any = ref([]); |
29 | 29 | |
... | ... | @@ -42,16 +42,7 @@ |
42 | 42 | showActionButtonGroup: false, |
43 | 43 | }); |
44 | 44 | |
45 | - const getData = (d, f) => { | |
46 | - if (f == 'input') { | |
47 | - if (d.id !== null) { | |
48 | - const findIndex = unref(inputParamData).findIndex((f) => f.id == d.id); | |
49 | - if (findIndex !== -1) unref(inputParamData).splice(findIndex, 1, d); | |
50 | - } else { | |
51 | - unref(inputParamData).push({ ...d, id: buildUUID() }); | |
52 | - } | |
53 | - } | |
54 | - }; | |
45 | + const getData = (d, f) => useGetInOrOutData(d, f, unref(inputParamData), []); | |
55 | 46 | |
56 | 47 | const handleAddInParam = (b, o) => openModal(b, o); |
57 | 48 | |
... | ... | @@ -64,8 +55,7 @@ |
64 | 55 | setFieldsValue(v[0]); |
65 | 56 | const { outputData } = v[0]; |
66 | 57 | if (outputData !== undefined) { |
67 | - inputParamData.value = [...new Array(outputData.length).keys()]; | |
68 | - inputParamData.value = outputData; | |
58 | + inputParamData.value = [...new Array(outputData.length).keys()] && outputData; | |
69 | 59 | } |
70 | 60 | }; |
71 | 61 | ... | ... |
... | ... | @@ -32,14 +32,16 @@ |
32 | 32 | import { BasicForm, useForm } from '/@/components/Form'; |
33 | 33 | import { serviceSchemas } from './config'; |
34 | 34 | import { useModal } from '/@/components/Modal'; |
35 | - import { buildUUID } from '/@/utils/uuid'; | |
36 | 35 | import AddParamsModal from './components/AddParamsModal.vue'; |
37 | 36 | import CommomParam from './components/CommomParam.vue'; |
37 | + import { useGetInOrOutData } from '../hook/useTypeGetForm'; | |
38 | 38 | |
39 | 39 | const inputParamData: any = ref([]); |
40 | + | |
40 | 41 | const outputParamData: any = ref([]); |
41 | 42 | |
42 | 43 | const CommomParamInParamRef = ref<InstanceType<typeof CommomParam>>(); |
44 | + | |
43 | 45 | const CommomParamOutParamRef = ref<InstanceType<typeof CommomParam>>(); |
44 | 46 | |
45 | 47 | const [registerModal, { openModal }] = useModal(); |
... | ... | @@ -55,23 +57,7 @@ |
55 | 57 | showActionButtonGroup: false, |
56 | 58 | }); |
57 | 59 | |
58 | - const getData = (d, f) => { | |
59 | - if (f == 'input') { | |
60 | - if (d.id !== null) { | |
61 | - const findIndex = unref(inputParamData).findIndex((f) => f.id == d.id); | |
62 | - if (findIndex !== -1) unref(inputParamData).splice(findIndex, 1, d); | |
63 | - } else { | |
64 | - unref(inputParamData).push({ ...d, id: buildUUID() }); | |
65 | - } | |
66 | - } else { | |
67 | - if (d.id !== null) { | |
68 | - const findIndex = unref(outputParamData).findIndex((f) => f.id == d.id); | |
69 | - if (findIndex !== -1) unref(outputParamData).splice(findIndex, 1, d); | |
70 | - } else { | |
71 | - unref(outputParamData).push({ ...d, id: buildUUID() }); | |
72 | - } | |
73 | - } | |
74 | - }; | |
60 | + const getData = (d, f) => useGetInOrOutData(d, f, unref(inputParamData), unref(outputParamData)); | |
75 | 61 | |
76 | 62 | const handleAddInParam = (b, o) => openModal(b, o); |
77 | 63 | |
... | ... | @@ -90,12 +76,10 @@ |
90 | 76 | setFieldsValue(v[0]); |
91 | 77 | const { inputParams, outputParams } = v[0]; |
92 | 78 | if (outputParams !== undefined) { |
93 | - outputParamData.value = [...new Array(outputParams.length).keys()]; | |
94 | - outputParamData.value = outputParams; | |
79 | + outputParamData.value = [...new Array(outputParams.length).keys()] && outputParams; | |
95 | 80 | } |
96 | 81 | if (inputParams !== undefined) { |
97 | - inputParamData.value = [...new Array(inputParams.length).keys()]; | |
98 | - inputParamData.value = inputParams; | |
82 | + inputParamData.value = [...new Array(inputParams.length).keys()] && inputParams; | |
99 | 83 | } |
100 | 84 | }; |
101 | 85 | ... | ... |
... | ... | @@ -21,8 +21,11 @@ |
21 | 21 | import { BasicForm, useForm } from '/@/components/Form'; |
22 | 22 | import { addParamsSchemas } from '../config'; |
23 | 23 | import { useModal } from '/@/components/Modal'; |
24 | - import { buildUUID } from '/@/utils/uuid'; | |
25 | - import { useChangeTypeGetTypeForm, useUpdateFormExcludeStruct } from '../../hook/useTypeGetForm'; | |
24 | + import { | |
25 | + useChangeTypeGetTypeForm, | |
26 | + useGetInOrOutData, | |
27 | + useUpdateFormExcludeStruct, | |
28 | + } from '../../hook/useTypeGetForm'; | |
26 | 29 | import AddParamsModal from './AddParamsModal.vue'; |
27 | 30 | import CommomParam from './CommomParam.vue'; |
28 | 31 | |
... | ... | @@ -45,16 +48,7 @@ |
45 | 48 | showActionButtonGroup: false, |
46 | 49 | }); |
47 | 50 | |
48 | - const getData = (d, f) => { | |
49 | - if (f === 'input') { | |
50 | - if (d.id !== null) { | |
51 | - const findIndex = unref(inputParamData).findIndex((f) => f.id == d.id); | |
52 | - if (findIndex !== -1) unref(inputParamData).splice(findIndex, 1, d); | |
53 | - } else { | |
54 | - unref(inputParamData).push({ ...d, id: buildUUID() }); | |
55 | - } | |
56 | - } | |
57 | - }; | |
51 | + const getData = (d, f) => useGetInOrOutData(d, f, unref(inputParamData), []); | |
58 | 52 | |
59 | 53 | const handleAddInParam = (b, o) => openModal(b, o); |
60 | 54 | ... | ... |
1 | 1 | import { validateValueBool, validateValueRangeAndStep } from './useValidateParital'; |
2 | 2 | import { findDictItemByCode } from '/@/api/system/dict'; |
3 | +import { buildUUID } from '/@/utils/uuid'; | |
3 | 4 | |
4 | 5 | ///根据不同数据类型得到不同表单数据 |
5 | 6 | type TForm = { |
... | ... | @@ -94,3 +95,22 @@ export const useUpdateFormExcludeStruct = async (F, U) => { |
94 | 95 | }, |
95 | 96 | }); |
96 | 97 | }; |
98 | + | |
99 | +//获取输入参数或者输出参数弹窗数据 | |
100 | +export const useGetInOrOutData = (d, f, inputData, outputData) => { | |
101 | + if (f == 'input') { | |
102 | + if (d.id !== null) { | |
103 | + const findIndex = inputData.findIndex((f) => f.id == d.id); | |
104 | + if (findIndex !== -1) inputData.splice(findIndex, 1, d); | |
105 | + } else { | |
106 | + inputData.push({ ...d, id: buildUUID() }); | |
107 | + } | |
108 | + } else { | |
109 | + if (d.id !== null) { | |
110 | + const findIndex = outputData.findIndex((f) => f.id == d.id); | |
111 | + if (findIndex !== -1) outputData.splice(findIndex, 1, d); | |
112 | + } else { | |
113 | + outputData.push({ ...d, id: buildUUID() }); | |
114 | + } | |
115 | + } | |
116 | +}; | ... | ... |