Commit a6e70c284dbe525c94e2bf58956160e34c5f9cae
Merge branch 'fix/DEFECT-1414' into 'main_dev'
fix: DEFECT-1414修复任务中心寄存器验证未通过 See merge request yunteng/thingskit-front!742
Showing
12 changed files
with
133 additions
and
39 deletions
| ... | ... | @@ -39,6 +39,8 @@ import CustomMinMaxInput from './externalCompns/components/CustomMinMaxInput.vue |
| 39 | 39 | import StructForm from './externalCompns/components/StructForm/StructForm.vue'; |
| 40 | 40 | import ApiSelectScrollLoad from './components/ApiSelectScrollLoad.vue'; |
| 41 | 41 | import InputGroup from './components/InputGroup.vue'; |
| 42 | +import RegisterAddressInput from '/@/views/task/center/components/PollCommandInput/RegisterAddressInput.vue'; | |
| 43 | +import ExtendDesc from '/@/components/Form/src/externalCompns/components/ExtendDesc/index.vue'; | |
| 42 | 44 | |
| 43 | 45 | const componentMap = new Map<ComponentType, Component>(); |
| 44 | 46 | |
| ... | ... | @@ -85,6 +87,8 @@ componentMap.set('CustomMinMaxInput', CustomMinMaxInput); |
| 85 | 87 | componentMap.set('StructForm', StructForm); |
| 86 | 88 | componentMap.set('ApiSelectScrollLoad', ApiSelectScrollLoad); |
| 87 | 89 | componentMap.set('InputGroup', InputGroup); |
| 90 | +componentMap.set('RegisterAddressInput', RegisterAddressInput); | |
| 91 | +componentMap.set('ExtendDesc', ExtendDesc); | |
| 88 | 92 | |
| 89 | 93 | export function add(compName: ComponentType, component: Component) { |
| 90 | 94 | componentMap.set(compName, component); | ... | ... |
| 1 | +<script lang="ts" setup> | |
| 2 | + import { Button } from 'ant-design-vue'; | |
| 3 | + import { nextTick, ref, watch } from 'vue'; | |
| 4 | + import { BasicForm, useForm } from '/@/components/Form'; | |
| 5 | + import { BasicModal } from '/@/components/Modal'; | |
| 6 | + | |
| 7 | + const show = ref(false); | |
| 8 | + | |
| 9 | + const props = withDefaults( | |
| 10 | + defineProps<{ | |
| 11 | + value?: object; | |
| 12 | + disabled?: boolean; | |
| 13 | + }>(), | |
| 14 | + { | |
| 15 | + value: () => ({}), | |
| 16 | + } | |
| 17 | + ); | |
| 18 | + | |
| 19 | + const emit = defineEmits(['update:value']); | |
| 20 | + | |
| 21 | + const [registerForm, { setFieldsValue, getFieldsValue, setProps }] = useForm({ | |
| 22 | + schemas: [ | |
| 23 | + { | |
| 24 | + field: 'registerAddress', | |
| 25 | + component: 'Input', | |
| 26 | + label: '寄存器地址', | |
| 27 | + componentProps: { | |
| 28 | + placeholder: '请输入寄存器地址', | |
| 29 | + }, | |
| 30 | + }, | |
| 31 | + ], | |
| 32 | + showActionButtonGroup: false, | |
| 33 | + }); | |
| 34 | + | |
| 35 | + const handleClick = async () => { | |
| 36 | + show.value = true; | |
| 37 | + await nextTick(); | |
| 38 | + setProps({ disabled: props.disabled }); | |
| 39 | + setFieldsValue(props.value); | |
| 40 | + }; | |
| 41 | + | |
| 42 | + const handleSubmit = () => { | |
| 43 | + const value = getFieldsValue(); | |
| 44 | + emit('update:value', value); | |
| 45 | + show.value = false; | |
| 46 | + }; | |
| 47 | + | |
| 48 | + watch( | |
| 49 | + () => props.value, | |
| 50 | + (value) => { | |
| 51 | + setFieldsValue(value); | |
| 52 | + } | |
| 53 | + ); | |
| 54 | +</script> | |
| 55 | + | |
| 56 | +<template> | |
| 57 | + <section> | |
| 58 | + <Button type="link" @click="handleClick">新增扩展描述</Button> | |
| 59 | + <BasicModal title="扩展描述" v-model:visible="show" @ok="handleSubmit"> | |
| 60 | + <BasicForm @register="registerForm" /> | |
| 61 | + </BasicModal> | |
| 62 | + </section> | |
| 63 | +</template> | ... | ... |
| ... | ... | @@ -28,7 +28,7 @@ export const validateJSON = (_rule, value = [] as ModelOfMatterParams[], _callba |
| 28 | 28 | return Promise.reject('JSON对象不能为空'); |
| 29 | 29 | }; |
| 30 | 30 | |
| 31 | -export const formSchemas = (hasStructForm: boolean): FormSchema[] => { | |
| 31 | +export const formSchemas = (hasStructForm: boolean, isTcp = false): FormSchema[] => { | |
| 32 | 32 | return [ |
| 33 | 33 | { |
| 34 | 34 | field: FormField.FUNCTION_NAME, |
| ... | ... | @@ -276,6 +276,27 @@ export const formSchemas = (hasStructForm: boolean): FormSchema[] => { |
| 276 | 276 | ifShow: ({ values }) => values[FormField.TYPE] === DataTypeEnum.IS_STRING, |
| 277 | 277 | }, |
| 278 | 278 | { |
| 279 | + field: FormField.EXTENSION_DESC, | |
| 280 | + component: 'ExtendDesc', | |
| 281 | + label: '扩展描述', | |
| 282 | + valueField: 'value', | |
| 283 | + changeEvent: 'update:value', | |
| 284 | + rules: [ | |
| 285 | + { | |
| 286 | + message: '请输入扩展描述', | |
| 287 | + required: true, | |
| 288 | + validator(_rule, value, _callback) { | |
| 289 | + if (!value?.['registerAddress']) return Promise.reject('请输入寄存器地址'); | |
| 290 | + return Promise.resolve(); | |
| 291 | + }, | |
| 292 | + }, | |
| 293 | + ], | |
| 294 | + ifShow: isTcp, | |
| 295 | + colProps: { | |
| 296 | + span: 16, | |
| 297 | + }, | |
| 298 | + }, | |
| 299 | + { | |
| 279 | 300 | field: FormField.ACCESS_MODE, |
| 280 | 301 | component: 'ApiRadioGroup', |
| 281 | 302 | label: '读写类型', | ... | ... |
| ... | ... | @@ -13,12 +13,13 @@ |
| 13 | 13 | import { isArray } from 'lodash'; |
| 14 | 14 | import { OpenModelMode } from '../types'; |
| 15 | 15 | import { formSchemas } from '/@/components/Form/src/externalCompns/components/StructForm/config'; |
| 16 | + import { TransportTypeEnum } from '../../../../components/TransportDescript/const'; | |
| 16 | 17 | |
| 17 | - defineProps<{ openModalMode: OpenModelMode }>(); | |
| 18 | + const props = defineProps<{ openModalMode: OpenModelMode; transportType: string }>(); | |
| 18 | 19 | |
| 19 | 20 | const [register, { validate, resetFields, setFieldsValue, setProps }] = useForm({ |
| 20 | 21 | labelWidth: 100, |
| 21 | - schemas: formSchemas(false), | |
| 22 | + schemas: formSchemas(false, props.transportType === TransportTypeEnum.TCP), | |
| 22 | 23 | actionColOptions: { |
| 23 | 24 | span: 14, |
| 24 | 25 | }, |
| ... | ... | @@ -37,13 +38,13 @@ |
| 37 | 38 | const { functionName, remark, identifier, accessMode } = _values; |
| 38 | 39 | const structJSON = transfromToStructJSON(_values); |
| 39 | 40 | const dataType = excludeIdInStructJSON(structJSON.dataType!); |
| 40 | - | |
| 41 | 41 | const value = { |
| 42 | 42 | functionName, |
| 43 | 43 | functionType: FunctionType.PROPERTIES, |
| 44 | 44 | remark, |
| 45 | 45 | identifier, |
| 46 | 46 | accessMode, |
| 47 | + extensionDesc: _values.extensionDesc, | |
| 47 | 48 | functionJson: { |
| 48 | 49 | dataType: dataType, |
| 49 | 50 | }, |
| ... | ... | @@ -67,7 +68,6 @@ |
| 67 | 68 | ...dataType, |
| 68 | 69 | ...(isArray(specs) ? specs : { ...specs }), |
| 69 | 70 | }; |
| 70 | - | |
| 71 | 71 | setFieldsValue(value); |
| 72 | 72 | }; |
| 73 | 73 | ... | ... |
| ... | ... | @@ -3,7 +3,7 @@ |
| 3 | 3 | import { ComponentType, ColEx } from '/@/components/Form/src/types/index'; |
| 4 | 4 | import { computed } from '@vue/reactivity'; |
| 5 | 5 | import { isFunction } from '/@/utils/is'; |
| 6 | - import { unref } from 'vue'; | |
| 6 | + import { toRaw, unref } from 'vue'; | |
| 7 | 7 | import { watch } from 'vue'; |
| 8 | 8 | import { nextTick } from 'vue'; |
| 9 | 9 | import { ref } from 'vue'; |
| ... | ... | @@ -48,17 +48,13 @@ |
| 48 | 48 | } |
| 49 | 49 | ); |
| 50 | 50 | |
| 51 | - const getProps = computed(() => { | |
| 52 | - return props; | |
| 53 | - }); | |
| 54 | - | |
| 55 | 51 | const batchSetValue = (value: any): ValueItemType[] => { |
| 56 | - const { length } = unref(getProps); | |
| 52 | + const { length } = props; | |
| 57 | 53 | return Array.from({ length }, () => ({ value })); |
| 58 | 54 | }; |
| 59 | 55 | |
| 60 | 56 | const getTotalControlItem = computed(() => { |
| 61 | - const { totalControlProps, component, showTotalControl } = unref(getProps); | |
| 57 | + const { totalControlProps, component, showTotalControl } = props; | |
| 62 | 58 | return { |
| 63 | 59 | ...totalControlProps, |
| 64 | 60 | field: FormFieldsEnum.TOTAL_CONTROL, |
| ... | ... | @@ -72,12 +68,12 @@ |
| 72 | 68 | } as FormSchema; |
| 73 | 69 | }); |
| 74 | 70 | |
| 75 | - const getSchemas = computed(() => { | |
| 76 | - const { itemProps, itemLabel, length, component } = unref(getProps); | |
| 71 | + const getSchemas = () => { | |
| 72 | + const { itemProps, itemLabel, length, component } = props; | |
| 77 | 73 | let label = isFunction(itemLabel) ? itemLabel : (index: number) => `#${index}`; |
| 78 | 74 | let _itemProps = isFunction(itemProps) ? itemProps : () => ({}); |
| 79 | 75 | const schemas = Array.from( |
| 80 | - { length }, | |
| 76 | + { length: props.length }, | |
| 81 | 77 | (_item, index) => |
| 82 | 78 | ({ |
| 83 | 79 | ..._itemProps(index), |
| ... | ... | @@ -93,14 +89,14 @@ |
| 93 | 89 | } as FormSchema) |
| 94 | 90 | ); |
| 95 | 91 | |
| 96 | - length && schemas.unshift(unref(getTotalControlItem)); | |
| 92 | + length && schemas.unshift(toRaw(getTotalControlItem.value)); | |
| 97 | 93 | |
| 98 | 94 | return schemas; |
| 99 | - }); | |
| 95 | + }; | |
| 100 | 96 | |
| 101 | 97 | const [registerForm, { getFieldsValue, setProps, setFieldsValue }] = useForm({ |
| 102 | 98 | showActionButtonGroup: false, |
| 103 | - schemas: unref(getSchemas), | |
| 99 | + schemas: toRaw(unref(getSchemas())), | |
| 104 | 100 | // baseColProps, |
| 105 | 101 | baseColProps: props.itemColProps, |
| 106 | 102 | }); |
| ... | ... | @@ -111,19 +107,16 @@ |
| 111 | 107 | return; |
| 112 | 108 | } |
| 113 | 109 | const allValue = getFieldsValue(); |
| 114 | - const sortKeyList = Array.from({ length: unref(getProps).length }, (_v, key) => key); | |
| 110 | + const sortKeyList = Array.from({ length: props.length }, (_v, key) => key); | |
| 115 | 111 | const res = sortKeyList.map((item) => ({ value: allValue[item] } as ValueItemType)); |
| 116 | 112 | |
| 117 | 113 | emit(EmitEventEnum.UPDATE_VALUE, res); |
| 118 | 114 | }; |
| 119 | 115 | |
| 120 | 116 | const transformValue = (value: ValueItemType[]) => { |
| 121 | - const { length } = unref(getProps); | |
| 117 | + const { length } = props; | |
| 122 | 118 | if (value.length !== length) { |
| 123 | - value = Array.from( | |
| 124 | - { length: unref(getProps).length }, | |
| 125 | - () => ({ value: null } as ValueItemType) | |
| 126 | - ); | |
| 119 | + value = Array.from({ length: props.length }, () => ({ value: null } as ValueItemType)); | |
| 127 | 120 | } |
| 128 | 121 | return value.reduce((prev, next, index) => ({ ...prev, [index]: next.value }), {}); |
| 129 | 122 | }; |
| ... | ... | @@ -153,13 +146,11 @@ |
| 153 | 146 | |
| 154 | 147 | watch( |
| 155 | 148 | () => [props.length, props.component], |
| 156 | - (target) => { | |
| 157 | - if (target !== undefined || target !== null) { | |
| 158 | - setProps({ | |
| 159 | - schemas: unref(getSchemas), | |
| 160 | - }); | |
| 161 | - handleUpdateValue(); | |
| 162 | - } | |
| 149 | + () => { | |
| 150 | + setProps({ | |
| 151 | + schemas: toRaw(unref(getSchemas())), | |
| 152 | + }); | |
| 153 | + handleUpdateValue(); | |
| 163 | 154 | } |
| 164 | 155 | ); |
| 165 | 156 | ... | ... |
| 1 | 1 | <script lang="ts" setup> |
| 2 | 2 | import { InputGroup, InputNumber, Select, Input } from 'ant-design-vue'; |
| 3 | - import { unref } from 'vue'; | |
| 3 | + import { unref, watch } from 'vue'; | |
| 4 | 4 | import { computed } from 'vue'; |
| 5 | 5 | import { ref } from 'vue'; |
| 6 | 6 | |
| ... | ... | @@ -13,10 +13,11 @@ |
| 13 | 13 | |
| 14 | 14 | const DEC_MAX_VALUE = parseInt('0xffff', 16); |
| 15 | 15 | |
| 16 | - withDefaults( | |
| 16 | + const props = withDefaults( | |
| 17 | 17 | defineProps<{ |
| 18 | 18 | value?: number | string; |
| 19 | 19 | inputProps?: Recordable; |
| 20 | + disabled?: boolean; | |
| 20 | 21 | }>(), |
| 21 | 22 | { |
| 22 | 23 | value: 0, |
| ... | ... | @@ -31,7 +32,7 @@ |
| 31 | 32 | |
| 32 | 33 | const type = ref(AddressTypeEnum.DEC); |
| 33 | 34 | |
| 34 | - const inputValue = ref<number | string>(0); | |
| 35 | + const inputValue = ref<number | string>(props.value); | |
| 35 | 36 | |
| 36 | 37 | const getHexValue = computed(() => { |
| 37 | 38 | return parseInt(unref(inputValue) || 0, 16); |
| ... | ... | @@ -61,6 +62,14 @@ |
| 61 | 62 | inputValue.value = syncValue; |
| 62 | 63 | emit('update:value', toDEC(syncValue)); |
| 63 | 64 | }; |
| 65 | + | |
| 66 | + const stop = watch( | |
| 67 | + () => props.value, | |
| 68 | + (value) => { | |
| 69 | + inputValue.value = value; | |
| 70 | + stop(); | |
| 71 | + } | |
| 72 | + ); | |
| 64 | 73 | </script> |
| 65 | 74 | |
| 66 | 75 | <template> |
| ... | ... | @@ -69,6 +78,7 @@ |
| 69 | 78 | v-model:value="type" |
| 70 | 79 | :options="addressTypeOptions" |
| 71 | 80 | @change="handleChange" |
| 81 | + :disabled="disabled" | |
| 72 | 82 | class="bg-gray-200 max-w-20" |
| 73 | 83 | /> |
| 74 | 84 | <InputNumber |
| ... | ... | @@ -76,6 +86,7 @@ |
| 76 | 86 | v-model:value="inputValue" |
| 77 | 87 | :step="1" |
| 78 | 88 | class="flex-1" |
| 89 | + :disabled="disabled" | |
| 79 | 90 | v-bind="inputProps" |
| 80 | 91 | @change="handleEmit" |
| 81 | 92 | /> | ... | ... |
| ... | ... | @@ -178,7 +178,7 @@ export const formSchemas: FormSchema[] = [ |
| 178 | 178 | changeEvent: 'update:value', |
| 179 | 179 | ifShow: ({ model }) => showCoilValue(model[FormFieldsEnum.METHOD]), |
| 180 | 180 | defaultValue: '0', |
| 181 | - rules: [{ required: true, message: '请输入线圈值' }], | |
| 181 | + rules: [{ required: true, message: '请输入线圈值', type: 'number' }], | |
| 182 | 182 | componentProps: { |
| 183 | 183 | placeholder: '请输入线圈值', |
| 184 | 184 | }, |
| ... | ... | @@ -191,7 +191,7 @@ export const formSchemas: FormSchema[] = [ |
| 191 | 191 | changeEvent: 'update:value', |
| 192 | 192 | ifShow: ({ model }) => showRegisterValue(model[FormFieldsEnum.METHOD]), |
| 193 | 193 | defaultValue: '0', |
| 194 | - rules: [{ required: true, message: '请输入寄存器值' }], | |
| 194 | + rules: [{ required: true, message: '请输入寄存器值', type: 'number' }], | |
| 195 | 195 | componentProps: { |
| 196 | 196 | placeholder: '请输入寄存器值', |
| 197 | 197 | }, | ... | ... |