iglooform 2.4.9 → 2.4.13
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/es/admin-upload/index.d.ts +2 -0
- package/es/admin-upload/index.js +25 -11
- package/es/admin-upload/job-list.js +2 -2
- package/es/alert-message/index.js +2 -2
- package/es/amount/index.js +2 -2
- package/es/back-top/index.js +2 -2
- package/es/button/index.js +2 -2
- package/es/button/style/index.less +23 -19
- package/es/card-detail/card-item.js +1 -1
- package/es/card-detail/card.js +2 -2
- package/es/card-detail/utils.js +3 -3
- package/es/checkbox/index.js +2 -2
- package/es/claim-list/index.js +2 -2
- package/es/confirmation/index.js +2 -2
- package/es/date-picker/buddhist.js +2 -2
- package/es/date-picker/index.js +2 -2
- package/es/declaration/index.js +2 -2
- package/es/detail-panel/index.js +2 -2
- package/es/example/index.js +6 -7
- package/es/filter/index.d.ts +1 -0
- package/es/filter/index.js +10 -6
- package/es/form/addable-section/index.d.ts +19 -0
- package/es/form/addable-section/index.js +211 -0
- package/es/form/addable-section/style/index.d.ts +1 -0
- package/es/form/addable-section/style/index.js +1 -0
- package/es/form/addable-section/style/index.less +22 -0
- package/es/form/divider/index.js +2 -2
- package/es/form/element/index.js +30 -11
- package/es/form/element/style/index.less +5 -0
- package/es/form/index.js +7 -5
- package/es/form/login/index.js +1 -1
- package/es/form/page/index.js +1 -1
- package/es/form/page/style/index.less +1 -1
- package/es/form/pages/index.js +2 -3
- package/es/form/pages/style/index.less +3 -1
- package/es/form/render/index.js +1 -1
- package/es/form/section/index.js +4 -4
- package/es/form/step/index.js +1 -1
- package/es/form/steps/index.js +2 -3
- package/es/{form/context.d.ts → form-context.d.ts} +1 -0
- package/es/{form/context.js → form-context.js} +0 -0
- package/es/free-form/addable-section/index.d.ts +18 -0
- package/es/free-form/addable-section/index.js +286 -0
- package/es/free-form/addable-section/style/index.d.ts +1 -0
- package/es/free-form/addable-section/style/index.js +1 -0
- package/es/free-form/addable-section/style/index.less +22 -0
- package/es/free-form/element/index.js +22 -14
- package/es/free-form/element/style/index.less +8 -2
- package/es/free-form/index.d.ts +5 -1
- package/es/free-form/index.js +8 -5
- package/es/free-form/page/index.js +8 -7
- package/es/free-form/page/style/index.less +3 -1
- package/es/free-form/pages/index.js +2 -2
- package/es/free-form/section/index.js +10 -9
- package/es/free-form/section/style/index.less +4 -0
- package/es/free-form/step/index.js +7 -6
- package/es/free-form/steps/index.js +2 -2
- package/es/global-message/index.js +1 -1
- package/es/index.d.ts +1 -0
- package/es/index.js +2 -1
- package/es/input/amount.js +2 -2
- package/es/input/credit-card.js +2 -2
- package/es/input/email.js +2 -2
- package/es/input/expiry-date.js +2 -2
- package/es/input/input-number.js +2 -2
- package/es/input/input.js +2 -2
- package/es/input/otp.js +2 -2
- package/es/input/password.js +2 -2
- package/es/input/style/index.less +9 -1
- package/es/input/text-area.js +2 -2
- package/es/layout/header.js +3 -3
- package/es/layout/index.js +2 -2
- package/es/locale/en-US/messages.json +2 -0
- package/es/locale/id-ID/messages.json +2 -0
- package/es/locale/locale-provider.js +2 -2
- package/es/locale/th-TH/messages.json +2 -0
- package/es/locale/vi-VN/messages.json +2 -0
- package/es/locale/zh-CN/messages.json +2 -0
- package/es/media/preview.js +2 -2
- package/es/mobile-insurer-detail/index.js +2 -2
- package/es/mobile-insurer-list/index.js +2 -2
- package/es/modal/index.d.ts +4 -3
- package/es/modal/index.js +6 -3
- package/es/modal/style/index.less +24 -5
- package/es/policy-list/index.js +2 -2
- package/es/policy-list/policy-card.js +2 -2
- package/es/radio/index.js +2 -2
- package/es/select/attached-select.js +2 -2
- package/es/select/select.js +2 -2
- package/es/select/style/index.less +1 -1
- package/es/status-box/index.js +2 -2
- package/es/table/index.js +3 -3
- package/es/tabs/index.js +2 -2
- package/es/tabs/style/index.less +1 -1
- package/es/types.d.ts +5 -2
- package/es/upload/index.d.ts +2 -1
- package/es/upload/index.js +121 -77
- package/es/upload-photo/index.d.ts +2 -1
- package/es/upload-photo/index.js +123 -79
- package/es/utils/form-utils.d.ts +1 -0
- package/es/utils/form-utils.js +34 -12
- package/lib/admin-upload/index.d.ts +2 -0
- package/lib/admin-upload/index.js +25 -11
- package/lib/admin-upload/job-list.js +2 -2
- package/lib/alert-message/index.js +2 -2
- package/lib/amount/index.js +2 -2
- package/lib/back-top/index.js +2 -2
- package/lib/button/index.js +2 -2
- package/lib/button/style/index.less +23 -19
- package/lib/card-detail/card-item.js +1 -1
- package/lib/card-detail/card.js +2 -2
- package/lib/card-detail/utils.js +3 -3
- package/lib/checkbox/index.js +2 -2
- package/lib/claim-list/index.js +2 -2
- package/lib/confirmation/index.js +2 -2
- package/lib/date-picker/buddhist.js +2 -2
- package/lib/date-picker/index.js +2 -2
- package/lib/declaration/index.js +2 -2
- package/lib/detail-panel/index.js +2 -2
- package/lib/example/index.js +7 -8
- package/lib/filter/index.d.ts +1 -0
- package/lib/filter/index.js +10 -6
- package/lib/form/addable-section/index.d.ts +19 -0
- package/lib/form/addable-section/index.js +232 -0
- package/lib/form/addable-section/style/index.d.ts +1 -0
- package/lib/form/addable-section/style/index.js +3 -0
- package/lib/form/addable-section/style/index.less +22 -0
- package/lib/form/divider/index.js +2 -2
- package/lib/form/element/index.js +32 -12
- package/lib/form/element/style/index.less +5 -0
- package/lib/form/elements.js +1 -1
- package/lib/form/index.js +8 -6
- package/lib/form/login/index.js +2 -2
- package/lib/form/page/index.js +2 -2
- package/lib/form/page/style/index.less +1 -1
- package/lib/form/pages/index.js +3 -4
- package/lib/form/pages/style/index.less +3 -1
- package/lib/form/render/index.js +2 -2
- package/lib/form/section/index.js +5 -5
- package/lib/form/step/index.js +2 -2
- package/lib/form/steps/index.js +3 -4
- package/lib/{form/context.d.ts → form-context.d.ts} +1 -0
- package/lib/{form/context.js → form-context.js} +0 -0
- package/lib/free-form/addable-section/index.d.ts +18 -0
- package/lib/free-form/addable-section/index.js +306 -0
- package/lib/free-form/addable-section/style/index.d.ts +1 -0
- package/lib/free-form/addable-section/style/index.js +3 -0
- package/lib/free-form/addable-section/style/index.less +22 -0
- package/lib/free-form/element/index.js +23 -15
- package/lib/free-form/element/style/index.less +8 -2
- package/lib/free-form/index.d.ts +5 -1
- package/lib/free-form/index.js +9 -6
- package/lib/free-form/page/index.js +9 -8
- package/lib/free-form/page/style/index.less +3 -1
- package/lib/free-form/pages/index.js +2 -2
- package/lib/free-form/section/index.js +11 -10
- package/lib/free-form/section/style/index.less +4 -0
- package/lib/free-form/step/index.js +8 -7
- package/lib/free-form/steps/index.js +3 -3
- package/lib/global-message/index.js +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +11 -2
- package/lib/input/amount.js +2 -2
- package/lib/input/credit-card.js +2 -2
- package/lib/input/email.js +2 -2
- package/lib/input/expiry-date.js +2 -2
- package/lib/input/input-number.js +2 -2
- package/lib/input/input.js +2 -2
- package/lib/input/otp.js +2 -2
- package/lib/input/password.js +2 -2
- package/lib/input/style/index.less +9 -1
- package/lib/input/text-area.js +2 -2
- package/lib/layout/header.js +3 -3
- package/lib/layout/index.js +2 -2
- package/lib/locale/en-US/messages.json +2 -0
- package/lib/locale/id-ID/messages.json +2 -0
- package/lib/locale/locale-provider.js +2 -2
- package/lib/locale/th-TH/messages.json +2 -0
- package/lib/locale/vi-VN/messages.json +2 -0
- package/lib/locale/zh-CN/messages.json +2 -0
- package/lib/media/preview.js +2 -2
- package/lib/mobile-insurer-detail/index.js +2 -2
- package/lib/mobile-insurer-list/index.js +2 -2
- package/lib/modal/index.d.ts +4 -3
- package/lib/modal/index.js +6 -3
- package/lib/modal/style/index.less +24 -5
- package/lib/policy-list/index.js +2 -2
- package/lib/policy-list/policy-card.js +2 -2
- package/lib/radio/index.js +2 -2
- package/lib/select/attached-select.js +2 -2
- package/lib/select/select.js +2 -2
- package/lib/select/style/index.less +1 -1
- package/lib/status-box/index.js +2 -2
- package/lib/table/index.js +3 -3
- package/lib/tabs/index.js +2 -2
- package/lib/tabs/style/index.less +1 -1
- package/lib/types.d.ts +5 -2
- package/lib/upload/index.d.ts +2 -1
- package/lib/upload/index.js +122 -77
- package/lib/upload-photo/index.d.ts +2 -1
- package/lib/upload-photo/index.js +124 -79
- package/lib/utils/form-utils.d.ts +1 -0
- package/lib/utils/form-utils.js +33 -12
- package/package.json +1 -1
- package/es/free-form/context.d.ts +0 -19
- package/es/free-form/context.js +0 -7
- package/lib/free-form/context.d.ts +0 -19
- package/lib/free-form/context.js +0 -19
package/lib/upload/index.js
CHANGED
|
@@ -37,15 +37,17 @@ var _locale = require("../locale");
|
|
|
37
37
|
|
|
38
38
|
var _media = _interopRequireDefault(require("../upload-preview/media"));
|
|
39
39
|
|
|
40
|
-
var
|
|
40
|
+
var _formContext = _interopRequireDefault(require("../form-context"));
|
|
41
|
+
|
|
42
|
+
var _excluded = ["value", "limit", "limitErrorMessage", "descriptions", "onChange", "bizKey", "handleUpload", "setFieldError", "className", "validateField", "containerRef", "placeholder"];
|
|
41
43
|
|
|
42
44
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
43
45
|
|
|
44
|
-
function _typeof(obj) { "@babel/helpers - typeof";
|
|
46
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
45
47
|
|
|
46
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object);
|
|
48
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
47
49
|
|
|
48
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]
|
|
50
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
49
51
|
|
|
50
52
|
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; }
|
|
51
53
|
|
|
@@ -57,10 +59,6 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
|
|
|
57
59
|
|
|
58
60
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
59
61
|
|
|
60
|
-
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); } }
|
|
61
|
-
|
|
62
|
-
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); }); }; }
|
|
63
|
-
|
|
64
62
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
65
63
|
|
|
66
64
|
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."); }
|
|
@@ -73,31 +71,79 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
|
|
|
73
71
|
|
|
74
72
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
75
73
|
|
|
74
|
+
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); } }
|
|
75
|
+
|
|
76
|
+
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); }); }; }
|
|
77
|
+
|
|
76
78
|
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; }
|
|
77
79
|
|
|
78
80
|
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; }
|
|
79
81
|
|
|
80
82
|
var Dragger = _upload.default.Dragger;
|
|
81
83
|
|
|
82
|
-
var IglooUpload = function IglooUpload(
|
|
83
|
-
var className = _ref.className,
|
|
84
|
-
placeholder = _ref.placeholder,
|
|
85
|
-
handleUpload = _ref.handleUpload,
|
|
86
|
-
_ref$value = _ref.value,
|
|
87
|
-
value = _ref$value === void 0 ? [] : _ref$value,
|
|
88
|
-
onChange = _ref.onChange,
|
|
89
|
-
limit = _ref.limit,
|
|
90
|
-
limitErrorMessage = _ref.limitErrorMessage,
|
|
91
|
-
containerRef = _ref.containerRef,
|
|
92
|
-
setFieldError = _ref.setFieldError,
|
|
93
|
-
descriptions = _ref.descriptions,
|
|
94
|
-
validateField = _ref.validateField,
|
|
95
|
-
rest = _objectWithoutProperties(_ref, _excluded);
|
|
96
|
-
|
|
84
|
+
var IglooUpload = function IglooUpload(props) {
|
|
97
85
|
var limitNumError = (0, _react.useRef)();
|
|
98
86
|
var DomRef = (0, _react.useRef)();
|
|
99
87
|
var dataUrlRef = (0, _react.useRef)([]);
|
|
100
88
|
|
|
89
|
+
var _useContext = (0, _react.useContext)(_formContext.default),
|
|
90
|
+
uploadApi = _useContext.uploadApi;
|
|
91
|
+
|
|
92
|
+
(0, _invariant.default)(typeof props.handleUpload === 'function' || uploadApi, '"handleUpload" should be a function. Or uploadApi should be set at Form/FreeForm');
|
|
93
|
+
(0, _invariant.default)(!uploadApi || props.bizKey, '"bizKey" should be set if Upload is used with uploadApi');
|
|
94
|
+
|
|
95
|
+
var _props$value = props.value,
|
|
96
|
+
value = _props$value === void 0 ? [] : _props$value,
|
|
97
|
+
limit = props.limit,
|
|
98
|
+
limitErrorMessage = props.limitErrorMessage,
|
|
99
|
+
descriptions = props.descriptions,
|
|
100
|
+
onChange = props.onChange,
|
|
101
|
+
bizKey = props.bizKey,
|
|
102
|
+
_props$handleUpload = props.handleUpload,
|
|
103
|
+
handleUpload = _props$handleUpload === void 0 ? /*#__PURE__*/function () {
|
|
104
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee(file) {
|
|
105
|
+
var formData, response, rst;
|
|
106
|
+
return regeneratorRuntime.wrap(function _callee$(_context) {
|
|
107
|
+
while (1) {
|
|
108
|
+
switch (_context.prev = _context.next) {
|
|
109
|
+
case 0:
|
|
110
|
+
formData = new FormData();
|
|
111
|
+
formData.append('file', file);
|
|
112
|
+
formData.append('biz_key', bizKey);
|
|
113
|
+
_context.next = 5;
|
|
114
|
+
return fetch(uploadApi, {
|
|
115
|
+
method: 'post',
|
|
116
|
+
body: formData
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
case 5:
|
|
120
|
+
response = _context.sent;
|
|
121
|
+
_context.next = 8;
|
|
122
|
+
return response.json();
|
|
123
|
+
|
|
124
|
+
case 8:
|
|
125
|
+
rst = _context.sent;
|
|
126
|
+
return _context.abrupt("return", rst.url);
|
|
127
|
+
|
|
128
|
+
case 10:
|
|
129
|
+
case "end":
|
|
130
|
+
return _context.stop();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
}, _callee);
|
|
134
|
+
}));
|
|
135
|
+
|
|
136
|
+
return function (_x) {
|
|
137
|
+
return _ref.apply(this, arguments);
|
|
138
|
+
};
|
|
139
|
+
}() : _props$handleUpload,
|
|
140
|
+
setFieldError = props.setFieldError,
|
|
141
|
+
className = props.className,
|
|
142
|
+
validateField = props.validateField,
|
|
143
|
+
containerRef = props.containerRef,
|
|
144
|
+
placeholder = props.placeholder,
|
|
145
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
146
|
+
|
|
101
147
|
var _useState = (0, _react.useState)(value.map(function (url, index) {
|
|
102
148
|
return {
|
|
103
149
|
url: url,
|
|
@@ -119,7 +165,7 @@ var IglooUpload = function IglooUpload(_ref) {
|
|
|
119
165
|
return;
|
|
120
166
|
}
|
|
121
167
|
|
|
122
|
-
if (!DomRef.current.contains(e.target) && limitNumError.current) {
|
|
168
|
+
if (DomRef.current && !DomRef.current.contains(e.target) && limitNumError.current) {
|
|
123
169
|
validateField && validateField();
|
|
124
170
|
limitNumError.current = undefined;
|
|
125
171
|
}
|
|
@@ -137,8 +183,8 @@ var IglooUpload = function IglooUpload(_ref) {
|
|
|
137
183
|
}
|
|
138
184
|
});
|
|
139
185
|
|
|
140
|
-
var
|
|
141
|
-
formatMessage =
|
|
186
|
+
var _useContext2 = (0, _react.useContext)(_locale.LocaleContext),
|
|
187
|
+
formatMessage = _useContext2.formatMessage;
|
|
142
188
|
|
|
143
189
|
(0, _react.useEffect)(function () {
|
|
144
190
|
return function () {
|
|
@@ -147,22 +193,21 @@ var IglooUpload = function IglooUpload(_ref) {
|
|
|
147
193
|
});
|
|
148
194
|
};
|
|
149
195
|
}, []);
|
|
150
|
-
(0, _invariant.default)(typeof handleUpload === 'function', '"handleUpload" should be a function.');
|
|
151
196
|
(0, _invariant.default)(limit === undefined || limit > 0, "\"limit\" should be a pasitive number.");
|
|
152
197
|
|
|
153
198
|
var onUpload = /*#__PURE__*/function () {
|
|
154
|
-
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
199
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2(file) {
|
|
155
200
|
var dataUrl, name, size, type, uid, errorMsg;
|
|
156
|
-
return regeneratorRuntime.wrap(function
|
|
201
|
+
return regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
157
202
|
while (1) {
|
|
158
|
-
switch (
|
|
203
|
+
switch (_context2.prev = _context2.next) {
|
|
159
204
|
case 0:
|
|
160
205
|
dataUrl = URL.createObjectURL(file);
|
|
161
206
|
dataUrlRef.current.push(dataUrl);
|
|
162
207
|
name = file.name, size = file.size, type = file.type, uid = file.uid;
|
|
163
208
|
|
|
164
209
|
if (!(limit && files.length >= limit)) {
|
|
165
|
-
|
|
210
|
+
_context2.next = 8;
|
|
166
211
|
break;
|
|
167
212
|
}
|
|
168
213
|
|
|
@@ -174,7 +219,7 @@ var IglooUpload = function IglooUpload(_ref) {
|
|
|
174
219
|
});
|
|
175
220
|
limitNumError.current = errorMsg;
|
|
176
221
|
setFieldError && setFieldError(errorMsg);
|
|
177
|
-
return
|
|
222
|
+
return _context2.abrupt("return", Promise.reject(errorMsg));
|
|
178
223
|
|
|
179
224
|
case 8:
|
|
180
225
|
limitNumError.current = undefined;
|
|
@@ -190,7 +235,7 @@ var IglooUpload = function IglooUpload(_ref) {
|
|
|
190
235
|
}]);
|
|
191
236
|
}); // 符合文件个数限制之后 上传时的错误处理
|
|
192
237
|
|
|
193
|
-
return
|
|
238
|
+
return _context2.abrupt("return", handleUploadPromise(file, function (url) {
|
|
194
239
|
var urls = [];
|
|
195
240
|
setFiles(function (files) {
|
|
196
241
|
return files.map(function (f) {
|
|
@@ -254,64 +299,64 @@ var IglooUpload = function IglooUpload(_ref) {
|
|
|
254
299
|
|
|
255
300
|
case 11:
|
|
256
301
|
case "end":
|
|
257
|
-
return
|
|
302
|
+
return _context2.stop();
|
|
258
303
|
}
|
|
259
304
|
}
|
|
260
|
-
},
|
|
305
|
+
}, _callee2);
|
|
261
306
|
}));
|
|
262
307
|
|
|
263
|
-
return function onUpload(
|
|
308
|
+
return function onUpload(_x2) {
|
|
264
309
|
return _ref2.apply(this, arguments);
|
|
265
310
|
};
|
|
266
311
|
}();
|
|
267
312
|
|
|
268
313
|
var handleUploadPromise = /*#__PURE__*/function () {
|
|
269
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
314
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3(file, onSuccess, onFailed) {
|
|
270
315
|
var rst, errorMsg;
|
|
271
|
-
return regeneratorRuntime.wrap(function
|
|
316
|
+
return regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
272
317
|
while (1) {
|
|
273
|
-
switch (
|
|
318
|
+
switch (_context3.prev = _context3.next) {
|
|
274
319
|
case 0:
|
|
275
|
-
|
|
276
|
-
|
|
320
|
+
_context3.prev = 0;
|
|
321
|
+
_context3.next = 3;
|
|
277
322
|
return handleUpload(file);
|
|
278
323
|
|
|
279
324
|
case 3:
|
|
280
|
-
rst =
|
|
325
|
+
rst = _context3.sent;
|
|
281
326
|
onSuccess(rst);
|
|
282
|
-
return
|
|
327
|
+
return _context3.abrupt("return", Promise.resolve(rst));
|
|
283
328
|
|
|
284
329
|
case 8:
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
errorMsg = _typeof(
|
|
330
|
+
_context3.prev = 8;
|
|
331
|
+
_context3.t0 = _context3["catch"](0);
|
|
332
|
+
errorMsg = _typeof(_context3.t0) === 'object' ? _context3.t0.message : _context3.t0;
|
|
288
333
|
onFailed(errorMsg);
|
|
289
|
-
return
|
|
334
|
+
return _context3.abrupt("return", Promise.reject(errorMsg));
|
|
290
335
|
|
|
291
336
|
case 13:
|
|
292
337
|
case "end":
|
|
293
|
-
return
|
|
338
|
+
return _context3.stop();
|
|
294
339
|
}
|
|
295
340
|
}
|
|
296
|
-
},
|
|
341
|
+
}, _callee3, null, [[0, 8]]);
|
|
297
342
|
}));
|
|
298
343
|
|
|
299
|
-
return function handleUploadPromise(
|
|
344
|
+
return function handleUploadPromise(_x3, _x4, _x5) {
|
|
300
345
|
return _ref3.apply(this, arguments);
|
|
301
346
|
};
|
|
302
347
|
}(); // 错误提示的优先级,上传报错 > 'quantity of files should be less than {limit}' > 'Please re-upload this file:{name}'
|
|
303
348
|
|
|
304
349
|
|
|
305
350
|
var handleDelete = /*#__PURE__*/function () {
|
|
306
|
-
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
351
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4(index) {
|
|
307
352
|
var arr, hasError, rst;
|
|
308
|
-
return regeneratorRuntime.wrap(function
|
|
353
|
+
return regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
309
354
|
while (1) {
|
|
310
|
-
switch (
|
|
355
|
+
switch (_context4.prev = _context4.next) {
|
|
311
356
|
case 0:
|
|
312
357
|
limitNumError.current = null;
|
|
313
358
|
arr = files;
|
|
314
|
-
|
|
359
|
+
_context4.next = 4;
|
|
315
360
|
return setFiles(function (files) {
|
|
316
361
|
var newArr = files.filter(function (_, i) {
|
|
317
362
|
return i !== index;
|
|
@@ -327,7 +372,7 @@ var IglooUpload = function IglooUpload(_ref) {
|
|
|
327
372
|
});
|
|
328
373
|
|
|
329
374
|
if (!hasError) {
|
|
330
|
-
|
|
375
|
+
_context4.next = 8;
|
|
331
376
|
break;
|
|
332
377
|
}
|
|
333
378
|
|
|
@@ -340,7 +385,7 @@ var IglooUpload = function IglooUpload(_ref) {
|
|
|
340
385
|
|
|
341
386
|
return f.url;
|
|
342
387
|
});
|
|
343
|
-
return
|
|
388
|
+
return _context4.abrupt("return", typeof onChange === 'function' && onChange(rst));
|
|
344
389
|
|
|
345
390
|
case 8:
|
|
346
391
|
typeof onChange === 'function' && onChange(arr.map(function (_ref5) {
|
|
@@ -350,36 +395,36 @@ var IglooUpload = function IglooUpload(_ref) {
|
|
|
350
395
|
|
|
351
396
|
case 9:
|
|
352
397
|
case "end":
|
|
353
|
-
return
|
|
398
|
+
return _context4.stop();
|
|
354
399
|
}
|
|
355
400
|
}
|
|
356
|
-
},
|
|
401
|
+
}, _callee4);
|
|
357
402
|
}));
|
|
358
403
|
|
|
359
|
-
return function handleDelete(
|
|
404
|
+
return function handleDelete(_x6) {
|
|
360
405
|
return _ref4.apply(this, arguments);
|
|
361
406
|
};
|
|
362
407
|
}();
|
|
363
408
|
|
|
364
409
|
var handleReUpload = /*#__PURE__*/function () {
|
|
365
|
-
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function
|
|
410
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee5(index) {
|
|
366
411
|
var _files$index, originFile, reUpUid, rst, latestFiles, fileListWithError, newList, _rst;
|
|
367
412
|
|
|
368
|
-
return regeneratorRuntime.wrap(function
|
|
413
|
+
return regeneratorRuntime.wrap(function _callee5$(_context5) {
|
|
369
414
|
while (1) {
|
|
370
|
-
switch (
|
|
415
|
+
switch (_context5.prev = _context5.next) {
|
|
371
416
|
case 0:
|
|
372
417
|
_files$index = files[index], originFile = _files$index.originFile, reUpUid = _files$index.uid;
|
|
373
418
|
|
|
374
419
|
if (originFile) {
|
|
375
|
-
|
|
420
|
+
_context5.next = 3;
|
|
376
421
|
break;
|
|
377
422
|
}
|
|
378
423
|
|
|
379
|
-
return
|
|
424
|
+
return _context5.abrupt("return");
|
|
380
425
|
|
|
381
426
|
case 3:
|
|
382
|
-
|
|
427
|
+
_context5.next = 5;
|
|
383
428
|
return setFiles(function (files) {
|
|
384
429
|
var newFiles = _toConsumableArray(files);
|
|
385
430
|
|
|
@@ -388,14 +433,14 @@ var IglooUpload = function IglooUpload(_ref) {
|
|
|
388
433
|
});
|
|
389
434
|
|
|
390
435
|
case 5:
|
|
391
|
-
|
|
392
|
-
|
|
436
|
+
_context5.prev = 5;
|
|
437
|
+
_context5.next = 8;
|
|
393
438
|
return handleUpload(originFile);
|
|
394
439
|
|
|
395
440
|
case 8:
|
|
396
|
-
rst =
|
|
441
|
+
rst = _context5.sent;
|
|
397
442
|
latestFiles = [];
|
|
398
|
-
|
|
443
|
+
_context5.next = 12;
|
|
399
444
|
return setFiles(function (files) {
|
|
400
445
|
var newFiles = _toConsumableArray(files);
|
|
401
446
|
|
|
@@ -423,19 +468,19 @@ var IglooUpload = function IglooUpload(_ref) {
|
|
|
423
468
|
return url;
|
|
424
469
|
});
|
|
425
470
|
onChange && onChange(fileListWithError);
|
|
426
|
-
|
|
471
|
+
_context5.next = 23;
|
|
427
472
|
break;
|
|
428
473
|
|
|
429
474
|
case 16:
|
|
430
|
-
|
|
431
|
-
|
|
475
|
+
_context5.prev = 16;
|
|
476
|
+
_context5.t0 = _context5["catch"](5);
|
|
432
477
|
newList = [];
|
|
433
|
-
|
|
478
|
+
_context5.next = 21;
|
|
434
479
|
return setFiles(function (files) {
|
|
435
480
|
var newFiles = _toConsumableArray(files);
|
|
436
481
|
|
|
437
482
|
newFiles[index].status = 'failed';
|
|
438
|
-
newFiles[index].errorMsg =
|
|
483
|
+
newFiles[index].errorMsg = _context5.t0;
|
|
439
484
|
newList = newFiles;
|
|
440
485
|
return newFiles;
|
|
441
486
|
});
|
|
@@ -461,13 +506,13 @@ var IglooUpload = function IglooUpload(_ref) {
|
|
|
461
506
|
|
|
462
507
|
case 23:
|
|
463
508
|
case "end":
|
|
464
|
-
return
|
|
509
|
+
return _context5.stop();
|
|
465
510
|
}
|
|
466
511
|
}
|
|
467
|
-
},
|
|
512
|
+
}, _callee5, null, [[5, 16]]);
|
|
468
513
|
}));
|
|
469
514
|
|
|
470
|
-
return function handleReUpload(
|
|
515
|
+
return function handleReUpload(_x7) {
|
|
471
516
|
return _ref6.apply(this, arguments);
|
|
472
517
|
};
|
|
473
518
|
}();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { FC, IglooComponentProps } from '../types';
|
|
2
2
|
import './style/index.less';
|
|
3
3
|
export interface Props extends IglooComponentProps {
|
|
4
|
-
handleUpload(file: File): PromiseLike<string>;
|
|
4
|
+
handleUpload?(file: File): PromiseLike<string>;
|
|
5
5
|
value?: (string | {
|
|
6
6
|
name: string;
|
|
7
7
|
status: 'failed';
|
|
@@ -15,6 +15,7 @@ export interface Props extends IglooComponentProps {
|
|
|
15
15
|
samples?: Sample[];
|
|
16
16
|
className?: any;
|
|
17
17
|
id?: string;
|
|
18
|
+
bizKey?: string;
|
|
18
19
|
}
|
|
19
20
|
export declare type Sample = {
|
|
20
21
|
src: string;
|