TransportConfigurationStep.vue
3.99 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<template>
<div
class="step2-style"
:style="[isMqttType == 'DEFAULT' ? { minHeight: 0 + 'px' } : { minHeight: 800 + 'px' }]"
>
<div
:style="[
isMqttType == 'MQTT'
? { minHeight: 45 + 'vh' }
: isMqttType == 'COAP'
? { minHeight: 35 + 'vh' }
: isMqttType == 'LWM2M'
? { minHeight: 55 + 'vh' }
: isMqttType == 'SNMP'
? { minHeight: 60 + 'vh' }
: { minHeight: 25 + 'vh' },
]"
>
<BasicForm :showResetButton="false" :showSubmitButton="false" @register="register" />
<div style="margin-top: 5vh" v-if="isMqttType == 'MQTT'">
<MqttCpns ref="mqttRef" />
</div>
<div style="margin-top: 5vh" v-else-if="isMqttType == 'COAP'">
<CoapCpns ref="coapRef" />
</div>
<div style="margin-top: 1vh" v-else-if="isMqttType == 'LWM2M'">
<Lwm2mCpns ref="lwm2mRef" />
</div>
<div style="margin-top: 5vh" v-else-if="isMqttType == 'SNMP'">
<SnmpCpns ref="snmpRef" />
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import { reactive, ref, onUnmounted, nextTick } from 'vue';
import { BasicForm, useForm } from '/@/components/Form';
import { step2Schemas } from '../device.profile.data';
import MqttCpns from './cpns/mqtt/Mqtt.vue';
import CoapCpns from './cpns/coap/Coap.vue';
import Lwm2mCpns from './cpns/lwm2m/index.vue';
import SnmpCpns from './cpns/snmp/index.vue';
const mqttRef = ref<InstanceType<typeof MqttCpns>>();
const coapRef = ref<InstanceType<typeof CoapCpns>>();
const lwm2mRef = ref<InstanceType<typeof Lwm2mCpns>>();
const snmpRef = ref<InstanceType<typeof SnmpCpns>>();
const isMqttType = ref('DEFAULT');
let step2Data = reactive({
transportConfiguration: {},
});
const [register, { validate, resetFields, setFieldsValue, updateSchema }] = useForm({
labelWidth: 80,
schemas: step2Schemas,
actionColOptions: {
span: 14,
},
showResetButton: false,
submitOnReset: false,
showActionButtonGroup: false,
});
const setFormData = (v) => {
setFieldsValue({
transportType: v?.profileData?.transportConfiguration?.type,
});
isMqttType.value = v?.profileData?.transportConfiguration?.type;
mqttRef.value?.setFormData(v?.profileData?.transportConfiguration);
coapRef.value?.setFormData(v?.profileData?.transportConfiguration);
lwm2mRef.value?.setFormData(v?.profileData?.transportConfiguration);
snmpRef.value?.setFormData(v?.profileData?.transportConfiguration);
};
const resetFormData = () => {
isMqttType.value = 'DEFAULT';
resetFields();
nextTick(() => {
mqttRef.value?.resetFormData();
coapRef.value?.resetFormData();
lwm2mRef.value?.resetFormData();
snmpRef.value?.resetFormData();
});
};
nextTick(() => {
updateSchema({
field: 'transportType',
componentProps() {
return {
options: [
{ label: '默认', value: 'DEFAULT' },
{ label: 'MQTT', value: 'MQTT' },
{ label: 'CoAP', value: 'COAP' },
{ label: 'LWM2M', value: 'LWM2M' },
{ label: 'SNMP', value: 'SNMP' },
],
onChange(e) {
isMqttType.value = e;
},
};
},
});
});
onUnmounted(() => {
isMqttType.value = 'DEFAULT';
});
const getFormData = async () => {
const val = await validate();
if (!val) return;
const getMqttVal = await mqttRef.value?.getFormData();
const getCoapVal = await coapRef.value?.getFormData();
const getLwm2mVal = await lwm2mRef.value?.getFormData();
const getSnmpVal = await snmpRef.value?.getFormData();
step2Data.transportConfiguration = {
...getMqttVal,
...getCoapVal,
...getLwm2mVal,
...getSnmpVal,
...val,
};
return step2Data;
};
defineExpose({
getFormData,
resetFormData,
setFormData,
});
</script>
<style lang="less" scoped>
@import url('./common/TransportConfigurationStep.less');
</style>