@jzwd/vnd-design 0.0.0-stage → 0.2.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.
Files changed (47) hide show
  1. package/README.md +259 -2
  2. package/dist/file-center/api/endpoints.d.ts +42 -0
  3. package/dist/file-center/api/endpoints.js +45 -0
  4. package/dist/file-center/api/error.d.ts +6 -0
  5. package/dist/file-center/api/error.js +34 -0
  6. package/dist/file-center/api/index.d.ts +64 -0
  7. package/dist/file-center/api/index.js +238 -0
  8. package/dist/file-center/api/request.d.ts +28 -0
  9. package/dist/file-center/api/request.js +170 -0
  10. package/dist/file-center/api/token.d.ts +10 -0
  11. package/dist/file-center/api/token.js +122 -0
  12. package/dist/file-center/components/FcFileList/index.d.ts +39 -0
  13. package/dist/file-center/components/FcFileList/index.js +804 -0
  14. package/dist/file-center/components/FcFileList/style.css +106 -0
  15. package/dist/file-center/components/FcImage/index.d.ts +30 -0
  16. package/dist/file-center/components/FcImage/index.js +144 -0
  17. package/dist/file-center/components/FcImage/style.css +14 -0
  18. package/dist/file-center/components/FcUpload/index.d.ts +5 -0
  19. package/dist/file-center/components/FcUpload/index.js +642 -0
  20. package/dist/file-center/components/FcUpload/interface.d.ts +65 -0
  21. package/dist/file-center/components/FcUpload/interface.js +1 -0
  22. package/dist/file-center/components/FcUpload/style.css +279 -0
  23. package/dist/file-center/context.d.ts +22 -0
  24. package/dist/file-center/context.js +22 -0
  25. package/dist/file-center/index.d.ts +26 -0
  26. package/dist/file-center/index.js +21 -0
  27. package/dist/file-center/types.d.ts +144 -0
  28. package/dist/file-center/types.js +1 -0
  29. package/dist/file-center/upload.d.ts +35 -0
  30. package/dist/file-center/upload.js +295 -0
  31. package/dist/file-center/utils/common.d.ts +10 -0
  32. package/dist/file-center/utils/common.js +165 -0
  33. package/dist/file-center/utils/compress.d.ts +18 -0
  34. package/dist/file-center/utils/compress.js +108 -0
  35. package/dist/file-center/utils/md5.d.ts +5 -0
  36. package/dist/file-center/utils/md5.js +41 -0
  37. package/dist/index.d.ts +11 -0
  38. package/dist/index.js +15 -0
  39. package/dist/mobile/FcImage/index.d.ts +26 -0
  40. package/dist/mobile/FcImage/index.js +114 -0
  41. package/dist/mobile/FcImage/style.css +11 -0
  42. package/dist/mobile/FcUpload/index.d.ts +74 -0
  43. package/dist/mobile/FcUpload/index.js +539 -0
  44. package/dist/mobile/FcUpload/style.css +233 -0
  45. package/dist/mobile/index.d.ts +13 -0
  46. package/dist/mobile/index.js +9 -0
  47. package/package.json +70 -4
@@ -0,0 +1,539 @@
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
+ 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 new 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 new 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 new 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; }
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
5
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
6
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
9
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
12
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
13
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
14
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
15
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
16
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
17
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
18
+ 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; } }
19
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
20
+ import React, { useRef, useState } from 'react';
21
+ import { Checkbox, Dialog, ImageViewer, ProgressBar, Toast } from 'antd-mobile';
22
+ import { AddOutline, DeleteOutline, ExclamationCircleFill, EyeOutline, FileOutline } from 'antd-mobile-icons';
23
+ import { deleteFile } from "../../file-center/api";
24
+ import { uploadFile } from "../../file-center/upload";
25
+ import { resolveFcContext } from "../../file-center/context";
26
+ import { formatFileSize } from "../../file-center/utils/common";
27
+ import "./style.css";
28
+
29
+ /**
30
+ * 移动端 FcUpload 的文件项(不依赖 antd 的 UploadFile 结构)
31
+ */
32
+ import { jsx as _jsx } from "react/jsx-runtime";
33
+ import { jsxs as _jsxs } from "react/jsx-runtime";
34
+ import { Fragment as _Fragment } from "react/jsx-runtime";
35
+ var newUid = function newUid() {
36
+ return "".concat(Date.now(), "-").concat(Math.random().toString(36).slice(2, 8));
37
+ };
38
+
39
+ /** 引用确认弹窗内容:引用清单 + 知晓勾选 */
40
+ function RefConfirmContent(_ref) {
41
+ var references = _ref.references,
42
+ onAckChange = _ref.onAckChange;
43
+ return /*#__PURE__*/_jsxs("div", {
44
+ className: "bcm-fc-upload-refs",
45
+ children: [/*#__PURE__*/_jsx("div", {
46
+ className: "bcm-fc-upload-refs-tip",
47
+ children: "\u8BE5\u6587\u4EF6\u6B63\u88AB\u4EE5\u4E0B\u4E1A\u52A1\u5F15\u7528\uFF0C\u5220\u9664\u540E\u5F15\u7528\u65B9\u5C06\u65E0\u6CD5\u8BBF\u95EE\uFF1A"
48
+ }), /*#__PURE__*/_jsx("ul", {
49
+ className: "bcm-fc-upload-refs-list",
50
+ children: references.map(function (ref) {
51
+ return /*#__PURE__*/_jsxs("li", {
52
+ children: [ref.projectName, ref.bizType ? " / ".concat(ref.bizType) : '', ref.bizId ? "\uFF08".concat(ref.bizId, "\uFF09") : '']
53
+ }, ref.id);
54
+ })
55
+ }), /*#__PURE__*/_jsx(Checkbox, {
56
+ onChange: onAckChange,
57
+ children: "\u6211\u5DF2\u77E5\u6653\u5220\u9664\u5F71\u54CD\uFF0C\u786E\u8BA4\u5220\u9664"
58
+ })]
59
+ });
60
+ }
61
+
62
+ /**
63
+ * 移动端文件中心上传组件(antd-mobile 版)
64
+ * 与 PC 端 FcUpload 共用同一套上传编排(压缩 → MD5 → 秒传 → 分片/普通上传 → 引用登记)
65
+ */
66
+ export default function FcUpload(props) {
67
+ var value = props.value,
68
+ onChange = props.onChange,
69
+ _props$listType = props.listType,
70
+ listType = _props$listType === void 0 ? 'picture-card' : _props$listType,
71
+ maxCount = props.maxCount,
72
+ _props$maxSizeMB = props.maxSizeMB,
73
+ maxSizeMB = _props$maxSizeMB === void 0 ? 50 : _props$maxSizeMB,
74
+ accept = props.accept,
75
+ multiple = props.multiple,
76
+ capture = props.capture,
77
+ disabled = props.disabled,
78
+ compress = props.compress,
79
+ _props$instant = props.instant,
80
+ instant = _props$instant === void 0 ? true : _props$instant,
81
+ _props$deleteOnRemove = props.deleteOnRemove,
82
+ deleteOnRemove = _props$deleteOnRemove === void 0 ? false : _props$deleteOnRemove,
83
+ bizType = props.bizType,
84
+ bizId = props.bizId,
85
+ bizUrl = props.bizUrl,
86
+ onUploadSuccess = props.onUploadSuccess,
87
+ onUploadError = props.onUploadError,
88
+ onPreview = props.onPreview,
89
+ _props$buttonText = props.buttonText,
90
+ buttonText = _props$buttonText === void 0 ? '上传文件' : _props$buttonText,
91
+ className = props.className,
92
+ style = props.style;
93
+ var ctx = resolveFcContext(props);
94
+ var _useState = useState([]),
95
+ _useState2 = _slicedToArray(_useState, 2),
96
+ innerList = _useState2[0],
97
+ setInnerList = _useState2[1];
98
+ var fileList = value !== null && value !== void 0 ? value : innerList;
99
+ var listRef = useRef(fileList);
100
+ listRef.current = fileList;
101
+ var inputRef = useRef(null);
102
+ var abortRef = useRef(new Map());
103
+
104
+ /** 函数式更新:并发上传时避免闭包拿到旧列表 */
105
+ var setList = function setList(updater) {
106
+ var next = updater(listRef.current);
107
+ listRef.current = next;
108
+ if (value === undefined) setInnerList(next);
109
+ onChange === null || onChange === void 0 || onChange(next);
110
+ };
111
+ var patchItem = function patchItem(uid, patch) {
112
+ setList(function (prev) {
113
+ return prev.map(function (item) {
114
+ return item.uid === uid ? _objectSpread(_objectSpread({}, item), patch) : item;
115
+ });
116
+ });
117
+ };
118
+
119
+ /* ---- 选择文件 ---- */
120
+ var handlePick = function handlePick(files) {
121
+ if (!(files !== null && files !== void 0 && files.length)) return;
122
+ var picked = Array.from(files);
123
+ var room = maxCount === undefined ? Infinity : maxCount - fileList.length;
124
+ if (picked.length > room) {
125
+ Toast.show({
126
+ icon: 'fail',
127
+ content: "\u6700\u591A\u4E0A\u4F20 ".concat(maxCount, " \u4E2A\u6587\u4EF6")
128
+ });
129
+ return;
130
+ }
131
+ var items = picked.map(function (file) {
132
+ return {
133
+ uid: newUid(),
134
+ name: file.name,
135
+ size: file.size,
136
+ type: file.type,
137
+ status: 'uploading',
138
+ percent: 0,
139
+ thumbUrl: file.type.startsWith('image/') ? URL.createObjectURL(file) : undefined
140
+ };
141
+ });
142
+ setList(function (prev) {
143
+ return [].concat(_toConsumableArray(prev), _toConsumableArray(items));
144
+ });
145
+ items.forEach(function (item, index) {
146
+ return doUpload(item, picked[index]);
147
+ });
148
+ };
149
+
150
+ /* ---- 上传编排 ---- */
151
+ var doUpload = /*#__PURE__*/function () {
152
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(item, file) {
153
+ var controller, _fileInfo, done, _error;
154
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
155
+ while (1) switch (_context.prev = _context.next) {
156
+ case 0:
157
+ if (!(file.size > maxSizeMB * 1024 * 1024)) {
158
+ _context.next = 5;
159
+ break;
160
+ }
161
+ patchItem(item.uid, {
162
+ status: 'error',
163
+ error: "\u8D85\u8FC7 ".concat(maxSizeMB, "MB \u9650\u5236")
164
+ });
165
+ Toast.show({
166
+ icon: 'fail',
167
+ content: "\u300C".concat(file.name, "\u300D\u8D85\u8FC7 ").concat(maxSizeMB, "MB \u9650\u5236")
168
+ });
169
+ onUploadError === null || onUploadError === void 0 || onUploadError(new Error("\u8D85\u8FC7 ".concat(maxSizeMB, "MB \u9650\u5236")), item);
170
+ return _context.abrupt("return");
171
+ case 5:
172
+ controller = new AbortController();
173
+ abortRef.current.set(item.uid, controller);
174
+ _context.prev = 7;
175
+ _context.next = 10;
176
+ return uploadFile({
177
+ file: file,
178
+ appKey: ctx.appKey,
179
+ baseUrl: ctx.baseUrl,
180
+ getToken: ctx.getToken,
181
+ bizType: bizType,
182
+ bizInfo: bizType && bizId ? {
183
+ bizType: bizType,
184
+ bizId: bizId,
185
+ bizUrl: bizUrl
186
+ } : undefined,
187
+ compress: compress,
188
+ instant: instant,
189
+ signal: controller.signal,
190
+ onProgress: function onProgress(progress) {
191
+ return patchItem(item.uid, {
192
+ percent: progress.percent,
193
+ stage: progress.stage
194
+ });
195
+ }
196
+ });
197
+ case 10:
198
+ _fileInfo = _context.sent;
199
+ done = _objectSpread(_objectSpread({}, item), {}, {
200
+ status: 'done',
201
+ percent: 100,
202
+ fileId: _fileInfo.id,
203
+ fileInfo: _fileInfo
204
+ });
205
+ setList(function (prev) {
206
+ return prev.map(function (it) {
207
+ return it.uid === item.uid ? done : it;
208
+ });
209
+ });
210
+ onUploadSuccess === null || onUploadSuccess === void 0 || onUploadSuccess(_fileInfo, done);
211
+ _context.next = 25;
212
+ break;
213
+ case 16:
214
+ _context.prev = 16;
215
+ _context.t0 = _context["catch"](7);
216
+ _error = _context.t0;
217
+ if (!(_error.name === 'AbortError')) {
218
+ _context.next = 22;
219
+ break;
220
+ }
221
+ setList(function (prev) {
222
+ return prev.filter(function (it) {
223
+ return it.uid !== item.uid;
224
+ });
225
+ });
226
+ return _context.abrupt("return");
227
+ case 22:
228
+ patchItem(item.uid, {
229
+ status: 'error',
230
+ error: _error.message
231
+ });
232
+ Toast.show({
233
+ icon: 'fail',
234
+ content: "\u300C".concat(file.name, "\u300D\u4E0A\u4F20\u5931\u8D25")
235
+ });
236
+ onUploadError === null || onUploadError === void 0 || onUploadError(_error, item);
237
+ case 25:
238
+ _context.prev = 25;
239
+ abortRef.current.delete(item.uid);
240
+ return _context.finish(25);
241
+ case 28:
242
+ case "end":
243
+ return _context.stop();
244
+ }
245
+ }, _callee, null, [[7, 16, 25, 28]]);
246
+ }));
247
+ return function doUpload(_x, _x2) {
248
+ return _ref2.apply(this, arguments);
249
+ };
250
+ }();
251
+
252
+ /* ---- 移除 / 删除 ---- */
253
+ var handleRemove = /*#__PURE__*/function () {
254
+ var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(item) {
255
+ var _abortRef$current$get, result, forceDeleted;
256
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
257
+ while (1) switch (_context3.prev = _context3.next) {
258
+ case 0:
259
+ if (!(item.status === 'uploading')) {
260
+ _context3.next = 3;
261
+ break;
262
+ }
263
+ (_abortRef$current$get = abortRef.current.get(item.uid)) === null || _abortRef$current$get === void 0 || _abortRef$current$get.abort();
264
+ return _context3.abrupt("return");
265
+ case 3:
266
+ if (!(item.status === 'done' && item.fileId && deleteOnRemove)) {
267
+ _context3.next = 20;
268
+ break;
269
+ }
270
+ _context3.prev = 4;
271
+ _context3.next = 7;
272
+ return deleteFile(ctx, item.fileId);
273
+ case 7:
274
+ result = _context3.sent;
275
+ if (!result.needConfirm) {
276
+ _context3.next = 14;
277
+ break;
278
+ }
279
+ _context3.next = 11;
280
+ return new Promise(function (resolve) {
281
+ var _result$references;
282
+ var ack = false;
283
+ var handler = Dialog.show({
284
+ title: '文件被引用',
285
+ content: /*#__PURE__*/_jsx(RefConfirmContent, {
286
+ references: (_result$references = result.references) !== null && _result$references !== void 0 ? _result$references : [],
287
+ onAckChange: function onAckChange(v) {
288
+ ack = v;
289
+ }
290
+ }),
291
+ actions: [{
292
+ key: 'cancel',
293
+ text: '取消',
294
+ onClick: function onClick() {
295
+ handler.close();
296
+ resolve(false);
297
+ }
298
+ }, {
299
+ key: 'confirm',
300
+ text: '删除',
301
+ bold: true,
302
+ danger: true,
303
+ onClick: function () {
304
+ var _onClick = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
305
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
306
+ while (1) switch (_context2.prev = _context2.next) {
307
+ case 0:
308
+ if (ack) {
309
+ _context2.next = 3;
310
+ break;
311
+ }
312
+ Toast.show('请先勾选确认删除影响');
313
+ return _context2.abrupt("return");
314
+ case 3:
315
+ _context2.prev = 3;
316
+ _context2.next = 6;
317
+ return deleteFile(ctx, item.fileId, {
318
+ force: true
319
+ });
320
+ case 6:
321
+ handler.close();
322
+ resolve(true);
323
+ _context2.next = 13;
324
+ break;
325
+ case 10:
326
+ _context2.prev = 10;
327
+ _context2.t0 = _context2["catch"](3);
328
+ Toast.show({
329
+ icon: 'fail',
330
+ content: '删除失败,请重试'
331
+ });
332
+ case 13:
333
+ case "end":
334
+ return _context2.stop();
335
+ }
336
+ }, _callee2, null, [[3, 10]]);
337
+ }));
338
+ function onClick() {
339
+ return _onClick.apply(this, arguments);
340
+ }
341
+ return onClick;
342
+ }()
343
+ }]
344
+ });
345
+ });
346
+ case 11:
347
+ forceDeleted = _context3.sent;
348
+ if (forceDeleted) {
349
+ _context3.next = 14;
350
+ break;
351
+ }
352
+ return _context3.abrupt("return");
353
+ case 14:
354
+ _context3.next = 20;
355
+ break;
356
+ case 16:
357
+ _context3.prev = 16;
358
+ _context3.t0 = _context3["catch"](4);
359
+ Toast.show({
360
+ icon: 'fail',
361
+ content: '删除失败,请重试'
362
+ });
363
+ return _context3.abrupt("return");
364
+ case 20:
365
+ if (item.thumbUrl) URL.revokeObjectURL(item.thumbUrl);
366
+ setList(function (prev) {
367
+ return prev.filter(function (it) {
368
+ return it.uid !== item.uid;
369
+ });
370
+ });
371
+ case 22:
372
+ case "end":
373
+ return _context3.stop();
374
+ }
375
+ }, _callee3, null, [[4, 16]]);
376
+ }));
377
+ return function handleRemove(_x3) {
378
+ return _ref3.apply(this, arguments);
379
+ };
380
+ }();
381
+
382
+ /* ---- 预览 ---- */
383
+ var handlePreview = function handlePreview(item) {
384
+ var _item$type, _item$fileInfo2;
385
+ if (onPreview) {
386
+ onPreview(item);
387
+ return;
388
+ }
389
+ var images = fileList.filter(function (it) {
390
+ var _it$type, _it$fileInfo;
391
+ return ((_it$type = it.type) === null || _it$type === void 0 ? void 0 : _it$type.startsWith('image/')) && (it.thumbUrl || ((_it$fileInfo = it.fileInfo) === null || _it$fileInfo === void 0 ? void 0 : _it$fileInfo.url));
392
+ }).map(function (it) {
393
+ var _it$fileInfo$url, _it$fileInfo2;
394
+ return (_it$fileInfo$url = (_it$fileInfo2 = it.fileInfo) === null || _it$fileInfo2 === void 0 ? void 0 : _it$fileInfo2.url) !== null && _it$fileInfo$url !== void 0 ? _it$fileInfo$url : it.thumbUrl;
395
+ });
396
+ if ((_item$type = item.type) !== null && _item$type !== void 0 && _item$type.startsWith('image/')) {
397
+ var _item$fileInfo$url, _item$fileInfo;
398
+ var current = (_item$fileInfo$url = (_item$fileInfo = item.fileInfo) === null || _item$fileInfo === void 0 ? void 0 : _item$fileInfo.url) !== null && _item$fileInfo$url !== void 0 ? _item$fileInfo$url : item.thumbUrl;
399
+ ImageViewer.Multi.show({
400
+ images: images,
401
+ defaultIndex: Math.max(0, images.indexOf(current))
402
+ });
403
+ } else if ((_item$fileInfo2 = item.fileInfo) !== null && _item$fileInfo2 !== void 0 && _item$fileInfo2.url) {
404
+ window.open(item.fileInfo.url, '_blank');
405
+ }
406
+ };
407
+ var reachedMax = maxCount !== undefined && fileList.length >= maxCount;
408
+ var picker = /*#__PURE__*/_jsx("input", {
409
+ ref: inputRef,
410
+ className: "bcm-fc-upload-input",
411
+ type: "file",
412
+ accept: accept,
413
+ multiple: multiple,
414
+ capture: capture ? 'environment' : undefined,
415
+ disabled: disabled,
416
+ onChange: function onChange(e) {
417
+ handlePick(e.target.files);
418
+ e.target.value = '';
419
+ }
420
+ });
421
+ return /*#__PURE__*/_jsxs("div", {
422
+ className: "bcm-fc-upload bcm-fc-upload-".concat(listType).concat(className ? " ".concat(className) : ''),
423
+ style: style,
424
+ children: [picker, listType === 'picture-card' ? /*#__PURE__*/_jsxs("div", {
425
+ className: "bcm-fc-upload-grid",
426
+ children: [fileList.map(function (item) {
427
+ var _item$fileInfo3, _item$fileInfo$url2, _item$fileInfo4, _item$percent, _item$percent2, _item$error;
428
+ return /*#__PURE__*/_jsxs("div", {
429
+ className: "bcm-fc-upload-tile",
430
+ onClick: function onClick() {
431
+ return item.status === 'done' && handlePreview(item);
432
+ },
433
+ children: [item.thumbUrl || (_item$fileInfo3 = item.fileInfo) !== null && _item$fileInfo3 !== void 0 && _item$fileInfo3.url ? /*#__PURE__*/_jsx("img", {
434
+ className: "bcm-fc-upload-tile-img",
435
+ src: (_item$fileInfo$url2 = (_item$fileInfo4 = item.fileInfo) === null || _item$fileInfo4 === void 0 ? void 0 : _item$fileInfo4.url) !== null && _item$fileInfo$url2 !== void 0 ? _item$fileInfo$url2 : item.thumbUrl,
436
+ alt: item.name
437
+ }) : /*#__PURE__*/_jsx("div", {
438
+ className: "bcm-fc-upload-tile-ph",
439
+ children: /*#__PURE__*/_jsx(FileOutline, {})
440
+ }), item.status === 'uploading' && /*#__PURE__*/_jsxs("div", {
441
+ className: "bcm-fc-upload-tile-mask",
442
+ children: [/*#__PURE__*/_jsxs("span", {
443
+ className: "bcm-fc-upload-tile-percent",
444
+ children: [(_item$percent = item.percent) !== null && _item$percent !== void 0 ? _item$percent : 0, "%"]
445
+ }), /*#__PURE__*/_jsx(ProgressBar, {
446
+ percent: (_item$percent2 = item.percent) !== null && _item$percent2 !== void 0 ? _item$percent2 : 0,
447
+ style: {
448
+ '--track-width': '2px'
449
+ }
450
+ })]
451
+ }), item.status === 'error' && /*#__PURE__*/_jsxs("div", {
452
+ className: "bcm-fc-upload-tile-mask bcm-fc-upload-tile-mask-error",
453
+ children: [/*#__PURE__*/_jsx(ExclamationCircleFill, {}), /*#__PURE__*/_jsx("span", {
454
+ children: (_item$error = item.error) !== null && _item$error !== void 0 ? _item$error : '上传失败'
455
+ })]
456
+ }), !disabled && /*#__PURE__*/_jsx("span", {
457
+ className: "bcm-fc-upload-tile-del",
458
+ onClick: function onClick(e) {
459
+ e.stopPropagation();
460
+ handleRemove(item);
461
+ },
462
+ children: /*#__PURE__*/_jsx(DeleteOutline, {})
463
+ })]
464
+ }, item.uid);
465
+ }), !reachedMax && !disabled && /*#__PURE__*/_jsxs("div", {
466
+ className: "bcm-fc-upload-tile bcm-fc-upload-tile-add",
467
+ onClick: function onClick() {
468
+ var _inputRef$current;
469
+ return (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 ? void 0 : _inputRef$current.click();
470
+ },
471
+ children: [/*#__PURE__*/_jsx(AddOutline, {}), /*#__PURE__*/_jsx("span", {
472
+ children: "\u4E0A\u4F20"
473
+ })]
474
+ })]
475
+ }) : /*#__PURE__*/_jsxs(_Fragment, {
476
+ children: [/*#__PURE__*/_jsx("div", {
477
+ className: "bcm-fc-upload-rows",
478
+ children: fileList.map(function (item) {
479
+ var _item$type2, _item$fileInfo$url3, _item$fileInfo5, _item$percent3, _item$percent4, _item$error2;
480
+ return /*#__PURE__*/_jsxs("div", {
481
+ className: "bcm-fc-upload-row",
482
+ children: [/*#__PURE__*/_jsx("div", {
483
+ className: "bcm-fc-upload-row-thumb",
484
+ onClick: function onClick() {
485
+ return item.status === 'done' && handlePreview(item);
486
+ },
487
+ children: (_item$type2 = item.type) !== null && _item$type2 !== void 0 && _item$type2.startsWith('image/') ? /*#__PURE__*/_jsx("img", {
488
+ src: (_item$fileInfo$url3 = (_item$fileInfo5 = item.fileInfo) === null || _item$fileInfo5 === void 0 ? void 0 : _item$fileInfo5.url) !== null && _item$fileInfo$url3 !== void 0 ? _item$fileInfo$url3 : item.thumbUrl,
489
+ alt: item.name
490
+ }) : /*#__PURE__*/_jsx(FileOutline, {})
491
+ }), /*#__PURE__*/_jsxs("div", {
492
+ className: "bcm-fc-upload-row-main",
493
+ children: [/*#__PURE__*/_jsx("div", {
494
+ className: "bcm-fc-upload-row-name",
495
+ children: item.name
496
+ }), item.status === 'uploading' ? /*#__PURE__*/_jsxs("div", {
497
+ className: "bcm-fc-upload-row-progress",
498
+ children: [/*#__PURE__*/_jsx(ProgressBar, {
499
+ percent: (_item$percent3 = item.percent) !== null && _item$percent3 !== void 0 ? _item$percent3 : 0,
500
+ style: {
501
+ '--track-width': '2px'
502
+ }
503
+ }), /*#__PURE__*/_jsx("span", {
504
+ children: item.stage === 'md5' ? '计算校验值' : item.stage === 'merging' ? '合并分片' : "".concat((_item$percent4 = item.percent) !== null && _item$percent4 !== void 0 ? _item$percent4 : 0, "%")
505
+ })]
506
+ }) : /*#__PURE__*/_jsx("div", {
507
+ className: "bcm-fc-upload-row-sub".concat(item.status === 'error' ? ' is-error' : ''),
508
+ children: item.status === 'error' ? (_item$error2 = item.error) !== null && _item$error2 !== void 0 ? _item$error2 : '上传失败' : formatFileSize(item.size)
509
+ })]
510
+ }), /*#__PURE__*/_jsxs("div", {
511
+ className: "bcm-fc-upload-row-actions",
512
+ children: [item.status === 'done' && /*#__PURE__*/_jsx("span", {
513
+ onClick: function onClick() {
514
+ return handlePreview(item);
515
+ },
516
+ children: /*#__PURE__*/_jsx(EyeOutline, {})
517
+ }), !disabled && /*#__PURE__*/_jsx("span", {
518
+ onClick: function onClick() {
519
+ return handleRemove(item);
520
+ },
521
+ children: /*#__PURE__*/_jsx(DeleteOutline, {})
522
+ })]
523
+ })]
524
+ }, item.uid);
525
+ })
526
+ }), !reachedMax && !disabled && /*#__PURE__*/_jsxs("div", {
527
+ className: "bcm-fc-upload-addbtn",
528
+ onClick: function onClick() {
529
+ var _inputRef$current2;
530
+ return (_inputRef$current2 = inputRef.current) === null || _inputRef$current2 === void 0 ? void 0 : _inputRef$current2.click();
531
+ },
532
+ children: [/*#__PURE__*/_jsx(AddOutline, {}), /*#__PURE__*/_jsx("span", {
533
+ children: buttonText
534
+ })]
535
+ })]
536
+ })]
537
+ });
538
+ }
539
+ export { FcUpload };