@ecoding/components.antd 0.3.2 → 0.3.4
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/date.picker/index.d.ts +3 -0
- package/lib/core/date.picker/index.js +12 -3
- package/lib/core/form.label.attachment/index.d.ts +1 -0
- package/lib/core/form.label.attachment/index.js +52 -19
- package/lib/core/range-picker/index.d.ts +3 -0
- package/lib/core/range-picker/index.js +13 -3
- package/package.json +2 -2
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import dayjs from "dayjs";
|
|
2
3
|
import { RangePickerProps } from "antd/es/date-picker";
|
|
3
4
|
declare type IProps = RangePickerProps & {
|
|
4
5
|
value?: string | number;
|
|
5
6
|
disabledDate?: (current: any) => RangePickerProps['disabledDate'];
|
|
6
7
|
onChange?: any;
|
|
7
8
|
showTime?: boolean;
|
|
9
|
+
startOf?: dayjs.OpUnitType | undefined;
|
|
10
|
+
endOf?: dayjs.OpUnitType | undefined;
|
|
8
11
|
className?: string;
|
|
9
12
|
style?: React.CSSProperties;
|
|
10
13
|
disabled?: boolean;
|
|
@@ -10,11 +10,18 @@ const Picker = (props) => {
|
|
|
10
10
|
const change = (v) => {
|
|
11
11
|
let value;
|
|
12
12
|
setDates(v);
|
|
13
|
+
let dayjsV = dayjs(v);
|
|
14
|
+
if (!props.showTime && props.endOf) {
|
|
15
|
+
dayjsV = dayjsV.endOf(props.endOf);
|
|
16
|
+
}
|
|
17
|
+
if (!props.showTime && props.startOf) {
|
|
18
|
+
dayjsV = dayjsV.startOf(props.startOf);
|
|
19
|
+
}
|
|
13
20
|
if (props.format) {
|
|
14
|
-
value =
|
|
21
|
+
value = dayjsV.format(props.format || "YYYY-MM-DD HH:mm:ss");
|
|
15
22
|
}
|
|
16
23
|
else {
|
|
17
|
-
value =
|
|
24
|
+
value = dayjsV.valueOf();
|
|
18
25
|
}
|
|
19
26
|
props.onChange && props.onChange(value);
|
|
20
27
|
};
|
|
@@ -36,5 +43,7 @@ const Picker = (props) => {
|
|
|
36
43
|
}, [props.value]);
|
|
37
44
|
return (React.createElement(DatePicker, { value: date, className: props.className || undefined, style: Object.assign({}, { width: "100%" }, props.style) || undefined, showTime: props.showTime ? { defaultValue: dayjs("00:00:00", "HH:mm:ss") } : undefined, disabledDate: props.disabledDate || undefined, disabled: props.disabled || undefined, onChange: change }));
|
|
38
45
|
};
|
|
39
|
-
Picker.defaultProps = {
|
|
46
|
+
Picker.defaultProps = {
|
|
47
|
+
endOf: "D"
|
|
48
|
+
};
|
|
40
49
|
export default Picker;
|
|
@@ -3,8 +3,10 @@ import { isSomething } from '@ecoding/helper.is';
|
|
|
3
3
|
import { LinkOutlined, CloudDownloadOutlined, EyeOutlined } from '@ant-design/icons';
|
|
4
4
|
import { Typography, Popover, Tag, Checkbox, Space } from 'antd';
|
|
5
5
|
import { jsonFormatNewKey } from "@ecoding/helper.json";
|
|
6
|
-
|
|
6
|
+
import http from "../../helpers/http";
|
|
7
|
+
const InfosRender = ({ infos, i18n, format, batchDownload }) => {
|
|
7
8
|
const [checkedList, setCheckedList] = useState([]);
|
|
9
|
+
const r = http.getRequest();
|
|
8
10
|
const style = {
|
|
9
11
|
display: 'flex',
|
|
10
12
|
justifyContent: 'space-between',
|
|
@@ -12,21 +14,40 @@ const InfosRender = ({ infos, i18n, format }) => {
|
|
|
12
14
|
};
|
|
13
15
|
const checkAll = infos.length === checkedList.length;
|
|
14
16
|
const indeterminate = checkedList.length > 0 && checkedList.length < infos.length;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
17
|
+
const downloadFile = (url, name) => {
|
|
18
|
+
r.get(url, {}, {
|
|
19
|
+
responseType: 'blob',
|
|
20
|
+
original: true
|
|
21
|
+
}).then((res) => {
|
|
22
|
+
/**
|
|
23
|
+
* blob下载思路
|
|
24
|
+
* 1) 使用ajax发起请求,指定接收类型为blob(responseType: 'blob')
|
|
25
|
+
* 2)读取请求返回的头部信息里的content-disposition,返回的文件名就在这里面(或者自定义文件名,可跳过此步骤)
|
|
26
|
+
* 3)使用URL.createObjectURL将请求的blob数据转为可下载的url地址
|
|
27
|
+
* 4)使用a标签下载
|
|
28
|
+
*
|
|
29
|
+
*/
|
|
30
|
+
let blob = res.data;
|
|
31
|
+
// 从response的headers中获取filename, 后端response.setHeader("Content-disposition", "attachment; filename=xxxx.docx") 设置的文件名;
|
|
32
|
+
// let patt = new RegExp('filename=([^;]+\\.[^\\.;]+);*')
|
|
33
|
+
// let contentDisposition = decodeURI(res.headers['content-disposition'])
|
|
34
|
+
// let result = patt.exec(contentDisposition)
|
|
35
|
+
// let fileName = result[1]
|
|
36
|
+
//将请求的blob数据转为可下载的url地址
|
|
37
|
+
let url = URL.createObjectURL(blob);
|
|
38
|
+
// 创建一个下载标签<a>
|
|
39
|
+
const aLink = document.createElement('a');
|
|
40
|
+
aLink.href = url;
|
|
41
|
+
// 2.直接使用自定义文件名,设置下载文件名称
|
|
42
|
+
aLink.setAttribute('download', name || "");
|
|
43
|
+
document.body.appendChild(aLink);
|
|
44
|
+
// 模拟点击下载
|
|
45
|
+
aLink.click();
|
|
46
|
+
// 移除改下载标签
|
|
47
|
+
document.body.removeChild(aLink);
|
|
48
|
+
window.URL.revokeObjectURL(url);
|
|
25
49
|
});
|
|
26
|
-
|
|
27
|
-
// clickEvent.initEvent("click", true, true);
|
|
28
|
-
a.dispatchEvent(evt);
|
|
29
|
-
}
|
|
50
|
+
};
|
|
30
51
|
const checkChange = (keys) => {
|
|
31
52
|
setCheckedList(keys);
|
|
32
53
|
};
|
|
@@ -39,8 +60,20 @@ const InfosRender = ({ infos, i18n, format }) => {
|
|
|
39
60
|
}
|
|
40
61
|
};
|
|
41
62
|
const downLoadAll = () => {
|
|
63
|
+
if (typeof batchDownload === "string") {
|
|
64
|
+
downloadFile(batchDownload);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
if (typeof batchDownload === "function") {
|
|
68
|
+
batchDownload();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const temp = [];
|
|
42
72
|
checkedList.forEach(key => {
|
|
43
|
-
|
|
73
|
+
temp.push(infos.find(info => info.url === key));
|
|
74
|
+
});
|
|
75
|
+
temp.forEach(info => {
|
|
76
|
+
downloadFile(info.url, info.name);
|
|
44
77
|
});
|
|
45
78
|
};
|
|
46
79
|
return (React.createElement("ul", { style: { width: 300, overflow: "hidden" } },
|
|
@@ -56,7 +89,7 @@ const InfosRender = ({ infos, i18n, format }) => {
|
|
|
56
89
|
React.createElement(LinkOutlined, null),
|
|
57
90
|
" ",
|
|
58
91
|
info.name)),
|
|
59
|
-
React.createElement(Typography.Link, { download: info.name, title: info.name,
|
|
92
|
+
React.createElement(Typography.Link, { download: info.name, title: info.name, onClick: () => downloadFile(info.url, info.name) },
|
|
60
93
|
React.createElement(CloudDownloadOutlined, null))),
|
|
61
94
|
info.time || info.user ? (React.createElement("div", { style: style },
|
|
62
95
|
React.createElement(Typography.Text, { type: "secondary", style: { fontSize: 12 } }, info.time),
|
|
@@ -67,12 +100,12 @@ const InfosRender = ({ infos, i18n, format }) => {
|
|
|
67
100
|
React.createElement(Checkbox, { indeterminate: indeterminate, onChange: onCheckAllChange, checked: checkAll }, i18n ? i18n.$t('global.checkbox.all', '全选') : '全选'),
|
|
68
101
|
React.createElement(Typography.Link, { disabled: checkedList.length === 0, onClick: () => downLoadAll() }, i18n ? i18n.$t('global.batch.download', '批量下载') : '批量下载')))) : null));
|
|
69
102
|
};
|
|
70
|
-
const C = ({ value, empty, render, i18n, format }) => {
|
|
103
|
+
const C = ({ value, empty, render, i18n, batchDownload, format }) => {
|
|
71
104
|
if (!isSomething(value) || (Array.isArray(value) && value.length === 0)) {
|
|
72
105
|
return React.createElement(React.Fragment, null, empty || '-');
|
|
73
106
|
}
|
|
74
107
|
if (Array.isArray(value)) {
|
|
75
|
-
return (React.createElement(Popover, { destroyTooltipOnHide: true, placement: "right", trigger: "hover", title: "Uploaded", content: render ? render(value) : React.createElement(InfosRender, { format: format, i18n: i18n, infos: value }) },
|
|
108
|
+
return (React.createElement(Popover, { destroyTooltipOnHide: true, placement: "right", trigger: "hover", title: "Uploaded", content: render ? render(value) : React.createElement(InfosRender, { batchDownload: batchDownload, format: format, i18n: i18n, infos: value }) },
|
|
76
109
|
React.createElement(Tag, { icon: React.createElement(EyeOutlined, null), color: "processing" }, i18n ? i18n.$t('global.attachment', '附件') : '附件')));
|
|
77
110
|
}
|
|
78
111
|
if (typeof value === 'string') {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import dayjs from "dayjs";
|
|
2
3
|
import type { Dayjs } from "dayjs";
|
|
3
4
|
declare type RangeValue = [Dayjs | null, Dayjs | null] | null;
|
|
4
5
|
interface IProps {
|
|
@@ -10,6 +11,8 @@ interface IProps {
|
|
|
10
11
|
style?: React.CSSProperties;
|
|
11
12
|
disabled?: boolean;
|
|
12
13
|
format?: string;
|
|
14
|
+
startOf?: dayjs.OpUnitType | undefined;
|
|
15
|
+
endOf?: dayjs.OpUnitType | undefined;
|
|
13
16
|
}
|
|
14
17
|
declare const Picker: React.FC<IProps>;
|
|
15
18
|
export default Picker;
|
|
@@ -19,11 +19,19 @@ const Picker = (props) => {
|
|
|
19
19
|
}
|
|
20
20
|
let value;
|
|
21
21
|
setDates(v);
|
|
22
|
+
let dayjsStart = dayjs(v[0]);
|
|
23
|
+
let dayjsEnd = dayjs(v[1]);
|
|
24
|
+
if (!props.showTime && props.startOf) {
|
|
25
|
+
dayjsStart = dayjsStart.startOf(props.startOf);
|
|
26
|
+
}
|
|
27
|
+
if (!props.showTime && props.endOf) {
|
|
28
|
+
dayjsEnd = dayjsEnd.endOf(props.endOf);
|
|
29
|
+
}
|
|
22
30
|
if (props.format) { // "YYYY-MM-DD HH:mm:ss"
|
|
23
|
-
value = [
|
|
31
|
+
value = [dayjsStart.format(props.format), dayjsEnd.format(props.format)];
|
|
24
32
|
}
|
|
25
33
|
else {
|
|
26
|
-
value = [
|
|
34
|
+
value = [dayjsStart.valueOf(), dayjsEnd.valueOf()];
|
|
27
35
|
}
|
|
28
36
|
props.onChange && props.onChange(value);
|
|
29
37
|
};
|
|
@@ -55,6 +63,8 @@ const Picker = (props) => {
|
|
|
55
63
|
} : undefined, onCalendarChange: (val) => setDates(val), disabledDate: props.rangeDay ? disabledDate : undefined, disabled: props.disabled || undefined, onChange: change }));
|
|
56
64
|
};
|
|
57
65
|
Picker.defaultProps = {
|
|
58
|
-
rangeDay: undefined
|
|
66
|
+
rangeDay: undefined,
|
|
67
|
+
startOf: "D",
|
|
68
|
+
endOf: "D"
|
|
59
69
|
};
|
|
60
70
|
export default Picker;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoding/components.antd",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.4",
|
|
4
4
|
"author": "cxc",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"antd": "^5.8.4",
|
|
44
44
|
"axios": "^1.1.2"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "c705fec6ca36ac140554d015ea65727f6b510abd"
|
|
47
47
|
}
|