@ecoding/components.antd 0.5.10 → 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.
|
@@ -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', '附件') : '附件'));
|
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
|
}
|