@ecoding/components.antd 0.5.9 → 0.5.11
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-select/index.d.ts +1 -0
- package/lib/core/async-select/index.js +2 -2
- package/lib/core/form.label.attachment/index.d.ts +1 -0
- package/lib/core/form.label.attachment/index.js +40 -12
- package/lib/core/multiple-file-upload/index.d.ts +1 -0
- package/lib/core/multiple-file-upload/index.js +6 -5
- package/package.json +2 -2
|
@@ -74,7 +74,7 @@ const AsyncSelect = memo((props) => {
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
const res = iface.format2 ? jsonFormatNewKey2(resOrigin, iface.format2) : iface.format ? jsonFormatNewKey(resOrigin, iface.format) : resOrigin;
|
|
77
|
-
return Promise.resolve(res);
|
|
77
|
+
return Promise.resolve(iface.filters ? iface.filters(res) : res);
|
|
78
78
|
}
|
|
79
79
|
return Promise.reject("没有iface或data");
|
|
80
80
|
});
|
|
@@ -131,7 +131,7 @@ const AsyncSelect = memo((props) => {
|
|
|
131
131
|
}
|
|
132
132
|
}
|
|
133
133
|
const res = searchIface.format2 ? jsonFormatNewKey2(resOrigin, searchIface.format2) : searchIface.format ? jsonFormatNewKey(resOrigin, searchIface.format) : resOrigin;
|
|
134
|
-
setOptions(res);
|
|
134
|
+
setOptions(searchIface.filters ? searchIface.filters(res) : res);
|
|
135
135
|
}
|
|
136
136
|
});
|
|
137
137
|
timeout = setTimeout(innerEx, 300);
|
|
@@ -1,10 +1,19 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import React, { useState } from 'react';
|
|
2
11
|
import { isSomething } from '@ecoding/helper.is';
|
|
3
12
|
import { LinkOutlined, CloudDownloadOutlined, EyeOutlined } from '@ant-design/icons';
|
|
4
13
|
import { Typography, Popover, Tag, Checkbox, Space } from 'antd';
|
|
5
14
|
import { jsonFormatNewKey2 } from "@ecoding/helper.json";
|
|
6
15
|
import http from "../../helpers/http";
|
|
7
|
-
const InfosRender = ({ infos, i18n, format, batchDownload }) => {
|
|
16
|
+
const InfosRender = ({ infos, i18n, format, batchDownload, domain }) => {
|
|
8
17
|
const [checkedList, setCheckedList] = useState([]);
|
|
9
18
|
const r = http.getRequest();
|
|
10
19
|
const style = {
|
|
@@ -48,6 +57,24 @@ const InfosRender = ({ infos, i18n, format, batchDownload }) => {
|
|
|
48
57
|
window.URL.revokeObjectURL(url);
|
|
49
58
|
});
|
|
50
59
|
};
|
|
60
|
+
const openUrl = (url, name) => {
|
|
61
|
+
const aLink = document.createElement('a');
|
|
62
|
+
aLink.href = url;
|
|
63
|
+
// 2.直接使用自定义文件名,设置下载文件名称
|
|
64
|
+
aLink.setAttribute('download', name || "");
|
|
65
|
+
document.body.appendChild(aLink);
|
|
66
|
+
// 模拟点击下载
|
|
67
|
+
aLink.click();
|
|
68
|
+
// 移除改下载标签
|
|
69
|
+
document.body.removeChild(aLink);
|
|
70
|
+
};
|
|
71
|
+
const waitMS = (ms) => {
|
|
72
|
+
return new Promise((resolve) => {
|
|
73
|
+
setTimeout(() => {
|
|
74
|
+
resolve(true);
|
|
75
|
+
}, ms);
|
|
76
|
+
});
|
|
77
|
+
};
|
|
51
78
|
const checkChange = (keys) => {
|
|
52
79
|
setCheckedList(keys);
|
|
53
80
|
};
|
|
@@ -59,23 +86,24 @@ const InfosRender = ({ infos, i18n, format, batchDownload }) => {
|
|
|
59
86
|
setCheckedList([]);
|
|
60
87
|
}
|
|
61
88
|
};
|
|
62
|
-
const downLoadAll = () => {
|
|
89
|
+
const downLoadAll = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
90
|
const temp = [];
|
|
64
91
|
checkedList.forEach(key => {
|
|
65
92
|
temp.push(infos.find(info => info.url === key));
|
|
66
93
|
});
|
|
67
94
|
if (typeof batchDownload === "string") {
|
|
68
|
-
|
|
95
|
+
openUrl(batchDownload);
|
|
69
96
|
return;
|
|
70
97
|
}
|
|
71
98
|
if (typeof batchDownload === "function") {
|
|
72
99
|
batchDownload(temp);
|
|
73
100
|
return;
|
|
74
101
|
}
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
102
|
+
for (const info of temp) {
|
|
103
|
+
openUrl(info.url, info.name);
|
|
104
|
+
yield waitMS(500);
|
|
105
|
+
}
|
|
106
|
+
});
|
|
79
107
|
return (React.createElement("ul", { style: { width: 300, overflow: "hidden" } },
|
|
80
108
|
React.createElement(Checkbox.Group, { style: { display: "block" }, onChange: checkChange, value: checkedList }, infos.map((info, i) => {
|
|
81
109
|
info = format ? jsonFormatNewKey2(info, format) : info;
|
|
@@ -89,7 +117,7 @@ const InfosRender = ({ infos, i18n, format, batchDownload }) => {
|
|
|
89
117
|
React.createElement(LinkOutlined, null),
|
|
90
118
|
" ",
|
|
91
119
|
info.name)),
|
|
92
|
-
React.createElement(Typography.Link, { download: info.name, title: info.name,
|
|
120
|
+
React.createElement(Typography.Link, { download: info.name, title: info.name, href: domain ? `${domain}${info === null || info === void 0 ? void 0 : info.url}` : info === null || info === void 0 ? void 0 : info.url, target: "_blank" },
|
|
93
121
|
React.createElement(CloudDownloadOutlined, null))),
|
|
94
122
|
info.time || info.user ? (React.createElement("div", { style: style },
|
|
95
123
|
React.createElement(Typography.Text, { type: "secondary", style: { fontSize: 12 } }, info.time),
|
|
@@ -100,21 +128,21 @@ const InfosRender = ({ infos, i18n, format, batchDownload }) => {
|
|
|
100
128
|
React.createElement(Checkbox, { indeterminate: indeterminate, onChange: onCheckAllChange, checked: checkAll }, i18n ? i18n.$t('global.checkbox.all', '全选') : '全选'),
|
|
101
129
|
React.createElement(Typography.Link, { disabled: checkedList.length === 0, onClick: () => downLoadAll() }, i18n ? i18n.$t('global.batch.download', '批量下载') : '批量下载')))) : null));
|
|
102
130
|
};
|
|
103
|
-
const C = ({ value, empty, render, i18n, batchDownload, format }) => {
|
|
131
|
+
const C = ({ value, empty, render, i18n, batchDownload, domain, format }) => {
|
|
104
132
|
if (!isSomething(value) || (Array.isArray(value) && value.length === 0)) {
|
|
105
133
|
return React.createElement(React.Fragment, null, empty || '-');
|
|
106
134
|
}
|
|
107
135
|
if (Array.isArray(value)) {
|
|
108
|
-
return (React.createElement(Popover, { destroyOnHidden: true, placement: "right", trigger: "hover", title: "Uploaded", content: render ? render(value) : React.createElement(InfosRender, { batchDownload: batchDownload, format: format, i18n: i18n, infos: value }) },
|
|
136
|
+
return (React.createElement(Popover, { destroyOnHidden: true, placement: "right", trigger: "hover", title: "Uploaded", content: render ? render(value) : React.createElement(InfosRender, { domain: domain, batchDownload: batchDownload, format: format, i18n: i18n, infos: value }) },
|
|
109
137
|
React.createElement(Tag, { icon: React.createElement(EyeOutlined, null), color: "processing" }, i18n ? i18n.$t('global.attachment', '附件') : '附件')));
|
|
110
138
|
}
|
|
111
139
|
if (typeof value === 'string') {
|
|
112
|
-
return (React.createElement(Typography.Link, { download: "", title: value, href: value, target: "_blank" },
|
|
140
|
+
return (React.createElement(Typography.Link, { download: "", title: value, href: domain ? `${domain}${value}` : value, target: "_blank" },
|
|
113
141
|
React.createElement(LinkOutlined, null),
|
|
114
142
|
" ",
|
|
115
143
|
i18n ? i18n.$t('global.attachment', '附件') : '附件'));
|
|
116
144
|
}
|
|
117
|
-
return (React.createElement(Typography.Link, { download: value === null || value === void 0 ? void 0 : value.name, title: value === null || value === void 0 ? void 0 : value.name, href: value === null || value === void 0 ? void 0 : value.url, target: "_blank" },
|
|
145
|
+
return (React.createElement(Typography.Link, { download: value === null || value === void 0 ? void 0 : value.name, title: value === null || value === void 0 ? void 0 : value.name, href: domain ? `${domain}${value === null || value === void 0 ? void 0 : value.url}` : value === null || value === void 0 ? void 0 : value.url, target: "_blank" },
|
|
118
146
|
React.createElement(LinkOutlined, null),
|
|
119
147
|
" ",
|
|
120
148
|
i18n ? i18n.$t('global.attachment', '附件') : '附件'));
|
|
@@ -12,7 +12,7 @@ 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
|
-
const InfosRender = ({ infos, updateItems, domain }) => {
|
|
15
|
+
const InfosRender = ({ infos, updateItems, domain, nameKey }) => {
|
|
16
16
|
const remove = (i) => {
|
|
17
17
|
const temp = infos.concat([]);
|
|
18
18
|
temp.splice(i, 1);
|
|
@@ -27,7 +27,7 @@ const InfosRender = ({ infos, updateItems, domain }) => {
|
|
|
27
27
|
}
|
|
28
28
|
else {
|
|
29
29
|
url = info.url;
|
|
30
|
-
name = info.name || info.filename || info.file_name || info.fileName || info.original_file_name || info.originalFilename || info.originalFileName;
|
|
30
|
+
name = info[nameKey || ''] || info.name || info.filename || info.file_name || info.fileName || info.original_file_name || info.originalFilename || info.originalFileName;
|
|
31
31
|
}
|
|
32
32
|
return (React.createElement("li", { key: url, style: {
|
|
33
33
|
display: "flex",
|
|
@@ -45,7 +45,7 @@ const InfosRender = ({ infos, updateItems, domain }) => {
|
|
|
45
45
|
return React.createElement(Empty, { style: { height: 30 }, image: Empty.PRESENTED_IMAGE_SIMPLE });
|
|
46
46
|
};
|
|
47
47
|
const MultipleUpload = (props) => {
|
|
48
|
-
const { value, domain, onChange, valueKey, objectInValue } = props;
|
|
48
|
+
const { value, domain, onChange, valueKey, objectInValue, nameKey } = props;
|
|
49
49
|
const isInnerChange = useRef(false);
|
|
50
50
|
const [infos, setInfos] = useState(() => {
|
|
51
51
|
return [];
|
|
@@ -162,6 +162,7 @@ const MultipleUpload = (props) => {
|
|
|
162
162
|
// 防止重复拼接domain
|
|
163
163
|
item.url = domain ? item.url.replace(domain, "") : item.url;
|
|
164
164
|
item.url = domain ? `${domain}${item.url}` : item.url;
|
|
165
|
+
item.name = item[nameKey || ''] || item.name || item.filename || item.file_name || item.fileName || item.original_file_name || item.originalFilename || item.originalFileName;
|
|
165
166
|
temp.push(item);
|
|
166
167
|
}
|
|
167
168
|
}
|
|
@@ -170,11 +171,11 @@ const MultipleUpload = (props) => {
|
|
|
170
171
|
}
|
|
171
172
|
}, [value]);
|
|
172
173
|
return (React.createElement(Space.Compact, { block: true },
|
|
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
|
+
React.createElement(Upload, { ref: props.uploadRef, withCredentials: true, multiple: true, fileList: infos, 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
175
|
props.onRemove && props.onRemove(file);
|
|
175
176
|
}, maxCount: props.maxCount },
|
|
176
177
|
React.createElement(Button, { disabled: props.disabled, icon: props.icon ? React.createElement(UploadOutlined, null) : null }, props.buttonText)),
|
|
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 }) },
|
|
178
|
+
React.createElement(Popover, { destroyOnHidden: true, open: open, placement: "right", trigger: "hover", title: "Uploaded", content: React.createElement(InfosRender, { infos: infos, nameKey: nameKey || '', updateItems: updateItems, domain: props.domain }) },
|
|
178
179
|
React.createElement(Button, { icon: React.createElement(EllipsisOutlined, null) }))));
|
|
179
180
|
};
|
|
180
181
|
MultipleUpload.defaultProps = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoding/components.antd",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.11",
|
|
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": "c5cad337bcd9a52bf1acf009be2792fbb2b57487"
|
|
51
51
|
}
|