@ecoding/components.antd 0.5.2 → 0.5.5

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.
@@ -8,7 +8,7 @@ interface IFace {
8
8
  cache?: boolean;
9
9
  format?: {
10
10
  [props: string]: any;
11
- isLeaf: boolean;
11
+ isLeaf: boolean | ((item: any) => boolean);
12
12
  };
13
13
  params?: any;
14
14
  fromKey?: string[] | string;
@@ -18,6 +18,7 @@ interface IProps {
18
18
  value?: IRes[];
19
19
  headers?: any;
20
20
  uploadRef?: any;
21
+ domain?: string;
21
22
  onChange?: (infos: IRes[]) => void;
22
23
  onDone?: (file: UploadFile, res: any) => void;
23
24
  onRemove?: (file: UploadFile) => void;
@@ -13,7 +13,7 @@ import { UploadOutlined, LinkOutlined, DeleteOutlined, EllipsisOutlined } from '
13
13
  import { buildURL } from '@ecoding/helper.url';
14
14
  import Toast from "../../core/toast";
15
15
  import Loading from "../../core/loading";
16
- const InfosRender = ({ infos, setInfos, onChange }) => {
16
+ const InfosRender = ({ infos, setInfos, onChange, domain }) => {
17
17
  const remove = (i) => {
18
18
  const temp = infos.concat([]);
19
19
  temp.splice(i, 1);
@@ -27,7 +27,7 @@ const InfosRender = ({ infos, setInfos, onChange }) => {
27
27
  justifyContent: "space-between",
28
28
  maxWidth: 250
29
29
  } },
30
- React.createElement(Typography.Link, { download: info.name, ellipsis: true, title: info.name, href: info.url, target: "_blank" },
30
+ React.createElement(Typography.Link, { download: info.name, ellipsis: true, title: info.name, href: domain ? `${domain}${info.url}` : info.url, target: "_blank" },
31
31
  React.createElement(LinkOutlined, null),
32
32
  " ",
33
33
  info.name),
@@ -125,7 +125,7 @@ const MultipleUpload = (props) => {
125
125
  props.onRemove && props.onRemove(e);
126
126
  }, maxCount: props.maxCount },
127
127
  React.createElement(Button, { disabled: props.disabled, icon: props.icon ? React.createElement(UploadOutlined, null) : null }, props.buttonText)),
128
- React.createElement(Popover, { destroyOnHidden: true, open: open, placement: "right", trigger: "hover", title: "Uploaded", content: React.createElement(InfosRender, { onChange: props.onChange, infos: infos, setInfos: setInfos }) },
128
+ React.createElement(Popover, { destroyOnHidden: true, open: open, placement: "right", trigger: "hover", title: "Uploaded", content: React.createElement(InfosRender, { onChange: props.onChange, infos: infos, setInfos: setInfos, domain: props.domain }) },
129
129
  React.createElement(Button, { icon: React.createElement(EllipsisOutlined, null) }))));
130
130
  };
131
131
  MultipleUpload.defaultProps = {
@@ -22,6 +22,7 @@ interface IProps {
22
22
  gif?: boolean;
23
23
  disabled?: boolean;
24
24
  objectInValue?: boolean;
25
+ domain?: string;
25
26
  type?: string;
26
27
  name?: string;
27
28
  action: string | (() => string);
@@ -7,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- import React, { useState, useCallback, useMemo } from 'react';
10
+ import React, { useState, useCallback, useMemo, useEffect } from 'react';
11
11
  import { Upload, Image as Img, Alert, Flex, message, Space } from 'antd';
12
12
  import { PlusOutlined } from '@ant-design/icons';
13
13
  import { buildURL } from "@ecoding/helper.url";
@@ -35,29 +35,10 @@ 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, objectInValue } = props;
38
+ const { i18n, name, buttonText, maxCount, disabled, value, onChange, objectInValue, domain } = props;
39
39
  const [previewOpen, setPreviewOpen] = useState(false);
40
40
  const [previewImage, setPreviewImage] = useState('');
41
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;
60
- }
61
42
  return [];
62
43
  });
63
44
  const updateItems = (newItems) => {
@@ -76,10 +57,11 @@ const MultipleImgUpload = (props) => {
76
57
  }
77
58
  });
78
59
  if (objectInValue) {
79
- onChange && onChange(!isEmpty ? temp : undefined);
60
+ const temp2 = temp && temp.map((item) => (Object.assign(Object.assign({}, item), { url: domain ? item.url.replace(domain, '') : item.url })));
61
+ onChange && onChange(!isEmpty ? temp2 : undefined);
80
62
  }
81
63
  else {
82
- const urls = temp.map((item) => item.url);
64
+ const urls = temp.map((item) => domain ? item.url.replace(domain, '') : item.url);
83
65
  onChange && onChange(!isEmpty ? urls : undefined);
84
66
  }
85
67
  };
@@ -221,6 +203,32 @@ const MultipleImgUpload = (props) => {
221
203
  resolve(file);
222
204
  }));
223
205
  }, []);
206
+ useEffect(() => {
207
+ if (value && value.length > 0) {
208
+ const temp = [];
209
+ value.forEach((item, index) => {
210
+ if (typeof item === "string" && item) {
211
+ // 防止重复拼接domain
212
+ item = domain ? item.replace(domain, "") : item;
213
+ temp.push({
214
+ uid: String(index),
215
+ status: 'done',
216
+ url: domain ? `${domain}${item}` : item,
217
+ name: item.substring(item.lastIndexOf('/') + 1, item.lastIndexOf('.'))
218
+ });
219
+ }
220
+ else {
221
+ if (item.url) {
222
+ // 防止重复拼接domain
223
+ item.url = domain ? item.url.replace(domain, "") : item.url;
224
+ item.url = domain ? `${domain}${item.url}` : item.url;
225
+ temp.push(item);
226
+ }
227
+ }
228
+ });
229
+ setImgList(temp);
230
+ }
231
+ }, [value]);
224
232
  return (React.createElement(React.Fragment, null,
225
233
  props.showMessage && (React.createElement(Alert, { className: 'mb20', message: props.message ? props.message : (React.createElement(Flex, { gap: 10, wrap: true },
226
234
  React.createElement("div", null,
@@ -263,7 +271,7 @@ const MultipleImgUpload = (props) => {
263
271
  visible: previewOpen,
264
272
  onVisibleChange: (visible) => setPreviewOpen(visible),
265
273
  afterOpenChange: (visible) => !visible && setPreviewImage('')
266
- }, src: previewImage }))))));
274
+ }, src: domain ? `${domain}${previewImage}` : previewImage }))))));
267
275
  };
268
276
  MultipleImgUpload.defaultProps = {
269
277
  maxCount: 6,
@@ -28,6 +28,7 @@ interface IProps {
28
28
  disabled?: boolean;
29
29
  objectInValue?: boolean;
30
30
  isTip?: boolean;
31
+ domain?: string;
31
32
  }
32
33
  declare const MultiPileImgUpload: React.FC<IProps>;
33
34
  export default MultiPileImgUpload;
@@ -20,6 +20,7 @@ interface IProps {
20
20
  icon?: boolean;
21
21
  openFileDialogOnClick?: boolean;
22
22
  style?: React.CSSProperties;
23
+ domain?: string;
23
24
  }
24
25
  declare const SingleFileUpload: React.FC<IProps>;
25
26
  export default SingleFileUpload;
@@ -80,11 +80,12 @@ const SingleFileUpload = (props) => {
80
80
  }, []);
81
81
  useEffect(() => {
82
82
  if (typeof props.value === "string") {
83
- setFileUrl(props.value);
83
+ const temp = props.domain ? props.value.replace(props.domain, "") : props.value;
84
+ setFileUrl(temp);
84
85
  }
85
86
  }, [props.value]);
86
87
  return (React.createElement(Space.Compact, { block: true },
87
- React.createElement(Input, { addonBefore: fileUrl ? (React.createElement("a", { style: { color: "#666" }, href: fileUrl, target: "_blank" }, "View")) : null, value: fileUrl, onChange: (e) => {
88
+ React.createElement(Input, { addonBefore: fileUrl ? (React.createElement("a", { style: { color: "#666" }, href: props.domain ? `${props.domain}${fileUrl}` : fileUrl, target: "_blank" }, "View")) : null, value: fileUrl ? props.domain ? `${props.domain}${fileUrl}` : fileUrl : "", onChange: (e) => {
88
89
  const v = e.target.value.trim();
89
90
  props.onChange && props.onChange(v);
90
91
  } }),
@@ -30,6 +30,7 @@ interface IProps {
30
30
  objectInValue?: boolean;
31
31
  isTip?: boolean;
32
32
  type?: string;
33
+ domain?: string;
33
34
  }
34
35
  declare const ImgUpload: React.FC<IProps>;
35
36
  export default ImgUpload;
@@ -15,16 +15,7 @@ import Toast from "../../core/toast";
15
15
  const ImgUpload = (props) => {
16
16
  var _a, _b, _c, _d;
17
17
  const [loading, setLoading] = useState(false);
18
- const [imageUrl, setImageUrl] = useState(() => {
19
- const item = props.value;
20
- if (typeof item === "string" && item) {
21
- return item;
22
- }
23
- if (item.url) {
24
- return item.url;
25
- }
26
- return undefined;
27
- });
18
+ const [imageUrl, setImageUrl] = useState(undefined);
28
19
  const action = useMemo(() => {
29
20
  if (typeof props.action === "string") {
30
21
  return buildURL(props.action, props.actionParams);
@@ -65,7 +56,11 @@ const ImgUpload = (props) => {
65
56
  response.code === 0 ||
66
57
  response.success ||
67
58
  response.successed) {
68
- const url = data && data.url;
59
+ let url = data && data.url;
60
+ if (props.domain) {
61
+ console.log(url, props.domain);
62
+ url = url.replace(props.domain, "");
63
+ }
69
64
  setImageUrl(url);
70
65
  if (props.objectInValue) {
71
66
  info.file.url = url;
@@ -171,11 +166,15 @@ const ImgUpload = (props) => {
171
166
  loading ? React.createElement(LoadingOutlined, null) : React.createElement(PlusOutlined, null),
172
167
  React.createElement("div", { style: { marginTop: 8 } }, props.buttonText))), [loading]);
173
168
  useEffect(() => {
174
- const item = props.value;
169
+ let item = props.value;
175
170
  if (typeof item === "string" && item) {
171
+ // 防止重复拼接domain
172
+ item = props.domain ? item.replace(props.domain, "") : item;
176
173
  setImageUrl(item);
177
174
  }
178
175
  if (item.url) {
176
+ // 防止重复拼接domain
177
+ item.url = props.domain ? item.url.replace(props.domain, "") : item.url;
179
178
  setImageUrl(item.url);
180
179
  }
181
180
  }, [props.value]);
@@ -195,7 +194,7 @@ const ImgUpload = (props) => {
195
194
  clear();
196
195
  } },
197
196
  React.createElement(DeleteOutlined, { style: { fontSize: 14 } }))),
198
- React.createElement(Img, { style: { width: "102px", height: "102px", objectFit: "contain", cursor: "pointer" }, src: imageUrl }))) : (React.createElement(Upload, { withCredentials: true, beforeUpload: beforeUpload, name: props.name, data: props.data, headers: props.headers, disabled: props.disabled, listType: "picture-card", showUploadList: false, action: action, onChange: handleChange }, uploadButton)),
197
+ React.createElement(Img, { style: { width: "102px", height: "102px", objectFit: "contain", cursor: "pointer" }, src: props.domain ? `${props.domain}${imageUrl}` : imageUrl }))) : (React.createElement(Upload, { withCredentials: true, beforeUpload: beforeUpload, name: props.name, data: props.data, headers: props.headers, disabled: props.disabled, listType: "picture-card", showUploadList: false, action: action, onChange: handleChange }, uploadButton)),
199
198
  props.isTip ? (React.createElement("div", { style: { fontSize: '13px', marginLeft: '18px', lineHeight: '22px' } },
200
199
  React.createElement("p", null,
201
200
  props.i18n ? props.i18n.$t("global.size", "大小") : "大小",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ecoding/components.antd",
3
- "version": "0.5.2",
3
+ "version": "0.5.5",
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": "531ea382cedf74735ce957b15e8860533a3af29e"
50
+ "gitHead": "e9f8a48bb5cc68182f37b2e14b0f4e30ea6e7d6a"
51
51
  }