Showing
6 changed files
with
75 additions
and
29 deletions
| @@ -14,6 +14,8 @@ | @@ -14,6 +14,8 @@ | ||
| 14 | import { OpenModalMode, OpenModalParams, StructRecord } from './type'; | 14 | import { OpenModalMode, OpenModalParams, StructRecord } from './type'; |
| 15 | import { cloneDeep } from 'lodash-es'; | 15 | import { cloneDeep } from 'lodash-es'; |
| 16 | import { isArray } from '/@/utils/is'; | 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 | const emit = defineEmits(['update:value']); | 20 | const emit = defineEmits(['update:value']); |
| 19 | 21 | ||
| @@ -53,7 +55,10 @@ | @@ -53,7 +55,10 @@ | ||
| 53 | const handleUpdate = (value: StructRecord) => { | 55 | const handleUpdate = (value: StructRecord) => { |
| 54 | openModal(true, { | 56 | openModal(true, { |
| 55 | mode: OpenModalMode.UPDATE, | 57 | mode: OpenModalMode.UPDATE, |
| 56 | - record: value, | 58 | + record: { |
| 59 | + ...value, | ||
| 60 | + [FormField.HAS_STRUCT_FROM]: value?.dataType?.type === DataTypeEnum.STRUCT, | ||
| 61 | + }, | ||
| 57 | } as OpenModalParams); | 62 | } as OpenModalParams); |
| 58 | }; | 63 | }; |
| 59 | 64 | ||
| @@ -90,15 +95,10 @@ | @@ -90,15 +95,10 @@ | ||
| 90 | <div>参数名称: {{ item.functionName }}</div> | 95 | <div>参数名称: {{ item.functionName }}</div> |
| 91 | <div class="flex"> | 96 | <div class="flex"> |
| 92 | <Button class="!p-0" type="link" @click="handleUpdate(item)"> | 97 | <Button class="!p-0" type="link" @click="handleUpdate(item)"> |
| 93 | - <span>{{ $props.disabled ? '查看' : '编辑' }}</span> | 98 | + <span>{{ disabled ? '查看' : '编辑' }}</span> |
| 94 | </Button> | 99 | </Button> |
| 95 | <Divider type="vertical" /> | 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 | <span>删除</span> | 102 | <span>删除</span> |
| 103 | </Button> | 103 | </Button> |
| 104 | </div> | 104 | </div> |
| @@ -114,7 +114,7 @@ | @@ -114,7 +114,7 @@ | ||
| 114 | <StructFormModel | 114 | <StructFormModel |
| 115 | :has-struct-form="hasStructForm!" | 115 | :has-struct-form="hasStructForm!" |
| 116 | :hidden-access-mode="hiddenAccessMode" | 116 | :hidden-access-mode="hiddenAccessMode" |
| 117 | - :disabled="$props.disabled" | 117 | + :disabled="disabled" |
| 118 | :value-list="getValue" | 118 | :value-list="getValue" |
| 119 | @register="registerModal" | 119 | @register="registerModal" |
| 120 | @submit="handleSaveStruct" | 120 | @submit="handleSaveStruct" |
| @@ -8,7 +8,7 @@ | @@ -8,7 +8,7 @@ | ||
| 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, StructRecord } from './type'; |
| 11 | - import { ref, unref } from 'vue'; | 11 | + import { computed, ref, unref } from 'vue'; |
| 12 | import { transfromToStructJSON } 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'; | 14 | import { DataType, StructJSON } from '/@/api/device/model/modelOfMatterModel'; |
| @@ -32,7 +32,6 @@ | @@ -32,7 +32,6 @@ | ||
| 32 | 32 | ||
| 33 | const [register, { validate, setFieldsValue, setProps }] = useForm({ | 33 | const [register, { validate, setFieldsValue, setProps }] = useForm({ |
| 34 | labelWidth: 100, | 34 | labelWidth: 100, |
| 35 | - schemas: formSchemas(props.hasStructForm, props.hiddenAccessMode), | ||
| 36 | actionColOptions: { | 35 | actionColOptions: { |
| 37 | span: 14, | 36 | span: 14, |
| 38 | }, | 37 | }, |
| @@ -42,6 +41,14 @@ | @@ -42,6 +41,14 @@ | ||
| 42 | showActionButtonGroup: false, | 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 | const [registerModal, { closeModal }] = useModalInner((record: OpenModalParams) => { | 52 | const [registerModal, { closeModal }] = useModalInner((record: OpenModalParams) => { |
| 46 | modalReceiveRecord.value = record; | 53 | modalReceiveRecord.value = record; |
| 47 | const data = record.record || {}; | 54 | const data = record.record || {}; |
| @@ -97,7 +104,7 @@ | @@ -97,7 +104,7 @@ | ||
| 97 | destroy-on-close | 104 | destroy-on-close |
| 98 | :show-ok-btn="!$props.disabled" | 105 | :show-ok-btn="!$props.disabled" |
| 99 | > | 106 | > |
| 100 | - <BasicForm @register="register" /> | 107 | + <BasicForm @register="register" :schemas="getFormSchemas" /> |
| 101 | </BasicModal> | 108 | </BasicModal> |
| 102 | </template> | 109 | </template> |
| 103 | 110 |
| @@ -21,11 +21,17 @@ export const validateJSON = (_rule, value = [] as ModelOfMatterParams[], _callba | @@ -21,11 +21,17 @@ export const validateJSON = (_rule, value = [] as ModelOfMatterParams[], _callba | ||
| 21 | return Promise.reject('JSON对象不能为空'); | 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 | return [ | 35 | return [ |
| 30 | { | 36 | { |
| 31 | field: FormField.FUNCTION_NAME, | 37 | field: FormField.FUNCTION_NAME, |
| @@ -54,6 +60,12 @@ export const formSchemas = ( | @@ -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 | field: FormField.TYPE, | 69 | field: FormField.TYPE, |
| 58 | label: '数据类型', | 70 | label: '数据类型', |
| 59 | required: true, | 71 | required: true, |
| @@ -63,7 +75,7 @@ export const formSchemas = ( | @@ -63,7 +75,7 @@ export const formSchemas = ( | ||
| 63 | }, | 75 | }, |
| 64 | defaultValue: 'INT', | 76 | defaultValue: 'INT', |
| 65 | componentProps: ({ formActionType }) => { | 77 | componentProps: ({ formActionType }) => { |
| 66 | - const { updateSchema, setFieldsValue } = formActionType; | 78 | + const { setFieldsValue } = formActionType; |
| 67 | return { | 79 | return { |
| 68 | placeholder: '请选择数据类型', | 80 | placeholder: '请选择数据类型', |
| 69 | api: async (params: Recordable) => { | 81 | api: async (params: Recordable) => { |
| @@ -84,13 +96,7 @@ export const formSchemas = ( | @@ -84,13 +96,7 @@ export const formSchemas = ( | ||
| 84 | getPopupContainer: () => document.body, | 96 | getPopupContainer: () => document.body, |
| 85 | onChange: (value: string) => { | 97 | onChange: (value: string) => { |
| 86 | if (value == DataTypeEnum.STRUCT) { | 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,6 +322,11 @@ export const formSchemas = ( | ||
| 316 | colProps: { span: 24 }, | 322 | colProps: { span: 24 }, |
| 317 | ifShow: ({ values }) => values[FormField.TYPE] === DataTypeEnum.STRUCT, | 323 | ifShow: ({ values }) => values[FormField.TYPE] === DataTypeEnum.STRUCT, |
| 318 | rules: [{ required: true, validator: validateJSON }], | 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 | field: FormField.REFARK, | 332 | field: FormField.REFARK, |
| @@ -14,12 +14,17 @@ | @@ -14,12 +14,17 @@ | ||
| 14 | import { OpenModelMode } from '../types'; | 14 | import { OpenModelMode } from '../types'; |
| 15 | import { formSchemas } from '/@/components/Form/src/externalCompns/components/StructForm/config'; | 15 | import { formSchemas } from '/@/components/Form/src/externalCompns/components/StructForm/config'; |
| 16 | import { TransportTypeEnum } from '../../../../components/TransportDescript/const'; | 16 | import { TransportTypeEnum } from '../../../../components/TransportDescript/const'; |
| 17 | + import { DataTypeEnum } from '/@/enums/objectModelEnum'; | ||
| 17 | 18 | ||
| 18 | const props = defineProps<{ openModalMode: OpenModelMode; transportType?: string | undefined }>(); | 19 | const props = defineProps<{ openModalMode: OpenModelMode; transportType?: string | undefined }>(); |
| 19 | 20 | ||
| 20 | const [register, { validate, resetFields, setFieldsValue, setProps }] = useForm({ | 21 | const [register, { validate, resetFields, setFieldsValue, setProps }] = useForm({ |
| 21 | labelWidth: 100, | 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 | actionColOptions: { | 28 | actionColOptions: { |
| 24 | span: 14, | 29 | span: 14, |
| 25 | }, | 30 | }, |
| @@ -67,7 +72,9 @@ | @@ -67,7 +72,9 @@ | ||
| 67 | ...functionJson, | 72 | ...functionJson, |
| 68 | ...dataType, | 73 | ...dataType, |
| 69 | ...(isArray(specs) ? specs : { ...specs }), | 74 | ...(isArray(specs) ? specs : { ...specs }), |
| 75 | + hasStructForm: (record?.functionJson?.dataType as DataType)?.type === DataTypeEnum.STRUCT, | ||
| 70 | }; | 76 | }; |
| 77 | + | ||
| 71 | setFieldsValue(value); | 78 | setFieldsValue(value); |
| 72 | }; | 79 | }; |
| 73 | 80 |
| @@ -3,13 +3,15 @@ | @@ -3,13 +3,15 @@ | ||
| 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 { serviceSchemas } from './config'; | 6 | + import { FormField, serviceSchemas } from './config'; |
| 7 | import { FunctionType } from './config'; | 7 | import { FunctionType } from './config'; |
| 8 | import { StructFormValue } from '/@/components/Form/src/externalCompns/components/StructForm/type'; | 8 | import { StructFormValue } from '/@/components/Form/src/externalCompns/components/StructForm/type'; |
| 9 | import { ModelOfMatterParams, StructJSON } from '/@/api/device/model/modelOfMatterModel'; | 9 | import { ModelOfMatterParams, StructJSON } from '/@/api/device/model/modelOfMatterModel'; |
| 10 | import { DeviceRecord } from '/@/api/device/model/deviceModel'; | 10 | import { DeviceRecord } from '/@/api/device/model/deviceModel'; |
| 11 | import { excludeIdInStructJSON } from '/@/components/Form/src/externalCompns/components/StructForm/util'; | 11 | import { excludeIdInStructJSON } from '/@/components/Form/src/externalCompns/components/StructForm/util'; |
| 12 | import { OpenModelMode } from '../types'; | 12 | import { OpenModelMode } from '../types'; |
| 13 | + import { isArray } from '/@/utils/is'; | ||
| 14 | + import { DataTypeEnum } from '/@/enums/objectModelEnum'; | ||
| 13 | 15 | ||
| 14 | const props = defineProps<{ | 16 | const props = defineProps<{ |
| 15 | record: DeviceRecord; | 17 | record: DeviceRecord; |
| @@ -48,6 +50,14 @@ | @@ -48,6 +50,14 @@ | ||
| 48 | serviceCommand, | 50 | serviceCommand, |
| 49 | callType, | 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 | setFieldsValue(value); | 61 | setFieldsValue(value); |
| 52 | }; | 62 | }; |
| 53 | 63 |
| @@ -28,6 +28,8 @@ export enum FormField { | @@ -28,6 +28,8 @@ export enum FormField { | ||
| 28 | REGISTER_ADDRESS = 'registerAddress', | 28 | REGISTER_ADDRESS = 'registerAddress', |
| 29 | EXTENSION_DESC = 'extensionDesc', | 29 | EXTENSION_DESC = 'extensionDesc', |
| 30 | STRUCT = 'struct', | 30 | STRUCT = 'struct', |
| 31 | + | ||
| 32 | + HAS_STRUCT_FROM = 'hasStructForm', | ||
| 31 | } | 33 | } |
| 32 | 34 | ||
| 33 | export enum FunctionType { | 35 | export enum FunctionType { |
| @@ -125,6 +127,12 @@ export const serviceSchemas = (tcpDeviceFlag: boolean): FormSchema[] => { | @@ -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 | field: FormField.INPUT_PARAM, | 136 | field: FormField.INPUT_PARAM, |
| 129 | label: '输入参数', | 137 | label: '输入参数', |
| 130 | component: 'StructForm', | 138 | component: 'StructForm', |
| @@ -133,8 +141,11 @@ export const serviceSchemas = (tcpDeviceFlag: boolean): FormSchema[] => { | @@ -133,8 +141,11 @@ export const serviceSchemas = (tcpDeviceFlag: boolean): FormSchema[] => { | ||
| 133 | rules: [{ message: '输入参数为必填项', required: true, type: 'array' }], | 141 | rules: [{ message: '输入参数为必填项', required: true, type: 'array' }], |
| 134 | ifShow: !tcpDeviceFlag, | 142 | ifShow: !tcpDeviceFlag, |
| 135 | colProps: { span: 24 }, | 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 | { |