fan-standard-comp 3.1.10 → 3.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 (170) hide show
  1. package/Readme.md +35 -0
  2. package/dist/fan-standard-comp.umd.js +15 -15
  3. package/es/ButtonGroup/ButtonList.js +0 -3
  4. package/es/ButtonGroup/ButtonMenu.js +0 -3
  5. package/es/ButtonGroup/PopConfirmTitle.js +5 -15
  6. package/es/ButtonGroup/index.js +212 -216
  7. package/es/ButtonGroup/style/index.less +1 -1
  8. package/es/DragContent/DragBar.js +2 -6
  9. package/es/DragContent/index.js +44 -75
  10. package/es/FormComp/ChunkUploader/api.js +6 -10
  11. package/es/FormComp/ChunkUploader/index.js +105 -171
  12. package/es/FormComp/ChunkUploader/lib.js +4 -17
  13. package/es/FormComp/ChunkUploader/upload-queue.class.js +10 -45
  14. package/es/FormComp/ChunkUploader/worker.js +0 -3
  15. package/es/FormComp/EditButton/index.js +24 -49
  16. package/es/FormComp/FieldComponent/ReUpload.js +18 -38
  17. package/es/FormComp/FieldComponent/RefactorTreeSelect.js +36 -74
  18. package/es/FormComp/FieldComponent/TitleNode.js +1 -3
  19. package/es/FormComp/FieldComponent/index.js +38 -74
  20. package/es/FormComp/FieldComponent/setReadonlyValues.js +34 -63
  21. package/es/FormComp/RenderItemGroup/index.js +46 -74
  22. package/es/FormComp/Uploader/index.js +36 -77
  23. package/es/FormComp/Uploader/util.js +0 -6
  24. package/es/FormComp/VarTemplate/index.js +58 -96
  25. package/es/NavLeafScroll/index.js +172 -154
  26. package/es/NavLeafScroll/style/index.less +33 -1
  27. package/es/RefactorTree/index.js +36 -53
  28. package/es/RefactorTree/indexTreeNode.js +35 -68
  29. package/es/RefactorTree/util.js +9 -43
  30. package/es/SpecIcon/fonts/iconfont.js +7 -12
  31. package/es/SpecIcon/index.js +16 -25
  32. package/es/SplitterLayout/Pane.js +2 -5
  33. package/es/SplitterLayout/index.js +20 -70
  34. package/es/StandardContent/SplitterLayout/Pane.js +6 -10
  35. package/es/StandardContent/SplitterLayout/index.js +12 -63
  36. package/es/StandardContent/SubfieldContent.js +12 -14
  37. package/es/StandardContent/WrapperContent.js +8 -10
  38. package/es/StandardDragModal/ChangeStandardModal.d.ts +44 -0
  39. package/es/StandardDragModal/ChangeStandardModal.js +493 -0
  40. package/es/StandardDragModal/DraggableModal.d.ts +7 -0
  41. package/es/StandardDragModal/DraggableModal.js +31 -0
  42. package/es/StandardDragModal/DraggableModalContext.d.ts +9 -0
  43. package/es/StandardDragModal/DraggableModalContext.js +5 -0
  44. package/es/StandardDragModal/DraggableModalInner.d.ts +16 -0
  45. package/es/StandardDragModal/DraggableModalInner.js +114 -0
  46. package/es/StandardDragModal/DraggableModalProvider.d.ts +4 -0
  47. package/es/StandardDragModal/DraggableModalProvider.js +40 -0
  48. package/es/StandardDragModal/Modal.d.ts +11 -0
  49. package/es/StandardDragModal/Modal.js +24 -0
  50. package/es/StandardDragModal/ResizeHandle.d.ts +2 -0
  51. package/es/StandardDragModal/ResizeHandle.js +8 -0
  52. package/es/StandardDragModal/clamp.d.ts +1 -0
  53. package/es/StandardDragModal/clamp.js +3 -0
  54. package/es/StandardDragModal/draggableModalReducer.d.ts +66 -0
  55. package/es/StandardDragModal/draggableModalReducer.js +157 -0
  56. package/es/StandardDragModal/getWindowSize.d.ts +4 -0
  57. package/es/StandardDragModal/getWindowSize.js +6 -0
  58. package/es/StandardDragModal/index.d.ts +3 -11
  59. package/es/StandardDragModal/index.js +3 -30
  60. package/es/StandardDragModal/index.less +65 -0
  61. package/es/StandardDragModal/useDrag.d.ts +5 -0
  62. package/es/StandardDragModal/useDrag.js +66 -0
  63. package/es/StandardDragModal/usePrevious.d.ts +1 -0
  64. package/es/StandardDragModal/usePrevious.js +8 -0
  65. package/es/StandardDragModal/useResize.d.ts +7 -0
  66. package/es/StandardDragModal/useResize.js +74 -0
  67. package/es/StandardFilter/index.js +30 -70
  68. package/es/StandardForm/ActionList.js +5 -7
  69. package/es/StandardForm/StepForm.js +50 -71
  70. package/es/StandardForm/TabForm.js +58 -70
  71. package/es/StandardForm/index.js +37 -56
  72. package/es/StandardModal/UpdateFormRef.js +1 -4
  73. package/es/StandardModal/index.d.ts +0 -1
  74. package/es/StandardModal/index.js +113 -157
  75. package/es/StandardPanel/index.js +19 -35
  76. package/es/StandardTable/index.js +18 -29
  77. package/es/components/IconNode/index.js +0 -4
  78. package/es/index.d.ts +1 -0
  79. package/es/index.js +15 -14
  80. package/es/utils/ValueFormat.js +0 -9
  81. package/es/utils/dictSelectUtil.js +153 -0
  82. package/es/utils/filterPermission.js +16 -34
  83. package/es/utils/getParentNodes.js +24 -47
  84. package/es/utils/index.js +2 -1
  85. package/lib/ButtonGroup/ButtonList.js +1 -13
  86. package/lib/ButtonGroup/ButtonMenu.js +1 -8
  87. package/lib/ButtonGroup/PopConfirmTitle.js +3 -16
  88. package/lib/ButtonGroup/index.js +215 -239
  89. package/lib/ButtonGroup/style/index.less +1 -1
  90. package/lib/DragContent/DragBar.js +2 -10
  91. package/lib/DragContent/index.js +47 -85
  92. package/lib/FormComp/ChunkUploader/api.js +6 -15
  93. package/lib/FormComp/ChunkUploader/index.js +107 -185
  94. package/lib/FormComp/ChunkUploader/lib.js +8 -27
  95. package/lib/FormComp/ChunkUploader/upload-queue.class.js +10 -46
  96. package/lib/FormComp/ChunkUploader/worker.js +1 -5
  97. package/lib/FormComp/EditButton/index.js +26 -60
  98. package/lib/FormComp/FieldComponent/ReUpload.js +21 -50
  99. package/lib/FormComp/FieldComponent/RefactorTreeSelect.js +38 -89
  100. package/lib/FormComp/FieldComponent/TitleNode.js +1 -5
  101. package/lib/FormComp/FieldComponent/index.js +38 -110
  102. package/lib/FormComp/FieldComponent/setReadonlyValues.js +37 -79
  103. package/lib/FormComp/RenderItemGroup/index.js +46 -87
  104. package/lib/FormComp/Uploader/index.js +38 -95
  105. package/lib/FormComp/Uploader/util.js +1 -9
  106. package/lib/FormComp/VarTemplate/index.js +62 -106
  107. package/lib/FormComp/index.js +0 -2
  108. package/lib/NavLeafScroll/index.js +174 -165
  109. package/lib/NavLeafScroll/style/index.less +33 -1
  110. package/lib/RefactorTree/index.js +36 -67
  111. package/lib/RefactorTree/indexTreeNode.js +37 -83
  112. package/lib/RefactorTree/util.js +11 -45
  113. package/lib/SpecIcon/fonts/iconfont.js +7 -12
  114. package/lib/SpecIcon/index.js +16 -30
  115. package/lib/SplitterLayout/Pane.js +0 -7
  116. package/lib/SplitterLayout/index.js +18 -72
  117. package/lib/StandardContent/SplitterLayout/Pane.js +6 -14
  118. package/lib/StandardContent/SplitterLayout/index.js +12 -68
  119. package/lib/StandardContent/SubfieldContent.js +12 -21
  120. package/lib/StandardContent/WrapperContent.js +8 -16
  121. package/lib/StandardDragModal/ChangeStandardModal.d.ts +44 -0
  122. package/lib/StandardDragModal/ChangeStandardModal.js +502 -0
  123. package/lib/StandardDragModal/DraggableModal.d.ts +7 -0
  124. package/lib/StandardDragModal/DraggableModal.js +40 -0
  125. package/lib/StandardDragModal/DraggableModalContext.d.ts +9 -0
  126. package/lib/StandardDragModal/DraggableModalContext.js +15 -0
  127. package/lib/StandardDragModal/DraggableModalInner.d.ts +16 -0
  128. package/lib/StandardDragModal/DraggableModalInner.js +124 -0
  129. package/lib/StandardDragModal/DraggableModalProvider.d.ts +4 -0
  130. package/lib/StandardDragModal/DraggableModalProvider.js +48 -0
  131. package/lib/StandardDragModal/Modal.d.ts +11 -0
  132. package/lib/StandardDragModal/Modal.js +32 -0
  133. package/lib/StandardDragModal/ResizeHandle.d.ts +2 -0
  134. package/lib/StandardDragModal/ResizeHandle.js +18 -0
  135. package/lib/StandardDragModal/clamp.d.ts +1 -0
  136. package/lib/StandardDragModal/clamp.js +10 -0
  137. package/lib/StandardDragModal/draggableModalReducer.d.ts +66 -0
  138. package/lib/StandardDragModal/draggableModalReducer.js +167 -0
  139. package/lib/StandardDragModal/getWindowSize.d.ts +4 -0
  140. package/lib/StandardDragModal/getWindowSize.js +13 -0
  141. package/lib/StandardDragModal/index.d.ts +3 -11
  142. package/lib/StandardDragModal/index.js +33 -38
  143. package/lib/StandardDragModal/index.less +65 -0
  144. package/lib/StandardDragModal/useDrag.d.ts +5 -0
  145. package/lib/StandardDragModal/useDrag.js +73 -0
  146. package/lib/StandardDragModal/usePrevious.d.ts +1 -0
  147. package/lib/StandardDragModal/usePrevious.js +15 -0
  148. package/lib/StandardDragModal/useResize.d.ts +7 -0
  149. package/lib/StandardDragModal/useResize.js +81 -0
  150. package/lib/StandardFilter/index.js +28 -78
  151. package/lib/StandardForm/ActionList.js +5 -12
  152. package/lib/StandardForm/StepForm.js +52 -90
  153. package/lib/StandardForm/TabForm.js +61 -88
  154. package/lib/StandardForm/index.js +40 -75
  155. package/lib/StandardModal/UpdateFormRef.js +4 -12
  156. package/lib/StandardModal/index.d.ts +0 -1
  157. package/lib/StandardModal/index.js +115 -182
  158. package/lib/StandardPanel/index.js +22 -48
  159. package/lib/StandardTable/index.js +18 -38
  160. package/lib/components/IconNode/index.js +0 -7
  161. package/lib/components/index.js +0 -2
  162. package/lib/data/index.js +4 -7
  163. package/lib/index.d.ts +1 -0
  164. package/lib/index.js +50 -68
  165. package/lib/utils/ValueFormat.js +0 -10
  166. package/lib/utils/dictSelectUtil.js +161 -0
  167. package/lib/utils/filterPermission.js +15 -39
  168. package/lib/utils/getParentNodes.js +25 -52
  169. package/lib/utils/index.js +24 -9
  170. package/package.json +5 -4
@@ -1,37 +1,23 @@
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); }
1
2
  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; }
2
-
3
3
  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; }
4
-
5
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
6
-
7
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
8
-
9
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
-
4
+ 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; }
5
+ 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; }
6
+ 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; }
7
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
8
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
9
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
12
-
13
10
  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."); }
14
-
15
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); }
16
-
11
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
17
12
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
18
-
19
13
  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); } }
20
-
21
14
  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); }); }; }
22
-
23
15
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
24
-
25
16
  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."); }
26
-
27
17
  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); }
28
-
29
18
  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
-
31
- function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
32
-
19
+ 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; } }
33
20
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
34
-
35
21
  /* eslint-disable no-unused-vars */
36
22
  import React, { useEffect, useState, useRef } from 'react';
37
23
  import PropTypes from 'prop-types';
@@ -39,139 +25,117 @@ import { getComponentDisplayName, splitFileToChunks, calFileContentHash, bytesTo
39
25
  import { queryFileInfo } from './api';
40
26
  import UploadQueue from './upload-queue.class';
41
27
  import './style/style.less';
28
+
42
29
  /**
43
30
  * 初始化组件
44
31
  * @param {ReactComponent} component 本高阶组件
45
32
  * @param {ReactComponent} WrappedComponent 被包装的具体实现组件
46
33
  */
47
-
48
34
  function useComponentInit(component, WrappedComponent) {
49
35
  var intervalIDArr = [];
50
-
51
36
  var _useState = useState([]),
52
- _useState2 = _slicedToArray(_useState, 2),
53
- filesList = _useState2[0],
54
- setFilesList = _useState2[1]; // 定义管理上传的列表
55
-
37
+ _useState2 = _slicedToArray(_useState, 2),
38
+ filesList = _useState2[0],
39
+ setFilesList = _useState2[1]; // 定义管理上传的列表
56
40
  /* 定义上传队列,初始化就创建一个UploadQueue类实例 */
57
-
58
-
59
41
  var _useState3 = useState(new UploadQueue({
60
- /* 设立一个定时器,定时(根据hash)查询文件是否上传完成(因为后端需要把所有分片合并起来,因此需要一定的时间) */
61
- fileFinishCb: function fileFinishCb(fileHash) {
62
- /* 查询文件是否上传完成;是的话则更新状态,渲染上传结果 */
63
- console.log('调用=》fileFinishCb==》查询文件是否上传完成;是的话则更新状态,渲染上传结果');
64
-
65
- function checkIfFinish() {
66
- return _checkIfFinish.apply(this, arguments);
67
- }
68
- /*
69
- 第一次定时器会很快触发,这是针对小文件,争取尽快渲染上传结果
70
- 之后的定时器则是针对较大的文件,以较大的时间间隔来触发查询
71
- */
72
-
73
-
74
- function _checkIfFinish() {
75
- _checkIfFinish = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
76
- var remoteFileInfo;
77
- return regeneratorRuntime.wrap(function _callee3$(_context3) {
42
+ /* 设立一个定时器,定时(根据hash)查询文件是否上传完成(因为后端需要把所有分片合并起来,因此需要一定的时间) */
43
+ fileFinishCb: function fileFinishCb(fileHash) {
44
+ /* 查询文件是否上传完成;是的话则更新状态,渲染上传结果 */
45
+ console.log('调用=》fileFinishCb==》查询文件是否上传完成;是的话则更新状态,渲染上传结果');
46
+ function checkIfFinish() {
47
+ return _checkIfFinish.apply(this, arguments);
48
+ }
49
+ /*
50
+ 第一次定时器会很快触发,这是针对小文件,争取尽快渲染上传结果
51
+ 之后的定时器则是针对较大的文件,以较大的时间间隔来触发查询
52
+ */
53
+ function _checkIfFinish() {
54
+ _checkIfFinish = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() {
55
+ var remoteFileInfo;
56
+ return regeneratorRuntime.wrap(function _callee3$(_context3) {
57
+ while (1) {
58
+ switch (_context3.prev = _context3.next) {
59
+ case 0:
60
+ _context3.next = 2;
61
+ return queryFileInfo({
62
+ fileHash: fileHash
63
+ });
64
+ case 2:
65
+ remoteFileInfo = _context3.sent;
66
+ console.log('请求接口queryFileInfo=》 完成分片上传后,更新上传状态');
67
+ if (!(remoteFileInfo.status === 'finish')) {
68
+ _context3.next = 7;
69
+ break;
70
+ }
71
+ updateFileInfo.call({
72
+ filesList: filesList,
73
+ setFilesList: setFilesList
74
+ }, fileHash, {
75
+ status: remoteFileInfo.status,
76
+ url: remoteFileInfo.publicPath
77
+ });
78
+ return _context3.abrupt("return", true);
79
+ case 7:
80
+ console.log('更新上传状态==》remoteFileInfo', remoteFileInfo);
81
+ return _context3.abrupt("return", false);
82
+ case 9:
83
+ case "end":
84
+ return _context3.stop();
85
+ }
86
+ }
87
+ }, _callee3);
88
+ }));
89
+ return _checkIfFinish.apply(this, arguments);
90
+ }
91
+ setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
92
+ var intervalID;
93
+ return regeneratorRuntime.wrap(function _callee2$(_context2) {
78
94
  while (1) {
79
- switch (_context3.prev = _context3.next) {
95
+ switch (_context2.prev = _context2.next) {
80
96
  case 0:
81
- _context3.next = 2;
82
- return queryFileInfo({
83
- fileHash: fileHash
84
- });
85
-
97
+ _context2.next = 2;
98
+ return checkIfFinish();
86
99
  case 2:
87
- remoteFileInfo = _context3.sent;
88
- console.log('请求接口queryFileInfo=》 完成分片上传后,更新上传状态');
89
-
90
- if (!(remoteFileInfo.status === 'finish')) {
91
- _context3.next = 7;
100
+ _context2.t0 = _context2.sent;
101
+ if (!(_context2.t0 === false)) {
102
+ _context2.next = 6;
92
103
  break;
93
104
  }
94
-
95
- updateFileInfo.call({
96
- filesList: filesList,
97
- setFilesList: setFilesList
98
- }, fileHash, {
99
- status: remoteFileInfo.status,
100
- url: remoteFileInfo.publicPath
101
- });
102
- return _context3.abrupt("return", true);
103
-
104
- case 7:
105
- console.log('更新上传状态==》remoteFileInfo', remoteFileInfo);
106
- return _context3.abrupt("return", false);
107
-
108
- case 9:
105
+ intervalID = setInterval( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
106
+ return regeneratorRuntime.wrap(function _callee$(_context) {
107
+ while (1) {
108
+ switch (_context.prev = _context.next) {
109
+ case 0:
110
+ _context.next = 2;
111
+ return checkIfFinish();
112
+ case 2:
113
+ _context.t0 = _context.sent;
114
+ if (!(_context.t0 === true)) {
115
+ _context.next = 6;
116
+ break;
117
+ }
118
+ clearInterval(intervalID);
119
+ intervalIDArr.splice(intervalIDArr.indexOf(intervalIDArr), 1);
120
+ case 6:
121
+ case "end":
122
+ return _context.stop();
123
+ }
124
+ }
125
+ }, _callee);
126
+ })), 5000);
127
+ intervalIDArr.push(intervalID);
128
+ case 6:
109
129
  case "end":
110
- return _context3.stop();
130
+ return _context2.stop();
111
131
  }
112
132
  }
113
- }, _callee3);
114
- }));
115
- return _checkIfFinish.apply(this, arguments);
133
+ }, _callee2);
134
+ })), 500);
116
135
  }
117
-
118
- setTimeout( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() {
119
- var intervalID;
120
- return regeneratorRuntime.wrap(function _callee2$(_context2) {
121
- while (1) {
122
- switch (_context2.prev = _context2.next) {
123
- case 0:
124
- _context2.next = 2;
125
- return checkIfFinish();
126
-
127
- case 2:
128
- _context2.t0 = _context2.sent;
129
-
130
- if (!(_context2.t0 === false)) {
131
- _context2.next = 6;
132
- break;
133
- }
134
-
135
- intervalID = setInterval( /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
136
- return regeneratorRuntime.wrap(function _callee$(_context) {
137
- while (1) {
138
- switch (_context.prev = _context.next) {
139
- case 0:
140
- _context.next = 2;
141
- return checkIfFinish();
142
-
143
- case 2:
144
- _context.t0 = _context.sent;
145
-
146
- if (!(_context.t0 === true)) {
147
- _context.next = 6;
148
- break;
149
- }
150
-
151
- clearInterval(intervalID);
152
- intervalIDArr.splice(intervalIDArr.indexOf(intervalIDArr), 1);
153
-
154
- case 6:
155
- case "end":
156
- return _context.stop();
157
- }
158
- }
159
- }, _callee);
160
- })), 5000);
161
- intervalIDArr.push(intervalID);
162
-
163
- case 6:
164
- case "end":
165
- return _context2.stop();
166
- }
167
- }
168
- }, _callee2);
169
- })), 500);
170
- }
171
- })),
172
- _useState4 = _slicedToArray(_useState3, 1),
173
- uploadQueue = _useState4[0];
174
-
136
+ })),
137
+ _useState4 = _slicedToArray(_useState3, 1),
138
+ uploadQueue = _useState4[0];
175
139
  useEffect(function () {
176
140
  /* 定义displayName是为了在浏览器开发者工具里更好地显示高阶组件名称 */
177
141
  component.displayName = "withUploader(".concat(getComponentDisplayName(WrappedComponent), ")");
@@ -186,8 +150,8 @@ function useComponentInit(component, WrappedComponent) {
186
150
  finishCb: PropTypes.func
187
151
  };
188
152
  }, [component, WrappedComponent]);
189
- /* 清理所有定时器 */
190
153
 
154
+ /* 清理所有定时器 */
191
155
  useEffect(function () {
192
156
  return function () {
193
157
  intervalIDArr.forEach(function (intervalID) {
@@ -205,8 +169,6 @@ function useComponentInit(component, WrappedComponent) {
205
169
  * 根据用户选择上传的文件来初始化文件信息,并添加到state里
206
170
  * @param {File} file 用户选择上传的文件
207
171
  */
208
-
209
-
210
172
  function initFilesListState(file) {
211
173
  var fileInfo = {
212
174
  hash: guid(),
@@ -216,8 +178,8 @@ function initFilesListState(file) {
216
178
  publicPath: '',
217
179
  size: file.size,
218
180
  sizeStr: bytesToSize(file.size) // 转换当前字节数
219
-
220
181
  };
182
+
221
183
  this.setFilesList([].concat(_toConsumableArray(this.filesList), [fileInfo]));
222
184
  console.log('根据用户选择上传的文件来初始化文件信息', fileInfo);
223
185
  return fileInfo;
@@ -226,8 +188,6 @@ function initFilesListState(file) {
226
188
  * 根据文件hash查询当前组件管理的文件列表里是否已存在目标文件
227
189
  * @param {String} hash 文件hash
228
190
  */
229
-
230
-
231
191
  function checkDuplicateByHash(hash) {
232
192
  return this.filesList.some(function (file) {
233
193
  return file.hash === hash;
@@ -237,8 +197,6 @@ function checkDuplicateByHash(hash) {
237
197
  * 根据文件hash,从当前组件管理的文件列表中删除目标文件信息
238
198
  * @param {Object} currentFileInfo 用户当前选择上传的文件的信息
239
199
  */
240
-
241
-
242
200
  function removeFile(currentFileInfo) {
243
201
  this.setFilesList(function (filesList) {
244
202
  return filesList.filter(function (file) {
@@ -251,8 +209,6 @@ function removeFile(currentFileInfo) {
251
209
  * @param {String} hash 文件hash
252
210
  * @param {Object} newFileAttrs 需要更新的文件信息字段;不需要更新的字段就不需要传进来
253
211
  */
254
-
255
-
256
212
  function updateFileInfo(hash, newFileAttrs) {
257
213
  console.log('updateFileInfo=》 更新state中的文件信息');
258
214
  this.setFilesList(function (filesList) {
@@ -267,13 +223,10 @@ function updateFileInfo(hash, newFileAttrs) {
267
223
  * @param {Number} perChunkSize 每个分片的大小
268
224
  * @param {Function} errorCb 错误异常的处理函数
269
225
  */
270
-
271
-
272
226
  function returnFileInputChangeCb(_ref3) {
273
227
  var _this = this;
274
-
275
228
  var perChunkSize = _ref3.perChunkSize,
276
- errorCb = _ref3.errorCb;
229
+ errorCb = _ref3.errorCb;
277
230
  console.log('调用input更新事件');
278
231
  return /*#__PURE__*/function () {
279
232
  var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(event) {
@@ -286,13 +239,10 @@ function returnFileInputChangeCb(_ref3) {
286
239
  currentFileInfo = initFilesListState.call(_this, file);
287
240
  console.log('当前已选择需要上传的文件', file);
288
241
  chunksArr = splitFileToChunks(file, perChunkSize); // 文件分片
289
-
290
242
  _context4.next = 6;
291
243
  return calFileContentHash(chunksArr);
292
-
293
244
  case 6:
294
245
  fileContentHash = _context4.sent;
295
-
296
246
  // 计算文件内容的hash
297
247
  if (checkDuplicateByHash.call(_this, fileContentHash)) {
298
248
  removeFile.call(_this, currentFileInfo);
@@ -301,19 +251,16 @@ function returnFileInputChangeCb(_ref3) {
301
251
  message: 'duplicate file found by hash'
302
252
  });
303
253
  }
304
-
305
254
  console.log('当前文件内的fileContentHash', fileContentHash);
306
255
  updateFileInfo.call(_this, currentFileInfo.hash, {
307
256
  hash: fileContentHash
308
257
  });
309
258
  /* 查询该文件上传情况 */
310
-
311
259
  _context4.next = 12;
312
260
  return queryFileInfo(_objectSpread(_objectSpread({}, currentFileInfo), {}, {
313
261
  fileHash: fileContentHash,
314
262
  chunksLength: chunksArr.length
315
263
  }));
316
-
317
264
  case 12:
318
265
  remoteFileInfo = _context4.sent;
319
266
  console.log('请求接口queryFileInfo=》初始化,返回当前文件上传情况 =>remoteFileInfo:', remoteFileInfo);
@@ -324,21 +271,14 @@ function returnFileInputChangeCb(_ref3) {
324
271
  chunksLength: remoteFileInfo.chunksLength
325
272
  });
326
273
  /* 秒传 */
327
-
328
274
  if (!(remoteFileInfo.status === 'finish')) {
329
275
  _context4.next = 17;
330
276
  break;
331
277
  }
332
-
333
278
  return _context4.abrupt("return");
334
-
335
279
  case 17:
336
280
  _this.uploadQueue.addChunksToQueue(remoteFileInfo, chunksArr); // 建立上传队列
337
-
338
-
339
281
  _this.uploadQueue.run(); // 触发上传
340
-
341
-
342
282
  case 19:
343
283
  case "end":
344
284
  return _context4.stop();
@@ -346,7 +286,6 @@ function returnFileInputChangeCb(_ref3) {
346
286
  }
347
287
  }, _callee4);
348
288
  }));
349
-
350
289
  return function (_x) {
351
290
  return _ref4.apply(this, arguments);
352
291
  };
@@ -356,18 +295,14 @@ function returnFileInputChangeCb(_ref3) {
356
295
  * 高阶组件的主函数
357
296
  * @param {ReactComponent} WrappedComponent 被封装的具体实现的组件
358
297
  */
359
-
360
-
361
298
  export default function withUploader(WrappedComponent) {
362
299
  return function UploaderHoc(props) {
363
300
  var perChunkSize = props.perChunkSize,
364
- errorCb = props.errorCb,
365
- restProps = _objectWithoutProperties(props, ["perChunkSize", "errorCb"]);
366
-
301
+ errorCb = props.errorCb,
302
+ restProps = _objectWithoutProperties(props, ["perChunkSize", "errorCb"]);
367
303
  var fileInputRef = useRef(null);
368
304
  var state = useComponentInit(UploaderHoc, WrappedComponent);
369
305
  /* 组装传给具体实现组件的props */
370
-
371
306
  var spreadProps = _objectSpread(_objectSpread({}, restProps), {}, {
372
307
  // 透传
373
308
  triggerFile: function triggerFile() {
@@ -375,7 +310,6 @@ export default function withUploader(WrappedComponent) {
375
310
  },
376
311
  filesList: state.filesList
377
312
  });
378
-
379
313
  return /*#__PURE__*/React.createElement("div", {
380
314
  className: "upload-hoc"
381
315
  }, /*#__PURE__*/React.createElement("input", {
@@ -1,7 +1,5 @@
1
1
  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); } }
2
-
3
2
  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); }); }; }
4
-
5
3
  // eslint-disable-next-line import/no-webpack-loader-syntax
6
4
  import Worker from 'worker-loader!./worker.js'; // 启动 Web Worker
7
5
 
@@ -9,33 +7,29 @@ import Worker from 'worker-loader!./worker.js'; // 启动 Web Worker
9
7
  * 获取组件名称
10
8
  * @param {ReactComponent} component
11
9
  */
12
-
13
10
  export function getComponentDisplayName(component) {
14
11
  return component.displayName || component.name || 'Component';
15
12
  }
13
+
16
14
  /**
17
15
  * 文件切分分片
18
16
  * @param {File} file 文件
19
17
  */
20
-
21
18
  export function splitFileToChunks(file, perChunkSize) {
22
19
  var fileSize = file.size;
23
20
  var total = Math.ceil(fileSize / perChunkSize); // 计算总共要分多少片
24
-
25
21
  var chunksArr = [];
26
-
27
22
  for (var i = 1; i <= total; i++) {
28
23
  chunksArr.push(file.slice((i - 1) * perChunkSize, i * perChunkSize));
29
24
  }
30
-
31
25
  console.log('splitFileToChunks==》文件切分分片', chunksArr);
32
26
  return chunksArr;
33
27
  }
28
+
34
29
  /**
35
30
  * 利用WebWorker计算文件内容的Hash
36
31
  * @param {File} file 文件
37
32
  */
38
-
39
33
  export function calFileContentHash(_x) {
40
34
  return _calFileContentHash.apply(this, arguments);
41
35
  }
@@ -44,7 +38,6 @@ export function calFileContentHash(_x) {
44
38
  * @param {String} bytes 字节数
45
39
  * @param {Number} precise 小数精度
46
40
  */
47
-
48
41
  function _calFileContentHash() {
49
42
  _calFileContentHash = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(chunksArr) {
50
43
  var worker;
@@ -56,15 +49,12 @@ function _calFileContentHash() {
56
49
  worker.postMessage({
57
50
  chunksArr: chunksArr
58
51
  }); // 传递文件分片
59
-
60
52
  /* 接受计算好的hash */
61
-
62
53
  return _context.abrupt("return", new Promise(function (resolve) {
63
54
  worker.onmessage = function (event) {
64
55
  resolve(event.data.hash);
65
56
  };
66
57
  }));
67
-
68
58
  case 3:
69
59
  case "end":
70
60
  return _context.stop();
@@ -74,23 +64,20 @@ function _calFileContentHash() {
74
64
  }));
75
65
  return _calFileContentHash.apply(this, arguments);
76
66
  }
77
-
78
67
  export function bytesToSize(bytes) {
79
68
  var precise = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
80
69
  if (bytes === 0) return '0 B';
81
70
  var k = 1024,
82
- sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
83
- i = Math.floor(Math.log(bytes) / Math.log(k));
71
+ sizes = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'],
72
+ i = Math.floor(Math.log(bytes) / Math.log(k));
84
73
  return (bytes / Math.pow(k, i)).toFixed(precise) + ' ' + sizes[i];
85
74
  }
86
75
  /**
87
76
  * 生成guid
88
77
  */
89
-
90
78
  export function guid() {
91
79
  function S4() {
92
80
  return ((1 + Math.random()) * 0x10000 | 0).toString(16).substring(1);
93
81
  }
94
-
95
82
  return "".concat(S4()).concat(S4(), "-").concat(S4(), "-").concat(S4(), "-").concat(S4(), "-").concat(S4()).concat(S4()).concat(S4());
96
83
  }