@ecoding/components.antd 0.5.1 → 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.
- package/lib/core/async-cascader/index.d.ts +1 -1
- package/lib/core/multiple-file-upload/index.d.ts +1 -0
- package/lib/core/multiple-file-upload/index.js +3 -3
- package/lib/core/multiple-img-upload/index.d.ts +2 -2
- package/lib/core/multiple-img-upload/index.js +39 -25
- package/lib/core/multiple-single-img-upload/index.d.ts +2 -0
- package/lib/core/single-file-upload/index.d.ts +1 -0
- package/lib/core/single-file-upload/index.js +3 -2
- package/lib/core/single-img-upload/index.d.ts +3 -1
- package/lib/core/single-img-upload/index.js +32 -8
- package/package.json +2 -2
|
@@ -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 = {
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type { UploadFile } from 'antd';
|
|
3
2
|
interface IOpts {
|
|
4
3
|
size?: number;
|
|
5
4
|
w?: number;
|
|
@@ -17,12 +16,13 @@ interface IProps {
|
|
|
17
16
|
actionParams?: any;
|
|
18
17
|
i18n?: any;
|
|
19
18
|
opts?: IOpts;
|
|
20
|
-
value?:
|
|
19
|
+
value?: any[];
|
|
21
20
|
headers?: any;
|
|
22
21
|
data?: any;
|
|
23
22
|
gif?: boolean;
|
|
24
23
|
disabled?: boolean;
|
|
25
24
|
objectInValue?: boolean;
|
|
25
|
+
domain?: string;
|
|
26
26
|
type?: string;
|
|
27
27
|
name?: string;
|
|
28
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
|
-
|
|
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
|
};
|
|
@@ -93,6 +75,10 @@ const MultipleImgUpload = (props) => {
|
|
|
93
75
|
response.successed) {
|
|
94
76
|
const data = response.data || response.model;
|
|
95
77
|
file.url = data.url;
|
|
78
|
+
delete file.response;
|
|
79
|
+
delete file.xhr;
|
|
80
|
+
delete file.lastModifiedDate;
|
|
81
|
+
delete file.originFileObj;
|
|
96
82
|
}
|
|
97
83
|
}
|
|
98
84
|
else if (file.status === "error") {
|
|
@@ -179,6 +165,8 @@ const MultipleImgUpload = (props) => {
|
|
|
179
165
|
}
|
|
180
166
|
const base64 = yield getBase64(file);
|
|
181
167
|
const wh = yield getImgwh(base64);
|
|
168
|
+
file.width = wh.w;
|
|
169
|
+
file.height = wh.h;
|
|
182
170
|
if (props.opts.w && props.opts.w !== wh.w) {
|
|
183
171
|
message.error(`${props.i18n ? props.i18n.$t('global.img.width') : '图片宽度不符合'} ${props.opts.w}px`);
|
|
184
172
|
return Upload.LIST_IGNORE;
|
|
@@ -212,9 +200,35 @@ const MultipleImgUpload = (props) => {
|
|
|
212
200
|
return Upload.LIST_IGNORE;
|
|
213
201
|
}
|
|
214
202
|
}
|
|
215
|
-
resolve();
|
|
203
|
+
resolve(file);
|
|
216
204
|
}));
|
|
217
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]);
|
|
218
232
|
return (React.createElement(React.Fragment, null,
|
|
219
233
|
props.showMessage && (React.createElement(Alert, { className: 'mb20', message: props.message ? props.message : (React.createElement(Flex, { gap: 10, wrap: true },
|
|
220
234
|
React.createElement("div", null,
|
|
@@ -257,7 +271,7 @@ const MultipleImgUpload = (props) => {
|
|
|
257
271
|
visible: previewOpen,
|
|
258
272
|
onVisibleChange: (visible) => setPreviewOpen(visible),
|
|
259
273
|
afterOpenChange: (visible) => !visible && setPreviewImage('')
|
|
260
|
-
}, src: previewImage }))))));
|
|
274
|
+
}, src: domain ? `${domain}${previewImage}` : previewImage }))))));
|
|
261
275
|
};
|
|
262
276
|
MultipleImgUpload.defaultProps = {
|
|
263
277
|
maxCount: 6,
|
|
@@ -80,11 +80,12 @@ const SingleFileUpload = (props) => {
|
|
|
80
80
|
}, []);
|
|
81
81
|
useEffect(() => {
|
|
82
82
|
if (typeof props.value === "string") {
|
|
83
|
-
|
|
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
|
} }),
|
|
@@ -20,15 +20,17 @@ interface IProps {
|
|
|
20
20
|
name?: string;
|
|
21
21
|
i18n?: any;
|
|
22
22
|
opts?: IOpts;
|
|
23
|
-
value?:
|
|
23
|
+
value?: any;
|
|
24
24
|
buttonText?: string;
|
|
25
25
|
headers?: any;
|
|
26
26
|
data?: any;
|
|
27
27
|
onChange?: any;
|
|
28
28
|
gif?: boolean;
|
|
29
29
|
disabled?: boolean;
|
|
30
|
+
objectInValue?: boolean;
|
|
30
31
|
isTip?: boolean;
|
|
31
32
|
type?: string;
|
|
33
|
+
domain?: string;
|
|
32
34
|
}
|
|
33
35
|
declare const ImgUpload: React.FC<IProps>;
|
|
34
36
|
export default ImgUpload;
|
|
@@ -15,7 +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(
|
|
18
|
+
const [imageUrl, setImageUrl] = useState(undefined);
|
|
19
19
|
const action = useMemo(() => {
|
|
20
20
|
if (typeof props.action === "string") {
|
|
21
21
|
return buildURL(props.action, props.actionParams);
|
|
@@ -56,10 +56,24 @@ const ImgUpload = (props) => {
|
|
|
56
56
|
response.code === 0 ||
|
|
57
57
|
response.success ||
|
|
58
58
|
response.successed) {
|
|
59
|
-
|
|
59
|
+
let url = data && data.url;
|
|
60
|
+
if (props.domain) {
|
|
61
|
+
console.log(url, props.domain);
|
|
62
|
+
url = url.replace(props.domain, "");
|
|
63
|
+
}
|
|
60
64
|
setImageUrl(url);
|
|
61
|
-
|
|
62
|
-
|
|
65
|
+
if (props.objectInValue) {
|
|
66
|
+
info.file.url = url;
|
|
67
|
+
delete info.file.response;
|
|
68
|
+
delete info.file.xhr;
|
|
69
|
+
delete info.file.lastModifiedDate;
|
|
70
|
+
delete info.file.originFileObj;
|
|
71
|
+
props.onChange && props.onChange(info.file);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
// Form.item 值注入关键
|
|
75
|
+
props.onChange && props.onChange(url);
|
|
76
|
+
}
|
|
63
77
|
}
|
|
64
78
|
else {
|
|
65
79
|
Toast.error({
|
|
@@ -103,6 +117,8 @@ const ImgUpload = (props) => {
|
|
|
103
117
|
}
|
|
104
118
|
const base64 = yield getBase64(file);
|
|
105
119
|
const wh = yield getImgwh(base64);
|
|
120
|
+
file.width = wh.w;
|
|
121
|
+
file.height = wh.h;
|
|
106
122
|
if (props.opts.w && props.opts.w !== wh.w) {
|
|
107
123
|
message.error(`${props.i18n ? props.i18n.$t('global.img.width') : '图片宽度不符合'} ${props.opts.w}px`);
|
|
108
124
|
reject();
|
|
@@ -143,15 +159,23 @@ const ImgUpload = (props) => {
|
|
|
143
159
|
return;
|
|
144
160
|
}
|
|
145
161
|
}
|
|
146
|
-
resolve();
|
|
162
|
+
resolve(file);
|
|
147
163
|
}));
|
|
148
164
|
}, []);
|
|
149
165
|
const uploadButton = useMemo(() => (React.createElement("div", null,
|
|
150
166
|
loading ? React.createElement(LoadingOutlined, null) : React.createElement(PlusOutlined, null),
|
|
151
167
|
React.createElement("div", { style: { marginTop: 8 } }, props.buttonText))), [loading]);
|
|
152
168
|
useEffect(() => {
|
|
153
|
-
|
|
154
|
-
|
|
169
|
+
let item = props.value;
|
|
170
|
+
if (typeof item === "string" && item) {
|
|
171
|
+
// 防止重复拼接domain
|
|
172
|
+
item = props.domain ? item.replace(props.domain, "") : item;
|
|
173
|
+
setImageUrl(item);
|
|
174
|
+
}
|
|
175
|
+
if (item.url) {
|
|
176
|
+
// 防止重复拼接domain
|
|
177
|
+
item.url = props.domain ? item.url.replace(props.domain, "") : item.url;
|
|
178
|
+
setImageUrl(item.url);
|
|
155
179
|
}
|
|
156
180
|
}, [props.value]);
|
|
157
181
|
return (React.createElement(Flex, { style: { fontSize: 0 } },
|
|
@@ -170,7 +194,7 @@ const ImgUpload = (props) => {
|
|
|
170
194
|
clear();
|
|
171
195
|
} },
|
|
172
196
|
React.createElement(DeleteOutlined, { style: { fontSize: 14 } }))),
|
|
173
|
-
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)),
|
|
174
198
|
props.isTip ? (React.createElement("div", { style: { fontSize: '13px', marginLeft: '18px', lineHeight: '22px' } },
|
|
175
199
|
React.createElement("p", null,
|
|
176
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.
|
|
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": "
|
|
50
|
+
"gitHead": "e9f8a48bb5cc68182f37b2e14b0f4e30ea6e7d6a"
|
|
51
51
|
}
|