@ecoding/components.antd 0.3.56 → 0.3.57
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/multiple-single-img-upload/index.d.ts +26 -0
- package/lib/core/multiple-single-img-upload/index.js +116 -0
- package/lib/core/search.input/index.d.ts +1 -0
- package/lib/core/single-img-upload/index.d.ts +1 -0
- package/lib/core/single-img-upload/index.js +10 -8
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/package.json +5 -3
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
interface IOpts {
|
|
3
|
+
size?: number;
|
|
4
|
+
w?: number;
|
|
5
|
+
h?: number;
|
|
6
|
+
}
|
|
7
|
+
interface IProps {
|
|
8
|
+
max?: number;
|
|
9
|
+
message?: string;
|
|
10
|
+
showMessage?: boolean;
|
|
11
|
+
action: string | (() => string);
|
|
12
|
+
actionParams?: any;
|
|
13
|
+
name?: string;
|
|
14
|
+
i18n?: any;
|
|
15
|
+
opts?: IOpts;
|
|
16
|
+
value?: string[];
|
|
17
|
+
buttonText?: string;
|
|
18
|
+
headers?: any;
|
|
19
|
+
data?: any;
|
|
20
|
+
onChange?: any;
|
|
21
|
+
gif?: boolean;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
isTip?: boolean;
|
|
24
|
+
}
|
|
25
|
+
declare const MultiPileImgUpload: React.FC<IProps>;
|
|
26
|
+
export default MultiPileImgUpload;
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import React, { useEffect, useState } from 'react';
|
|
2
|
+
import { Space, Alert } from 'antd';
|
|
3
|
+
import { DragOutlined } from '@ant-design/icons';
|
|
4
|
+
import { DndContext, closestCenter, PointerSensor, useSensor, useSensors } from '@dnd-kit/core';
|
|
5
|
+
import { arrayMove, SortableContext, horizontalListSortingStrategy, useSortable } from '@dnd-kit/sortable';
|
|
6
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
7
|
+
import ImgUpload from '../single-img-upload';
|
|
8
|
+
const SortableItem = (props) => {
|
|
9
|
+
const { index, items, updateItems } = props;
|
|
10
|
+
const { attributes, listeners, setNodeRef, transform, transition } = useSortable({
|
|
11
|
+
id: props.id
|
|
12
|
+
});
|
|
13
|
+
const style = {
|
|
14
|
+
transform: CSS.Transform.toString(transform),
|
|
15
|
+
transition,
|
|
16
|
+
position: 'relative',
|
|
17
|
+
margin: '0 8px'
|
|
18
|
+
};
|
|
19
|
+
const handleChange = (url) => {
|
|
20
|
+
const newItems = [...items];
|
|
21
|
+
newItems[index].url = url;
|
|
22
|
+
updateItems(newItems);
|
|
23
|
+
};
|
|
24
|
+
return (React.createElement("div", { ref: setNodeRef, style: style },
|
|
25
|
+
React.createElement("div", Object.assign({}, attributes, listeners, { style: {
|
|
26
|
+
position: 'absolute',
|
|
27
|
+
top: '4px',
|
|
28
|
+
left: '4px',
|
|
29
|
+
width: '20px',
|
|
30
|
+
height: '20px',
|
|
31
|
+
background: 'rgba(0,0,0,0.1)',
|
|
32
|
+
borderRadius: '50%',
|
|
33
|
+
cursor: 'grab',
|
|
34
|
+
zIndex: 10,
|
|
35
|
+
display: 'flex',
|
|
36
|
+
alignItems: 'center',
|
|
37
|
+
justifyContent: 'center'
|
|
38
|
+
} }),
|
|
39
|
+
React.createElement(DragOutlined, null)),
|
|
40
|
+
React.createElement(ImgUpload, Object.assign({}, props, { value: props.value, onChange: handleChange }))));
|
|
41
|
+
};
|
|
42
|
+
const MultiPileImgUpload = (props) => {
|
|
43
|
+
const [items, setItems] = useState([]);
|
|
44
|
+
const sensors = useSensors(useSensor(PointerSensor));
|
|
45
|
+
const handleDragEnd = (event) => {
|
|
46
|
+
const { active, over } = event;
|
|
47
|
+
if (active.id !== over.id) {
|
|
48
|
+
const temp = [...items];
|
|
49
|
+
const activeIndex = temp.findIndex((i) => i.id === active.id);
|
|
50
|
+
const overIndex = temp.findIndex((i) => i.id === (over === null || over === void 0 ? void 0 : over.id));
|
|
51
|
+
// 使用arrayMove计算新的排序结果
|
|
52
|
+
const newItems = arrayMove(temp, activeIndex, overIndex);
|
|
53
|
+
updateItems(newItems);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
const updateItems = (newItems) => {
|
|
57
|
+
var _a;
|
|
58
|
+
setItems(newItems);
|
|
59
|
+
props.onChange && ((_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, newItems.map((item) => item.url)));
|
|
60
|
+
};
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
const initItems = Array(props.max)
|
|
63
|
+
.fill(undefined)
|
|
64
|
+
.map((item, i) => ({ id: i + 1, url: '' }));
|
|
65
|
+
if (props.value) {
|
|
66
|
+
const sorts = props.value.map((item, i) => ({ id: i + 1, url: item }));
|
|
67
|
+
const len = initItems.length - sorts.length;
|
|
68
|
+
for (let i = 0; i < len; i++) {
|
|
69
|
+
sorts.push({ id: sorts.length + 1 + i, url: '' });
|
|
70
|
+
}
|
|
71
|
+
setItems(sorts);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
setItems(initItems);
|
|
75
|
+
}
|
|
76
|
+
}, [props.value]);
|
|
77
|
+
return (React.createElement("div", null,
|
|
78
|
+
props.showMessage && (React.createElement(Alert, { className: 'mb20', message: props.message ? props.message : (React.createElement(Space, null,
|
|
79
|
+
React.createElement("div", null,
|
|
80
|
+
props.i18n ? props.i18n.$t("global.size", "大小") : "大小",
|
|
81
|
+
"\uFF1A",
|
|
82
|
+
props.i18n ? props.i18n.$t("global.lt", "小于") : "小于",
|
|
83
|
+
" ",
|
|
84
|
+
props.opts.size || 1,
|
|
85
|
+
"MB;"),
|
|
86
|
+
React.createElement("div", null,
|
|
87
|
+
props.i18n ? props.i18n.$t("global.dimension", "尺寸") : "尺寸",
|
|
88
|
+
"\uFF1A",
|
|
89
|
+
props.opts.w ? `${props.opts.w}px` : "n",
|
|
90
|
+
" * ",
|
|
91
|
+
props.opts.h ? `${props.opts.h}px` : "n",
|
|
92
|
+
";"),
|
|
93
|
+
React.createElement("div", null,
|
|
94
|
+
props.i18n ? props.i18n.$t("global.support", "支持") : "支持",
|
|
95
|
+
"\uFF1Ajpg\u3001jpeg\u3001png",
|
|
96
|
+
props.gif ? "、gif" : "",
|
|
97
|
+
";"))), type: "warning", showIcon: true })),
|
|
98
|
+
React.createElement(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragEnd: handleDragEnd },
|
|
99
|
+
React.createElement(SortableContext, { items: items, strategy: horizontalListSortingStrategy },
|
|
100
|
+
React.createElement(Space, { wrap: true, align: "start" }, items.map((item, index) => (React.createElement(SortableItem, Object.assign({}, props, { index: index, items: items, updateItems: updateItems, value: item.url, key: item.id, id: item.id })))))))));
|
|
101
|
+
};
|
|
102
|
+
MultiPileImgUpload.defaultProps = {
|
|
103
|
+
showMessage: true,
|
|
104
|
+
max: 6,
|
|
105
|
+
action: '/api/upload/img',
|
|
106
|
+
name: 'file',
|
|
107
|
+
gif: false,
|
|
108
|
+
buttonText: '上传图片',
|
|
109
|
+
data: {},
|
|
110
|
+
isTip: false,
|
|
111
|
+
actionParams: {},
|
|
112
|
+
opts: {
|
|
113
|
+
size: 1
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
export default MultiPileImgUpload;
|
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
11
|
-
import { Upload, message, Space } from "antd";
|
|
11
|
+
import { Upload, message, Space, Image as Img } from "antd";
|
|
12
12
|
import { LoadingOutlined, PlusOutlined, DeleteOutlined } from "@ant-design/icons";
|
|
13
13
|
import { buildURL } from "@ecoding/helper.url";
|
|
14
14
|
import Toast from "../../core/toast";
|
|
@@ -119,27 +119,28 @@ const ImgUpload = (props) => {
|
|
|
119
119
|
loading ? React.createElement(LoadingOutlined, null) : React.createElement(PlusOutlined, null),
|
|
120
120
|
React.createElement("div", { style: { marginTop: 8 } }, props.buttonText))), [loading]);
|
|
121
121
|
useEffect(() => {
|
|
122
|
-
if (props.value) {
|
|
122
|
+
if (props.value || props.value == "") {
|
|
123
123
|
setImageUrl(props.value);
|
|
124
124
|
}
|
|
125
125
|
}, [props.value]);
|
|
126
126
|
return (React.createElement(Space, null,
|
|
127
|
-
|
|
127
|
+
imageUrl ? (React.createElement("div", { style: { position: "relative" } },
|
|
128
128
|
React.createElement("span", { style: {
|
|
129
129
|
position: "absolute",
|
|
130
|
-
background: "#fff",
|
|
131
130
|
bottom: "6px",
|
|
132
131
|
right: "2px",
|
|
133
132
|
width: "18px",
|
|
134
133
|
height: "18px",
|
|
135
|
-
opacity: ".9"
|
|
134
|
+
opacity: ".9",
|
|
135
|
+
cursor: "pointer",
|
|
136
|
+
zIndex: 10
|
|
136
137
|
}, onClick: (e) => {
|
|
137
138
|
e.stopPropagation();
|
|
138
139
|
clear();
|
|
139
140
|
} },
|
|
140
141
|
React.createElement(DeleteOutlined, null)),
|
|
141
|
-
React.createElement(
|
|
142
|
-
React.createElement("div", null,
|
|
142
|
+
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)),
|
|
143
|
+
props.isTip ? (React.createElement("div", null,
|
|
143
144
|
React.createElement("p", null,
|
|
144
145
|
props.i18n ? props.i18n.$t("global.size", "大小") : "大小",
|
|
145
146
|
"\uFF1A",
|
|
@@ -156,7 +157,7 @@ const ImgUpload = (props) => {
|
|
|
156
157
|
React.createElement("p", null,
|
|
157
158
|
props.i18n ? props.i18n.$t("global.support", "支持") : "支持",
|
|
158
159
|
"\uFF1Ajpg\u3001jpeg\u3001png",
|
|
159
|
-
props.gif ? "、gif" : ""))));
|
|
160
|
+
props.gif ? "、gif" : ""))) : null));
|
|
160
161
|
};
|
|
161
162
|
ImgUpload.defaultProps = {
|
|
162
163
|
action: "/api/upload/img",
|
|
@@ -165,6 +166,7 @@ ImgUpload.defaultProps = {
|
|
|
165
166
|
gif: false,
|
|
166
167
|
buttonText: '上传图片',
|
|
167
168
|
data: {},
|
|
169
|
+
isTip: true,
|
|
168
170
|
actionParams: {},
|
|
169
171
|
opts: {
|
|
170
172
|
size: 1
|
package/lib/index.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export { default as PhoneInput } from "./core/phone-input";
|
|
|
11
11
|
export { default as RangePicker } from "./core/range-picker";
|
|
12
12
|
export { default as DatePicker } from "./core/date.picker";
|
|
13
13
|
export { default as SingleImgUpload } from "./core/single-img-upload";
|
|
14
|
+
export { default as MultipleSingleImgUpload } from "./core/multiple-single-img-upload";
|
|
14
15
|
export { default as SingleFileUpload } from "./core/single-file-upload";
|
|
15
16
|
export { default as MultipleUpload } from "./core/multiple-upload";
|
|
16
17
|
export { default as FormLabel } from "./core/form.label";
|
package/lib/index.js
CHANGED
|
@@ -11,6 +11,7 @@ export { default as PhoneInput } from "./core/phone-input";
|
|
|
11
11
|
export { default as RangePicker } from "./core/range-picker";
|
|
12
12
|
export { default as DatePicker } from "./core/date.picker";
|
|
13
13
|
export { default as SingleImgUpload } from "./core/single-img-upload";
|
|
14
|
+
export { default as MultipleSingleImgUpload } from "./core/multiple-single-img-upload";
|
|
14
15
|
export { default as SingleFileUpload } from "./core/single-file-upload";
|
|
15
16
|
export { default as MultipleUpload } from "./core/multiple-upload";
|
|
16
17
|
export { default as FormLabel } from "./core/form.label";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoding/components.antd",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.57",
|
|
4
4
|
"author": "cxc",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,14 +34,16 @@
|
|
|
34
34
|
"axios": ">=1.1.2"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
+
"@dnd-kit/core": "^6.3.1",
|
|
38
|
+
"@dnd-kit/sortable": "^10.0.0",
|
|
37
39
|
"@ecoding/helper.event": "*",
|
|
38
40
|
"@ecoding/helper.is": "*",
|
|
39
41
|
"@ecoding/helper.json": "*",
|
|
40
42
|
"@ecoding/helper.request": "*",
|
|
41
43
|
"@ecoding/helper.request.hook": "*",
|
|
42
44
|
"@ecoding/helper.url": "*",
|
|
43
|
-
"antd": "
|
|
45
|
+
"antd": "5.27.0",
|
|
44
46
|
"axios": "^1.1.2"
|
|
45
47
|
},
|
|
46
|
-
"gitHead": "
|
|
48
|
+
"gitHead": "2a522cbf03eb8695fb6abf0d8df807743fd7fdd9"
|
|
47
49
|
}
|