@mi-avalon/libs 1.0.2 → 1.0.3

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.
@@ -56,7 +56,15 @@ export class MFormItemConst {
56
56
  return _jsx(Checkbox.Group, { disabled: item.disabled, ...item.props });
57
57
  };
58
58
  static upload = (item) => {
59
- return (_jsx(Upload, { ...item.props, children: item.children || (_jsxs(Button, { children: [_jsx(UploadOutlined, {}), " \u70B9\u51FB\u4E0A\u4F20"] })) }));
59
+ // 确保fileList是数组类型,防止forEach错误
60
+ const uploadProps = {
61
+ ...item.props,
62
+ };
63
+ // 如果fileList存在但不是数组,转换为数组
64
+ if (uploadProps.fileList && !Array.isArray(uploadProps.fileList)) {
65
+ uploadProps.fileList = [uploadProps.fileList];
66
+ }
67
+ return (_jsx(Upload, { ...uploadProps, children: item.children || (_jsxs(Button, { children: [_jsx(UploadOutlined, {}), " \u70B9\u51FB\u4E0A\u4F20"] })) }));
60
68
  };
61
69
  static mentions = (item) => {
62
70
  return (_jsx(Mentions, { ...item.props, placeholder: item.placeholder || MFormItemConst.getDefaultPlaceholder(item) }));
@@ -41,7 +41,26 @@ function MForm(props) {
41
41
  ...itemLayout,
42
42
  ...item.itemLayout,
43
43
  };
44
- 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, ...formItemLayout, ...item.formItemProps, children: renderItem(item, form) }) }), item.suffix] }) }, `col-${item.id}`));
44
+ // 为Upload类型的表单项默认添加valuePropName="fileList"和值转换逻辑
45
+ const formItemProps = {
46
+ ...item.formItemProps,
47
+ };
48
+ if (item.type === 'upload') {
49
+ // 如果用户没有明确设置valuePropName,则默认使用fileList
50
+ if (!formItemProps.valuePropName) {
51
+ formItemProps.valuePropName = 'fileList';
52
+ }
53
+ // 添加getValueProps确保传递给Upload的fileList始终是数组
54
+ if (!formItemProps.getValueProps) {
55
+ formItemProps.getValueProps = (value) => {
56
+ // 确保fileList始终是数组
57
+ return {
58
+ fileList: Array.isArray(value) ? value : [],
59
+ };
60
+ };
61
+ }
62
+ }
63
+ 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, ...formItemLayout, ...formItemProps, children: renderItem(item, form) }) }), item.suffix] }) }, `col-${item.id}`));
45
64
  };
46
65
  return (_jsx(CompThemeProvider, { children: _jsx(Form, { form: form, ...formProps, className: `${classname()} ${formProps?.className}`, children: _jsx(Row, { gutter: MFormItemConst.defaultRowGutter, ...formRowProps, className: `${classname('grid')} ${formRowProps?.className}`, children: formItems.map(e => renderFormItem(e)) }) }) }));
47
66
  }