@mi-avalon/libs 1.0.4 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -39,37 +39,32 @@ const MForm = React.memo((props) => {
39
39
  const { show = true } = item;
40
40
  if (!show)
41
41
  return null;
42
- const rules = useMemo(() => {
43
- const rulesArray = [...(item.rules || [])];
44
- if (item.required) {
45
- rulesArray.push({ required: true, message: item.required });
46
- }
47
- return rulesArray;
48
- }, [item.rules, item.required]);
42
+ // 直接计算rules,不在函数内使用hook
43
+ const rules = [...(item.rules || [])];
44
+ if (item.required) {
45
+ rules.push({ required: true, message: item.required });
46
+ }
49
47
  // 为Upload类型的表单项默认添加valuePropName="fileList"和值转换逻辑
50
- const formItemProps = useMemo(() => {
51
- const props = { ...item.formItemProps };
52
- if (item.type === 'upload') {
53
- // 如果用户没有明确设置valuePropName,则默认使用fileList
54
- if (!props.valuePropName) {
55
- props.valuePropName = 'fileList';
56
- }
57
- // 添加getValueProps确保传递给Upload的fileList始终是数组
58
- if (!props.getValueProps) {
59
- props.getValueProps = (value) => {
60
- // 确保fileList始终是数组
61
- return {
62
- fileList: Array.isArray(value) ? value : [],
63
- };
48
+ let formItemProps = { ...item.formItemProps };
49
+ if (item.type === 'upload') {
50
+ // 如果用户没有明确设置valuePropName,则默认使用fileList
51
+ if (!formItemProps.valuePropName) {
52
+ formItemProps.valuePropName = 'fileList';
53
+ }
54
+ // 添加getValueProps确保传递给Upload的fileList始终是数组
55
+ if (!formItemProps.getValueProps) {
56
+ formItemProps.getValueProps = (value) => {
57
+ // 确保fileList始终是数组
58
+ return {
59
+ fileList: Array.isArray(value) ? value : [],
64
60
  };
65
- }
61
+ };
66
62
  }
67
- return props;
68
- }, [item.formItemProps, item.type]);
69
- const mergedFormItemLayout = useMemo(() => ({
63
+ }
64
+ const mergedFormItemLayout = {
70
65
  ...formItemLayout,
71
66
  ...item.itemLayout,
72
- }), [formItemLayout, item.itemLayout]);
67
+ };
73
68
  return (_jsx(Col, { span: item.span || 24 / column, children: _jsxs(Row, { className: 'item-row', children: [_jsx("div", { className: classname('item-wrapper'), children: _jsx(Form.Item, { label: item.label, name: item.id, rules: rules, initialValue: item.initialValue, ...mergedFormItemLayout, ...formItemProps, children: renderItem(item, form) }) }), item.suffix] }) }, `col-${item.id}`));
74
69
  }, [column, form, formItemLayout, renderItem]);
75
70
  // 优化:缓存表单容器类名