Coap.vue
2.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<template>
<div style="border: 1px solid gray; border-radius: 5px">
<div style="margin-top: 1.2vh">
<BasicForm :showResetButton="false" :showSubmitButton="false" @register="register" />
</div>
</div>
</template>
<script lang="ts" setup>
import { reactive } from 'vue';
import { BasicForm, useForm } from '/@/components/Form';
import { CoapSchemas } from './Coap';
const emits = defineEmits(['prev']);
const coapAllData = reactive({
coapData: {},
});
const transportCoapData: any = reactive({
coapDeviceTypeConfiguration: {
coapDeviceType: null,
transportPayloadTypeConfiguration: {
transportPayloadType: null,
deviceTelemetryProtoSchema: null,
deviceAttributesProtoSchema: null,
deviceRpcRequestProtoSchema: null,
deviceRpcResponseProtoSchema: null,
},
},
clientSettings: {
powerMode: null,
edrxCycle: null,
pagingTransmissionWindow: null,
psmActivityTimer: null,
},
type: 'COAP',
});
const [register, { validate, resetFields, setFieldsValue }] = useForm({
labelWidth: 200,
schemas: CoapSchemas,
actionColOptions: {
span: 14,
},
});
const setFormData = (v) => {
setFieldsValue({
...v?.clientSettings,
...v?.coapDeviceTypeConfiguration,
...v?.coapDeviceTypeConfiguration?.transportPayloadTypeConfiguration,
});
};
const resetFormData = () => {
resetFields();
};
function customResetFunc() {
emits('prev');
}
const getFormData = async () => {
const val = await validate();
if (!val) return;
for (let o in val) {
for (let u in transportCoapData) {
switch (u) {
case 'coapDeviceTypeConfiguration':
for (let t in transportCoapData.coapDeviceTypeConfiguration) {
if (t === 'coapDeviceType') {
Reflect.set(transportCoapData.coapDeviceTypeConfiguration, t, val[t]);
}
if (t === 'transportPayloadTypeConfiguration') {
for (let t in transportCoapData.coapDeviceTypeConfiguration
.transportPayloadTypeConfiguration) {
if (t === o) {
Reflect.set(
transportCoapData.coapDeviceTypeConfiguration
.transportPayloadTypeConfiguration,
t,
val[t]
);
}
}
}
}
break;
case 'clientSettings':
for (let t in transportCoapData.clientSettings) {
if (t === o) {
Reflect.set(transportCoapData.clientSettings, t, val[t]);
}
}
break;
}
}
}
coapAllData.coapData = {
...transportCoapData,
};
return coapAllData.coapData;
};
defineExpose({
getFormData,
resetFormData,
setFormData,
customResetFunc,
});
</script>
<style lang="less" scoped></style>