@ecoding/components.antd 0.5.0 → 0.5.1

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.
@@ -22,12 +22,13 @@ interface IProps {
22
22
  data?: any;
23
23
  gif?: boolean;
24
24
  disabled?: boolean;
25
+ objectInValue?: boolean;
25
26
  type?: string;
26
27
  name?: string;
27
28
  action: string | (() => string);
28
29
  buttonText?: string;
29
30
  maxCount?: number;
30
- onChange?: (infos: string[]) => void;
31
+ onChange?: (infos: any[] | undefined) => void;
31
32
  }
32
33
  /**
33
34
  * @returns 返回地址的string
@@ -35,33 +35,53 @@ const DraggableUploadListItem = ({ originNode, file, disabled }) => {
35
35
  */
36
36
  const MultipleImgUpload = (props) => {
37
37
  var _a, _b, _c, _d;
38
- const { i18n, name, buttonText, maxCount, disabled, value, onChange } = props;
38
+ const { i18n, name, buttonText, maxCount, disabled, value, onChange, objectInValue } = props;
39
39
  const [previewOpen, setPreviewOpen] = useState(false);
40
40
  const [previewImage, setPreviewImage] = useState('');
41
- const [imgList, setImgList] = useState((value === null || value === void 0 ? void 0 : value.map((url, index) => {
42
- if (typeof url === "string") {
43
- return {
44
- uid: String(index),
45
- status: 'done',
46
- url,
47
- name: url.substring(url.lastIndexOf('/') + 1, url.lastIndexOf('.'))
48
- };
49
- }
50
- else {
51
- return url;
41
+ const [imgList, setImgList] = useState(() => {
42
+ if (value && value.length > 0) {
43
+ const temp = [];
44
+ value.forEach((item, index) => {
45
+ if (typeof item === "string" && item) {
46
+ temp.push({
47
+ uid: String(index),
48
+ status: 'done',
49
+ url: item,
50
+ name: item.substring(item.lastIndexOf('/') + 1, item.lastIndexOf('.'))
51
+ });
52
+ }
53
+ else {
54
+ if (item.url) {
55
+ temp.push(item);
56
+ }
57
+ }
58
+ });
59
+ return temp;
52
60
  }
53
- })) || []);
61
+ return [];
62
+ });
54
63
  const updateItems = (newItems) => {
55
64
  setImgList(newItems);
56
65
  let isEmpty = true;
57
- const urls = newItems.map((item) => item.url);
58
- urls.forEach((item) => {
66
+ const temp = [];
67
+ newItems && newItems.forEach((item) => {
68
+ if (item.url) {
69
+ temp.push(item);
70
+ }
71
+ });
72
+ temp.forEach((item) => {
59
73
  if (item) {
60
74
  isEmpty = false;
61
75
  return;
62
76
  }
63
77
  });
64
- onChange && (onChange === null || onChange === void 0 ? void 0 : onChange(!isEmpty ? urls : undefined));
78
+ if (objectInValue) {
79
+ onChange && onChange(!isEmpty ? temp : undefined);
80
+ }
81
+ else {
82
+ const urls = temp.map((item) => item.url);
83
+ onChange && onChange(!isEmpty ? urls : undefined);
84
+ }
65
85
  };
66
86
  const handleChange = ({ fileList }) => {
67
87
  fileList && fileList.forEach((file) => {
@@ -242,6 +262,7 @@ const MultipleImgUpload = (props) => {
242
262
  MultipleImgUpload.defaultProps = {
243
263
  maxCount: 6,
244
264
  showMessage: true,
265
+ objectInValue: false,
245
266
  action: "/api/upload/img",
246
267
  name: "file",
247
268
  gif: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecoding/components.antd",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "author": "cxc",
5
5
  "homepage": "",
6
6
  "license": "MIT",
@@ -47,5 +47,5 @@
47
47
  "antd": "^6.0.0",
48
48
  "axios": "^1.1.2"
49
49
  },
50
- "gitHead": "5d9c405730775cb0373521dd2532b1918719eaa3"
50
+ "gitHead": "84c695854492c49bcdf11c73cb5908a7b87f16b5"
51
51
  }