@ecoding/components.antd 0.2.37 → 0.3.0
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-upload/index.js +3 -7
- package/lib/core/single-file-upload/index.js +3 -7
- package/lib/core/single-img-upload/index.js +3 -7
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/package.json +15 -16
- package/lib/core/quill/index.d.ts +0 -13
- package/lib/core/quill/index.js +0 -137
|
@@ -13,7 +13,6 @@ import { UploadOutlined, LinkOutlined, DeleteOutlined, EllipsisOutlined } from '
|
|
|
13
13
|
import { buildURL } from '@ecoding/helper.url';
|
|
14
14
|
import Toast from "../../core/toast";
|
|
15
15
|
import Loading from "../../core/loading";
|
|
16
|
-
import http from "../../helpers/http";
|
|
17
16
|
const InfosRender = ({ infos, setInfos }) => {
|
|
18
17
|
const remove = (i) => {
|
|
19
18
|
const temp = infos.concat([]);
|
|
@@ -41,15 +40,12 @@ const SingleFileUpload = (props) => {
|
|
|
41
40
|
const [infos, setInfos] = useState([]);
|
|
42
41
|
const [open, setOpen] = useState(undefined);
|
|
43
42
|
const timeout = useRef();
|
|
44
|
-
const r = http.getRequest();
|
|
45
43
|
const action = useMemo(() => {
|
|
46
44
|
if (typeof props.action === "string") {
|
|
47
|
-
return
|
|
48
|
-
? buildURL(props.action, props.actionParams)
|
|
49
|
-
: buildURL(`${r.domain}${props.action}`, props.actionParams);
|
|
45
|
+
return buildURL(props.action, props.actionParams);
|
|
50
46
|
}
|
|
51
|
-
return props.action();
|
|
52
|
-
}, [props.actionParams]);
|
|
47
|
+
return buildURL(props.action(), props.actionParams);
|
|
48
|
+
}, [props.actionParams, props.action]);
|
|
53
49
|
const handleChange = (info, type) => {
|
|
54
50
|
var _a, _b;
|
|
55
51
|
switch (info.file.status) {
|
|
@@ -12,18 +12,14 @@ import { Upload, message, Button, Input, Space } from "antd";
|
|
|
12
12
|
import { UploadOutlined } from "@ant-design/icons";
|
|
13
13
|
import { buildURL } from "@ecoding/helper.url";
|
|
14
14
|
import Toast from "../../core/toast";
|
|
15
|
-
import http from "../../helpers/http";
|
|
16
15
|
const SingleFileUpload = (props) => {
|
|
17
|
-
const r = http.getRequest();
|
|
18
16
|
const [fileUrl, setFileUrl] = useState('');
|
|
19
17
|
const action = useMemo(() => {
|
|
20
18
|
if (typeof props.action === "string") {
|
|
21
|
-
return
|
|
22
|
-
? buildURL(props.action, props.actionParams)
|
|
23
|
-
: buildURL(`${r.domain}${props.action}`, props.actionParams);
|
|
19
|
+
return buildURL(props.action, props.actionParams);
|
|
24
20
|
}
|
|
25
|
-
return props.action();
|
|
26
|
-
}, [props.actionParams]);
|
|
21
|
+
return buildURL(props.action(), props.actionParams);
|
|
22
|
+
}, [props.actionParams, props.action]);
|
|
27
23
|
const handleChange = (info) => {
|
|
28
24
|
// props.onChange && props.onChange(info.file);
|
|
29
25
|
switch (info.file.status) {
|
|
@@ -12,19 +12,15 @@ import { Upload, message, Space } 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";
|
|
15
|
-
import http from "../../helpers/http";
|
|
16
15
|
const ImgUpload = (props) => {
|
|
17
|
-
const r = http.getRequest();
|
|
18
16
|
const [loading, setLoading] = useState(false);
|
|
19
17
|
const [imageUrl, setImageUrl] = useState(props.value || "");
|
|
20
18
|
const action = useMemo(() => {
|
|
21
19
|
if (typeof props.action === "string") {
|
|
22
|
-
return
|
|
23
|
-
? buildURL(props.action, props.actionParams)
|
|
24
|
-
: buildURL(`${r.domain}${props.action}`, props.actionParams);
|
|
20
|
+
return buildURL(props.action, props.actionParams);
|
|
25
21
|
}
|
|
26
|
-
return props.action();
|
|
27
|
-
}, [props.actionParams]);
|
|
22
|
+
return buildURL(props.action(), props.actionParams);
|
|
23
|
+
}, [props.actionParams, props.action]);
|
|
28
24
|
const getBase64 = useCallback((imgFile) => {
|
|
29
25
|
return new Promise((resolve) => {
|
|
30
26
|
const reader = new FileReader();
|
package/lib/index.d.ts
CHANGED
|
@@ -18,5 +18,4 @@ export { default as FormList } from "./core/form.list";
|
|
|
18
18
|
export { default as AsyncSelect } from "./core/async-select";
|
|
19
19
|
export { default as AsyncTransfer } from "./core/async-transfer";
|
|
20
20
|
export { default as TablePro } from "./core/table-pro";
|
|
21
|
-
export { default as Quill } from "./core/quill";
|
|
22
21
|
export { default as http } from "./helpers/http";
|
package/lib/index.js
CHANGED
|
@@ -18,5 +18,4 @@ export { default as FormList } from "./core/form.list";
|
|
|
18
18
|
export { default as AsyncSelect } from "./core/async-select";
|
|
19
19
|
export { default as AsyncTransfer } from "./core/async-transfer";
|
|
20
20
|
export { default as TablePro } from "./core/table-pro";
|
|
21
|
-
export { default as Quill } from "./core/quill";
|
|
22
21
|
export { default as http } from "./helpers/http";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ecoding/components.antd",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"author": "cxc",
|
|
5
5
|
"homepage": "",
|
|
6
6
|
"license": "MIT",
|
|
@@ -24,25 +24,24 @@
|
|
|
24
24
|
"build": "rm -rf lib && tsc"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
27
|
-
"@ecoding/helper.event": "
|
|
28
|
-
"@ecoding/helper.is": "
|
|
29
|
-
"@ecoding/helper.json": "
|
|
30
|
-
"@ecoding/helper.request
|
|
31
|
-
"@ecoding/helper.
|
|
32
|
-
"
|
|
27
|
+
"@ecoding/helper.event": "*",
|
|
28
|
+
"@ecoding/helper.is": "*",
|
|
29
|
+
"@ecoding/helper.json": "*",
|
|
30
|
+
"@ecoding/helper.request": "*",
|
|
31
|
+
"@ecoding/helper.request.hook": "*",
|
|
32
|
+
"@ecoding/helper.url": "*",
|
|
33
|
+
"antd": ">=5.8.4",
|
|
33
34
|
"axios": ">=1.1.2"
|
|
34
35
|
},
|
|
35
36
|
"devDependencies": {
|
|
36
|
-
"@ecoding/helper.event": "
|
|
37
|
-
"@ecoding/helper.is": "
|
|
38
|
-
"@ecoding/helper.json": "
|
|
39
|
-
"@ecoding/helper.request
|
|
40
|
-
"@ecoding/helper.
|
|
37
|
+
"@ecoding/helper.event": "*",
|
|
38
|
+
"@ecoding/helper.is": "*",
|
|
39
|
+
"@ecoding/helper.json": "*",
|
|
40
|
+
"@ecoding/helper.request": "*",
|
|
41
|
+
"@ecoding/helper.request.hook": "*",
|
|
42
|
+
"@ecoding/helper.url": "*",
|
|
41
43
|
"antd": "^5.8.4",
|
|
42
44
|
"axios": "^1.1.2"
|
|
43
45
|
},
|
|
44
|
-
"
|
|
45
|
-
"react-quill": "^2.0.0"
|
|
46
|
-
},
|
|
47
|
-
"gitHead": "4168d23cb6d60d5e7c3e38794d26ea48a5758dbc"
|
|
46
|
+
"gitHead": "4f377d30d902349469ba97c8ee98c49b0d576c4a"
|
|
48
47
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
interface IProps {
|
|
3
|
-
action?: string;
|
|
4
|
-
value?: string;
|
|
5
|
-
className?: string;
|
|
6
|
-
style?: any;
|
|
7
|
-
onChange?: any;
|
|
8
|
-
gif?: boolean;
|
|
9
|
-
size?: number;
|
|
10
|
-
disabled?: boolean;
|
|
11
|
-
}
|
|
12
|
-
declare const Quill: React.FC<IProps>;
|
|
13
|
-
export default Quill;
|
package/lib/core/quill/index.js
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
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
|
-
};
|
|
10
|
-
import React, { useMemo, useCallback, useState, useRef, lazy } from "react";
|
|
11
|
-
import { Upload, message } from "antd";
|
|
12
|
-
import Toast from "../../core/toast";
|
|
13
|
-
import http from "../../helpers/http";
|
|
14
|
-
const ReactQuill = lazy(() => import(/* webpackChunkName: "ReactQuill" */ /* webpackPrefetch: true */ "react-quill"));
|
|
15
|
-
const Quill = (props) => {
|
|
16
|
-
const r = http.getRequest();
|
|
17
|
-
const upRef = useRef();
|
|
18
|
-
const quillRef = useRef();
|
|
19
|
-
const [urlParams, setUrlParams] = useState("");
|
|
20
|
-
const modules = useMemo(() => {
|
|
21
|
-
return {
|
|
22
|
-
toolbar: {
|
|
23
|
-
container: [
|
|
24
|
-
["bold", "italic", "underline", "strike"],
|
|
25
|
-
["blockquote", "code-block"],
|
|
26
|
-
[{ header: 1 }, { header: 2 }],
|
|
27
|
-
[{ list: "ordered" }, { list: "bullet" }],
|
|
28
|
-
[{ script: "sub" }, { script: "super" }],
|
|
29
|
-
[{ indent: "-1" }, { indent: "+1" }],
|
|
30
|
-
[{ direction: "rtl" }],
|
|
31
|
-
[{ size: ["small", false, "large", "huge"] }],
|
|
32
|
-
[{ header: [1, 2, 3, 4, 5, 6, false] }],
|
|
33
|
-
[{ color: [] }, { background: [] }],
|
|
34
|
-
[{ font: [] }],
|
|
35
|
-
[{ align: [] }],
|
|
36
|
-
["link", "image"],
|
|
37
|
-
["clean"]
|
|
38
|
-
],
|
|
39
|
-
handlers: {
|
|
40
|
-
image: (value) => {
|
|
41
|
-
if (value) {
|
|
42
|
-
// ref.current && upRef.current.upload.uploader.uploadFiles([file]);
|
|
43
|
-
upRef.current && upRef.current.upload.uploader.fileInput.click();
|
|
44
|
-
}
|
|
45
|
-
else {
|
|
46
|
-
quillRef.current.format("image", false);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
}, []);
|
|
53
|
-
const getBase64 = useCallback((imgFile) => {
|
|
54
|
-
return new Promise((resolve) => {
|
|
55
|
-
const reader = new FileReader();
|
|
56
|
-
reader.addEventListener("load", () => resolve(reader.result));
|
|
57
|
-
reader.readAsDataURL(imgFile);
|
|
58
|
-
});
|
|
59
|
-
}, []);
|
|
60
|
-
const getImgwh = useCallback((base64) => {
|
|
61
|
-
return new Promise((resolve, reject) => {
|
|
62
|
-
const img = new Image();
|
|
63
|
-
img.onload = () => {
|
|
64
|
-
// 宽度固定
|
|
65
|
-
resolve({
|
|
66
|
-
w: img.width,
|
|
67
|
-
h: img.height
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
img.onerror = () => reject();
|
|
71
|
-
img.src = base64;
|
|
72
|
-
});
|
|
73
|
-
}, []);
|
|
74
|
-
const beforeUpload = useCallback((file) => {
|
|
75
|
-
return new Promise((resolve, reject) => __awaiter(void 0, void 0, void 0, function* () {
|
|
76
|
-
const ary = ["jpg", "jpeg", "png"];
|
|
77
|
-
if (props.gif) {
|
|
78
|
-
ary.push("gif");
|
|
79
|
-
}
|
|
80
|
-
const isLt2M = file.size / 1024 / 1024 < (props.size || 1);
|
|
81
|
-
if (!isLt2M) {
|
|
82
|
-
message.error(`图片大小必须小于${props.size} MB!`);
|
|
83
|
-
reject();
|
|
84
|
-
}
|
|
85
|
-
if (ary.indexOf(file.type.toLowerCase().replace(/image\//g, "")) === -1) {
|
|
86
|
-
message.error(`请上传 ${ary.join(",")} 格式的图片!`);
|
|
87
|
-
reject();
|
|
88
|
-
}
|
|
89
|
-
const base64 = yield getBase64(file);
|
|
90
|
-
const wh = yield getImgwh(base64);
|
|
91
|
-
setUrlParams(`height=${wh.h}`);
|
|
92
|
-
resolve();
|
|
93
|
-
}));
|
|
94
|
-
}, []);
|
|
95
|
-
const handleChange = (info) => {
|
|
96
|
-
switch (info.file.status) {
|
|
97
|
-
case "uploading":
|
|
98
|
-
break;
|
|
99
|
-
case "done":
|
|
100
|
-
const url = info.file.response.data && info.file.response.data[0].imageUrl;
|
|
101
|
-
// setImageUrl(url);
|
|
102
|
-
// 获取富文本组件实例
|
|
103
|
-
const quill = quillRef.current.getEditor();
|
|
104
|
-
// 获取光标所在位置
|
|
105
|
-
const length = quill.getSelection().index;
|
|
106
|
-
// 插入图片,res为服务器返回的图片链接地址
|
|
107
|
-
quill.insertEmbed(length, "image", url);
|
|
108
|
-
// 调整光标到最后
|
|
109
|
-
quill.setSelection(length + 1);
|
|
110
|
-
break;
|
|
111
|
-
case "error":
|
|
112
|
-
Toast.error({
|
|
113
|
-
mask: true,
|
|
114
|
-
title: info.file.response
|
|
115
|
-
? info.file.response.retDesc || info.file.response.desc || info.file.response.message
|
|
116
|
-
: "服务出错,图片上传失败"
|
|
117
|
-
});
|
|
118
|
-
break;
|
|
119
|
-
default:
|
|
120
|
-
break;
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
|
-
const action = /^http|^\/\//i.test(props.action) ? `${props.action}?${urlParams}` : `${r.domain}${props.action}?${urlParams}`;
|
|
124
|
-
return (React.createElement(React.Suspense, { fallback: null },
|
|
125
|
-
React.createElement(ReactQuill, { onChange: props.onChange, defaultValue: props.value, ref: quillRef, modules: modules, theme: "snow", className: props.className, style: props.style }),
|
|
126
|
-
React.createElement("span", { style: { display: "none" } },
|
|
127
|
-
React.createElement(Upload, { ref: upRef, withCredentials: true, beforeUpload: beforeUpload, name: "file", listType: "picture-card", showUploadList: false, action: action, onChange: handleChange }))));
|
|
128
|
-
};
|
|
129
|
-
Quill.defaultProps = {
|
|
130
|
-
action: "/upload/img",
|
|
131
|
-
value: "",
|
|
132
|
-
gif: false,
|
|
133
|
-
size: 1,
|
|
134
|
-
className: "",
|
|
135
|
-
style: {}
|
|
136
|
-
};
|
|
137
|
-
export default Quill;
|