Commit fc91d5604ca79dd6ea9ea5697a9f8e03fce07102

Authored by ww
1 parent 4628e016

fix: DEFECT-1414修复任务中心寄存器验证未通过

@@ -3,7 +3,7 @@ @@ -3,7 +3,7 @@
3 import { ComponentType, ColEx } from '/@/components/Form/src/types/index'; 3 import { ComponentType, ColEx } from '/@/components/Form/src/types/index';
4 import { computed } from '@vue/reactivity'; 4 import { computed } from '@vue/reactivity';
5 import { isFunction } from '/@/utils/is'; 5 import { isFunction } from '/@/utils/is';
6 - import { unref } from 'vue'; 6 + import { toRaw, unref } from 'vue';
7 import { watch } from 'vue'; 7 import { watch } from 'vue';
8 import { nextTick } from 'vue'; 8 import { nextTick } from 'vue';
9 import { ref } from 'vue'; 9 import { ref } from 'vue';
@@ -48,17 +48,13 @@ @@ -48,17 +48,13 @@
48 } 48 }
49 ); 49 );
50 50
51 - const getProps = computed(() => {  
52 - return props;  
53 - });  
54 -  
55 const batchSetValue = (value: any): ValueItemType[] => { 51 const batchSetValue = (value: any): ValueItemType[] => {
56 - const { length } = unref(getProps); 52 + const { length } = props;
57 return Array.from({ length }, () => ({ value })); 53 return Array.from({ length }, () => ({ value }));
58 }; 54 };
59 55
60 const getTotalControlItem = computed(() => { 56 const getTotalControlItem = computed(() => {
61 - const { totalControlProps, component, showTotalControl } = unref(getProps); 57 + const { totalControlProps, component, showTotalControl } = props;
62 return { 58 return {
63 ...totalControlProps, 59 ...totalControlProps,
64 field: FormFieldsEnum.TOTAL_CONTROL, 60 field: FormFieldsEnum.TOTAL_CONTROL,
@@ -72,12 +68,12 @@ @@ -72,12 +68,12 @@
72 } as FormSchema; 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 let label = isFunction(itemLabel) ? itemLabel : (index: number) => `#${index}`; 73 let label = isFunction(itemLabel) ? itemLabel : (index: number) => `#${index}`;
78 let _itemProps = isFunction(itemProps) ? itemProps : () => ({}); 74 let _itemProps = isFunction(itemProps) ? itemProps : () => ({});
79 const schemas = Array.from( 75 const schemas = Array.from(
80 - { length }, 76 + { length: props.length },
81 (_item, index) => 77 (_item, index) =>
82 ({ 78 ({
83 ..._itemProps(index), 79 ..._itemProps(index),
@@ -93,14 +89,14 @@ @@ -93,14 +89,14 @@
93 } as FormSchema) 89 } as FormSchema)
94 ); 90 );
95 91
96 - length && schemas.unshift(unref(getTotalControlItem)); 92 + length && schemas.unshift(toRaw(getTotalControlItem.value));
97 93
98 return schemas; 94 return schemas;
99 - }); 95 + };
100 96
101 const [registerForm, { getFieldsValue, setProps, setFieldsValue }] = useForm({ 97 const [registerForm, { getFieldsValue, setProps, setFieldsValue }] = useForm({
102 showActionButtonGroup: false, 98 showActionButtonGroup: false,
103 - schemas: unref(getSchemas), 99 + schemas: toRaw(unref(getSchemas())),
104 // baseColProps, 100 // baseColProps,
105 baseColProps: props.itemColProps, 101 baseColProps: props.itemColProps,
106 }); 102 });
@@ -111,19 +107,16 @@ @@ -111,19 +107,16 @@
111 return; 107 return;
112 } 108 }
113 const allValue = getFieldsValue(); 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 const res = sortKeyList.map((item) => ({ value: allValue[item] } as ValueItemType)); 111 const res = sortKeyList.map((item) => ({ value: allValue[item] } as ValueItemType));
116 112
117 emit(EmitEventEnum.UPDATE_VALUE, res); 113 emit(EmitEventEnum.UPDATE_VALUE, res);
118 }; 114 };
119 115
120 const transformValue = (value: ValueItemType[]) => { 116 const transformValue = (value: ValueItemType[]) => {
121 - const { length } = unref(getProps); 117 + const { length } = props;
122 if (value.length !== length) { 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 return value.reduce((prev, next, index) => ({ ...prev, [index]: next.value }), {}); 121 return value.reduce((prev, next, index) => ({ ...prev, [index]: next.value }), {});
129 }; 122 };
@@ -153,13 +146,11 @@ @@ -153,13 +146,11 @@
153 146
154 watch( 147 watch(
155 () => [props.length, props.component], 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
@@ -178,7 +178,7 @@ export const formSchemas: FormSchema[] = [ @@ -178,7 +178,7 @@ export const formSchemas: FormSchema[] = [
178 changeEvent: 'update:value', 178 changeEvent: 'update:value',
179 ifShow: ({ model }) => showCoilValue(model[FormFieldsEnum.METHOD]), 179 ifShow: ({ model }) => showCoilValue(model[FormFieldsEnum.METHOD]),
180 defaultValue: '0', 180 defaultValue: '0',
181 - rules: [{ required: true, message: '请输入线圈值' }], 181 + rules: [{ required: true, message: '请输入线圈值', type: 'number' }],
182 componentProps: { 182 componentProps: {
183 placeholder: '请输入线圈值', 183 placeholder: '请输入线圈值',
184 }, 184 },
@@ -191,7 +191,7 @@ export const formSchemas: FormSchema[] = [ @@ -191,7 +191,7 @@ export const formSchemas: FormSchema[] = [
191 changeEvent: 'update:value', 191 changeEvent: 'update:value',
192 ifShow: ({ model }) => showRegisterValue(model[FormFieldsEnum.METHOD]), 192 ifShow: ({ model }) => showRegisterValue(model[FormFieldsEnum.METHOD]),
193 defaultValue: '0', 193 defaultValue: '0',
194 - rules: [{ required: true, message: '请输入寄存器值' }], 194 + rules: [{ required: true, message: '请输入寄存器值', type: 'number' }],
195 componentProps: { 195 componentProps: {
196 placeholder: '请输入寄存器值', 196 placeholder: '请输入寄存器值',
197 }, 197 },