Commit 41cb7dbedfe1607a93ff74143d324d4377e104c8
1 parent
dd853e5b
feat: basic implement model of matter
Showing
11 changed files
with
289 additions
and
178 deletions
... | ... | @@ -15,11 +15,25 @@ export interface Specs { |
15 | 15 | }; |
16 | 16 | } |
17 | 17 | |
18 | -export interface FunctionJson { | |
18 | +export interface DataType { | |
19 | 19 | type: string; |
20 | 20 | specs?: Partial<Specs> | ModelOfMatterParams[]; |
21 | 21 | } |
22 | 22 | |
23 | +export interface StructJSON { | |
24 | + functionName?: string; | |
25 | + identifier?: string; | |
26 | + remark?: string; | |
27 | + dataType?: DataType; | |
28 | +} | |
29 | + | |
30 | +export interface FunctionJson { | |
31 | + dataType?: DataType | DataType[]; | |
32 | + inputData?: DataType[]; | |
33 | + outputData?: DataType[]; | |
34 | + serviceCommand?: string; | |
35 | +} | |
36 | + | |
23 | 37 | export interface ModelOfMatterParams { |
24 | 38 | deviceProfileId: string; |
25 | 39 | functionJson: FunctionJson; |
... | ... | @@ -28,6 +42,7 @@ export interface ModelOfMatterParams { |
28 | 42 | identifier: string; |
29 | 43 | remark: string; |
30 | 44 | id?: string; |
45 | + // callType | |
31 | 46 | } |
32 | 47 | |
33 | 48 | export interface GetModelTslParams { | ... | ... |
... | ... | @@ -7,10 +7,12 @@ |
7 | 7 | import { BasicForm, useForm } from '/@/components/Form'; |
8 | 8 | import { formSchemas } from './config'; |
9 | 9 | import { BasicModal, useModalInner } from '/@/components/Modal'; |
10 | - import { OpenModalMode, OpenModalParams, StructRecord } from './type'; | |
10 | + import { OpenModalMode, OpenModalParams } from './type'; | |
11 | 11 | import { ref, unref } from 'vue'; |
12 | - import { transformFormValue } from './util'; | |
12 | + import { transfromToStructJSON } from './util'; | |
13 | 13 | import { cloneDeep } from 'lodash-es'; |
14 | + import { DataType, StructJSON } from '/@/api/device/model/modelOfMatterModel'; | |
15 | + import { isArray } from '/@/utils/is'; | |
14 | 16 | |
15 | 17 | const modalReceiveRecord = ref<OpenModalParams>({ |
16 | 18 | mode: OpenModalMode.CREATE, |
... | ... | @@ -32,17 +34,14 @@ |
32 | 34 | const [registerModal, { closeModal }] = useModalInner((record: OpenModalParams) => { |
33 | 35 | modalReceiveRecord.value = record; |
34 | 36 | const data = record.record || {}; |
35 | - const { functionJson = {} } = data! as StructRecord; | |
36 | - const { specs = {} } = functionJson as StructRecord['functionJson']; | |
37 | + const { dataType = {} } = data! as StructJSON; | |
38 | + const { specs = {}, type } = dataType as DataType; | |
39 | + | |
37 | 40 | if (record.record) { |
38 | 41 | const value = { |
42 | + type, | |
39 | 43 | ...data, |
40 | - ...functionJson, | |
41 | - ...specs, | |
42 | - valueRange: { | |
43 | - min: specs.min, | |
44 | - max: specs.max, | |
45 | - }, | |
44 | + ...(isArray(specs) ? { specs } : { ...specs }), | |
46 | 45 | }; |
47 | 46 | |
48 | 47 | setFieldsValue(value); |
... | ... | @@ -52,9 +51,9 @@ |
52 | 51 | const handleSubmit = async () => { |
53 | 52 | try { |
54 | 53 | const _value = await validate(); |
55 | - let value = transformFormValue(_value); | |
56 | - value = { | |
57 | - ...value, | |
54 | + let structJSON = transfromToStructJSON(_value); | |
55 | + const value = { | |
56 | + ...structJSON, | |
58 | 57 | ...(unref(modalReceiveRecord)?.record?.id |
59 | 58 | ? { id: unref(modalReceiveRecord)?.record?.id } |
60 | 59 | : {}), | ... | ... |
1 | 1 | import { h } from 'vue'; |
2 | +import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; | |
2 | 3 | import { findDictItemByCode } from '/@/api/system/dict'; |
3 | 4 | import { FormSchema } from '/@/components/Table'; |
4 | 5 | import { FormField } from '/@/views/device/profiles/step/cpns/physical/cpns/config'; |
... | ... | @@ -11,6 +12,23 @@ export enum DateTypeEnum { |
11 | 12 | IS_BOOL = 'BOOL', |
12 | 13 | } |
13 | 14 | |
15 | +const validateValueRange = (_rule, value: Record<'min' | 'max', number>, _callback) => { | |
16 | + value = value || {}; | |
17 | + const { min, max } = value; | |
18 | + if (min >= max) { | |
19 | + return Promise.reject('最大值小于最小值'); | |
20 | + } | |
21 | + return Promise.resolve(); | |
22 | +}; | |
23 | + | |
24 | +const validateJSON = (_rule, value: ModelOfMatterParams[], _callback) => { | |
25 | + console.log('validate json', value); | |
26 | + if (value.length) { | |
27 | + return Promise.resolve(); | |
28 | + } | |
29 | + return Promise.reject('JSON对象不能为空'); | |
30 | +}; | |
31 | + | |
14 | 32 | export const formSchemas: FormSchema[] = [ |
15 | 33 | { |
16 | 34 | field: FormField.FUNCTION_NAME, |
... | ... | @@ -70,6 +88,7 @@ export const formSchemas: FormSchema[] = [ |
70 | 88 | ifShow: ({ values }) => |
71 | 89 | values[FormField.TYPE] === DateTypeEnum.IS_NUMBER_INT || |
72 | 90 | values[FormField.TYPE] === DateTypeEnum.IS_NUMBER_DOUBLE, |
91 | + rules: [{ validator: validateValueRange }], | |
73 | 92 | }, |
74 | 93 | { |
75 | 94 | field: FormField.STEP, |
... | ... | @@ -81,10 +100,29 @@ export const formSchemas: FormSchema[] = [ |
81 | 100 | componentProps: { |
82 | 101 | maxLength: 255, |
83 | 102 | placeholder: '请输入步长', |
103 | + min: 1, | |
104 | + formatter: (value: number | string) => { | |
105 | + return value ? Math.floor(Number(value)) : value; | |
106 | + }, | |
84 | 107 | }, |
85 | 108 | ifShow: ({ values }) => |
86 | 109 | values[FormField.TYPE] === DateTypeEnum.IS_NUMBER_INT || |
87 | 110 | values[FormField.TYPE] === DateTypeEnum.IS_NUMBER_DOUBLE, |
111 | + dynamicRules: ({ model }) => { | |
112 | + const valueRange = model[FormField.VALUE_RANGE] || {}; | |
113 | + const { min = 0, max = 0 } = valueRange; | |
114 | + const step = model[FormField.STEP]; | |
115 | + return [ | |
116 | + { | |
117 | + validator: () => { | |
118 | + if (step > max - min) { | |
119 | + return Promise.reject('步长不能大于取值范围的差值'); | |
120 | + } | |
121 | + return Promise.resolve(); | |
122 | + }, | |
123 | + }, | |
124 | + ]; | |
125 | + }, | |
88 | 126 | }, |
89 | 127 | { |
90 | 128 | field: FormField.UNIT_NAME, |
... | ... | @@ -140,6 +178,18 @@ export const formSchemas: FormSchema[] = [ |
140 | 178 | placeholder: '如:关', |
141 | 179 | }, |
142 | 180 | ifShow: ({ values }) => values[FormField.TYPE] === DateTypeEnum.IS_BOOL, |
181 | + dynamicRules: ({ model }) => { | |
182 | + const close = model[FormField.BOOL_CLOSE]; | |
183 | + const open = model[FormField.BOOL_OPEN]; | |
184 | + return [ | |
185 | + { | |
186 | + validator() { | |
187 | + if (open === close) return Promise.reject('布尔值不能相同'); | |
188 | + return Promise.resolve(); | |
189 | + }, | |
190 | + }, | |
191 | + ]; | |
192 | + }, | |
143 | 193 | }, |
144 | 194 | { |
145 | 195 | field: FormField.BOOL_OPEN, |
... | ... | @@ -153,6 +203,18 @@ export const formSchemas: FormSchema[] = [ |
153 | 203 | placeholder: '如:开', |
154 | 204 | }, |
155 | 205 | ifShow: ({ values }) => values[FormField.TYPE] === DateTypeEnum.IS_BOOL, |
206 | + dynamicRules: ({ model }) => { | |
207 | + const close = model[FormField.BOOL_CLOSE]; | |
208 | + const open = model[FormField.BOOL_OPEN]; | |
209 | + return [ | |
210 | + { | |
211 | + validator() { | |
212 | + if (open === close) return Promise.reject('布尔值不能相同'); | |
213 | + return Promise.resolve(); | |
214 | + }, | |
215 | + }, | |
216 | + ]; | |
217 | + }, | |
156 | 218 | }, |
157 | 219 | { |
158 | 220 | field: FormField.LENGTH, |
... | ... | @@ -200,15 +262,7 @@ export const formSchemas: FormSchema[] = [ |
200 | 262 | changeEvent: 'update:value', |
201 | 263 | colProps: { span: 24 }, |
202 | 264 | ifShow: ({ values }) => values[FormField.TYPE] === DateTypeEnum.IS_STRUCT, |
203 | - rules: [ | |
204 | - { | |
205 | - required: true, | |
206 | - validator(_rule, value, _callback) { | |
207 | - console.log(value); | |
208 | - return Promise.resolve(); | |
209 | - }, | |
210 | - }, | |
211 | - ], | |
265 | + rules: [{ required: true, validator: validateJSON }], | |
212 | 266 | }, |
213 | 267 | { |
214 | 268 | field: FormField.REFARK, | ... | ... |
1 | 1 | import { DateTypeEnum } from './config'; |
2 | -import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; | |
2 | +import { StructJSON } from '/@/api/device/model/modelOfMatterModel'; | |
3 | 3 | import { FormField } from '/@/views/device/profiles/step/cpns/physical/cpns/config'; |
4 | 4 | |
5 | 5 | export enum OpenModalMode { |
... | ... | @@ -22,6 +22,6 @@ export interface StructFormValue |
22 | 22 | [FormField.STRUCT]: StructRecord[]; |
23 | 23 | } |
24 | 24 | |
25 | -export interface StructRecord extends ModelOfMatterParams { | |
25 | +export interface StructRecord extends StructJSON { | |
26 | 26 | id: string; |
27 | 27 | } | ... | ... |
1 | 1 | import { DateTypeEnum } from './config'; |
2 | 2 | import { StructFormValue } from './type'; |
3 | -import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; | |
4 | -import { useMessage } from '/@/hooks/web/useMessage'; | |
5 | -import { FunctionType } from '/@/views/device/profiles/step/cpns/physical/cpns/config'; | |
3 | +import { DataType, ModelOfMatterParams, StructJSON } from '/@/api/device/model/modelOfMatterModel'; | |
6 | 4 | |
7 | -export const validateValueRangeAndStep = (min: number, step: number, max: number) => { | |
8 | - const { createMessage } = useMessage(); | |
9 | - if (min > max) { | |
10 | - createMessage.error('最大值必须大于最小值,整数型不能有小数位,单精度有效位为7,双精度为16'); | |
11 | - throw '最大值必须大于最小值,整数型不能有小数位,单精度有效位为7,双精度为16'; | |
12 | - } | |
13 | - | |
14 | - if (step > max - min) { | |
15 | - createMessage.error('步长不能大于取值范围的差值'); | |
16 | - throw '步长不能大于取值范围的差值'; | |
17 | - } | |
18 | -}; | |
19 | - | |
20 | -export const validateValueBool = (boolClose, boolOpen) => { | |
21 | - const { createMessage } = useMessage(); | |
22 | - | |
23 | - if (boolClose == boolOpen) { | |
24 | - createMessage.error('布尔值不能相同'); | |
25 | - throw '布尔值不能相同'; | |
26 | - } | |
27 | -}; | |
28 | - | |
29 | -export const validateValueStruct = (data: []) => { | |
30 | - const { createMessage } = useMessage(); | |
31 | - | |
32 | - if (data.length === 0) { | |
33 | - createMessage.error('struct不能为空'); | |
34 | - throw 'struct不能为空'; | |
35 | - } | |
36 | -}; | |
37 | - | |
38 | -export function transformFormValue(value: StructFormValue): Partial<ModelOfMatterParams> { | |
5 | +export function transfromToStructJSON(value: StructFormValue): StructJSON { | |
39 | 6 | const { |
40 | 7 | type, |
41 | 8 | valueRange, |
... | ... | @@ -50,31 +17,26 @@ export function transformFormValue(value: StructFormValue): Partial<ModelOfMatte |
50 | 17 | remark, |
51 | 18 | specs, |
52 | 19 | } = value; |
53 | - const { min, max } = valueRange! || {}; | |
54 | 20 | const basic = { functionName, identifier, remark }; |
55 | - let functionJson = {} as unknown as ModelOfMatterParams['functionJson']; | |
21 | + let dataType = {} as unknown as DataType; | |
56 | 22 | |
57 | - console.log(value); | |
58 | 23 | switch (type) { |
59 | 24 | case DateTypeEnum.IS_NUMBER_INT: |
60 | - validateValueRangeAndStep(Number(min), Number(step), Number(max)); | |
61 | - functionJson = { | |
25 | + dataType = { | |
62 | 26 | type, |
63 | - specs: { max, min, valueRange, step, unit, unitName }, | |
27 | + specs: { valueRange, step, unit, unitName }, | |
64 | 28 | }; |
65 | 29 | break; |
66 | 30 | |
67 | 31 | case DateTypeEnum.IS_NUMBER_DOUBLE: |
68 | - validateValueRangeAndStep(Number(min), Number(step), Number(max)); | |
69 | - functionJson = { | |
32 | + dataType = { | |
70 | 33 | type, |
71 | - specs: { max, min, valueRange, step, unit, unitName }, | |
34 | + specs: { valueRange, step, unit, unitName }, | |
72 | 35 | }; |
73 | 36 | break; |
74 | 37 | |
75 | 38 | case DateTypeEnum.IS_BOOL: |
76 | - validateValueBool(Number(boolClose), Number(boolOpen)); | |
77 | - functionJson = { | |
39 | + dataType = { | |
78 | 40 | type, |
79 | 41 | specs: { |
80 | 42 | boolOpen: boolOpen, |
... | ... | @@ -84,22 +46,18 @@ export function transformFormValue(value: StructFormValue): Partial<ModelOfMatte |
84 | 46 | break; |
85 | 47 | |
86 | 48 | case DateTypeEnum.IS_STRING: |
87 | - functionJson = { | |
49 | + dataType = { | |
88 | 50 | type, |
89 | 51 | specs: { length }, |
90 | 52 | }; |
91 | 53 | break; |
92 | 54 | |
93 | 55 | case DateTypeEnum.IS_STRUCT: |
94 | - functionJson = { | |
56 | + dataType = { | |
95 | 57 | type, |
96 | 58 | specs: specs! as unknown as ModelOfMatterParams[], |
97 | 59 | }; |
98 | 60 | break; |
99 | 61 | } |
100 | - return { | |
101 | - ...basic, | |
102 | - functionType: FunctionType.PROPERTIES, | |
103 | - functionJson, | |
104 | - }; | |
62 | + return { ...basic, dataType }; | |
105 | 63 | } | ... | ... |
... | ... | @@ -32,7 +32,11 @@ |
32 | 32 | /> |
33 | 33 | </Tabs> |
34 | 34 | <Attribute v-show="activeKey === FunctionType.PROPERTIES" ref="AttrRef" /> |
35 | - <Service v-show="activeKey === FunctionType.SERVICE" ref="ServiceRef" /> | |
35 | + <Service | |
36 | + v-show="activeKey === FunctionType.SERVICE" | |
37 | + :record="$props.record" | |
38 | + ref="ServiceRef" | |
39 | + /> | |
36 | 40 | <Events v-show="activeKey === FunctionType.EVENTS" ref="EventsRef" /> |
37 | 41 | </div> |
38 | 42 | </BasicModal> |
... | ... | @@ -51,7 +55,6 @@ |
51 | 55 | import { useMessage } from '/@/hooks/web/useMessage'; |
52 | 56 | import { OpenModelMode, OpenModelOfMatterModelParams } from './types/index'; |
53 | 57 | import { FunctionType } from './cpns/config'; |
54 | - import { StructRecord } from '/@/components/Form/src/externalCompns/components/StructForm/type'; | |
55 | 58 | |
56 | 59 | const emit = defineEmits(['register', 'success']); |
57 | 60 | |
... | ... | @@ -75,9 +78,9 @@ |
75 | 78 | const functionType = ref<FunctionType>(); |
76 | 79 | const { createMessage } = useMessage(); |
77 | 80 | |
78 | - const setAttrFormData = (data: StructRecord) => AttrRef.value?.setFormData(data); | |
79 | - const setServiceFormData = (data) => ServiceRef.value?.setFormData(data); | |
80 | - const setEventsFormData = (data) => EventsRef.value?.setFormData(data); | |
81 | + const setAttrFormData = (data: ModelOfMatterParams) => AttrRef.value?.setFormData(data); | |
82 | + const setServiceFormData = (data: ModelOfMatterParams) => ServiceRef.value?.setFormData(data); | |
83 | + const setEventsFormData = (data: ModelOfMatterParams) => EventsRef.value?.setFormData(data); | |
81 | 84 | |
82 | 85 | const enums = { |
83 | 86 | [FunctionType.PROPERTIES]: setAttrFormData, |
... | ... | @@ -85,7 +88,7 @@ |
85 | 88 | [FunctionType.EVENTS]: setEventsFormData, |
86 | 89 | }; |
87 | 90 | |
88 | - function setFormData(type: FunctionType, value: StructRecord) { | |
91 | + function setFormData(type: FunctionType, value: ModelOfMatterParams) { | |
89 | 92 | const setFn = enums[type]; |
90 | 93 | setFn(value); |
91 | 94 | } |
... | ... | @@ -98,7 +101,7 @@ |
98 | 101 | if (record) { |
99 | 102 | functionType.value = data.record.functionType; |
100 | 103 | activeKey.value = data.record.functionType; |
101 | - setFormData(record.functionType, record as unknown as StructRecord); | |
104 | + setFormData(record.functionType, record as unknown as ModelOfMatterParams); | |
102 | 105 | } |
103 | 106 | if (unref(openModalMode) === OpenModelMode.VIEW) { |
104 | 107 | setModalProps({ showOkBtn: false, showCancelBtn: false, title: '查看物模型' }); |
... | ... | @@ -133,7 +136,7 @@ |
133 | 136 | } else if (activeKey.value == FunctionType.SERVICE) { |
134 | 137 | params = (await ServiceRef.value?.getFormData()) || {}; |
135 | 138 | } else { |
136 | - params = await EventsRef.value?.getFormData(); | |
139 | + params = (await EventsRef.value?.getFormData()) || {}; | |
137 | 140 | } |
138 | 141 | params.deviceProfileId = props.record.id; |
139 | 142 | if (unref(openModalMode) === OpenModelMode.CREATE) { | ... | ... |
... | ... | @@ -3,14 +3,12 @@ |
3 | 3 | </template> |
4 | 4 | <script lang="ts" setup> |
5 | 5 | import { BasicForm, useForm } from '/@/components/Form'; |
6 | - import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; | |
6 | + import { DataType, ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; | |
7 | 7 | import { formSchemas } from '/@/components/Form/src/externalCompns/components/StructForm/config'; |
8 | - import { transformFormValue } from '/@/components/Form/src/externalCompns/components/StructForm/util'; | |
9 | - import { | |
10 | - StructFormValue, | |
11 | - StructRecord, | |
12 | - } from '/@/components/Form/src/externalCompns/components/StructForm/type'; | |
13 | - import { isObject } from 'lodash'; | |
8 | + import { StructFormValue } from '/@/components/Form/src/externalCompns/components/StructForm/type'; | |
9 | + import { transfromToStructJSON } from '/@/components/Form/src/externalCompns/components/StructForm/util'; | |
10 | + import { FunctionType } from './config'; | |
11 | + import { isArray } from 'lodash'; | |
14 | 12 | |
15 | 13 | const [register, { validate, resetFields, setFieldsValue }] = useForm({ |
16 | 14 | labelWidth: 100, |
... | ... | @@ -26,7 +24,17 @@ |
26 | 24 | async function getFormData(): Promise<Partial<ModelOfMatterParams>> { |
27 | 25 | const _values = (await validate()) as StructFormValue; |
28 | 26 | if (!_values) return {}; |
29 | - let value = transformFormValue(_values); | |
27 | + const { functionName, remark, identifier } = _values; | |
28 | + const structJSON = transfromToStructJSON(_values); | |
29 | + const value = { | |
30 | + functionName, | |
31 | + functionType: FunctionType.PROPERTIES, | |
32 | + remark, | |
33 | + identifier, | |
34 | + functionJson: { | |
35 | + dataType: structJSON.dataType, | |
36 | + }, | |
37 | + } as ModelOfMatterParams; | |
30 | 38 | return value; |
31 | 39 | } |
32 | 40 | |
... | ... | @@ -34,14 +42,17 @@ |
34 | 42 | resetFields(); |
35 | 43 | }; |
36 | 44 | |
37 | - const setFormData = (record: StructRecord) => { | |
38 | - const { functionJson } = record as StructRecord; | |
39 | - const { specs = {} } = functionJson || ({} as StructRecord['functionJson']); | |
45 | + const setFormData = (record: ModelOfMatterParams) => { | |
46 | + const { functionJson } = record; | |
47 | + const { dataType = {} } = functionJson!; | |
48 | + | |
49 | + const { specs } = dataType! as DataType; | |
40 | 50 | |
41 | 51 | const value = { |
42 | 52 | ...record, |
43 | 53 | ...functionJson, |
44 | - ...(isObject(specs) ? specs : {}), | |
54 | + ...dataType, | |
55 | + ...(isArray(specs) ? specs : { ...specs }), | |
45 | 56 | }; |
46 | 57 | |
47 | 58 | setFieldsValue(value); | ... | ... |
... | ... | @@ -3,10 +3,11 @@ |
3 | 3 | </template> |
4 | 4 | <script lang="ts" setup> |
5 | 5 | import { BasicForm, useForm } from '/@/components/Form'; |
6 | - import { eventSchemas } from './config'; | |
6 | + import { eventSchemas, FunctionType } from './config'; | |
7 | 7 | import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; |
8 | + import { StructFormValue } from '/@/components/Form/src/externalCompns/components/StructForm/type'; | |
8 | 9 | |
9 | - const [register, { validate, resetFields }] = useForm({ | |
10 | + const [register, { validate, resetFields, setFieldsValue }] = useForm({ | |
10 | 11 | labelWidth: 100, |
11 | 12 | schemas: eventSchemas, |
12 | 13 | actionColOptions: { |
... | ... | @@ -18,12 +19,35 @@ |
18 | 19 | }); |
19 | 20 | |
20 | 21 | //回显数据 |
21 | - const setFormData = () => {}; | |
22 | + const setFormData = (record: ModelOfMatterParams) => { | |
23 | + const { functionJson = {}, functionName, identifier, remark } = record; | |
24 | + const { outputData } = functionJson; | |
25 | + const value = { | |
26 | + functionName, | |
27 | + identifier, | |
28 | + remark, | |
29 | + outputData, | |
30 | + }; | |
31 | + setFieldsValue(value); | |
32 | + }; | |
22 | 33 | |
23 | 34 | async function getFormData() { |
24 | - const values = (await validate()) as ModelOfMatterParams; | |
25 | - if (!values) return; | |
26 | - console.log(values); | |
35 | + const _values = (await validate()) as StructFormValue; | |
36 | + const { functionName, remark, identifier, outputData } = _values; | |
37 | + if (!_values) return {} as unknown as ModelOfMatterParams; | |
38 | + const value = { | |
39 | + functionName, | |
40 | + identifier, | |
41 | + remark, | |
42 | + functionType: FunctionType.EVENTS, | |
43 | + // callType, | |
44 | + // eventType, | |
45 | + functionJson: { | |
46 | + outputData, | |
47 | + }, | |
48 | + } as ModelOfMatterParams; | |
49 | + | |
50 | + return value; | |
27 | 51 | } |
28 | 52 | |
29 | 53 | //清空数据 | ... | ... |
... | ... | @@ -4,11 +4,18 @@ |
4 | 4 | <script lang="ts" setup> |
5 | 5 | import { BasicForm, useForm } from '/@/components/Form'; |
6 | 6 | import { serviceSchemas } from './config'; |
7 | - import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; | |
8 | 7 | import { FunctionType } from './config'; |
9 | - const [register, { validate, resetFields }] = useForm({ | |
8 | + import { StructFormValue } from '/@/components/Form/src/externalCompns/components/StructForm/type'; | |
9 | + import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; | |
10 | + import { DeviceRecord } from '/@/api/device/model/deviceModel'; | |
11 | + | |
12 | + const props = defineProps<{ | |
13 | + record: DeviceRecord; | |
14 | + }>(); | |
15 | + | |
16 | + const [register, { validate, resetFields, setFieldsValue }] = useForm({ | |
10 | 17 | labelWidth: 100, |
11 | - schemas: serviceSchemas, | |
18 | + schemas: serviceSchemas(props.record.transportType === 'TCP'), | |
12 | 19 | actionColOptions: { |
13 | 20 | span: 14, |
14 | 21 | }, |
... | ... | @@ -18,15 +25,39 @@ |
18 | 25 | }); |
19 | 26 | |
20 | 27 | //回显数据 |
21 | - const setFormData = () => {}; | |
28 | + const setFormData = (record: ModelOfMatterParams) => { | |
29 | + const { functionJson = {}, functionName, identifier, remark } = record; | |
30 | + const { inputData, outputData, serviceCommand } = functionJson; | |
31 | + const value = { | |
32 | + functionName, | |
33 | + identifier, | |
34 | + remark, | |
35 | + inputData, | |
36 | + outputData, | |
37 | + serviceCommand, | |
38 | + }; | |
39 | + setFieldsValue(value); | |
40 | + }; | |
22 | 41 | |
23 | 42 | //获取数据 |
24 | 43 | async function getFormData() { |
25 | - const values = (await validate()) as ModelOfMatterParams; | |
26 | - if (!values) return; | |
27 | - values.functionType = FunctionType.SERVICE; | |
28 | - console.log(values); | |
29 | - return values; | |
44 | + const _values = (await validate()) as StructFormValue; | |
45 | + const { functionName, remark, identifier, inputData, outputData, serviceCommand } = _values; | |
46 | + if (!_values) return {}; | |
47 | + const value = { | |
48 | + functionName, | |
49 | + identifier, | |
50 | + remark, | |
51 | + functionType: FunctionType.SERVICE, | |
52 | + // callType, | |
53 | + functionJson: { | |
54 | + inputData, | |
55 | + outputData, | |
56 | + serviceCommand, | |
57 | + }, | |
58 | + } as ModelOfMatterParams; | |
59 | + | |
60 | + return value; | |
30 | 61 | } |
31 | 62 | |
32 | 63 | //清空数据 | ... | ... |
... | ... | @@ -23,6 +23,7 @@ export enum FormField { |
23 | 23 | INPUT_PARAM = 'inputData', |
24 | 24 | OUTPUT_PARAM = 'outputData', |
25 | 25 | EVENT_TYPE = 'eventType', |
26 | + SERVICE_COMMAND = 'serviceCommand', | |
26 | 27 | |
27 | 28 | STRUCT = 'struct', |
28 | 29 | } |
... | ... | @@ -82,79 +83,92 @@ export const defaultTslContent = { |
82 | 83 | ], |
83 | 84 | }; |
84 | 85 | |
85 | -export const serviceSchemas: FormSchema[] = [ | |
86 | - { | |
87 | - field: FormField.FUNCTION_NAME, | |
88 | - label: '功能名称', | |
89 | - required: true, | |
90 | - component: 'Input', | |
91 | - colProps: { | |
92 | - span: 18, | |
86 | +export const serviceSchemas = (tcpDeviceFlag: boolean): FormSchema[] => { | |
87 | + return [ | |
88 | + { | |
89 | + field: FormField.FUNCTION_NAME, | |
90 | + label: '功能名称', | |
91 | + required: true, | |
92 | + component: 'Input', | |
93 | + colProps: { | |
94 | + span: 18, | |
95 | + }, | |
96 | + componentProps: { | |
97 | + maxLength: 255, | |
98 | + placeholder: '请输入功能名称', | |
99 | + }, | |
93 | 100 | }, |
94 | - componentProps: { | |
95 | - maxLength: 255, | |
96 | - placeholder: '请输入功能名称', | |
101 | + { | |
102 | + field: FormField.IDENTIFIER, | |
103 | + label: '标识符', | |
104 | + required: true, | |
105 | + component: 'Input', | |
106 | + colProps: { | |
107 | + span: 18, | |
108 | + }, | |
109 | + componentProps: { | |
110 | + maxLength: 255, | |
111 | + placeholder: '请输入标识符', | |
112 | + }, | |
97 | 113 | }, |
98 | - }, | |
99 | - { | |
100 | - field: FormField.IDENTIFIER, | |
101 | - label: '标识符', | |
102 | - required: true, | |
103 | - component: 'Input', | |
104 | - colProps: { | |
105 | - span: 18, | |
114 | + { | |
115 | + field: FormField.CALL_TYPE, | |
116 | + component: 'ApiRadioGroup', | |
117 | + label: '调用方式', | |
118 | + required: true, | |
119 | + colProps: { | |
120 | + span: 24, | |
121 | + }, | |
122 | + defaultValue: 'ASYNC', | |
123 | + componentProps: { | |
124 | + placeholder: '请选择调用方式', | |
125 | + api: findDictItemByCode, | |
126 | + params: { | |
127 | + dictCode: 'call_mode', | |
128 | + }, | |
129 | + labelField: 'itemText', | |
130 | + valueField: 'itemValue', | |
131 | + }, | |
106 | 132 | }, |
107 | - componentProps: { | |
108 | - maxLength: 255, | |
109 | - placeholder: '请输入标识符', | |
133 | + { | |
134 | + field: FormField.INPUT_PARAM, | |
135 | + label: '输入参数', | |
136 | + component: 'StructForm', | |
137 | + valueField: 'value', | |
138 | + changeEvent: 'update:value', | |
139 | + ifShow: !tcpDeviceFlag, | |
140 | + colProps: { span: 24 }, | |
110 | 141 | }, |
111 | - }, | |
112 | - { | |
113 | - field: FormField.CALL_TYPE, | |
114 | - component: 'ApiRadioGroup', | |
115 | - label: '调用方式', | |
116 | - required: true, | |
117 | - colProps: { | |
118 | - span: 24, | |
142 | + { | |
143 | + field: FormField.OUTPUT_PARAM, | |
144 | + label: '输出参数', | |
145 | + component: 'StructForm', | |
146 | + valueField: 'value', | |
147 | + changeEvent: 'update:value', | |
148 | + ifShow: !tcpDeviceFlag, | |
149 | + colProps: { span: 24 }, | |
119 | 150 | }, |
120 | - defaultValue: 'ASYNC', | |
121 | - componentProps: { | |
122 | - placeholder: '请选择调用方式', | |
123 | - api: findDictItemByCode, | |
124 | - params: { | |
125 | - dictCode: 'call_mode', | |
151 | + { | |
152 | + field: FormField.SERVICE_COMMAND, | |
153 | + label: '服务命令', | |
154 | + component: 'Input', | |
155 | + ifShow: tcpDeviceFlag, | |
156 | + componentProps: { | |
157 | + placeholder: '请输入服务命令', | |
126 | 158 | }, |
127 | - labelField: 'itemText', | |
128 | - valueField: 'itemValue', | |
129 | 159 | }, |
130 | - }, | |
131 | - { | |
132 | - field: FormField.INPUT_PARAM, | |
133 | - label: '输入参数', | |
134 | - component: 'StructForm', | |
135 | - valueField: 'value', | |
136 | - changeEvent: 'update:value', | |
137 | - colProps: { span: 24 }, | |
138 | - }, | |
139 | - { | |
140 | - field: FormField.OUTPUT_PARAM, | |
141 | - label: '输出参数', | |
142 | - component: 'StructForm', | |
143 | - valueField: 'value', | |
144 | - changeEvent: 'update:value', | |
145 | - colProps: { span: 24 }, | |
146 | - }, | |
147 | - { | |
148 | - field: FormField.REFARK, | |
149 | - label: '备注', | |
150 | - component: 'InputTextArea', | |
151 | - componentProps: { | |
152 | - rows: 6, | |
153 | - maxLength: 100, | |
154 | - placeholder: '请输入描述', | |
160 | + { | |
161 | + field: FormField.REFARK, | |
162 | + label: '备注', | |
163 | + component: 'InputTextArea', | |
164 | + componentProps: { | |
165 | + rows: 6, | |
166 | + maxLength: 100, | |
167 | + placeholder: '请输入描述', | |
168 | + }, | |
155 | 169 | }, |
156 | - }, | |
157 | -]; | |
170 | + ]; | |
171 | +}; | |
158 | 172 | |
159 | 173 | export const eventSchemas: FormSchema[] = [ |
160 | 174 | { | ... | ... |