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