Service.vue
1.94 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
<template>
<BasicForm @register="register" />
</template>
<script lang="ts" setup>
import { BasicForm, useForm } from '/@/components/Form';
import { serviceSchemas } from './config';
import { FunctionType } from './config';
import { StructFormValue } from '/@/components/Form/src/externalCompns/components/StructForm/type';
import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel';
import { DeviceRecord } from '/@/api/device/model/deviceModel';
const props = defineProps<{
record: DeviceRecord;
}>();
const [register, { validate, resetFields, setFieldsValue }] = useForm({
labelWidth: 100,
schemas: serviceSchemas(props.record.transportType === 'TCP'),
actionColOptions: {
span: 14,
},
showResetButton: false,
submitOnReset: false,
showActionButtonGroup: false,
});
//回显数据
const setFormData = (record: ModelOfMatterParams) => {
const { functionJson = {}, functionName, identifier, remark, callType } = record;
const { inputData, outputData, serviceCommand } = functionJson;
const value = {
functionName,
identifier,
remark,
inputData,
outputData,
serviceCommand,
callType,
};
setFieldsValue(value);
};
//获取数据
async function getFormData() {
const _values = (await validate()) as StructFormValue;
const { functionName, remark, identifier, inputData, outputData, serviceCommand, callType } =
_values;
if (!_values) return {};
const value = {
functionName,
identifier,
remark,
functionType: FunctionType.SERVICE,
callType,
functionJson: {
inputData,
outputData,
serviceCommand,
},
} as ModelOfMatterParams;
return value;
}
//清空数据
const resetFormData = () => {
resetFields();
};
defineExpose({
setFormData,
resetFormData,
getFormData,
});
</script>
<style lang="less" scoped></style>