index.vue
2.34 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
<script setup lang="ts">
import { useForm, BasicForm } from '/@/components/Form';
import { formSchemas, FormFieldsValueType, TCPConfigurationType } from './config';
import { TransportTypeEnum } from '/@/enums/deviceEnum';
import { ref } from 'vue';
import { ScriptTypeEnum } from '/@/views/rule/script/TcpConversionScript/config';
const props = defineProps({
deviceTypeStr: {
type: String,
default: '',
},
});
const serviceType = ref<string>(props.deviceTypeStr);
const [register, formActionType] = useForm({
schemas: formSchemas(serviceType.value),
showActionButtonGroup: false,
layout: 'horizontal',
labelWidth: 140,
});
const { updateSchema } = formActionType || {};
const setServiceType = (type) => {
updateSchema({
field: 'upScriptId',
componentProps: {
scriptType: ScriptTypeEnum.TRANSPORT_TCP_UP,
serviceType: type,
},
});
serviceType.value = type;
};
const getFormFieldsValue = async (): Promise<TCPConfigurationType> => {
await formActionType.validate();
const result = formActionType.getFieldsValue() as FormFieldsValueType;
const { splitRange, protocol, tcpAuthType, hexLength, filterPrefix, upScriptId } = result;
return {
protocol,
type: TransportTypeEnum.TCP,
tcpAuthType,
upScriptId,
combinationInfo: {
...splitRange,
hexLength: hexLength!,
filterPrefix,
},
};
};
const setFormFieldsValue = (value: TCPConfigurationType) => {
const { upScriptId, protocol, combinationInfo, tcpAuthType } = value;
const { subBeginIndex, subEndIndex, hexLength, filterPrefix } = combinationInfo || {};
const data: FormFieldsValueType = {
splitRange: {
subBeginIndex: subBeginIndex!,
subEndIndex: subEndIndex!,
},
hexLength,
filterPrefix,
upScriptId,
protocol,
tcpAuthType,
};
formActionType.setFieldsValue(data);
};
defineExpose({
getFormData: getFormFieldsValue,
// resetFormData:,
setFormData: setFormFieldsValue,
setServiceType,
});
</script>
<template>
<BasicForm @register="register" class="tcp-configuration-form w-1/2" />
</template>
<style lang="less" scoped>
.tcp-configuration-form {
:deep(.ant-input-number) {
min-width: initial;
width: 100%;
}
}
</style>