DeviceProfileStep2.vue
3.56 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
<template>
<div class="step2-style">
<div style="margin-top: 0.1vh; overflow: scroll">
<BasicForm :showResetButton="false" :showSubmitButton="false" @register="register" />
<div v-if="isMqttType == 'MQTT'">
<MqttCpns ref="mqttRef" />
</div>
<div v-else-if="isMqttType == 'COAP'">
<CoapCpns ref="coapRef" />
</div>
<div
style="
display: flex;
width: 11vw;
height: 8vh;
flex-direction: row;
justify-content: space-between;
margin-left: 19vw;
margin-top: -0.35vh;
"
>
<div style="display: flex; width: 4vw; height: 4vh; margin-top: 1.65vh">
<Button type="default" style="border-radius: 2px" class="mt-5" @click="customResetFunc"
>上一步</Button
>
</div>
</div>
</div>
</div>
</template>
<script lang="ts">
import { defineComponent, watch, reactive, ref, getCurrentInstance } from 'vue';
import { BasicForm, useForm } from '/@/components/Form';
import { step2Schemas, isChangeType } from './data';
import { Alert, Divider, Descriptions } from 'ant-design-vue';
import { Button } from '/@/components/Button';
import MqttCpns from '../step/cpns/mqtt/Mqtt.vue';
import CoapCpns from '../step/cpns/coap/Coap.vue';
export default defineComponent({
components: {
BasicForm,
[Alert.name]: Alert,
[Divider.name]: Divider,
[Descriptions.name]: Descriptions,
[Descriptions.Item.name]: Descriptions.Item,
Button,
MqttCpns,
CoapCpns,
},
emits: ['next', 'prev', 'register'],
setup(_, { emit }) {
const { proxy } = getCurrentInstance() as any;
const mqttRef = ref(null);
const coapRef = ref(null);
const isMqttType = ref('');
let step2Data = reactive({
transportConfiguration: {},
});
const [register, { validate, resetFields, setFieldsValue }] = useForm({
labelWidth: 80,
schemas: step2Schemas,
actionColOptions: {
span: 14,
},
});
const setStepTwoFieldsValueFunc = (v) => {
setFieldsValue({
transportType: v?.profileData?.transportConfiguration?.type,
});
isMqttType.value = v?.profileData?.transportConfiguration?.type;
setTimeout(() => {
proxy.$refs.mqttRef?.setStepFieldsValueFunc(v?.profileData?.transportConfiguration);
proxy.$refs.coapRef?.setStepFieldsValueFunc(v?.profileData?.transportConfiguration);
}, 100);
};
const customClearStepTwoValueFunc = () => {
isMqttType.value = 'other';
resetFields();
};
async function customResetFunc() {
emit('prev');
}
watch(isChangeType, (v) => {
isMqttType.value = v;
});
const getStep2DataFunc = async () => {
const val = await validate();
if (!val) return;
const getMqttVal = await proxy.$refs.mqttRef?.getDataFunc();
const getCoapVal = await proxy.$refs.coapRef?.getDataFunc();
step2Data.transportConfiguration = {
...getMqttVal,
...getCoapVal,
...val,
};
return step2Data;
};
return {
customResetFunc,
register,
setStepTwoFieldsValueFunc,
customClearStepTwoValueFunc,
getStep2DataFunc,
isMqttType,
mqttRef,
coapRef,
};
},
});
</script>
<style lang="less" scoped>
.step2-style {
margin: 0vh 0.6vw;
border-radius: 4px;
}
::-webkit-scrollbar {
display: none;
}
</style>