@ecoding/components.antd 0.5.7 → 0.5.9
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/form.list/index.js +2 -2
- package/lib/core/multiple-file-upload/index.d.ts +4 -8
- package/lib/core/multiple-file-upload/index.js +105 -57
- package/lib/core/multiple-img-upload/index.d.ts +1 -0
- package/lib/core/multiple-img-upload/index.js +21 -10
- package/lib/core/single-file-upload/index.d.ts +1 -0
- package/lib/core/single-file-upload/index.js +26 -6
- package/lib/core/single-img-upload/index.js +2 -2
- package/package.json +2 -2
|
@@ -46,7 +46,7 @@ const SortableItem = (props) => {
|
|
|
46
46
|
index + 1)),
|
|
47
47
|
columns.map((column, i) => {
|
|
48
48
|
if (column.type == "operation") {
|
|
49
|
-
return (React.createElement("td", { style: Object.assign({}, tdStyle, { right: 0, position: "sticky", backgroundColor: "#fff" }) },
|
|
49
|
+
return (React.createElement("td", { style: Object.assign({}, tdStyle, { right: 0, zIndex: 10, position: "sticky", backgroundColor: "#fff" }) },
|
|
50
50
|
React.createElement(Space, null,
|
|
51
51
|
column.render && column.render(field, index, { add, remove }),
|
|
52
52
|
(typeof column.hideRemove == "function" && column.hideRemove(field, index)) || (typeof column.hideRemove == "boolean" && column.hideRemove) ? (React.createElement(Typography.Text, { style: { cursor: 'no-drop', 'color': '#ccc' }, disabled: true }, i18n ? i18n.$t("global.del", '删除') : '删除')) : (React.createElement(Typography.Text, { style: disabled ? { cursor: 'no-drop', 'color': '#ccc' } : { cursor: 'pointer' }, type: disabled ? undefined : "danger", disabled: disabled, onClick: () => {
|
|
@@ -66,7 +66,7 @@ const SortableItem = (props) => {
|
|
|
66
66
|
React.createElement(Form.Item, { style: { marginBottom: 0 }, name: [field.name, column.name], rules: column.rules || [] }, column.render(field, index, { add, remove }))));
|
|
67
67
|
}
|
|
68
68
|
}),
|
|
69
|
-
needDefaultOperation ? (React.createElement("td", { style: Object.assign({}, tdStyle, { right: 0, position: "sticky", backgroundColor: "#fff" }) },
|
|
69
|
+
needDefaultOperation ? (React.createElement("td", { style: Object.assign({}, tdStyle, { right: 0, zIndex: 10, position: "sticky", backgroundColor: "#fff" }) },
|
|
70
70
|
React.createElement(Typography.Text, { style: disabled ? { cursor: 'no-drop', 'color': '#ccc' } : { cursor: 'pointer' }, type: disabled ? undefined : "danger", onClick: () => {
|
|
71
71
|
if (disabled) {
|
|
72
72
|
return;
|
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { UploadFile } from 'antd/lib/upload/interface';
|
|
3
|
-
interface IRes {
|
|
4
|
-
name: string;
|
|
5
|
-
url: string;
|
|
6
|
-
[props: string]: any;
|
|
7
|
-
}
|
|
8
3
|
interface IProps {
|
|
9
4
|
action: string | (() => string);
|
|
10
5
|
actionParams?: any;
|
|
@@ -14,12 +9,13 @@ interface IProps {
|
|
|
14
9
|
i18n?: any;
|
|
15
10
|
name?: string;
|
|
16
11
|
data?: any;
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
value?: UploadFile[] | string[];
|
|
13
|
+
valueKey?: string;
|
|
19
14
|
headers?: any;
|
|
20
15
|
uploadRef?: any;
|
|
21
16
|
domain?: string;
|
|
22
|
-
|
|
17
|
+
objectInValue?: boolean;
|
|
18
|
+
onChange?: (infos: any[] | undefined) => void;
|
|
23
19
|
onDone?: (file: UploadFile, res: any) => void;
|
|
24
20
|
onRemove?: (file: UploadFile) => void;
|
|
25
21
|
onError?: (file: UploadFile) => void;
|
|
@@ -12,25 +12,32 @@ import { Upload, message, Button, Popover, Typography, Space, Empty } from 'antd
|
|
|
12
12
|
import { UploadOutlined, LinkOutlined, DeleteOutlined, EllipsisOutlined } from '@ant-design/icons';
|
|
13
13
|
import { buildURL } from '@ecoding/helper.url';
|
|
14
14
|
import Toast from "../../core/toast";
|
|
15
|
-
|
|
16
|
-
const InfosRender = ({ infos, setInfos, onChange, domain }) => {
|
|
15
|
+
const InfosRender = ({ infos, updateItems, domain }) => {
|
|
17
16
|
const remove = (i) => {
|
|
18
17
|
const temp = infos.concat([]);
|
|
19
18
|
temp.splice(i, 1);
|
|
20
|
-
|
|
21
|
-
onChange && onChange(temp);
|
|
19
|
+
updateItems(temp, false);
|
|
22
20
|
};
|
|
23
21
|
if (infos && infos.length > 0) {
|
|
24
22
|
return (React.createElement("ul", null, infos.map((info, i) => {
|
|
25
|
-
|
|
23
|
+
let name, url;
|
|
24
|
+
if (typeof info == "string") {
|
|
25
|
+
url = info;
|
|
26
|
+
name = info.substring(info.lastIndexOf('/') + 1, info.lastIndexOf('.'));
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
url = info.url;
|
|
30
|
+
name = info.name || info.filename || info.file_name || info.fileName || info.original_file_name || info.originalFilename || info.originalFileName;
|
|
31
|
+
}
|
|
32
|
+
return (React.createElement("li", { key: url, style: {
|
|
26
33
|
display: "flex",
|
|
27
34
|
justifyContent: "space-between",
|
|
28
35
|
maxWidth: 250
|
|
29
36
|
} },
|
|
30
|
-
React.createElement(Typography.Link, { download:
|
|
37
|
+
React.createElement(Typography.Link, { download: name, ellipsis: true, title: name, href: domain ? `${domain}${url}` : url, target: "_blank" },
|
|
31
38
|
React.createElement(LinkOutlined, null),
|
|
32
39
|
" ",
|
|
33
|
-
|
|
40
|
+
name),
|
|
34
41
|
React.createElement(Typography.Text, { style: { cursor: 'pointer' }, type: "danger", onClick: () => remove(i) },
|
|
35
42
|
React.createElement(DeleteOutlined, null))));
|
|
36
43
|
})));
|
|
@@ -38,7 +45,11 @@ const InfosRender = ({ infos, setInfos, onChange, domain }) => {
|
|
|
38
45
|
return React.createElement(Empty, { style: { height: 30 }, image: Empty.PRESENTED_IMAGE_SIMPLE });
|
|
39
46
|
};
|
|
40
47
|
const MultipleUpload = (props) => {
|
|
41
|
-
const
|
|
48
|
+
const { value, domain, onChange, valueKey, objectInValue } = props;
|
|
49
|
+
const isInnerChange = useRef(false);
|
|
50
|
+
const [infos, setInfos] = useState(() => {
|
|
51
|
+
return [];
|
|
52
|
+
});
|
|
42
53
|
const [open, setOpen] = useState(undefined);
|
|
43
54
|
const timeout = useRef();
|
|
44
55
|
const action = useMemo(() => {
|
|
@@ -47,56 +58,69 @@ const MultipleUpload = (props) => {
|
|
|
47
58
|
}
|
|
48
59
|
return buildURL(props.action(), props.actionParams);
|
|
49
60
|
}, [props.actionParams, props.action]);
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
const updateItems = (newItems, open = true) => {
|
|
62
|
+
isInnerChange.current = true;
|
|
63
|
+
setInfos(newItems);
|
|
64
|
+
let isEmpty = true;
|
|
65
|
+
const temp = [];
|
|
66
|
+
newItems && newItems.forEach((item) => {
|
|
67
|
+
if (item && item.url) {
|
|
68
|
+
// 防止重复拼接
|
|
69
|
+
item.url = domain ? item.url.replace(domain, '') : item.url;
|
|
70
|
+
item.url = domain ? `${domain}${item.url}` : item.url;
|
|
71
|
+
temp.push(item);
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
temp.forEach((item) => {
|
|
75
|
+
if (item) {
|
|
76
|
+
isEmpty = false;
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
if (objectInValue) {
|
|
81
|
+
const temp2 = temp && temp.map((item) => {
|
|
82
|
+
const responseData = item.responseData;
|
|
83
|
+
return Object.assign(Object.assign(Object.assign({}, item), responseData), { url: domain ? item.url.replace(domain, '') : item.url });
|
|
84
|
+
});
|
|
85
|
+
onChange && onChange(!isEmpty ? temp2 : undefined);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const urls = temp.map((item) => domain ? item.url.replace(domain, '') : item.url);
|
|
89
|
+
onChange && onChange(!isEmpty ? urls : undefined);
|
|
90
|
+
}
|
|
91
|
+
if (open) {
|
|
92
|
+
setOpen(true);
|
|
93
|
+
clearTimeout(timeout.current);
|
|
94
|
+
timeout.current = setTimeout(() => {
|
|
95
|
+
setOpen(undefined);
|
|
96
|
+
}, 3000);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const handleChange = ({ fileList }) => {
|
|
100
|
+
fileList && fileList.forEach((file) => {
|
|
101
|
+
if (file.status == "done") {
|
|
102
|
+
const response = file.response || {};
|
|
60
103
|
if (response.code === 200 ||
|
|
61
104
|
response.code === 0 ||
|
|
62
105
|
response.success ||
|
|
63
106
|
response.successed) {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
timeout.current = setTimeout(() => {
|
|
72
|
-
setOpen(undefined);
|
|
73
|
-
}, 3000);
|
|
74
|
-
props.onChange && props.onChange(tempRes);
|
|
107
|
+
const data = response.data || response.model;
|
|
108
|
+
file.url = data && data[valueKey || "url"];
|
|
109
|
+
file.responseData = data;
|
|
110
|
+
delete file.response;
|
|
111
|
+
delete file.xhr;
|
|
112
|
+
delete file.lastModifiedDate;
|
|
113
|
+
delete file.originFileObj;
|
|
75
114
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
Toast.error({
|
|
79
|
-
mask: true,
|
|
80
|
-
title: response
|
|
81
|
-
? `${file.name}-${response.msg}` || `${file.name}-${response.message}`
|
|
82
|
-
: `${file.name}-${props.i18n ? props.i18n.$t('global.upload.error.file') : '服务出错,文件上传失败'}`
|
|
83
|
-
});
|
|
84
|
-
}
|
|
85
|
-
break;
|
|
86
|
-
case 'error':
|
|
87
|
-
Loading.hide();
|
|
115
|
+
}
|
|
116
|
+
else if (file.status === "error") {
|
|
88
117
|
Toast.error({
|
|
89
118
|
mask: true,
|
|
90
|
-
title:
|
|
91
|
-
? `${info.file.name}-${(_a = info.file.response) === null || _a === void 0 ? void 0 : _a.msg}` || `${info.file.name}-${(_b = info.file.response) === null || _b === void 0 ? void 0 : _b.message}`
|
|
92
|
-
: `${info.file.name}-${props.i18n ? props.i18n.$t('global.upload.error.file') : '服务出错,文件上传失败'}`
|
|
119
|
+
title: file.response ? file.response.msg || file.response.message : `${props.i18n ? props.i18n.$t('global.upload.error.img') : '服务出错,文件上传失败'}`
|
|
93
120
|
});
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
Loading.hide();
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
updateItems(fileList);
|
|
100
124
|
};
|
|
101
125
|
const beforeUpload = useCallback((file) => {
|
|
102
126
|
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -116,16 +140,41 @@ const MultipleUpload = (props) => {
|
|
|
116
140
|
}));
|
|
117
141
|
}, []);
|
|
118
142
|
useEffect(() => {
|
|
119
|
-
if (
|
|
120
|
-
|
|
143
|
+
if (isInnerChange.current) {
|
|
144
|
+
isInnerChange.current = false;
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
if (value && value.length > 0) {
|
|
148
|
+
const temp = [];
|
|
149
|
+
value.forEach((item, index) => {
|
|
150
|
+
if (typeof item === "string" && item) {
|
|
151
|
+
// 防止重复拼接domain
|
|
152
|
+
item = domain ? item.replace(domain, "") : item;
|
|
153
|
+
temp.push({
|
|
154
|
+
uid: String(index),
|
|
155
|
+
status: 'done',
|
|
156
|
+
url: domain ? `${domain}${item}` : item,
|
|
157
|
+
name: item.substring(item.lastIndexOf('/') + 1, item.lastIndexOf('.'))
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
else {
|
|
161
|
+
if (item === null || item === void 0 ? void 0 : item.url) {
|
|
162
|
+
// 防止重复拼接domain
|
|
163
|
+
item.url = domain ? item.url.replace(domain, "") : item.url;
|
|
164
|
+
item.url = domain ? `${domain}${item.url}` : item.url;
|
|
165
|
+
temp.push(item);
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
setInfos(temp);
|
|
121
170
|
}
|
|
122
|
-
}, [
|
|
171
|
+
}, [value]);
|
|
123
172
|
return (React.createElement(Space.Compact, { block: true },
|
|
124
|
-
React.createElement(Upload, { ref: props.uploadRef, withCredentials: true, multiple: true, data: props.data, openFileDialogOnClick: props.openFileDialogOnClick, beforeUpload: beforeUpload, name: props.name, disabled: props.disabled, headers: props.headers, action: action, onChange: handleChange, showUploadList: false, onRemove: (
|
|
125
|
-
props.onRemove && props.onRemove(
|
|
173
|
+
React.createElement(Upload, { ref: props.uploadRef, withCredentials: true, multiple: true, data: props.data, openFileDialogOnClick: props.openFileDialogOnClick, beforeUpload: beforeUpload, name: props.name, disabled: props.disabled, headers: props.headers, action: action, onChange: handleChange, showUploadList: false, onRemove: (file) => {
|
|
174
|
+
props.onRemove && props.onRemove(file);
|
|
126
175
|
}, maxCount: props.maxCount },
|
|
127
176
|
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, {
|
|
177
|
+
React.createElement(Popover, { destroyOnHidden: true, open: open, placement: "right", trigger: "hover", title: "Uploaded", content: React.createElement(InfosRender, { infos: infos, updateItems: updateItems, domain: props.domain }) },
|
|
129
178
|
React.createElement(Button, { icon: React.createElement(EllipsisOutlined, null) }))));
|
|
130
179
|
};
|
|
131
180
|
MultipleUpload.defaultProps = {
|
|
@@ -133,7 +182,6 @@ MultipleUpload.defaultProps = {
|
|
|
133
182
|
openFileDialogOnClick: true,
|
|
134
183
|
icon: true,
|
|
135
184
|
data: {},
|
|
136
|
-
extraData: {},
|
|
137
185
|
maxCount: 10,
|
|
138
186
|
headers: undefined,
|
|
139
187
|
buttonText: 'Upload',
|
|
@@ -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, useEffect } from 'react';
|
|
10
|
+
import React, { useState, useCallback, useMemo, useEffect, useRef } 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,18 +35,20 @@ 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, domain } = props;
|
|
38
|
+
const { i18n, name, buttonText, maxCount, disabled, value, onChange, objectInValue, domain, valueKey } = props;
|
|
39
|
+
const isInnerChange = useRef(false);
|
|
39
40
|
const [previewOpen, setPreviewOpen] = useState(false);
|
|
40
41
|
const [previewImage, setPreviewImage] = useState('');
|
|
41
42
|
const [imgList, setImgList] = useState(() => {
|
|
42
43
|
return [];
|
|
43
44
|
});
|
|
44
45
|
const updateItems = (newItems) => {
|
|
46
|
+
isInnerChange.current = true;
|
|
45
47
|
setImgList(newItems);
|
|
46
48
|
let isEmpty = true;
|
|
47
49
|
const temp = [];
|
|
48
50
|
newItems && newItems.forEach((item) => {
|
|
49
|
-
if (item.url) {
|
|
51
|
+
if (item && item.url) {
|
|
50
52
|
// 防止重复拼接
|
|
51
53
|
item.url = domain ? item.url.replace(domain, '') : item.url;
|
|
52
54
|
item.url = domain ? `${domain}${item.url}` : item.url;
|
|
@@ -60,7 +62,10 @@ const MultipleImgUpload = (props) => {
|
|
|
60
62
|
}
|
|
61
63
|
});
|
|
62
64
|
if (objectInValue) {
|
|
63
|
-
const temp2 = temp && temp.map((item) =>
|
|
65
|
+
const temp2 = temp && temp.map((item) => {
|
|
66
|
+
const responseData = item.responseData;
|
|
67
|
+
return Object.assign(Object.assign(Object.assign({}, item), responseData), { url: domain ? item.url.replace(domain, '') : item.url });
|
|
68
|
+
});
|
|
64
69
|
onChange && onChange(!isEmpty ? temp2 : undefined);
|
|
65
70
|
}
|
|
66
71
|
else {
|
|
@@ -69,7 +74,8 @@ const MultipleImgUpload = (props) => {
|
|
|
69
74
|
}
|
|
70
75
|
};
|
|
71
76
|
const handleChange = ({ fileList }) => {
|
|
72
|
-
|
|
77
|
+
const newFileList = [...fileList];
|
|
78
|
+
newFileList && newFileList.forEach((file) => {
|
|
73
79
|
if (file.status == "done") {
|
|
74
80
|
const response = file.response || {};
|
|
75
81
|
if (response.code === 200 ||
|
|
@@ -77,7 +83,8 @@ const MultipleImgUpload = (props) => {
|
|
|
77
83
|
response.success ||
|
|
78
84
|
response.successed) {
|
|
79
85
|
const data = response.data || response.model;
|
|
80
|
-
file.
|
|
86
|
+
file.responseData = data;
|
|
87
|
+
file.url = data && data[valueKey || "url"];
|
|
81
88
|
delete file.response;
|
|
82
89
|
delete file.xhr;
|
|
83
90
|
delete file.lastModifiedDate;
|
|
@@ -91,7 +98,7 @@ const MultipleImgUpload = (props) => {
|
|
|
91
98
|
});
|
|
92
99
|
}
|
|
93
100
|
});
|
|
94
|
-
updateItems(
|
|
101
|
+
updateItems(newFileList);
|
|
95
102
|
};
|
|
96
103
|
const handleRemove = (file) => {
|
|
97
104
|
const lefts = imgList.filter(item => item.uid !== file.uid);
|
|
@@ -116,7 +123,7 @@ const MultipleImgUpload = (props) => {
|
|
|
116
123
|
file.preview = yield getBase64(file.originFileObj);
|
|
117
124
|
}
|
|
118
125
|
let url;
|
|
119
|
-
if (file.url) {
|
|
126
|
+
if (file === null || file === void 0 ? void 0 : file.url) {
|
|
120
127
|
url = domain ? file.url.replace(domain, '') : file.url;
|
|
121
128
|
}
|
|
122
129
|
setPreviewImage(url || file.preview);
|
|
@@ -211,6 +218,10 @@ const MultipleImgUpload = (props) => {
|
|
|
211
218
|
}));
|
|
212
219
|
}, []);
|
|
213
220
|
useEffect(() => {
|
|
221
|
+
if (isInnerChange.current) {
|
|
222
|
+
isInnerChange.current = false;
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
214
225
|
if (value && value.length > 0) {
|
|
215
226
|
const temp = [];
|
|
216
227
|
value.forEach((item, index) => {
|
|
@@ -225,7 +236,7 @@ const MultipleImgUpload = (props) => {
|
|
|
225
236
|
});
|
|
226
237
|
}
|
|
227
238
|
else {
|
|
228
|
-
if (item.url) {
|
|
239
|
+
if (item === null || item === void 0 ? void 0 : item.url) {
|
|
229
240
|
// 防止重复拼接domain
|
|
230
241
|
item.url = domain ? item.url.replace(domain, "") : item.url;
|
|
231
242
|
item.url = domain ? `${domain}${item.url}` : item.url;
|
|
@@ -273,7 +284,7 @@ const MultipleImgUpload = (props) => {
|
|
|
273
284
|
!((_d = props.opts) === null || _d === void 0 ? void 0 : _d.maxH) ? null : (React.createElement("span", null, i18n ? `${i18n.$t("global.maxH", "最大高")}:${props.opts.maxH}` : `最大高:${props.opts.maxH}`))))) : null)), type: "warning", showIcon: true })),
|
|
274
285
|
React.createElement(DndContext, { sensors: disabled ? [] : [sensor], onDragEnd: disabled ? undefined : onDragEnd },
|
|
275
286
|
React.createElement(SortableContext, { items: imgList === null || imgList === void 0 ? void 0 : imgList.map((i) => i.uid), strategy: rectSortingStrategy },
|
|
276
|
-
React.createElement(Upload, { listType: "picture-card", fileList: imgList, action: action, beforeUpload: beforeUpload, onPreview: handlePreview, onChange: handleChange, onRemove: handleRemove, name: name, data: props.data, multiple: true, disabled: disabled, withCredentials: true, itemRender: (originNode, file) => (React.createElement(DraggableUploadListItem, { originNode: originNode, file: file, disabled: disabled })) }, maxCount == 0 ? uploadButton : maxCount && imgList.length >= maxCount ? null : uploadButton),
|
|
287
|
+
React.createElement(Upload, { listType: "picture-card", fileList: imgList, action: action, beforeUpload: beforeUpload, onPreview: handlePreview, onChange: handleChange, onRemove: handleRemove, name: name, data: props.data, multiple: true, headers: props.headers, disabled: disabled, withCredentials: true, itemRender: (originNode, file) => (React.createElement(DraggableUploadListItem, { originNode: originNode, file: file, disabled: disabled })) }, maxCount == 0 ? uploadButton : maxCount && imgList.length >= maxCount ? null : uploadButton),
|
|
277
288
|
previewImage && (React.createElement(Img, { wrapperStyle: { display: 'none' }, preview: {
|
|
278
289
|
visible: previewOpen,
|
|
279
290
|
onVisibleChange: (visible) => setPreviewOpen(visible),
|
|
@@ -35,9 +35,22 @@ const SingleFileUpload = (props) => {
|
|
|
35
35
|
response.success ||
|
|
36
36
|
response.successed) {
|
|
37
37
|
setLoading(false);
|
|
38
|
-
|
|
38
|
+
let url = data && data[props.valueKey || "url"];
|
|
39
|
+
if (props.domain) {
|
|
40
|
+
url = url.replace(props.domain, "");
|
|
41
|
+
}
|
|
39
42
|
setFileUrl(url);
|
|
40
|
-
|
|
43
|
+
if (props.objectInValue) {
|
|
44
|
+
delete info.file.response;
|
|
45
|
+
delete info.file.xhr;
|
|
46
|
+
delete info.file.lastModifiedDate;
|
|
47
|
+
delete info.file.originFileObj;
|
|
48
|
+
props.onChange && props.onChange(Object.assign(Object.assign({}, info.file), data));
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// Form.item 值注入关键
|
|
52
|
+
props.onChange && props.onChange(url);
|
|
53
|
+
}
|
|
41
54
|
props.onDone && props.onDone(info.file, data);
|
|
42
55
|
}
|
|
43
56
|
else {
|
|
@@ -79,16 +92,23 @@ const SingleFileUpload = (props) => {
|
|
|
79
92
|
}));
|
|
80
93
|
}, []);
|
|
81
94
|
useEffect(() => {
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
95
|
+
let item = props.value;
|
|
96
|
+
if (typeof item === "string" && (item || item == '') && fileUrl != item) {
|
|
97
|
+
// 防止重复拼接domain
|
|
98
|
+
item = props.domain ? item.replace(props.domain, "") : item;
|
|
99
|
+
setFileUrl(item);
|
|
100
|
+
}
|
|
101
|
+
if (((item === null || item === void 0 ? void 0 : item.url) || (item === null || item === void 0 ? void 0 : item.url) == '') && fileUrl != item.url) {
|
|
102
|
+
// 防止重复拼接domain
|
|
103
|
+
item.url = props.domain ? item.url.replace(props.domain, "") : item.url;
|
|
104
|
+
setFileUrl(item.url);
|
|
85
105
|
}
|
|
86
106
|
}, [props.value]);
|
|
87
107
|
return (React.createElement(Space.Compact, { block: true },
|
|
88
108
|
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) => {
|
|
89
109
|
const v = e.target.value.trim();
|
|
90
110
|
props.onChange && props.onChange(v);
|
|
91
|
-
} }),
|
|
111
|
+
}, disabled: props.disabled || props.objectInValue }),
|
|
92
112
|
React.createElement(Upload, { ref: props.uploadRef, withCredentials: true, openFileDialogOnClick: props.openFileDialogOnClick, beforeUpload: beforeUpload, name: props.name, disabled: props.disabled, headers: props.headers, data: props.data, action: action, onChange: handleChange, showUploadList: false, onRemove: (e) => {
|
|
93
113
|
props.onRemove && props.onRemove(e);
|
|
94
114
|
}, maxCount: 1 },
|
|
@@ -67,7 +67,7 @@ const ImgUpload = (props) => {
|
|
|
67
67
|
delete info.file.xhr;
|
|
68
68
|
delete info.file.lastModifiedDate;
|
|
69
69
|
delete info.file.originFileObj;
|
|
70
|
-
props.onChange && props.onChange(info.file);
|
|
70
|
+
props.onChange && props.onChange(Object.assign(Object.assign({}, info.file), data));
|
|
71
71
|
}
|
|
72
72
|
else {
|
|
73
73
|
// Form.item 值注入关键
|
|
@@ -171,7 +171,7 @@ const ImgUpload = (props) => {
|
|
|
171
171
|
item = props.domain ? item.replace(props.domain, "") : item;
|
|
172
172
|
setImageUrl(item);
|
|
173
173
|
}
|
|
174
|
-
if (item.url) {
|
|
174
|
+
if (item === null || item === void 0 ? void 0 : item.url) {
|
|
175
175
|
// 防止重复拼接domain
|
|
176
176
|
item.url = props.domain ? item.url.replace(props.domain, "") : item.url;
|
|
177
177
|
setImageUrl(item.url);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoding/components.antd",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.9",
|
|
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": "b9691a891b05214151e9ec74cb5a6392c038f3ef"
|
|
51
51
|
}
|