@nokecy/qc-ui 1.1.78 → 1.1.80

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 (48) hide show
  1. package/dist/cjs/ag-grid-plus/ag-gridPlus.js +2 -12
  2. package/dist/cjs/ag-grid-plus/utils/columnProcessors.d.ts +13 -2
  3. package/dist/cjs/ag-grid-plus/utils/columnProcessors.js +26 -15
  4. package/dist/cjs/attachment/AttachmentFileButton.d.ts +4 -0
  5. package/dist/cjs/attachment/AttachmentFileButton.js +86 -0
  6. package/dist/cjs/attachment/AttachmentImageUpload.d.ts +16 -0
  7. package/dist/cjs/attachment/AttachmentImageUpload.js +206 -0
  8. package/dist/cjs/attachment/AttachmentPanel.d.ts +8 -0
  9. package/dist/cjs/attachment/AttachmentPanel.js +63 -0
  10. package/dist/cjs/attachment/AttachmentVideoUpload.d.ts +13 -0
  11. package/dist/cjs/attachment/AttachmentVideoUpload.js +88 -0
  12. package/dist/cjs/attachment/ChunkedDragger.d.ts +14 -0
  13. package/dist/cjs/attachment/ChunkedDragger.js +160 -0
  14. package/dist/cjs/attachment/attachmentList.d.ts +91 -0
  15. package/dist/cjs/attachment/attachmentList.js +214 -0
  16. package/dist/cjs/attachment/chunkUpload.d.ts +26 -0
  17. package/dist/cjs/attachment/chunkUpload.js +276 -0
  18. package/dist/cjs/attachment/env.d.ts +41 -0
  19. package/dist/cjs/attachment/env.js +41 -0
  20. package/dist/cjs/attachment/index.d.ts +20 -0
  21. package/dist/cjs/attachment/index.js +92 -0
  22. package/dist/cjs/index.d.ts +1 -0
  23. package/dist/cjs/index.js +12 -0
  24. package/dist/esm/ag-grid-plus/ag-gridPlus.js +3 -13
  25. package/dist/esm/ag-grid-plus/utils/columnProcessors.d.ts +13 -2
  26. package/dist/esm/ag-grid-plus/utils/columnProcessors.js +25 -15
  27. package/dist/esm/attachment/AttachmentFileButton.d.ts +4 -0
  28. package/dist/esm/attachment/AttachmentFileButton.js +77 -0
  29. package/dist/esm/attachment/AttachmentImageUpload.d.ts +16 -0
  30. package/dist/esm/attachment/AttachmentImageUpload.js +199 -0
  31. package/dist/esm/attachment/AttachmentPanel.d.ts +8 -0
  32. package/dist/esm/attachment/AttachmentPanel.js +52 -0
  33. package/dist/esm/attachment/AttachmentVideoUpload.d.ts +13 -0
  34. package/dist/esm/attachment/AttachmentVideoUpload.js +82 -0
  35. package/dist/esm/attachment/ChunkedDragger.d.ts +14 -0
  36. package/dist/esm/attachment/ChunkedDragger.js +153 -0
  37. package/dist/esm/attachment/attachmentList.d.ts +91 -0
  38. package/dist/esm/attachment/attachmentList.js +207 -0
  39. package/dist/esm/attachment/chunkUpload.d.ts +26 -0
  40. package/dist/esm/attachment/chunkUpload.js +272 -0
  41. package/dist/esm/attachment/env.d.ts +41 -0
  42. package/dist/esm/attachment/env.js +35 -0
  43. package/dist/esm/attachment/index.d.ts +20 -0
  44. package/dist/esm/attachment/index.js +14 -0
  45. package/dist/esm/index.d.ts +1 -0
  46. package/dist/esm/index.js +1 -0
  47. package/dist/umd/qc-ui.min.js +1 -1
  48. package/package.json +1 -1
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+
3
+ 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); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = void 0;
8
+ var _icons = require("@ant-design/icons");
9
+ var _antd = require("antd");
10
+ var _react = _interopRequireDefault(require("react"));
11
+ var _chunkUpload = require("./chunkUpload");
12
+ var _env = require("./env");
13
+ var _excluded = ["env", "kind", "chongfuVerify", "children"];
14
+ /**
15
+ * 拖拽上传:大于 5MB 的文件切块上传,小文件整体上传。
16
+ * `kind="file"` 走普通文件协议(断点续传 + 合并校验,带全屏遮罩),`kind="video"` 走视频协议。
17
+ * 传输层与接口路径由 `env` 注入。
18
+ *
19
+ * @author nokecy
20
+ */
21
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
23
+ 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; }
24
+ 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); } }
25
+ 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); }); }; }
26
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
27
+ 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."); }
28
+ 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); }
29
+ 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; }
30
+ 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; } }
31
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
32
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
33
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
34
+ var Dragger = _antd.Upload.Dragger;
35
+ var successTip = function successTip() {
36
+ return _antd.message.success({
37
+ icon: /*#__PURE__*/_react.default.createElement(_icons.SmileOutlined, {
38
+ style: {
39
+ color: '#00b96b',
40
+ fontSize: 24
41
+ }
42
+ }),
43
+ content: '文件上传成功!感谢您的耐心,我们已成功收到您的文件。'
44
+ });
45
+ };
46
+ var ChunkedDragger = function ChunkedDragger(props) {
47
+ var env = props.env,
48
+ _props$kind = props.kind,
49
+ kind = _props$kind === void 0 ? 'file' : _props$kind,
50
+ chongfuVerify = props.chongfuVerify,
51
+ children = props.children,
52
+ draggerProps = _objectWithoutProperties(props, _excluded);
53
+ var isVideo = kind === 'video';
54
+ // 通知位置只作用于本组件,不改全局 notification 配置。
55
+ var _notification$useNoti = _antd.notification.useNotification({
56
+ top: 380
57
+ }),
58
+ _notification$useNoti2 = _slicedToArray(_notification$useNoti, 2),
59
+ notificationApi = _notification$useNoti2[0],
60
+ notificationHolder = _notification$useNoti2[1];
61
+ var _React$useState = _react.default.useState(false),
62
+ _React$useState2 = _slicedToArray(_React$useState, 2),
63
+ spinning = _React$useState2[0],
64
+ setSpinning = _React$useState2[1];
65
+ var protocol = _react.default.useMemo(function () {
66
+ return isVideo ? (0, _chunkUpload.createVideoProtocol)(env) : (0, _chunkUpload.createFileProtocol)(env);
67
+ }, [env, isVideo]);
68
+ var notificationKey = isVideo ? 'upload-progress-notification-copy' : 'upload-progress-notification';
69
+ var uploadWithFeedback = /*#__PURE__*/function () {
70
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(file, onProgress) {
71
+ var data, res;
72
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
73
+ while (1) switch (_context.prev = _context.next) {
74
+ case 0:
75
+ if (!isVideo) setSpinning(true);
76
+ if (!(file.size > _chunkUpload.CHUNK_SIZE)) {
77
+ _context.next = 20;
78
+ break;
79
+ }
80
+ notificationApi.open({
81
+ icon: /*#__PURE__*/_react.default.createElement(_icons.LoadingOutlined, {
82
+ style: {
83
+ color: '#00b96b',
84
+ fontSize: 24
85
+ }
86
+ }),
87
+ message: '文件上传中',
88
+ btn: null,
89
+ key: notificationKey,
90
+ closeIcon: null,
91
+ description: '您的文件正在传送中,耐心是一种美德,很快就会完成!',
92
+ duration: 60,
93
+ placement: 'top'
94
+ });
95
+ _context.prev = 3;
96
+ _context.next = 6;
97
+ return protocol.uploadChunked(file, onProgress);
98
+ case 6:
99
+ data = _context.sent;
100
+ notificationApi.destroy(notificationKey);
101
+ successTip();
102
+ return _context.abrupt("return", data);
103
+ case 12:
104
+ _context.prev = 12;
105
+ _context.t0 = _context["catch"](3);
106
+ notificationApi.destroy(notificationKey);
107
+ _antd.message.error('抱歉,文件上传遇到了点小问题,但别担心,您可以再试一次。');
108
+ throw _context.t0;
109
+ case 17:
110
+ _context.prev = 17;
111
+ setSpinning(false);
112
+ return _context.finish(17);
113
+ case 20:
114
+ _context.prev = 20;
115
+ _context.next = 23;
116
+ return protocol.uploadSingle(file, onProgress);
117
+ case 23:
118
+ res = _context.sent;
119
+ // 视频的小文件没有成功提示,沿用原行为。
120
+ if (!isVideo) successTip();
121
+ return _context.abrupt("return", res);
122
+ case 26:
123
+ _context.prev = 26;
124
+ setSpinning(false);
125
+ return _context.finish(26);
126
+ case 29:
127
+ case "end":
128
+ return _context.stop();
129
+ }
130
+ }, _callee, null, [[3, 12, 17, 20], [20,, 26, 29]]);
131
+ }));
132
+ return function uploadWithFeedback(_x, _x2) {
133
+ return _ref.apply(this, arguments);
134
+ };
135
+ }();
136
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(Dragger, _extends({
137
+ multiple: !isVideo
138
+ }, draggerProps, {
139
+ withCredentials: true,
140
+ action: "".concat(env.serverUrl()).concat((0, _env.resolveEndpoints)(env).upload)
141
+ }, isVideo ? {} : {
142
+ beforeUpload: chongfuVerify
143
+ }, {
144
+ customRequest: function customRequest(_ref2) {
145
+ var file = _ref2.file,
146
+ onError = _ref2.onError,
147
+ onProgress = _ref2.onProgress,
148
+ onSuccess = _ref2.onSuccess;
149
+ uploadWithFeedback(file, onProgress).then(function (res) {
150
+ return onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(res, file);
151
+ }).catch(function (error) {
152
+ return onError === null || onError === void 0 ? void 0 : onError(error);
153
+ });
154
+ }
155
+ }), children), notificationHolder, !isVideo && /*#__PURE__*/_react.default.createElement(_antd.Spin, {
156
+ spinning: spinning,
157
+ fullscreen: true
158
+ }));
159
+ };
160
+ var _default = exports.default = ChunkedDragger;
@@ -0,0 +1,91 @@
1
+ import type { UploadChangeParam } from 'antd/lib/upload/interface';
2
+ import React from 'react';
3
+ import { type AttachmentEnv } from './env';
4
+ /** 附件组件的公共属性。 */
5
+ export interface AttachmentListProps {
6
+ /** 宿主环境(传输层、地址前缀、接口路径) */
7
+ env: AttachmentEnv;
8
+ /** 当前用户名,写入每个文件的上传者列 */
9
+ currentUserName?: string;
10
+ /** 列表使用的表格组件,默认 `AgGridPlus`;宿主可注入自己封装过的表格基座 */
11
+ gridComponent?: React.ComponentType<any>;
12
+ value?: any[];
13
+ defaultValue?: any[];
14
+ onChange?: (value: any[]) => void;
15
+ disabled?: boolean;
16
+ /** 移除一项后的回调,参数是移除后的列表 */
17
+ removeCallBack?: (list: any[]) => void;
18
+ /** 上传或移除后的回调,参数是最新列表 */
19
+ changeCallBack?: (list: any[]) => void;
20
+ /** 不允许删除(只能下载) */
21
+ notDelete?: boolean;
22
+ /** 隐藏上传进度列 */
23
+ hidePercent?: boolean;
24
+ /** 隐藏操作列 */
25
+ hideDownBtn?: boolean;
26
+ [key: string]: any;
27
+ }
28
+ /** 取 `YYYY-MM-DD`:无时区的字符串按本地日期取,带时区或时间戳按本地时间换算。 */
29
+ export declare const formatAttachmentDate: (value: unknown) => string;
30
+ /** 当前时间 `YYYY-MM-DD HH:mm`。 */
31
+ export declare const nowText: () => string;
32
+ export declare const useAttachmentFiles: (props: AttachmentListProps) => {
33
+ state: any;
34
+ onFileChange: (info: UploadChangeParam) => void;
35
+ chongfuVerify: (file: any) => string | true;
36
+ columnDefs: ({
37
+ field: string;
38
+ headerName: string;
39
+ flex: number;
40
+ cellRenderer: ({ value, data }: any) => React.JSX.Element;
41
+ width?: undefined;
42
+ hideInSearch?: undefined;
43
+ hide?: undefined;
44
+ hideInTable?: undefined;
45
+ } | {
46
+ field: string;
47
+ headerName: string;
48
+ width: number;
49
+ hideInSearch: boolean;
50
+ flex?: undefined;
51
+ cellRenderer?: undefined;
52
+ hide?: undefined;
53
+ hideInTable?: undefined;
54
+ } | {
55
+ field: string;
56
+ headerName: string;
57
+ width: number;
58
+ hideInSearch: boolean;
59
+ cellRenderer: (params: any) => React.JSX.Element;
60
+ flex?: undefined;
61
+ hide?: undefined;
62
+ hideInTable?: undefined;
63
+ } | {
64
+ field: string;
65
+ headerName: string;
66
+ width: number;
67
+ hideInSearch: boolean;
68
+ hide: boolean;
69
+ flex?: undefined;
70
+ cellRenderer?: undefined;
71
+ hideInTable?: undefined;
72
+ } | {
73
+ field: string;
74
+ headerName: string;
75
+ width: number;
76
+ hideInTable: boolean | undefined;
77
+ hideInSearch: boolean;
78
+ cellRenderer: ({ value, data }: any) => React.JSX.Element;
79
+ flex?: undefined;
80
+ hide?: undefined;
81
+ } | {
82
+ field: string;
83
+ headerName: string;
84
+ width: number;
85
+ hideInTable: boolean | undefined;
86
+ cellRenderer: (row: any) => React.JSX.Element;
87
+ flex?: undefined;
88
+ hideInSearch?: undefined;
89
+ hide?: undefined;
90
+ })[];
91
+ };
@@ -0,0 +1,214 @@
1
+ "use strict";
2
+
3
+ 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); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.useAttachmentFiles = exports.nowText = exports.formatAttachmentDate = void 0;
8
+ var _ahooks = require("ahooks");
9
+ var _antd = require("antd");
10
+ var _react = _interopRequireWildcard(require("react"));
11
+ var _env = require("./env");
12
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
13
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
14
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
15
+ 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."); }
16
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
17
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
18
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
19
+ 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."); }
20
+ 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); }
21
+ 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; }
22
+ 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; } }
23
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } /**
24
+ * 附件列表的共用逻辑:值的受控、重复文件拦截、上传回调字段补全、列定义。
25
+ * `AttachmentPanel`(直接铺开)与 `AttachmentFileButton`(按钮 + 弹窗)共用。
26
+ *
27
+ * @author nokecy
28
+ */
29
+ /** 附件组件的公共属性。 */
30
+
31
+ var pad = function pad(n) {
32
+ return String(n).padStart(2, '0');
33
+ };
34
+
35
+ /** 取 `YYYY-MM-DD`:无时区的字符串按本地日期取,带时区或时间戳按本地时间换算。 */
36
+ var formatAttachmentDate = exports.formatAttachmentDate = function formatAttachmentDate(value) {
37
+ // 与 dayjs 一致:未传值取今天,null 与空串是无效日期。
38
+ if (value === undefined) value = new Date();
39
+ if (value === null || value === '') return 'Invalid Date';
40
+ if (typeof value === 'string' && !/(?:Z|[+-]\d{2}:?\d{2})$/i.test(value)) {
41
+ var m = /^(\d{4})-(\d{2})-(\d{2})/.exec(value);
42
+ if (m) return "".concat(m[1], "-").concat(m[2], "-").concat(m[3]);
43
+ }
44
+ var d = new Date(value);
45
+ if (Number.isNaN(d.getTime())) return 'Invalid Date';
46
+ return "".concat(d.getFullYear(), "-").concat(pad(d.getMonth() + 1), "-").concat(pad(d.getDate()));
47
+ };
48
+
49
+ /** 当前时间 `YYYY-MM-DD HH:mm`。 */
50
+ var nowText = exports.nowText = function nowText() {
51
+ var d = new Date();
52
+ return "".concat(d.getFullYear(), "-").concat(pad(d.getMonth() + 1), "-").concat(pad(d.getDate()), " ").concat(pad(d.getHours()), ":").concat(pad(d.getMinutes()));
53
+ };
54
+ var useAttachmentFiles = exports.useAttachmentFiles = function useAttachmentFiles(props) {
55
+ var env = props.env,
56
+ currentUserName = props.currentUserName,
57
+ disabled = props.disabled,
58
+ removeCallBack = props.removeCallBack,
59
+ changeCallBack = props.changeCallBack,
60
+ notDelete = props.notDelete,
61
+ hidePercent = props.hidePercent,
62
+ hideDownBtn = props.hideDownBtn;
63
+ var _useControllableValue = (0, _ahooks.useControllableValue)(props),
64
+ _useControllableValue2 = _slicedToArray(_useControllableValue, 2),
65
+ state = _useControllableValue2[0],
66
+ setState = _useControllableValue2[1];
67
+ var _useState = (0, _react.useState)([]),
68
+ _useState2 = _slicedToArray(_useState, 2),
69
+ uploadedFiles = _useState2[0],
70
+ setUploadedFiles = _useState2[1];
71
+ (0, _react.useEffect)(function () {
72
+ setUploadedFiles(Array.isArray(state) ? state.map(function (i) {
73
+ return i.fileName || i.name;
74
+ }) : []);
75
+ }, [state]);
76
+ var onFileChange = function onFileChange(info) {
77
+ var file = info.file;
78
+ if (file && file.error) {
79
+ var _file$error;
80
+ _antd.message.error((file === null || file === void 0 || (_file$error = file.error) === null || _file$error === void 0 ? void 0 : _file$error.message) || '上传失败请稍后重试');
81
+ return;
82
+ }
83
+ var list = info.fileList.map(function (a) {
84
+ var _a$response, _a$response2;
85
+ a.blobName = (_a$response = a.response) !== null && _a$response !== void 0 && _a$response.filename ? (_a$response2 = a.response) === null || _a$response2 === void 0 ? void 0 : _a$response2.filename : a.blobName;
86
+ a.contentType = a.contentType ? a.contentType : a.type;
87
+ a.fileName = a.fileName ? a.fileName : a.name;
88
+ a.creator = currentUserName;
89
+ // 属性名沿用历史数据里的拼写
90
+ a.ceaterTime = nowText();
91
+ return a;
92
+ });
93
+ setState(list);
94
+ changeCallBack === null || changeCallBack === void 0 || changeCallBack(list);
95
+ };
96
+ var removeFile = function removeFile(row) {
97
+ var data = row.data;
98
+ var next = function next(fileList) {
99
+ removeCallBack === null || removeCallBack === void 0 || removeCallBack(fileList.filter(function (a) {
100
+ return a.uid != data.uid;
101
+ }));
102
+ var files = _toConsumableArray(fileList);
103
+ var index = files.findIndex(function (a) {
104
+ return a.uid === data.uid;
105
+ });
106
+ files.splice(index, 1);
107
+ return files;
108
+ };
109
+ if (data.name) {
110
+ // 同时移除已上传文件名记录
111
+ setUploadedFiles(uploadedFiles.filter(function (a) {
112
+ return a !== data.name;
113
+ }));
114
+ }
115
+ setState(next);
116
+ };
117
+ var chongfuVerify = function chongfuVerify(file) {
118
+ if (uploadedFiles.includes(file.name)) {
119
+ _antd.message.error('上传文件重复');
120
+ return _antd.Upload.LIST_IGNORE;
121
+ }
122
+ uploadedFiles.push(file.name);
123
+ setUploadedFiles(uploadedFiles);
124
+ return true;
125
+ };
126
+ var download = function download(blobName) {
127
+ if (blobName) window.open((0, _env.getBlobDownloadUrl)(env, blobName));else _antd.message.error('下载失败请稍后重试');
128
+ };
129
+ var columnDefs = [{
130
+ field: 'fileName',
131
+ headerName: '文档名称',
132
+ flex: 1,
133
+ cellRenderer: function cellRenderer(_ref) {
134
+ var value = _ref.value,
135
+ data = _ref.data;
136
+ return /*#__PURE__*/_react.default.createElement("a", {
137
+ target: "_blank",
138
+ onClick: function onClick(event) {
139
+ event.stopPropagation();
140
+ download(data.blobName);
141
+ },
142
+ rel: "noreferrer"
143
+ }, data.name || value || data.fileName);
144
+ }
145
+ }, {
146
+ field: 'creator',
147
+ headerName: '上传者',
148
+ width: 100,
149
+ hideInSearch: true
150
+ }, {
151
+ field: 'creationTime',
152
+ headerName: '时间',
153
+ width: 130,
154
+ hideInSearch: true,
155
+ cellRenderer: function cellRenderer(params) {
156
+ var _params$data, _params$data2;
157
+ return /*#__PURE__*/_react.default.createElement("div", null, formatAttachmentDate(((_params$data = params.data) === null || _params$data === void 0 ? void 0 : _params$data.creationTime) || ((_params$data2 = params.data) === null || _params$data2 === void 0 ? void 0 : _params$data2.ceaterTime)));
158
+ }
159
+ }, {
160
+ field: 'type',
161
+ headerName: '类型',
162
+ width: 150,
163
+ hideInSearch: true,
164
+ hide: true
165
+ }, {
166
+ field: 'percent',
167
+ headerName: '上传进度',
168
+ width: 100,
169
+ hideInTable: hidePercent,
170
+ hideInSearch: true,
171
+ cellRenderer: function cellRenderer(_ref2) {
172
+ var value = _ref2.value,
173
+ data = _ref2.data;
174
+ return /*#__PURE__*/_react.default.createElement(_antd.Progress, {
175
+ percent: (data === null || data === void 0 ? void 0 : data.id) !== null ? 100 : value
176
+ });
177
+ }
178
+ }, {
179
+ field: 'options',
180
+ headerName: '操作',
181
+ width: 150,
182
+ hideInTable: hideDownBtn,
183
+ cellRenderer: function cellRenderer(row) {
184
+ return /*#__PURE__*/_react.default.createElement(_antd.Space, {
185
+ onClick: function onClick(event) {
186
+ event.stopPropagation();
187
+ event.preventDefault();
188
+ }
189
+ }, /*#__PURE__*/_react.default.createElement("a", {
190
+ target: "_blank",
191
+ onClick: function onClick(event) {
192
+ event.stopPropagation();
193
+ download(row === null || row === void 0 ? void 0 : row.data.blobName);
194
+ },
195
+ rel: "noreferrer"
196
+ }, "\u4E0B\u8F7D"), disabled || notDelete ? null : /*#__PURE__*/_react.default.createElement("a", {
197
+ style: {
198
+ color: 'red'
199
+ },
200
+ onClick: function onClick(event) {
201
+ event.stopPropagation();
202
+ event.preventDefault();
203
+ removeFile(row);
204
+ }
205
+ }, "\u79FB\u9664"));
206
+ }
207
+ }];
208
+ return {
209
+ state: state,
210
+ onFileChange: onFileChange,
211
+ chongfuVerify: chongfuVerify,
212
+ columnDefs: columnDefs
213
+ };
214
+ };
@@ -0,0 +1,26 @@
1
+ /**
2
+ * 附件上传协议:普通文件(带断点续传与合并校验)与视频(分块后确认)。
3
+ * 两套协议的端点、参数大小写、进度算法与收尾都不同,各自照原样实现,不合并成带开关的一套。
4
+ *
5
+ * @author nokecy
6
+ */
7
+ import { type AttachmentEnv } from './env';
8
+ /** 分块大小,同时也是切块上传的阈值。 */
9
+ export declare const CHUNK_SIZE: number;
10
+ type Progress = (event: any) => void;
11
+ /** 把文件切成 `chunks` 块。 */
12
+ export declare const splitFile: (file: Blob, eachSize: number, chunks: number) => Promise<Blob[]>;
13
+ /** 普通文件协议。 */
14
+ export declare const createFileProtocol: (env: AttachmentEnv) => {
15
+ uploadSingle: (file: any, onProgress: Progress) => Promise<{
16
+ nextchunk: any;
17
+ filename: any;
18
+ }>;
19
+ uploadChunked: (file: any, onProgress: Progress) => Promise<any>;
20
+ };
21
+ /** 视频协议。 */
22
+ export declare const createVideoProtocol: (env: AttachmentEnv) => {
23
+ uploadSingle: (file: any, onProgress: Progress) => Promise<any>;
24
+ uploadChunked: (file: any, onProgress: Progress) => Promise<any>;
25
+ };
26
+ export {};