fan-standard-comp 3.2.2 → 3.2.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/Readme.md +3 -1
- package/dist/fan-standard-comp.umd.js +33 -11
- package/es/FormComp/FieldComponent/index.js +4 -3
- package/es/FormComp/Uploader/index.d.ts +6 -1
- package/es/FormComp/Uploader/index.js +172 -127
- package/es/ImageGallery/PreviewStyles/ImagePreview.less +5 -2
- package/lib/FormComp/FieldComponent/index.js +3 -2
- package/lib/FormComp/Uploader/index.d.ts +6 -1
- package/lib/FormComp/Uploader/index.js +171 -126
- package/lib/ImageGallery/PreviewStyles/ImagePreview.less +5 -2
- package/package.json +3 -2
|
@@ -28,7 +28,7 @@ import React, { useContext } from "react";
|
|
|
28
28
|
import Uploader from '../Uploader';
|
|
29
29
|
import SpecIcon from '../../SpecIcon';
|
|
30
30
|
import RefactorTreeSelect from './RefactorTreeSelect.js';
|
|
31
|
-
import { setSelectValue,
|
|
31
|
+
import { setSelectValue, setDatePickerValue, setTimePickerValue, setCascaderValue } from './setReadonlyValues.js';
|
|
32
32
|
import TitleNode from './TitleNode';
|
|
33
33
|
import ReUpload from './ReUpload';
|
|
34
34
|
import { FanContext } from '../../ConfigContext';
|
|
@@ -327,10 +327,11 @@ var FieldComponent = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
327
327
|
}), " \u70B9\u51FB\u4E0A\u4F20")));
|
|
328
328
|
break;
|
|
329
329
|
case 'uploader':
|
|
330
|
-
compContent = viewOnly ? setUploaderValue(value) :
|
|
330
|
+
// compContent = viewOnly ? setUploaderValue(value) : <Uploader {...defaultProps} size={protoConfig?.size}/>
|
|
331
|
+
compContent = /*#__PURE__*/React.createElement(Uploader, Object.assign({}, defaultProps, {
|
|
332
|
+
viewOnly: viewOnly,
|
|
331
333
|
size: protoConfig === null || protoConfig === void 0 ? void 0 : protoConfig.size
|
|
332
334
|
}));
|
|
333
|
-
// compContent = <Uploader {...defaultProps}></Uploader>
|
|
334
335
|
break;
|
|
335
336
|
case 'cascader':
|
|
336
337
|
compContent = viewOnly ? setCascaderValue(value, {
|
|
@@ -8,7 +8,10 @@ interface UploaderProps {
|
|
|
8
8
|
className?: string;
|
|
9
9
|
isOnly?: boolean;
|
|
10
10
|
children?: React.ReactNode;
|
|
11
|
-
onChange?: (file?: any
|
|
11
|
+
onChange?: (file?: any, defaultFile?: {
|
|
12
|
+
file: any;
|
|
13
|
+
fileList: any[];
|
|
14
|
+
}) => void;
|
|
12
15
|
value?: any;
|
|
13
16
|
size?: number;
|
|
14
17
|
modalSize?: string;
|
|
@@ -17,6 +20,8 @@ interface UploaderProps {
|
|
|
17
20
|
limit?: number;
|
|
18
21
|
modalConfig?: any;
|
|
19
22
|
modalZIndex?: number;
|
|
23
|
+
crop?: boolean;
|
|
24
|
+
cropConfig?: any;
|
|
20
25
|
[k: string]: any;
|
|
21
26
|
}
|
|
22
27
|
declare const Uploader: React.ForwardRefExoticComponent<Omit<UploaderProps, "ref"> & React.RefAttributes<unknown>>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
-
import "antd/es/upload/style";
|
|
3
|
-
import _Upload from "antd/es/upload";
|
|
4
2
|
import "antd/es/button/style";
|
|
5
3
|
import _Button from "antd/es/button";
|
|
4
|
+
import "antd/es/upload/style";
|
|
5
|
+
import _Upload from "antd/es/upload";
|
|
6
6
|
import "antd/es/message/style";
|
|
7
7
|
import _message from "antd/es/message";
|
|
8
8
|
function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
@@ -16,7 +16,7 @@ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r)
|
|
|
16
16
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
17
17
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
18
18
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
19
|
-
import { __awaiter } from "tslib";
|
|
19
|
+
import { __awaiter, __rest } from "tslib";
|
|
20
20
|
/* eslint-disable */
|
|
21
21
|
import React, { useMemo, useState, useCallback, useEffect } from 'react';
|
|
22
22
|
import { PlusOutlined } from '@ant-design/icons';
|
|
@@ -24,6 +24,7 @@ import { getAccept, getBase64 } from "./util";
|
|
|
24
24
|
// import StandardModal from "../../StandardModal";
|
|
25
25
|
import './style/index.less';
|
|
26
26
|
import ImagePreview from '../../ImageGallery/ImagePreview';
|
|
27
|
+
import ImgCrop from 'antd-img-crop';
|
|
27
28
|
var Uploader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
28
29
|
var accept = props.accept,
|
|
29
30
|
extraExt = props.extraExt,
|
|
@@ -37,7 +38,12 @@ var Uploader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
37
38
|
size = _props$size === void 0 ? 2 * 1024 * 1024 : _props$size,
|
|
38
39
|
onPreview = props.onPreview,
|
|
39
40
|
beforeUpload = props.beforeUpload,
|
|
40
|
-
limit = props.limit
|
|
41
|
+
limit = props.limit,
|
|
42
|
+
maxCount = props.maxCount,
|
|
43
|
+
viewOnly = props.viewOnly,
|
|
44
|
+
crop = props.crop,
|
|
45
|
+
cropConfig = props.cropConfig,
|
|
46
|
+
otherProps = __rest(props, ["accept", "extraExt", "fileType", "className", "isOnly", "children", "onChange", "value", "size", "onPreview", "beforeUpload", "limit", "maxCount", "viewOnly", "crop", "cropConfig"]);
|
|
41
47
|
// 图片预览数据
|
|
42
48
|
// const [showConfig, setShowConfig] = useState({ visible: false, url: '' })
|
|
43
49
|
// 用于展示的缩略图
|
|
@@ -54,6 +60,26 @@ var Uploader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
54
60
|
_useState6 = _slicedToArray(_useState5, 2),
|
|
55
61
|
previewCurrent = _useState6[0],
|
|
56
62
|
setPreviewerCurrent = _useState6[1];
|
|
63
|
+
var _useState7 = useState(null),
|
|
64
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
65
|
+
cropFile = _useState8[0],
|
|
66
|
+
setCropFile = _useState8[1]; // 存储裁剪的图片file信息
|
|
67
|
+
var maxCountLimit = useMemo(function () {
|
|
68
|
+
if (isOnly) {
|
|
69
|
+
return 1;
|
|
70
|
+
}
|
|
71
|
+
return maxCount || limit;
|
|
72
|
+
}, [isOnly, limit, maxCount]);
|
|
73
|
+
var splitAccept = useMemo(function () {
|
|
74
|
+
var res = getAccept(fileType);
|
|
75
|
+
if (extraExt) {
|
|
76
|
+
res = res + ',' + extraExt;
|
|
77
|
+
}
|
|
78
|
+
if (accept) {
|
|
79
|
+
res = res + ',' + accept;
|
|
80
|
+
}
|
|
81
|
+
return res;
|
|
82
|
+
}, [fileType, extraExt]);
|
|
57
83
|
useEffect(function () {
|
|
58
84
|
if (!value) {
|
|
59
85
|
setUploaderFileList([]);
|
|
@@ -68,7 +94,7 @@ var Uploader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
68
94
|
file.uid = file.uid || "".concat(S4(), "-").concat(S4());
|
|
69
95
|
file.url = file.downloadUrl || file.url;
|
|
70
96
|
file.status = 'done';
|
|
71
|
-
file.previewUrl = file.downloadUrl || file.url; // 给预览地址
|
|
97
|
+
file.previewUrl = file.previewUrl || file.downloadUrl || file.url; // 给预览地址
|
|
72
98
|
return file;
|
|
73
99
|
}));
|
|
74
100
|
return;
|
|
@@ -79,7 +105,7 @@ var Uploader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
79
105
|
uid: "".concat(S4(), "-").concat(S4()),
|
|
80
106
|
url: value.downloadUrl || value.url,
|
|
81
107
|
status: 'done',
|
|
82
|
-
previewUrl: value.downloadUrl || value.url
|
|
108
|
+
previewUrl: value.previewUrl || value.downloadUrl || value.url
|
|
83
109
|
}, value)]);
|
|
84
110
|
/* eslint-enable no-multi-spaces */
|
|
85
111
|
return;
|
|
@@ -95,16 +121,6 @@ var Uploader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
95
121
|
return;
|
|
96
122
|
}
|
|
97
123
|
}, [value]);
|
|
98
|
-
var splitAccept = useMemo(function () {
|
|
99
|
-
var res = getAccept(fileType);
|
|
100
|
-
if (extraExt) {
|
|
101
|
-
res = res + ',' + extraExt;
|
|
102
|
-
}
|
|
103
|
-
if (accept) {
|
|
104
|
-
res = res + ',' + accept;
|
|
105
|
-
}
|
|
106
|
-
return res;
|
|
107
|
-
}, [fileType, extraExt]);
|
|
108
124
|
// 点击文件链接或预览图标时的回调
|
|
109
125
|
var handlePreview = useCallback(function (file, files) {
|
|
110
126
|
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
@@ -112,10 +128,10 @@ var Uploader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
112
128
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
113
129
|
while (1) switch (_context.prev = _context.next) {
|
|
114
130
|
case 0:
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
pList =
|
|
131
|
+
// 方式一:直接全部转换成base64后再打开预览(问题:会出现时间过长)
|
|
132
|
+
// const pList: any = await fileListPreviewer([...files])
|
|
133
|
+
// 方式三:上传时已经转换过
|
|
134
|
+
pList = _toConsumableArray(files);
|
|
119
135
|
setUploaderFileList(pList);
|
|
120
136
|
setPreviewerCurrent(pList.findIndex(function (item) {
|
|
121
137
|
return item.uid === file.uid;
|
|
@@ -149,7 +165,7 @@ var Uploader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
149
165
|
// console.log('file', file.uid)
|
|
150
166
|
// const previewItem = pList.find((item: FileTypeProps) => item.uid === file.uid)
|
|
151
167
|
// setShowConfig({ visible: true, url: previewItem.previewUrl })
|
|
152
|
-
case
|
|
168
|
+
case 4:
|
|
153
169
|
case "end":
|
|
154
170
|
return _context.stop();
|
|
155
171
|
}
|
|
@@ -157,17 +173,17 @@ var Uploader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
157
173
|
}));
|
|
158
174
|
}, []);
|
|
159
175
|
// 检查文件是否规范
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
}, [fileType, size])
|
|
176
|
+
// const handleCheck = useCallback((file: any) => {
|
|
177
|
+
// const isLtSize = file.size < size;
|
|
178
|
+
// if (!isLtSize) {
|
|
179
|
+
// message.error(`文件大小不能超过${Math.round(((size / 1024) / 1024) * 100) / 100}MB!`);
|
|
180
|
+
// return false;
|
|
181
|
+
// }
|
|
182
|
+
// return true;
|
|
183
|
+
// }, [fileType, size])
|
|
168
184
|
var handleChange = useCallback(function (res) {
|
|
169
185
|
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
170
|
-
var
|
|
186
|
+
var result, fileRes, matchAddIndex, matchAdd;
|
|
171
187
|
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
172
188
|
while (1) switch (_context2.prev = _context2.next) {
|
|
173
189
|
case 0:
|
|
@@ -176,99 +192,123 @@ var Uploader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
176
192
|
break;
|
|
177
193
|
}
|
|
178
194
|
setUploaderFileList(res.fileList);
|
|
179
|
-
onChange && onChange(isOnly ? res.fileList[0] && res.fileList[0].originFileObj : res.fileList)
|
|
195
|
+
// onChange && onChange(isOnly ? res.fileList[0] && res.fileList[0].originFileObj : res.fileList)
|
|
196
|
+
onChange && onChange(res.fileList, res);
|
|
180
197
|
return _context2.abrupt("return");
|
|
181
198
|
case 4:
|
|
182
|
-
|
|
183
|
-
if (
|
|
184
|
-
|
|
185
|
-
if (!file.previewUrl) {
|
|
186
|
-
console.log('无预览URL', file);
|
|
187
|
-
}
|
|
188
|
-
// if (!file.url) {
|
|
189
|
-
// file.url = file.thumbUrl
|
|
190
|
-
// }
|
|
191
|
-
return file;
|
|
192
|
-
}); // const previewUrls = ( res.fileList || []).map((item: any) => {
|
|
193
|
-
// return getPreviewInfo(item)
|
|
194
|
-
// });
|
|
195
|
-
// let resultList = await Promise.all(previewUrls).catch((err) => {
|
|
196
|
-
// console.log('Promise.all==>转换base64失败', err)
|
|
197
|
-
// })
|
|
198
|
-
result = _toConsumableArray(list || []);
|
|
199
|
-
setUploaderFileList(result);
|
|
200
|
-
onChange && onChange(isOnly ? result[0] && result[0].originFileObj : result);
|
|
199
|
+
result = []; // 裁剪模式下,把裁剪后的文件信息传过来
|
|
200
|
+
if (crop && cropFile) {
|
|
201
|
+
res.file = cropFile;
|
|
201
202
|
}
|
|
202
|
-
|
|
203
|
+
_context2.next = 8;
|
|
204
|
+
return getBase64(res.file);
|
|
205
|
+
case 8:
|
|
206
|
+
fileRes = _context2.sent;
|
|
207
|
+
matchAddIndex = res.fileList.findIndex(function (item) {
|
|
208
|
+
return item.uid === res.file.uid;
|
|
209
|
+
});
|
|
210
|
+
matchAdd = res.fileList[matchAddIndex];
|
|
211
|
+
matchAdd.previewUrl = fileRes === null || fileRes === void 0 ? void 0 : fileRes.url; // 预览URL
|
|
212
|
+
if (crop && cropFile) {
|
|
213
|
+
// 将当前裁剪后的文件传出来
|
|
214
|
+
matchAdd.originFileObj = res.file;
|
|
215
|
+
matchAdd.size = res.file.size;
|
|
216
|
+
matchAdd.lastModified = res.file.lastModified;
|
|
217
|
+
matchAdd.lastModifiedDate = res.file.lastModifiedDate;
|
|
218
|
+
}
|
|
219
|
+
res.fileList.splice(matchAddIndex, 1, matchAdd);
|
|
220
|
+
result = _toConsumableArray(res.fileList || []);
|
|
221
|
+
setUploaderFileList(result);
|
|
222
|
+
setCropFile(null);
|
|
223
|
+
onChange && onChange(isOnly ? result[0] && result[0].originFileObj : result, res);
|
|
224
|
+
// const isOk = handleCheck(res.file)
|
|
225
|
+
// if (isOk) {
|
|
226
|
+
// let result: any = []
|
|
227
|
+
// const fileRes = await getBase64(res.file)
|
|
228
|
+
// const matchAddIndex = res.fileList.findIndex((item: any) => item.uid === res.file.uid)
|
|
229
|
+
// const matchAdd = res.fileList[matchAddIndex]
|
|
230
|
+
// console.log('matchAdd', matchAdd, maxCountLimit)
|
|
231
|
+
// matchAdd.previewUrl = fileRes?.url
|
|
232
|
+
// res.fileList.splice(matchAddIndex, 1, matchAdd)
|
|
233
|
+
// result = [...(res.fileList || [])]
|
|
234
|
+
// setUploaderFileList(result)
|
|
235
|
+
// onChange && onChange(isOnly ? result[0] && result[0].originFileObj : result, res)
|
|
236
|
+
// }
|
|
237
|
+
case 18:
|
|
203
238
|
case "end":
|
|
204
239
|
return _context2.stop();
|
|
205
240
|
}
|
|
206
241
|
}, _callee2);
|
|
207
242
|
}));
|
|
208
|
-
}, [isOnly,
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
return _context3.stop();
|
|
241
|
-
}
|
|
242
|
-
}, _callee3);
|
|
243
|
-
}));
|
|
244
|
-
});
|
|
243
|
+
}, [isOnly, uploaderFileList, maxCountLimit, crop, cropFile]);
|
|
244
|
+
//
|
|
245
|
+
// const getPreviewInfo = (file: any) => {
|
|
246
|
+
// return new Promise(async (resolve, reject) => {
|
|
247
|
+
// if (!file.url && !file.previewUrl) {
|
|
248
|
+
// const res = await getBase64(file.originFileObj);
|
|
249
|
+
// if (res && res.status === 'success') {
|
|
250
|
+
// file.previewUrl = res.url;
|
|
251
|
+
// }
|
|
252
|
+
// // console.log('转换成功', file)
|
|
253
|
+
// resolve({ ...file })
|
|
254
|
+
// } else {
|
|
255
|
+
// if (!file.previewUrl) {
|
|
256
|
+
// file.previewUrl = file.url
|
|
257
|
+
// }
|
|
258
|
+
// // 已经转换过,无需再转换
|
|
259
|
+
// // console.log('已经转换过,无需再转换', file)
|
|
260
|
+
// resolve({ ...file })
|
|
261
|
+
// }
|
|
262
|
+
// })
|
|
263
|
+
// }
|
|
264
|
+
// const fileListPreviewer = async (files?: any) => {
|
|
265
|
+
// const previewUrls = (files || []).map((item: any) => {
|
|
266
|
+
// return getPreviewInfo(item)
|
|
267
|
+
// });
|
|
268
|
+
// let resultList = await Promise.all(previewUrls).catch((err) => {
|
|
269
|
+
// console.log('Promise.all==>转换base64失败', err)
|
|
270
|
+
// });
|
|
271
|
+
// return resultList
|
|
272
|
+
// }
|
|
273
|
+
var handleClose = function handleClose() {
|
|
274
|
+
setShowPreview(false);
|
|
245
275
|
};
|
|
246
|
-
var
|
|
247
|
-
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
248
|
-
var
|
|
249
|
-
return _regeneratorRuntime().wrap(function
|
|
250
|
-
while (1) switch (
|
|
276
|
+
var handleBeforeUpload = useCallback(function (file) {
|
|
277
|
+
return __awaiter(void 0, void 0, void 0, /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
278
|
+
var isLtSize;
|
|
279
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
280
|
+
while (1) switch (_context3.prev = _context3.next) {
|
|
251
281
|
case 0:
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
282
|
+
//限制图片 格式、size、分辨率
|
|
283
|
+
// const isJPG = file.type === 'image/jpeg';
|
|
284
|
+
// const isJPEG = file.type === 'image/jpeg';
|
|
285
|
+
// const isGIF = file.type === 'image/gif';
|
|
286
|
+
// const isPNG = file.type === 'image/png';
|
|
287
|
+
// if (!(isJPG || isJPEG || isGIF || isPNG)) {
|
|
288
|
+
// message.error("上传图片的格式不正确,不是JPG、JPEG、GIF、PNG");
|
|
289
|
+
// return false;
|
|
290
|
+
// }
|
|
291
|
+
isLtSize = file.size < size;
|
|
292
|
+
if (isLtSize) {
|
|
293
|
+
_context3.next = 4;
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
_message.error("\u6587\u4EF6\u5927\u5C0F\u4E0D\u80FD\u8D85\u8FC7".concat(Math.round(size / 1024 / 1024 * 100) / 100, "MB!"));
|
|
297
|
+
// 如果直接返回false或者true,还是会触发额外的onChange,所以需要改成 Upload.LIST_IGNORE
|
|
298
|
+
return _context3.abrupt("return", _Upload.LIST_IGNORE);
|
|
299
|
+
case 4:
|
|
300
|
+
// 存储裁剪后的文件信息(只有fileType=image,且在单选情况下才可以)
|
|
301
|
+
if (crop && fileType === 'image') {
|
|
302
|
+
setCropFile(file);
|
|
303
|
+
}
|
|
304
|
+
return _context3.abrupt("return", false);
|
|
305
|
+
case 6:
|
|
263
306
|
case "end":
|
|
264
|
-
return
|
|
307
|
+
return _context3.stop();
|
|
265
308
|
}
|
|
266
|
-
},
|
|
309
|
+
}, _callee3);
|
|
267
310
|
}));
|
|
268
|
-
};
|
|
269
|
-
var handleClose = function handleClose() {
|
|
270
|
-
setShowPreview(false);
|
|
271
|
-
};
|
|
311
|
+
}, [fileType, size, crop]);
|
|
272
312
|
// 渲染预览窗口
|
|
273
313
|
/* const renderPreviewComponent = useMemo(
|
|
274
314
|
() => {
|
|
@@ -291,7 +331,7 @@ var Uploader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
291
331
|
)*/
|
|
292
332
|
var renderChildrenComponent = useMemo(function () {
|
|
293
333
|
var renderButton = function renderButton() {
|
|
294
|
-
if (fileType === 'image' || fileType === 'svg') {
|
|
334
|
+
if (fileType === 'image' || fileType === 'svg' || fileType === 'video') {
|
|
295
335
|
return /*#__PURE__*/React.createElement("div", {
|
|
296
336
|
className: 'spec-uploader-control'
|
|
297
337
|
}, /*#__PURE__*/React.createElement(PlusOutlined, null), /*#__PURE__*/React.createElement("div", {
|
|
@@ -302,28 +342,33 @@ var Uploader = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
302
342
|
className: 'spec-uploader-button'
|
|
303
343
|
}, /*#__PURE__*/React.createElement(PlusOutlined, null), "\u70B9\u51FB\u9009\u62E9");
|
|
304
344
|
};
|
|
305
|
-
if (
|
|
345
|
+
if (maxCountLimit && uploaderFileList.length === maxCountLimit) {
|
|
306
346
|
return null;
|
|
307
347
|
}
|
|
308
348
|
if (children) {
|
|
309
349
|
return /*#__PURE__*/React.createElement(React.Fragment, null, " ", children, " ");
|
|
310
350
|
}
|
|
311
351
|
return /*#__PURE__*/React.createElement(React.Fragment, null, renderButton());
|
|
312
|
-
}, [fileType,
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
352
|
+
}, [fileType, children, uploaderFileList, maxCountLimit]);
|
|
353
|
+
var RenderUpload = function RenderUpload() {
|
|
354
|
+
return /*#__PURE__*/React.createElement(_Upload, Object.assign({}, otherProps, {
|
|
355
|
+
disabled: otherProps.disabled || viewOnly,
|
|
356
|
+
maxCount: maxCountLimit,
|
|
357
|
+
ref: ref,
|
|
358
|
+
accept: splitAccept,
|
|
359
|
+
fileList: uploaderFileList,
|
|
360
|
+
listType: fileType === 'image' || fileType === 'svg' ? 'picture-card' : 'text',
|
|
361
|
+
className: "spec-uploader ".concat(className),
|
|
362
|
+
onPreview: onPreview ? onPreview : fileType === 'image' || fileType === 'svg' ? function (file) {
|
|
363
|
+
return handlePreview(file, uploaderFileList);
|
|
364
|
+
} : function () {},
|
|
365
|
+
beforeUpload: beforeUpload ? beforeUpload : handleBeforeUpload,
|
|
366
|
+
onChange: handleChange
|
|
367
|
+
}), viewOnly ? null : renderChildrenComponent);
|
|
368
|
+
};
|
|
369
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null,
|
|
370
|
+
// multiple 情况下不可用
|
|
371
|
+
!(otherProps === null || otherProps === void 0 ? void 0 : otherProps.multiple) && fileType === 'image' && crop ? /*#__PURE__*/React.createElement(ImgCrop, Object.assign({}, cropConfig || {}), RenderUpload()) : RenderUpload(), (fileType === 'image' || fileType === 'svg') && showPreview && /*#__PURE__*/React.createElement(ImagePreview, {
|
|
327
372
|
hasThumbnail: true,
|
|
328
373
|
open: showPreview,
|
|
329
374
|
onClose: handleClose,
|
|
@@ -28,12 +28,14 @@
|
|
|
28
28
|
|
|
29
29
|
.spec-image-preview-next,
|
|
30
30
|
.spec-image-preview-prev {
|
|
31
|
-
background-color: rgba(
|
|
31
|
+
background-color: rgba(255, 255, 255, 0.25);
|
|
32
32
|
border-radius: 2px;
|
|
33
33
|
color: #999;
|
|
34
|
+
//color: #333;
|
|
34
35
|
cursor: pointer;
|
|
35
36
|
display: block;
|
|
36
|
-
font-size: 22px;
|
|
37
|
+
//font-size: 22px;
|
|
38
|
+
font-size: 30px;
|
|
37
39
|
margin-top: -10px;
|
|
38
40
|
padding: 8px 10px 9px;
|
|
39
41
|
position: absolute;
|
|
@@ -51,6 +53,7 @@
|
|
|
51
53
|
|
|
52
54
|
.spec-image-preview-next:hover:not(.disabled),
|
|
53
55
|
.spec-image-preview-prev:hover:not(.disabled) {
|
|
56
|
+
background-color: rgba(255, 255, 255, 0.45);
|
|
54
57
|
color: #fff;
|
|
55
58
|
}
|
|
56
59
|
|
|
@@ -337,10 +337,11 @@ var FieldComponent = /*#__PURE__*/_react.default.forwardRef(function (props, ref
|
|
|
337
337
|
}), " \u70B9\u51FB\u4E0A\u4F20")));
|
|
338
338
|
break;
|
|
339
339
|
case 'uploader':
|
|
340
|
-
compContent = viewOnly ?
|
|
340
|
+
// compContent = viewOnly ? setUploaderValue(value) : <Uploader {...defaultProps} size={protoConfig?.size}/>
|
|
341
|
+
compContent = /*#__PURE__*/_react.default.createElement(_Uploader.default, Object.assign({}, defaultProps, {
|
|
342
|
+
viewOnly: viewOnly,
|
|
341
343
|
size: protoConfig === null || protoConfig === void 0 ? void 0 : protoConfig.size
|
|
342
344
|
}));
|
|
343
|
-
// compContent = <Uploader {...defaultProps}></Uploader>
|
|
344
345
|
break;
|
|
345
346
|
case 'cascader':
|
|
346
347
|
compContent = viewOnly ? (0, _setReadonlyValues.setCascaderValue)(value, {
|
|
@@ -8,7 +8,10 @@ interface UploaderProps {
|
|
|
8
8
|
className?: string;
|
|
9
9
|
isOnly?: boolean;
|
|
10
10
|
children?: React.ReactNode;
|
|
11
|
-
onChange?: (file?: any
|
|
11
|
+
onChange?: (file?: any, defaultFile?: {
|
|
12
|
+
file: any;
|
|
13
|
+
fileList: any[];
|
|
14
|
+
}) => void;
|
|
12
15
|
value?: any;
|
|
13
16
|
size?: number;
|
|
14
17
|
modalSize?: string;
|
|
@@ -17,6 +20,8 @@ interface UploaderProps {
|
|
|
17
20
|
limit?: number;
|
|
18
21
|
modalConfig?: any;
|
|
19
22
|
modalZIndex?: number;
|
|
23
|
+
crop?: boolean;
|
|
24
|
+
cropConfig?: any;
|
|
20
25
|
[k: string]: any;
|
|
21
26
|
}
|
|
22
27
|
declare const Uploader: React.ForwardRefExoticComponent<Omit<UploaderProps, "ref"> & React.RefAttributes<unknown>>;
|