DataFlowMethodIsMqtt.vue
2.28 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
<template>
<div>
<BasicForm @register="register">
<template #uploadFilesSlot="{ model }">
<UploadFile
:url="credentialsFile.caCertFileName"
@fileUrlEmit="handleFileUrlEmitH"
v-show="model['type'] === CredentialsEnum.IS_PEM"
/>
<div class="h-4"></div>
<UploadFile
:url="credentialsFile.certFileName"
@fileUrlEmit="handleFileUrlEmitC"
v-show="model['type'] === CredentialsEnum.IS_PEM"
/>
<div class="h-4"></div>
<UploadFile
:url="credentialsFile.privateKeyFileName"
@fileUrlEmit="handleFileUrlEmitB"
v-show="model['type'] === CredentialsEnum.IS_PEM"
/>
</template>
</BasicForm>
</div>
</template>
<script lang="ts" setup name="DataFlowMethodIsMqtt">
import { reactive } from 'vue';
import { BasicForm, useForm } from '/@/components/Form';
import { modeMqttForm } from './config';
import { UploadFile } from '../../../uploadfile';
import { CredentialsEnum } from './enum';
import { modelFormPublicConfig } from '../../../dataflowmodal/config';
const credentialsFile = reactive({
caCertFileName: undefined,
certFileName: undefined,
privateKeyFileName: undefined,
});
const [register, { validateFields, setFieldsValue, resetFields }] = useForm({
schemas: modeMqttForm,
...modelFormPublicConfig,
});
const handleFileUrlEmitH = (fileUrl) => (credentialsFile.caCertFileName = fileUrl);
const handleFileUrlEmitC = (fileUrl) => (credentialsFile.certFileName = fileUrl);
const handleFileUrlEmitB = (fileUrl) => (credentialsFile.privateKeyFileName = fileUrl);
const getValue = async () => {
const values = await validateFields();
if (!values) return;
const credentials = {
type: values['type'],
...credentialsFile,
};
const mergeValues = {
...values,
...{ credentials },
};
return mergeValues;
};
const setValue = (value) => {
const { credentials } = value;
if (credentials) {
for (let i in credentials) Reflect.set(credentialsFile, i, credentials[i]);
}
setFieldsValue(value);
};
const resetValue = () => resetFields();
defineExpose({
getValue,
setValue,
resetValue,
});
</script>
<style lang="less" scoped></style>