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,11 +15,25 @@ export interface Specs { | ||
15 | }; | 15 | }; |
16 | } | 16 | } |
17 | 17 | ||
18 | -export interface FunctionJson { | 18 | +export interface DataType { |
19 | type: string; | 19 | type: string; |
20 | specs?: Partial<Specs> | ModelOfMatterParams[]; | 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 | export interface ModelOfMatterParams { | 37 | export interface ModelOfMatterParams { |
24 | deviceProfileId: string; | 38 | deviceProfileId: string; |
25 | functionJson: FunctionJson; | 39 | functionJson: FunctionJson; |
@@ -28,6 +42,7 @@ export interface ModelOfMatterParams { | @@ -28,6 +42,7 @@ export interface ModelOfMatterParams { | ||
28 | identifier: string; | 42 | identifier: string; |
29 | remark: string; | 43 | remark: string; |
30 | id?: string; | 44 | id?: string; |
45 | + // callType | ||
31 | } | 46 | } |
32 | 47 | ||
33 | export interface GetModelTslParams { | 48 | export interface GetModelTslParams { |
@@ -7,10 +7,12 @@ | @@ -7,10 +7,12 @@ | ||
7 | import { BasicForm, useForm } from '/@/components/Form'; | 7 | import { BasicForm, useForm } from '/@/components/Form'; |
8 | import { formSchemas } from './config'; | 8 | import { formSchemas } from './config'; |
9 | import { BasicModal, useModalInner } from '/@/components/Modal'; | 9 | import { BasicModal, useModalInner } from '/@/components/Modal'; |
10 | - import { OpenModalMode, OpenModalParams, StructRecord } from './type'; | 10 | + import { OpenModalMode, OpenModalParams } from './type'; |
11 | import { ref, unref } from 'vue'; | 11 | import { ref, unref } from 'vue'; |
12 | - import { transformFormValue } from './util'; | 12 | + import { transfromToStructJSON } from './util'; |
13 | import { cloneDeep } from 'lodash-es'; | 13 | import { cloneDeep } from 'lodash-es'; |
14 | + import { DataType, StructJSON } from '/@/api/device/model/modelOfMatterModel'; | ||
15 | + import { isArray } from '/@/utils/is'; | ||
14 | 16 | ||
15 | const modalReceiveRecord = ref<OpenModalParams>({ | 17 | const modalReceiveRecord = ref<OpenModalParams>({ |
16 | mode: OpenModalMode.CREATE, | 18 | mode: OpenModalMode.CREATE, |
@@ -32,17 +34,14 @@ | @@ -32,17 +34,14 @@ | ||
32 | const [registerModal, { closeModal }] = useModalInner((record: OpenModalParams) => { | 34 | const [registerModal, { closeModal }] = useModalInner((record: OpenModalParams) => { |
33 | modalReceiveRecord.value = record; | 35 | modalReceiveRecord.value = record; |
34 | const data = record.record || {}; | 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 | if (record.record) { | 40 | if (record.record) { |
38 | const value = { | 41 | const value = { |
42 | + type, | ||
39 | ...data, | 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 | setFieldsValue(value); | 47 | setFieldsValue(value); |
@@ -52,9 +51,9 @@ | @@ -52,9 +51,9 @@ | ||
52 | const handleSubmit = async () => { | 51 | const handleSubmit = async () => { |
53 | try { | 52 | try { |
54 | const _value = await validate(); | 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 | ...(unref(modalReceiveRecord)?.record?.id | 57 | ...(unref(modalReceiveRecord)?.record?.id |
59 | ? { id: unref(modalReceiveRecord)?.record?.id } | 58 | ? { id: unref(modalReceiveRecord)?.record?.id } |
60 | : {}), | 59 | : {}), |
1 | import { h } from 'vue'; | 1 | import { h } from 'vue'; |
2 | +import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; | ||
2 | import { findDictItemByCode } from '/@/api/system/dict'; | 3 | import { findDictItemByCode } from '/@/api/system/dict'; |
3 | import { FormSchema } from '/@/components/Table'; | 4 | import { FormSchema } from '/@/components/Table'; |
4 | import { FormField } from '/@/views/device/profiles/step/cpns/physical/cpns/config'; | 5 | import { FormField } from '/@/views/device/profiles/step/cpns/physical/cpns/config'; |
@@ -11,6 +12,23 @@ export enum DateTypeEnum { | @@ -11,6 +12,23 @@ export enum DateTypeEnum { | ||
11 | IS_BOOL = 'BOOL', | 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 | export const formSchemas: FormSchema[] = [ | 32 | export const formSchemas: FormSchema[] = [ |
15 | { | 33 | { |
16 | field: FormField.FUNCTION_NAME, | 34 | field: FormField.FUNCTION_NAME, |
@@ -70,6 +88,7 @@ export const formSchemas: FormSchema[] = [ | @@ -70,6 +88,7 @@ export const formSchemas: FormSchema[] = [ | ||
70 | ifShow: ({ values }) => | 88 | ifShow: ({ values }) => |
71 | values[FormField.TYPE] === DateTypeEnum.IS_NUMBER_INT || | 89 | values[FormField.TYPE] === DateTypeEnum.IS_NUMBER_INT || |
72 | values[FormField.TYPE] === DateTypeEnum.IS_NUMBER_DOUBLE, | 90 | values[FormField.TYPE] === DateTypeEnum.IS_NUMBER_DOUBLE, |
91 | + rules: [{ validator: validateValueRange }], | ||
73 | }, | 92 | }, |
74 | { | 93 | { |
75 | field: FormField.STEP, | 94 | field: FormField.STEP, |
@@ -81,10 +100,29 @@ export const formSchemas: FormSchema[] = [ | @@ -81,10 +100,29 @@ export const formSchemas: FormSchema[] = [ | ||
81 | componentProps: { | 100 | componentProps: { |
82 | maxLength: 255, | 101 | maxLength: 255, |
83 | placeholder: '请输入步长', | 102 | placeholder: '请输入步长', |
103 | + min: 1, | ||
104 | + formatter: (value: number | string) => { | ||
105 | + return value ? Math.floor(Number(value)) : value; | ||
106 | + }, | ||
84 | }, | 107 | }, |
85 | ifShow: ({ values }) => | 108 | ifShow: ({ values }) => |
86 | values[FormField.TYPE] === DateTypeEnum.IS_NUMBER_INT || | 109 | values[FormField.TYPE] === DateTypeEnum.IS_NUMBER_INT || |
87 | values[FormField.TYPE] === DateTypeEnum.IS_NUMBER_DOUBLE, | 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 | field: FormField.UNIT_NAME, | 128 | field: FormField.UNIT_NAME, |
@@ -140,6 +178,18 @@ export const formSchemas: FormSchema[] = [ | @@ -140,6 +178,18 @@ export const formSchemas: FormSchema[] = [ | ||
140 | placeholder: '如:关', | 178 | placeholder: '如:关', |
141 | }, | 179 | }, |
142 | ifShow: ({ values }) => values[FormField.TYPE] === DateTypeEnum.IS_BOOL, | 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 | field: FormField.BOOL_OPEN, | 195 | field: FormField.BOOL_OPEN, |
@@ -153,6 +203,18 @@ export const formSchemas: FormSchema[] = [ | @@ -153,6 +203,18 @@ export const formSchemas: FormSchema[] = [ | ||
153 | placeholder: '如:开', | 203 | placeholder: '如:开', |
154 | }, | 204 | }, |
155 | ifShow: ({ values }) => values[FormField.TYPE] === DateTypeEnum.IS_BOOL, | 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 | field: FormField.LENGTH, | 220 | field: FormField.LENGTH, |
@@ -200,15 +262,7 @@ export const formSchemas: FormSchema[] = [ | @@ -200,15 +262,7 @@ export const formSchemas: FormSchema[] = [ | ||
200 | changeEvent: 'update:value', | 262 | changeEvent: 'update:value', |
201 | colProps: { span: 24 }, | 263 | colProps: { span: 24 }, |
202 | ifShow: ({ values }) => values[FormField.TYPE] === DateTypeEnum.IS_STRUCT, | 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 | field: FormField.REFARK, | 268 | field: FormField.REFARK, |
1 | import { DateTypeEnum } from './config'; | 1 | import { DateTypeEnum } from './config'; |
2 | -import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; | 2 | +import { StructJSON } from '/@/api/device/model/modelOfMatterModel'; |
3 | import { FormField } from '/@/views/device/profiles/step/cpns/physical/cpns/config'; | 3 | import { FormField } from '/@/views/device/profiles/step/cpns/physical/cpns/config'; |
4 | 4 | ||
5 | export enum OpenModalMode { | 5 | export enum OpenModalMode { |
@@ -22,6 +22,6 @@ export interface StructFormValue | @@ -22,6 +22,6 @@ export interface StructFormValue | ||
22 | [FormField.STRUCT]: StructRecord[]; | 22 | [FormField.STRUCT]: StructRecord[]; |
23 | } | 23 | } |
24 | 24 | ||
25 | -export interface StructRecord extends ModelOfMatterParams { | 25 | +export interface StructRecord extends StructJSON { |
26 | id: string; | 26 | id: string; |
27 | } | 27 | } |
1 | import { DateTypeEnum } from './config'; | 1 | import { DateTypeEnum } from './config'; |
2 | import { StructFormValue } from './type'; | 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 | const { | 6 | const { |
40 | type, | 7 | type, |
41 | valueRange, | 8 | valueRange, |
@@ -50,31 +17,26 @@ export function transformFormValue(value: StructFormValue): Partial<ModelOfMatte | @@ -50,31 +17,26 @@ export function transformFormValue(value: StructFormValue): Partial<ModelOfMatte | ||
50 | remark, | 17 | remark, |
51 | specs, | 18 | specs, |
52 | } = value; | 19 | } = value; |
53 | - const { min, max } = valueRange! || {}; | ||
54 | const basic = { functionName, identifier, remark }; | 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 | switch (type) { | 23 | switch (type) { |
59 | case DateTypeEnum.IS_NUMBER_INT: | 24 | case DateTypeEnum.IS_NUMBER_INT: |
60 | - validateValueRangeAndStep(Number(min), Number(step), Number(max)); | ||
61 | - functionJson = { | 25 | + dataType = { |
62 | type, | 26 | type, |
63 | - specs: { max, min, valueRange, step, unit, unitName }, | 27 | + specs: { valueRange, step, unit, unitName }, |
64 | }; | 28 | }; |
65 | break; | 29 | break; |
66 | 30 | ||
67 | case DateTypeEnum.IS_NUMBER_DOUBLE: | 31 | case DateTypeEnum.IS_NUMBER_DOUBLE: |
68 | - validateValueRangeAndStep(Number(min), Number(step), Number(max)); | ||
69 | - functionJson = { | 32 | + dataType = { |
70 | type, | 33 | type, |
71 | - specs: { max, min, valueRange, step, unit, unitName }, | 34 | + specs: { valueRange, step, unit, unitName }, |
72 | }; | 35 | }; |
73 | break; | 36 | break; |
74 | 37 | ||
75 | case DateTypeEnum.IS_BOOL: | 38 | case DateTypeEnum.IS_BOOL: |
76 | - validateValueBool(Number(boolClose), Number(boolOpen)); | ||
77 | - functionJson = { | 39 | + dataType = { |
78 | type, | 40 | type, |
79 | specs: { | 41 | specs: { |
80 | boolOpen: boolOpen, | 42 | boolOpen: boolOpen, |
@@ -84,22 +46,18 @@ export function transformFormValue(value: StructFormValue): Partial<ModelOfMatte | @@ -84,22 +46,18 @@ export function transformFormValue(value: StructFormValue): Partial<ModelOfMatte | ||
84 | break; | 46 | break; |
85 | 47 | ||
86 | case DateTypeEnum.IS_STRING: | 48 | case DateTypeEnum.IS_STRING: |
87 | - functionJson = { | 49 | + dataType = { |
88 | type, | 50 | type, |
89 | specs: { length }, | 51 | specs: { length }, |
90 | }; | 52 | }; |
91 | break; | 53 | break; |
92 | 54 | ||
93 | case DateTypeEnum.IS_STRUCT: | 55 | case DateTypeEnum.IS_STRUCT: |
94 | - functionJson = { | 56 | + dataType = { |
95 | type, | 57 | type, |
96 | specs: specs! as unknown as ModelOfMatterParams[], | 58 | specs: specs! as unknown as ModelOfMatterParams[], |
97 | }; | 59 | }; |
98 | break; | 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,7 +32,11 @@ | ||
32 | /> | 32 | /> |
33 | </Tabs> | 33 | </Tabs> |
34 | <Attribute v-show="activeKey === FunctionType.PROPERTIES" ref="AttrRef" /> | 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 | <Events v-show="activeKey === FunctionType.EVENTS" ref="EventsRef" /> | 40 | <Events v-show="activeKey === FunctionType.EVENTS" ref="EventsRef" /> |
37 | </div> | 41 | </div> |
38 | </BasicModal> | 42 | </BasicModal> |
@@ -51,7 +55,6 @@ | @@ -51,7 +55,6 @@ | ||
51 | import { useMessage } from '/@/hooks/web/useMessage'; | 55 | import { useMessage } from '/@/hooks/web/useMessage'; |
52 | import { OpenModelMode, OpenModelOfMatterModelParams } from './types/index'; | 56 | import { OpenModelMode, OpenModelOfMatterModelParams } from './types/index'; |
53 | import { FunctionType } from './cpns/config'; | 57 | import { FunctionType } from './cpns/config'; |
54 | - import { StructRecord } from '/@/components/Form/src/externalCompns/components/StructForm/type'; | ||
55 | 58 | ||
56 | const emit = defineEmits(['register', 'success']); | 59 | const emit = defineEmits(['register', 'success']); |
57 | 60 | ||
@@ -75,9 +78,9 @@ | @@ -75,9 +78,9 @@ | ||
75 | const functionType = ref<FunctionType>(); | 78 | const functionType = ref<FunctionType>(); |
76 | const { createMessage } = useMessage(); | 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 | const enums = { | 85 | const enums = { |
83 | [FunctionType.PROPERTIES]: setAttrFormData, | 86 | [FunctionType.PROPERTIES]: setAttrFormData, |
@@ -85,7 +88,7 @@ | @@ -85,7 +88,7 @@ | ||
85 | [FunctionType.EVENTS]: setEventsFormData, | 88 | [FunctionType.EVENTS]: setEventsFormData, |
86 | }; | 89 | }; |
87 | 90 | ||
88 | - function setFormData(type: FunctionType, value: StructRecord) { | 91 | + function setFormData(type: FunctionType, value: ModelOfMatterParams) { |
89 | const setFn = enums[type]; | 92 | const setFn = enums[type]; |
90 | setFn(value); | 93 | setFn(value); |
91 | } | 94 | } |
@@ -98,7 +101,7 @@ | @@ -98,7 +101,7 @@ | ||
98 | if (record) { | 101 | if (record) { |
99 | functionType.value = data.record.functionType; | 102 | functionType.value = data.record.functionType; |
100 | activeKey.value = data.record.functionType; | 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 | if (unref(openModalMode) === OpenModelMode.VIEW) { | 106 | if (unref(openModalMode) === OpenModelMode.VIEW) { |
104 | setModalProps({ showOkBtn: false, showCancelBtn: false, title: '查看物模型' }); | 107 | setModalProps({ showOkBtn: false, showCancelBtn: false, title: '查看物模型' }); |
@@ -133,7 +136,7 @@ | @@ -133,7 +136,7 @@ | ||
133 | } else if (activeKey.value == FunctionType.SERVICE) { | 136 | } else if (activeKey.value == FunctionType.SERVICE) { |
134 | params = (await ServiceRef.value?.getFormData()) || {}; | 137 | params = (await ServiceRef.value?.getFormData()) || {}; |
135 | } else { | 138 | } else { |
136 | - params = await EventsRef.value?.getFormData(); | 139 | + params = (await EventsRef.value?.getFormData()) || {}; |
137 | } | 140 | } |
138 | params.deviceProfileId = props.record.id; | 141 | params.deviceProfileId = props.record.id; |
139 | if (unref(openModalMode) === OpenModelMode.CREATE) { | 142 | if (unref(openModalMode) === OpenModelMode.CREATE) { |
@@ -3,14 +3,12 @@ | @@ -3,14 +3,12 @@ | ||
3 | </template> | 3 | </template> |
4 | <script lang="ts" setup> | 4 | <script lang="ts" setup> |
5 | import { BasicForm, useForm } from '/@/components/Form'; | 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 | import { formSchemas } from '/@/components/Form/src/externalCompns/components/StructForm/config'; | 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 | const [register, { validate, resetFields, setFieldsValue }] = useForm({ | 13 | const [register, { validate, resetFields, setFieldsValue }] = useForm({ |
16 | labelWidth: 100, | 14 | labelWidth: 100, |
@@ -26,7 +24,17 @@ | @@ -26,7 +24,17 @@ | ||
26 | async function getFormData(): Promise<Partial<ModelOfMatterParams>> { | 24 | async function getFormData(): Promise<Partial<ModelOfMatterParams>> { |
27 | const _values = (await validate()) as StructFormValue; | 25 | const _values = (await validate()) as StructFormValue; |
28 | if (!_values) return {}; | 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 | return value; | 38 | return value; |
31 | } | 39 | } |
32 | 40 | ||
@@ -34,14 +42,17 @@ | @@ -34,14 +42,17 @@ | ||
34 | resetFields(); | 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 | const value = { | 51 | const value = { |
42 | ...record, | 52 | ...record, |
43 | ...functionJson, | 53 | ...functionJson, |
44 | - ...(isObject(specs) ? specs : {}), | 54 | + ...dataType, |
55 | + ...(isArray(specs) ? specs : { ...specs }), | ||
45 | }; | 56 | }; |
46 | 57 | ||
47 | setFieldsValue(value); | 58 | setFieldsValue(value); |
@@ -3,10 +3,11 @@ | @@ -3,10 +3,11 @@ | ||
3 | </template> | 3 | </template> |
4 | <script lang="ts" setup> | 4 | <script lang="ts" setup> |
5 | import { BasicForm, useForm } from '/@/components/Form'; | 5 | import { BasicForm, useForm } from '/@/components/Form'; |
6 | - import { eventSchemas } from './config'; | 6 | + import { eventSchemas, FunctionType } from './config'; |
7 | import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; | 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 | labelWidth: 100, | 11 | labelWidth: 100, |
11 | schemas: eventSchemas, | 12 | schemas: eventSchemas, |
12 | actionColOptions: { | 13 | actionColOptions: { |
@@ -18,12 +19,35 @@ | @@ -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 | async function getFormData() { | 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,11 +4,18 @@ | ||
4 | <script lang="ts" setup> | 4 | <script lang="ts" setup> |
5 | import { BasicForm, useForm } from '/@/components/Form'; | 5 | import { BasicForm, useForm } from '/@/components/Form'; |
6 | import { serviceSchemas } from './config'; | 6 | import { serviceSchemas } from './config'; |
7 | - import { ModelOfMatterParams } from '/@/api/device/model/modelOfMatterModel'; | ||
8 | import { FunctionType } from './config'; | 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 | labelWidth: 100, | 17 | labelWidth: 100, |
11 | - schemas: serviceSchemas, | 18 | + schemas: serviceSchemas(props.record.transportType === 'TCP'), |
12 | actionColOptions: { | 19 | actionColOptions: { |
13 | span: 14, | 20 | span: 14, |
14 | }, | 21 | }, |
@@ -18,15 +25,39 @@ | @@ -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 | async function getFormData() { | 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,6 +23,7 @@ export enum FormField { | ||
23 | INPUT_PARAM = 'inputData', | 23 | INPUT_PARAM = 'inputData', |
24 | OUTPUT_PARAM = 'outputData', | 24 | OUTPUT_PARAM = 'outputData', |
25 | EVENT_TYPE = 'eventType', | 25 | EVENT_TYPE = 'eventType', |
26 | + SERVICE_COMMAND = 'serviceCommand', | ||
26 | 27 | ||
27 | STRUCT = 'struct', | 28 | STRUCT = 'struct', |
28 | } | 29 | } |
@@ -82,79 +83,92 @@ export const defaultTslContent = { | @@ -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 | export const eventSchemas: FormSchema[] = [ | 173 | export const eventSchemas: FormSchema[] = [ |
160 | { | 174 | { |