Commit 8dccf1bdd83710a38c9e82d7ae5f568d6dcc9ce9
Merge branch 'fix/product-objcet-model' into 'main_dev'
fix: 修复物模型在修改编辑时可重复设置结构体类型 See merge request yunteng/thingskit-front!1071
Showing
6 changed files
with
75 additions
and
29 deletions
... | ... | @@ -14,6 +14,8 @@ |
14 | 14 | import { OpenModalMode, OpenModalParams, StructRecord } from './type'; |
15 | 15 | import { cloneDeep } from 'lodash-es'; |
16 | 16 | import { isArray } from '/@/utils/is'; |
17 | + import { FormField } from '/@/views/device/profiles/step/cpns/physical/cpns/config'; | |
18 | + import { DataTypeEnum } from '/@/enums/objectModelEnum'; | |
17 | 19 | |
18 | 20 | const emit = defineEmits(['update:value']); |
19 | 21 | |
... | ... | @@ -53,7 +55,10 @@ |
53 | 55 | const handleUpdate = (value: StructRecord) => { |
54 | 56 | openModal(true, { |
55 | 57 | mode: OpenModalMode.UPDATE, |
56 | - record: value, | |
58 | + record: { | |
59 | + ...value, | |
60 | + [FormField.HAS_STRUCT_FROM]: value?.dataType?.type === DataTypeEnum.STRUCT, | |
61 | + }, | |
57 | 62 | } as OpenModalParams); |
58 | 63 | }; |
59 | 64 | |
... | ... | @@ -90,15 +95,10 @@ |
90 | 95 | <div>参数名称: {{ item.functionName }}</div> |
91 | 96 | <div class="flex"> |
92 | 97 | <Button class="!p-0" type="link" @click="handleUpdate(item)"> |
93 | - <span>{{ $props.disabled ? '查看' : '编辑' }}</span> | |
98 | + <span>{{ disabled ? '查看' : '编辑' }}</span> | |
94 | 99 | </Button> |
95 | 100 | <Divider type="vertical" /> |
96 | - <Button | |
97 | - :disabled="$props.disabled" | |
98 | - class="!p-0" | |
99 | - type="link" | |
100 | - @click="handleDelete(item)" | |
101 | - > | |
101 | + <Button :disabled="disabled" class="!p-0" type="link" @click="handleDelete(item)"> | |
102 | 102 | <span>删除</span> |
103 | 103 | </Button> |
104 | 104 | </div> |
... | ... | @@ -114,7 +114,7 @@ |
114 | 114 | <StructFormModel |
115 | 115 | :has-struct-form="hasStructForm!" |
116 | 116 | :hidden-access-mode="hiddenAccessMode" |
117 | - :disabled="$props.disabled" | |
117 | + :disabled="disabled" | |
118 | 118 | :value-list="getValue" |
119 | 119 | @register="registerModal" |
120 | 120 | @submit="handleSaveStruct" | ... | ... |
... | ... | @@ -8,7 +8,7 @@ |
8 | 8 | import { formSchemas } from './config'; |
9 | 9 | import { BasicModal, useModalInner } from '/@/components/Modal'; |
10 | 10 | import { OpenModalMode, OpenModalParams, StructRecord } from './type'; |
11 | - import { ref, unref } from 'vue'; | |
11 | + import { computed, ref, unref } from 'vue'; | |
12 | 12 | import { transfromToStructJSON } from './util'; |
13 | 13 | import { cloneDeep } from 'lodash-es'; |
14 | 14 | import { DataType, StructJSON } from '/@/api/device/model/modelOfMatterModel'; |
... | ... | @@ -32,7 +32,6 @@ |
32 | 32 | |
33 | 33 | const [register, { validate, setFieldsValue, setProps }] = useForm({ |
34 | 34 | labelWidth: 100, |
35 | - schemas: formSchemas(props.hasStructForm, props.hiddenAccessMode), | |
36 | 35 | actionColOptions: { |
37 | 36 | span: 14, |
38 | 37 | }, |
... | ... | @@ -42,6 +41,14 @@ |
42 | 41 | showActionButtonGroup: false, |
43 | 42 | }); |
44 | 43 | |
44 | + const getFormSchemas = computed(() => { | |
45 | + const { hasStructForm, hiddenAccessMode } = props; | |
46 | + return formSchemas({ | |
47 | + hasStructForm, | |
48 | + hiddenAccessMode, | |
49 | + }); | |
50 | + }); | |
51 | + | |
45 | 52 | const [registerModal, { closeModal }] = useModalInner((record: OpenModalParams) => { |
46 | 53 | modalReceiveRecord.value = record; |
47 | 54 | const data = record.record || {}; |
... | ... | @@ -97,7 +104,7 @@ |
97 | 104 | destroy-on-close |
98 | 105 | :show-ok-btn="!$props.disabled" |
99 | 106 | > |
100 | - <BasicForm @register="register" /> | |
107 | + <BasicForm @register="register" :schemas="getFormSchemas" /> | |
101 | 108 | </BasicModal> |
102 | 109 | </template> |
103 | 110 | ... | ... |
... | ... | @@ -21,11 +21,17 @@ export const validateJSON = (_rule, value = [] as ModelOfMatterParams[], _callba |
21 | 21 | return Promise.reject('JSON对象不能为空'); |
22 | 22 | }; |
23 | 23 | |
24 | -export const formSchemas = ( | |
25 | - hasStructForm: boolean, | |
26 | - hiddenAccessMode: boolean, | |
27 | - isTcp = false | |
28 | -): FormSchema[] => { | |
24 | +interface StructFormSchemasParmasType { | |
25 | + hasStructForm: boolean; | |
26 | + hiddenAccessMode: boolean; | |
27 | + isTcp?: boolean; | |
28 | +} | |
29 | + | |
30 | +export const formSchemas = ({ | |
31 | + hasStructForm, | |
32 | + hiddenAccessMode, | |
33 | + isTcp = false, | |
34 | +}: StructFormSchemasParmasType): FormSchema[] => { | |
29 | 35 | return [ |
30 | 36 | { |
31 | 37 | field: FormField.FUNCTION_NAME, |
... | ... | @@ -54,6 +60,12 @@ export const formSchemas = ( |
54 | 60 | }, |
55 | 61 | }, |
56 | 62 | { |
63 | + field: FormField.HAS_STRUCT_FROM, | |
64 | + label: '是否已存在结构体', | |
65 | + component: 'Input', | |
66 | + ifShow: false, | |
67 | + }, | |
68 | + { | |
57 | 69 | field: FormField.TYPE, |
58 | 70 | label: '数据类型', |
59 | 71 | required: true, |
... | ... | @@ -63,7 +75,7 @@ export const formSchemas = ( |
63 | 75 | }, |
64 | 76 | defaultValue: 'INT', |
65 | 77 | componentProps: ({ formActionType }) => { |
66 | - const { updateSchema, setFieldsValue } = formActionType; | |
78 | + const { setFieldsValue } = formActionType; | |
67 | 79 | return { |
68 | 80 | placeholder: '请选择数据类型', |
69 | 81 | api: async (params: Recordable) => { |
... | ... | @@ -84,13 +96,7 @@ export const formSchemas = ( |
84 | 96 | getPopupContainer: () => document.body, |
85 | 97 | onChange: (value: string) => { |
86 | 98 | if (value == DataTypeEnum.STRUCT) { |
87 | - updateSchema({ | |
88 | - field: FormField.SPECS_LIST, | |
89 | - componentProps: { | |
90 | - hasStructForm: true, | |
91 | - }, | |
92 | - }); | |
93 | - setFieldsValue({ [FormField.SPECS_LIST]: [] }); | |
99 | + setFieldsValue({ [FormField.SPECS_LIST]: [], [FormField.HAS_STRUCT_FROM]: true }); | |
94 | 100 | } |
95 | 101 | }, |
96 | 102 | }; |
... | ... | @@ -316,6 +322,11 @@ export const formSchemas = ( |
316 | 322 | colProps: { span: 24 }, |
317 | 323 | ifShow: ({ values }) => values[FormField.TYPE] === DataTypeEnum.STRUCT, |
318 | 324 | rules: [{ required: true, validator: validateJSON }], |
325 | + componentProps: ({ formModel }) => { | |
326 | + return { | |
327 | + hasStructForm: formModel[FormField.HAS_STRUCT_FROM], | |
328 | + }; | |
329 | + }, | |
319 | 330 | }, |
320 | 331 | { |
321 | 332 | field: FormField.REFARK, | ... | ... |
... | ... | @@ -14,12 +14,17 @@ |
14 | 14 | import { OpenModelMode } from '../types'; |
15 | 15 | import { formSchemas } from '/@/components/Form/src/externalCompns/components/StructForm/config'; |
16 | 16 | import { TransportTypeEnum } from '../../../../components/TransportDescript/const'; |
17 | + import { DataTypeEnum } from '/@/enums/objectModelEnum'; | |
17 | 18 | |
18 | 19 | const props = defineProps<{ openModalMode: OpenModelMode; transportType?: string | undefined }>(); |
19 | 20 | |
20 | 21 | const [register, { validate, resetFields, setFieldsValue, setProps }] = useForm({ |
21 | 22 | labelWidth: 100, |
22 | - schemas: formSchemas(false, false, props.transportType === TransportTypeEnum.TCP), | |
23 | + schemas: formSchemas({ | |
24 | + hasStructForm: false, | |
25 | + hiddenAccessMode: false, | |
26 | + isTcp: props.transportType === TransportTypeEnum.TCP, | |
27 | + }), | |
23 | 28 | actionColOptions: { |
24 | 29 | span: 14, |
25 | 30 | }, |
... | ... | @@ -67,7 +72,9 @@ |
67 | 72 | ...functionJson, |
68 | 73 | ...dataType, |
69 | 74 | ...(isArray(specs) ? specs : { ...specs }), |
75 | + hasStructForm: (record?.functionJson?.dataType as DataType)?.type === DataTypeEnum.STRUCT, | |
70 | 76 | }; |
77 | + | |
71 | 78 | setFieldsValue(value); |
72 | 79 | }; |
73 | 80 | ... | ... |
... | ... | @@ -3,13 +3,15 @@ |
3 | 3 | </template> |
4 | 4 | <script lang="ts" setup> |
5 | 5 | import { BasicForm, useForm } from '/@/components/Form'; |
6 | - import { serviceSchemas } from './config'; | |
6 | + import { FormField, serviceSchemas } from './config'; | |
7 | 7 | import { FunctionType } from './config'; |
8 | 8 | import { StructFormValue } from '/@/components/Form/src/externalCompns/components/StructForm/type'; |
9 | 9 | import { ModelOfMatterParams, StructJSON } from '/@/api/device/model/modelOfMatterModel'; |
10 | 10 | import { DeviceRecord } from '/@/api/device/model/deviceModel'; |
11 | 11 | import { excludeIdInStructJSON } from '/@/components/Form/src/externalCompns/components/StructForm/util'; |
12 | 12 | import { OpenModelMode } from '../types'; |
13 | + import { isArray } from '/@/utils/is'; | |
14 | + import { DataTypeEnum } from '/@/enums/objectModelEnum'; | |
13 | 15 | |
14 | 16 | const props = defineProps<{ |
15 | 17 | record: DeviceRecord; |
... | ... | @@ -48,6 +50,14 @@ |
48 | 50 | serviceCommand, |
49 | 51 | callType, |
50 | 52 | }; |
53 | + | |
54 | + if ( | |
55 | + isArray(inputData) && | |
56 | + inputData.find((item) => item?.dataType?.type === DataTypeEnum.STRUCT) | |
57 | + ) { | |
58 | + Reflect.set(value, FormField.HAS_STRUCT_FROM, true); | |
59 | + } | |
60 | + | |
51 | 61 | setFieldsValue(value); |
52 | 62 | }; |
53 | 63 | ... | ... |
... | ... | @@ -28,6 +28,8 @@ export enum FormField { |
28 | 28 | REGISTER_ADDRESS = 'registerAddress', |
29 | 29 | EXTENSION_DESC = 'extensionDesc', |
30 | 30 | STRUCT = 'struct', |
31 | + | |
32 | + HAS_STRUCT_FROM = 'hasStructForm', | |
31 | 33 | } |
32 | 34 | |
33 | 35 | export enum FunctionType { |
... | ... | @@ -125,6 +127,12 @@ export const serviceSchemas = (tcpDeviceFlag: boolean): FormSchema[] => { |
125 | 127 | }, |
126 | 128 | }, |
127 | 129 | { |
130 | + field: FormField.HAS_STRUCT_FROM, | |
131 | + component: 'Input', | |
132 | + label: '是否已存在结构体', | |
133 | + ifShow: false, | |
134 | + }, | |
135 | + { | |
128 | 136 | field: FormField.INPUT_PARAM, |
129 | 137 | label: '输入参数', |
130 | 138 | component: 'StructForm', |
... | ... | @@ -133,8 +141,11 @@ export const serviceSchemas = (tcpDeviceFlag: boolean): FormSchema[] => { |
133 | 141 | rules: [{ message: '输入参数为必填项', required: true, type: 'array' }], |
134 | 142 | ifShow: !tcpDeviceFlag, |
135 | 143 | colProps: { span: 24 }, |
136 | - componentProps: { | |
137 | - hiddenAccessMode: true, | |
144 | + componentProps: ({ formModel }) => { | |
145 | + return { | |
146 | + hiddenAccessMode: true, | |
147 | + hasStructForm: formModel[FormField.HAS_STRUCT_FROM], | |
148 | + }; | |
138 | 149 | }, |
139 | 150 | }, |
140 | 151 | { | ... | ... |