easy3wui 1.5.0 → 1.5.4

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.
@@ -1,10 +1,8 @@
1
1
  .ant-upload-list-item {
2
- width: -webkit-max-content;
3
2
  width: -moz-max-content;
4
3
  width: max-content;
5
4
  }
6
5
  .ant-upload-list-item .ant-upload-list-item-info {
7
- width: -webkit-max-content;
8
6
  width: -moz-max-content;
9
7
  width: max-content;
10
8
  }
package/assets/index.css CHANGED
@@ -1380,12 +1380,10 @@ s {
1380
1380
  cursor: pointer;
1381
1381
  }
1382
1382
  .ant-upload-list-item {
1383
- width: -webkit-max-content;
1384
1383
  width: -moz-max-content;
1385
1384
  width: max-content;
1386
1385
  }
1387
1386
  .ant-upload-list-item .ant-upload-list-item-info {
1388
- width: -webkit-max-content;
1389
1387
  width: -moz-max-content;
1390
1388
  width: max-content;
1391
1389
  }
@@ -40,13 +40,19 @@ var Easy3wRCView = function (_PureComponent) {
40
40
  };
41
41
 
42
42
  Easy3wRCView.prototype.render = function render() {
43
- var imgUrl = this.props.imgUrl;
43
+ var _props = this.props,
44
+ imgUrl = _props.imgUrl,
45
+ hideModal = _props.hideModal;
44
46
 
45
47
  return _react2['default'].createElement(
46
- _rcViewer2['default']
47
- // eslint-disable-next-line react/no-string-refs
48
- ,
49
- { ref: 'viewer'
48
+ _rcViewer2['default'],
49
+ {
50
+ options: {
51
+ // 关闭时的回调
52
+ hide: hideModal
53
+ }
54
+ // eslint-disable-next-line react/no-string-refs
55
+ , ref: 'viewer'
50
56
  },
51
57
  _react2['default'].createElement('img', { style: { display: 'none' }, src: imgUrl, alt: '' })
52
58
  );
@@ -100,6 +100,10 @@ var Easy3wDownLoad = function (_Component) {
100
100
  _this.setState({ imageViewURL: url });
101
101
  };
102
102
 
103
+ _this.hideImageView = function () {
104
+ _this.setState({ imageViewURL: '' });
105
+ };
106
+
103
107
  _this.state = {
104
108
  pdfViewFlag: false, // pdf预览
105
109
  fileViewFlag: false, // xls、xlsx、doc、docx等office文件预览
@@ -200,7 +204,7 @@ var Easy3wDownLoad = function (_Component) {
200
204
  hideModal: this.hideFileModal,
201
205
  viewFileUrl: this.state.viewFileUrl
202
206
  });
203
- var viewImgObj = _react2['default'].createElement(_Easy3wRCView2['default'], { imgUrl: this.state.imageViewURL });
207
+ var viewImgObj = _react2['default'].createElement(_Easy3wRCView2['default'], { imgUrl: this.state.imageViewURL, hideModal: this.hideImageView });
204
208
  return _react2['default'].createElement(
205
209
  'div',
206
210
  null,
@@ -286,7 +286,7 @@ var Easy3wGridPage = function (_Component) {
286
286
  rowKey: rowKey,
287
287
  rowSelection: rowSelection,
288
288
  bordered: bordered,
289
- scroll: printFlag ? '' : scroll || { x: true },
289
+ scroll: printFlag ? {} : scroll || { x: true },
290
290
  onChange: this.handleTableChange,
291
291
  onRow: this.props.rowType ? function (record) {
292
292
  return {
@@ -133,7 +133,8 @@ var Easy3wUpload = function (_Component) {
133
133
  extend = _props.extend,
134
134
  extendBack = _props.extendBack,
135
135
  uploadDoneCallback = _props.uploadDoneCallback,
136
- removeCallback = _props.removeCallback;
136
+ removeCallback = _props.removeCallback,
137
+ hadUpdBtn = _props.hadUpdBtn;
137
138
  var warnMessage = this.props.warnMessage;
138
139
 
139
140
  var iniVal = [];
@@ -415,13 +416,13 @@ var Easy3wUpload = function (_Component) {
415
416
  arrowPointAtCenter: true,
416
417
  style: { width: 200, height: 'auto' }
417
418
  },
418
- _react2['default'].createElement(
419
+ hadUpdBtn ? _react2['default'].createElement(
419
420
  _button2['default'],
420
421
  null,
421
422
  _react2['default'].createElement(_icon2['default'], { type: 'upload' }),
422
423
  ' ',
423
424
  buttonName
424
- )
425
+ ) : ''
425
426
  )
426
427
  )),
427
428
  extendBackShowFlag ? extendBack : ''
@@ -450,7 +451,8 @@ Easy3wUpload.propTypes = {
450
451
  wrapperCol: _propTypes2['default'].object, // CSS类名
451
452
  warnMessage: _propTypes2['default'].string, // 提示
452
453
  extend: _propTypes2['default'].object, // 上传按钮之前的扩展
453
- extendBack: _propTypes2['default'].object // 上传按钮之后的扩展
454
+ extendBack: _propTypes2['default'].object, // 上传按钮之后的扩展
455
+ hadUpdBtn: _propTypes2['default'].bool // 是否有上传按钮
454
456
  };
455
457
  Easy3wUpload.defaultProps = {
456
458
  initialValue: [],
@@ -469,7 +471,8 @@ Easy3wUpload.defaultProps = {
469
471
  wrapperCol: {},
470
472
  warnMessage: '',
471
473
  extend: undefined,
472
- extendBack: undefined
474
+ extendBack: undefined,
475
+ hadUpdBtn: true
473
476
  };
474
477
  exports['default'] = Easy3wUpload;
475
478
  module.exports = exports['default'];
@@ -0,0 +1,1020 @@
1
+ 'use strict';
2
+
3
+ exports.__esModule = true;
4
+
5
+ var _extends2 = require('babel-runtime/helpers/extends');
6
+
7
+ var _extends3 = _interopRequireDefault(_extends2);
8
+
9
+ var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
10
+
11
+ var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
12
+
13
+ var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
14
+
15
+ var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
16
+
17
+ var _inherits2 = require('babel-runtime/helpers/inherits');
18
+
19
+ var _inherits3 = _interopRequireDefault(_inherits2);
20
+
21
+ var _react = require('react');
22
+
23
+ var _react2 = _interopRequireDefault(_react);
24
+
25
+ var _propTypes = require('prop-types');
26
+
27
+ var _propTypes2 = _interopRequireDefault(_propTypes);
28
+
29
+ var _form = require('antd/lib/form');
30
+
31
+ var _form2 = _interopRequireDefault(_form);
32
+
33
+ require('antd/lib/form/style');
34
+
35
+ var _upload = require('antd/lib/upload');
36
+
37
+ var _upload2 = _interopRequireDefault(_upload);
38
+
39
+ require('antd/lib/upload/style');
40
+
41
+ var _icon = require('antd/lib/icon');
42
+
43
+ var _icon2 = _interopRequireDefault(_icon);
44
+
45
+ require('antd/lib/icon/style');
46
+
47
+ var _button = require('antd/lib/button');
48
+
49
+ var _button2 = _interopRequireDefault(_button);
50
+
51
+ require('antd/lib/button/style');
52
+
53
+ var _progress = require('antd/lib/progress');
54
+
55
+ var _progress2 = _interopRequireDefault(_progress);
56
+
57
+ require('antd/lib/progress/style');
58
+
59
+ var _popover = require('antd/lib/popover');
60
+
61
+ var _popover2 = _interopRequireDefault(_popover);
62
+
63
+ require('antd/lib/popover/style');
64
+
65
+ var _superagent = require('superagent');
66
+
67
+ var _superagent2 = _interopRequireDefault(_superagent);
68
+
69
+ var _sparkMd = require('spark-md5');
70
+
71
+ var _sparkMd2 = _interopRequireDefault(_sparkMd);
72
+
73
+ var _modal = require('antd/lib/modal');
74
+
75
+ var _modal2 = _interopRequireDefault(_modal);
76
+
77
+ require('antd/lib/modal/style');
78
+
79
+ var _comonConfig = require('comonConfigPath/comonConfig');
80
+
81
+ var _Easy3wGetCookie = require('./../Easy3wGetCookie');
82
+
83
+ var _Easy3wGetCookie2 = _interopRequireDefault(_Easy3wGetCookie);
84
+
85
+ var _Easy3wDownLoad = require('./../Easy3wDownLoad');
86
+
87
+ var _Easy3wDownLoad2 = _interopRequireDefault(_Easy3wDownLoad);
88
+
89
+ var _Easy3wAESEncrypt = require('./../Easy3wAESEncrypt');
90
+
91
+ var _Easy3wAESEncrypt2 = _interopRequireDefault(_Easy3wAESEncrypt);
92
+
93
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
94
+
95
+ var formItemStyle = {
96
+ marginBottom: 6
97
+ };
98
+
99
+ var BigFileUpload = function (_Component) {
100
+ (0, _inherits3['default'])(BigFileUpload, _Component);
101
+
102
+ function BigFileUpload(props) {
103
+ (0, _classCallCheck3['default'])(this, BigFileUpload);
104
+
105
+ var _this = (0, _possibleConstructorReturn3['default'])(this, _Component.call(this, props));
106
+
107
+ _initialiseProps.call(_this);
108
+
109
+ var initialValue = _this.props.initialValue;
110
+
111
+ _this.state = {
112
+ preUploading: false, // 文件预处理中
113
+ uploadPercent: -1, // 上传率
114
+ preUploadPercent: -1, // 预处理率
115
+ uploadRequest: false, // 上传校验
116
+ uploading: false, // 文件上传中状态
117
+ cancelStatus: false, // 取消状态
118
+ loading: false, // 上传是否可用
119
+ fileList: initialValue && initialValue.length > 0 ? _this.iniValDeal(initialValue) : [], // 上传附件信息
120
+ chunkProgressStatus: 'active',
121
+ currentFile: null, // 当前附件
122
+ uploadData: null, // 上传的数据
123
+ iniSetedFlag: false, // 是否初始化
124
+ CUSize: 0, // 当前上传附件大小
125
+ speed: 0 // 上传速率
126
+ };
127
+ return _this;
128
+ }
129
+
130
+ BigFileUpload.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
131
+ var iniSetedFlag = this.state.iniSetedFlag;
132
+
133
+ if (!iniSetedFlag) {
134
+ var initialValue = nextProps.initialValue;
135
+ var fileList = this.state.fileList;
136
+
137
+ if (fileList && fileList.length > 0) {
138
+ return;
139
+ }
140
+ if (initialValue && initialValue.length > 0) {
141
+ var iniVal = this.iniValDeal(initialValue);
142
+ this.setState((0, _extends3['default'])({}, this.state, {
143
+ iniSetedFlag: true,
144
+ fileList: iniVal
145
+ }));
146
+ }
147
+ }
148
+ };
149
+
150
+ BigFileUpload.prototype.render = function render() {
151
+ var _this2 = this;
152
+
153
+ var _props = this.props,
154
+ name = _props.name,
155
+ listType = _props.listType,
156
+ accept = _props.accept,
157
+ required = _props.required,
158
+ help = _props.help,
159
+ buttonName = _props.buttonName,
160
+ form = _props.form,
161
+ isRead = _props.isRead,
162
+ label = _props.label,
163
+ className = _props.className,
164
+ labelCol = _props.labelCol,
165
+ wrapperCol = _props.wrapperCol,
166
+ showUploadList = _props.showUploadList,
167
+ urlDownloadFile = _props.urlDownloadFile,
168
+ initialValue = _props.initialValue;
169
+ var _state = this.state,
170
+ preUploading = _state.preUploading,
171
+ uploadPercent = _state.uploadPercent,
172
+ preUploadPercent = _state.preUploadPercent,
173
+ uploadRequest = _state.uploadRequest,
174
+ uploading = _state.uploading;
175
+ var getFieldDecorator = form.getFieldDecorator;
176
+
177
+ var uploadProp = {
178
+ // name,
179
+ listType: listType,
180
+ showUploadList: showUploadList,
181
+ accept: accept,
182
+ onRemove: function onRemove(file) {
183
+ var _state2 = _this2.state,
184
+ fileList = _state2.fileList,
185
+ currentFile = _state2.currentFile;
186
+ var iniSetedFlag = _this2.state.iniSetedFlag;
187
+
188
+ if (!iniSetedFlag) {
189
+ iniSetedFlag = true;
190
+ }
191
+ var index = fileList.indexOf(file);
192
+ if (index >= 0) {
193
+ fileList.splice(index, 1);
194
+ }
195
+ if (fileList.length === 0) {
196
+ _this2.setState((0, _extends3['default'])({}, _this2.state, {
197
+ cancelStatus: true,
198
+ loading: false,
199
+ fileList: fileList,
200
+ iniSetedFlag: iniSetedFlag
201
+ }), function () {
202
+ _this2.setUploadValue(fileList);
203
+ });
204
+ return;
205
+ }
206
+ if (currentFile && currentFile.uid) {
207
+ if (file.uid === currentFile.uid) {
208
+ _this2.setState((0, _extends3['default'])({}, _this2.state, {
209
+ cancelStatus: true,
210
+ loading: false,
211
+ fileList: fileList,
212
+ currentFile: null,
213
+ iniSetedFlag: iniSetedFlag
214
+ }), function () {
215
+ _this2.setUploadValue(fileList);
216
+ });
217
+ } else {
218
+ _this2.setState((0, _extends3['default'])({}, _this2.state, {
219
+ cancelStatus: false,
220
+ loading: true,
221
+ fileList: fileList,
222
+ iniSetedFlag: iniSetedFlag
223
+ }), function () {
224
+ _this2.setUploadValue(fileList);
225
+ });
226
+ }
227
+ } else {
228
+ _this2.setState((0, _extends3['default'])({}, _this2.state, {
229
+ cancelStatus: true,
230
+ loading: false,
231
+ fileList: fileList,
232
+ iniSetedFlag: iniSetedFlag
233
+ }), function () {
234
+ _this2.setUploadValue(fileList);
235
+ });
236
+ }
237
+ return true;
238
+ },
239
+ beforeUpload: function beforeUpload(file) {
240
+ var fileTypePass = true;
241
+ var fileNameArr = file.name.toLowerCase().split('.');
242
+ var fileType = fileNameArr[fileNameArr.length - 1];
243
+ if (file.name.length > 100) {
244
+ _modal2['default'].info({
245
+ style: { top: '38%' },
246
+ content: '文件名称至多100个字符',
247
+ okText: '知道了'
248
+ });
249
+ return false;
250
+ }
251
+ var acceptDefault = '.rplib,.xls,.doc,.jpg,.pdf,.png,.zip,.bmp,.rar,.txt,.docx,.ico,.bid,.xlsx,.jpeg,.json,.xml,.ebid,.dwg,.pptx,.xmind,.xps,.crx,.7z,.ppt,.svg,.pdm,.xlsm,.vsd,.gif,.tif,.docm,.csv,.ttf,.wps,.psd,.mp4,.tiff,.rtf,.tlb,.xlsb';
252
+ if (accept && accept.length > 0) {
253
+ acceptDefault = accept;
254
+ }
255
+ if (acceptDefault.indexOf(fileType) < 0) {
256
+ fileTypePass = false;
257
+ }
258
+ if (!fileTypePass) {
259
+ _modal2['default'].error({
260
+ style: { top: '38%' },
261
+ content: '\u4E0D\u652F\u6301' + fileType + '\u7C7B\u578B\u7684\u6587\u4EF6!'
262
+ });
263
+ return false;
264
+ }
265
+ if (file.size === 0) {
266
+ _modal2['default'].error({
267
+ style: { top: '38%' },
268
+ content: '附件必须大于0MB!'
269
+ });
270
+ return false;
271
+ }
272
+ var multiple = _this2.props.multiple;
273
+ var _state3 = _this2.state,
274
+ fileList = _state3.fileList,
275
+ iniSetedFlag = _state3.iniSetedFlag;
276
+
277
+ if (!iniSetedFlag) {
278
+ iniSetedFlag = true;
279
+ }
280
+ if (!multiple) {
281
+ fileList = [file];
282
+ } else {
283
+ fileList.push(file);
284
+ }
285
+ if (!iniSetedFlag) {
286
+ iniSetedFlag = true;
287
+ }
288
+ // 首先清除一下各种上传的状态
289
+ _this2.setState((0, _extends3['default'])({}, _this2.state, {
290
+ fileList: fileList,
291
+ currentFile: file,
292
+ preUploading: true, // 预处理中
293
+ uploading: false, // 上传中
294
+ uploadRequest: false, // 上传预处理
295
+ uploadPercent: -1,
296
+ preUploadPercent: -1,
297
+ chunkProgressStatus: 'active',
298
+ cancelStatus: false, // 取消状态
299
+ CUSize: 0, // 当前附件上传大小
300
+ loading: true, // 禁用上传
301
+ iniSetedFlag: iniSetedFlag
302
+ }), function () {
303
+ setImmediate(_this2.readFile, file);
304
+ });
305
+ return false;
306
+ },
307
+ fileList: this.state.fileList
308
+ };
309
+ if (isRead) {
310
+ uploadProp = (0, _extends3['default'])({}, uploadProp, { showUploadList: { showPreviewIcon: true, showRemoveIcon: false } });
311
+ }
312
+ return isRead ? _react2['default'].createElement(
313
+ _form2['default'].Item,
314
+ {
315
+ label: label,
316
+ className: className,
317
+ labelCol: labelCol,
318
+ wrapperCol: wrapperCol,
319
+ style: formItemStyle
320
+ },
321
+ getFieldDecorator('' + name, {})(_react2['default'].createElement(_Easy3wDownLoad2['default'], {
322
+ pdfViewFlag: true,
323
+ imgVisible: true,
324
+ urlDownloadFile: urlDownloadFile,
325
+ downloadArr: initialValue
326
+ }))
327
+ ) : _react2['default'].createElement(
328
+ _form2['default'].Item,
329
+ {
330
+ label: label,
331
+ className: className,
332
+ labelCol: labelCol,
333
+ wrapperCol: wrapperCol,
334
+ style: formItemStyle
335
+ },
336
+ _react2['default'].createElement(
337
+ 'div',
338
+ null,
339
+ getFieldDecorator('' + name, {
340
+ initialValue: this.state.fileList,
341
+ rules: [{ validator: this.requiredFile }, { required: required, message: help }]
342
+ })(_react2['default'].createElement(
343
+ _upload2['default'],
344
+ (0, _extends3['default'])({}, uploadProp, {
345
+ disabled: this.state.loading
346
+ }),
347
+ isRead ? null : _react2['default'].createElement(
348
+ _popover2['default'],
349
+ {
350
+ placement: 'right',
351
+ content: _react2['default'].createElement(
352
+ 'div',
353
+ { style: { padding: '4px 0' } },
354
+ _react2['default'].createElement(
355
+ 'span',
356
+ { style: { color: '#5468b2', width: 200, height: 300 } },
357
+ help
358
+ )
359
+ ),
360
+ arrowPointAtCenter: true,
361
+ style: { width: 200, height: 'auto' }
362
+ },
363
+ _react2['default'].createElement(
364
+ _button2['default'],
365
+ null,
366
+ _react2['default'].createElement(_icon2['default'], { type: 'upload' }),
367
+ ' ',
368
+ buttonName
369
+ )
370
+ )
371
+ )),
372
+ !this.state.cancelStatus && preUploading ? _react2['default'].createElement(
373
+ 'div',
374
+ null,
375
+ _react2['default'].createElement(
376
+ 'span',
377
+ { style: { margin: '10px auto', color: '#1890ff' } },
378
+ '\u6587\u4EF6\u8BFB\u53D6\u4E2D...'
379
+ ),
380
+ _react2['default'].createElement(
381
+ 'div',
382
+ { style: { width: '90%' } },
383
+ _react2['default'].createElement(_progress2['default'], { width: 80, percent: preUploadPercent, status: 'active' })
384
+ )
385
+ ) : '',
386
+ !this.state.cancelStatus && this.state.fileList.length > 0 && !!uploadRequest && _react2['default'].createElement(
387
+ 'span',
388
+ { style: { margin: '10px auto', color: '#1890ff' } },
389
+ '\u6587\u4EF6\u6821\u9A8C\u4E2D...'
390
+ ),
391
+ !this.state.cancelStatus && this.state.fileList.length > 0 && uploadPercent >= 0 && uploadPercent < 100 && _react2['default'].createElement(
392
+ 'div',
393
+ null,
394
+ !!uploading && _react2['default'].createElement(
395
+ 'span',
396
+ { style: { margin: '10px auto', color: '#1890ff' } },
397
+ '\u6587\u4EF6\u4E0A\u4F20\u4E2D(',
398
+ Math.floor(this.state.speed / 1024),
399
+ 'KB/S)'
400
+ ),
401
+ this.state.chunkProgressStatus === 'exception' ? _react2['default'].createElement(
402
+ 'div',
403
+ { style: { width: '90%' } },
404
+ _react2['default'].createElement(_progress2['default'], { percent: uploadPercent, size: 'small', status: this.state.chunkProgressStatus })
405
+ ) : _react2['default'].createElement(
406
+ 'div',
407
+ { style: { width: '90%' } },
408
+ _react2['default'].createElement(_progress2['default'], { percent: uploadPercent, size: 'small' })
409
+ )
410
+ )
411
+ )
412
+ );
413
+ };
414
+
415
+ return BigFileUpload;
416
+ }(_react.Component);
417
+
418
+ BigFileUpload.propTypes = {
419
+ name: _propTypes2['default'].string.isRequired, // 上传名称
420
+ sendData: _propTypes2['default'].object, // 传送数据接口
421
+ initialValue: _propTypes2['default'].array, // 初始值
422
+ urlUpBigFileGeneral: _propTypes2['default'].string.isRequired, // 上传附件服务地址
423
+ urlCheckProgress: _propTypes2['default'].string.isRequired, // 检查附件地址
424
+ urlDownloadFile: _propTypes2['default'].string.isRequired, // 下载附件地址
425
+ required: _propTypes2['default'].bool, // 是否必须
426
+ help: _propTypes2['default'].string, // 后台附件服务地址
427
+ limitChunkSize: _propTypes2['default'].number, // 分片大小
428
+ listType: _propTypes2['default'].string, // 附件类型
429
+ accept: _propTypes2['default'].string, // 接受类型
430
+ buttonName: _propTypes2['default'].string, // 上传名称
431
+ isRead: _propTypes2['default'].bool, // 是否只读
432
+ label: _propTypes2['default'].string, // lable名称
433
+ className: _propTypes2['default'].string, // CSS类名
434
+ labelCol: _propTypes2['default'].object, // CSS类名
435
+ wrapperCol: _propTypes2['default'].object, // CSS类名
436
+ multiple: _propTypes2['default'].bool, // 是否多附件
437
+ readFileSize: _propTypes2['default'].number // 读取文件大小
438
+ };
439
+ BigFileUpload.defaultProps = {
440
+ initialValue: [],
441
+ listType: 'text',
442
+ accept: '',
443
+ limitChunkSize: 1024 * 1024, // 不限定单位 默认单位byte 1024KB
444
+ buttonName: '选择附件',
445
+ help: '请上传附件',
446
+ required: true,
447
+ isRead: false,
448
+ label: '',
449
+ multiple: false, // 默认单附件上传
450
+ className: '',
451
+ labelCol: {},
452
+ wrapperCol: {},
453
+ readFileSize: 10 * 1024 * 1024, // 默认最小10MB
454
+ sendData: {}
455
+ };
456
+
457
+ var _initialiseProps = function _initialiseProps() {
458
+ var _this3 = this;
459
+
460
+ this.setUploadValue = function (v) {
461
+ var _setFieldsValue;
462
+
463
+ var _props2 = _this3.props,
464
+ form = _props2.form,
465
+ name = _props2.name;
466
+ var setFieldsValue = form.setFieldsValue;
467
+
468
+ setFieldsValue((_setFieldsValue = {}, _setFieldsValue[name] = v, _setFieldsValue));
469
+ };
470
+
471
+ this.urlDeal = function (urlDownloadFile, uid) {
472
+ var retUrl = '';
473
+ if (uid !== '' && _comonConfig.aFlag && (_comonConfig.aFlag === '1' || _comonConfig.aFlag === '2')) {
474
+ var authToken = (0, _Easy3wGetCookie2['default'])('userToken') || 'E3WSAFEAPPQWEFGHYI7I483S';
475
+ var nowStr = _.now();
476
+ var encUrl = (0, _Easy3wAESEncrypt2['default'])(uid + '@#' + nowStr + '@#' + authToken, _comonConfig.a, _comonConfig.b);
477
+ return '' + urlDownloadFile + encUrl;
478
+ } else {
479
+ retUrl = '' + urlDownloadFile + uid;
480
+ return retUrl;
481
+ }
482
+ };
483
+
484
+ this.iniValDeal = function (initialValue) {
485
+ var urlDownloadFile = _this3.props.urlDownloadFile;
486
+
487
+ var iniVal = initialValue.map(function (obj) {
488
+ var uid = obj.uid,
489
+ name = obj.name;
490
+
491
+ var url = _this3.urlDeal(urlDownloadFile, uid);
492
+ var status = 'done';
493
+ return { uid: uid, name: name, url: url, status: status };
494
+ });
495
+ return iniVal;
496
+ };
497
+
498
+ this.checkFile = function (uploadParams) {
499
+ _this3.setState({ uploadRequest: true });
500
+ var formData = new FormData();
501
+ var authToken = (0, _Easy3wGetCookie2['default'])('userToken') || 'E3WSAFEAPPQWEFGHYI7I483S';
502
+
503
+ // const timeStr = new Date().getTime();
504
+ // if (AESFlag && AESFlag === '1') {
505
+ // authToken = Easy3wAESEncrypt(`${authToken}@#${timeStr}`, AESKey, AESIV);
506
+ // }
507
+ var _props3 = _this3.props,
508
+ name = _props3.name,
509
+ urlCheckProgress = _props3.urlCheckProgress,
510
+ urlDownloadFile = _props3.urlDownloadFile,
511
+ uploadDoneCallback = _props3.uploadDoneCallback;
512
+
513
+ formData.append('sendTime', new Date().getTime());
514
+ formData.append('appType', '01');
515
+ formData.append('authToken', authToken);
516
+ formData.append('devId', '');
517
+ formData.append('data', JSON.stringify({ uploadParams: uploadParams }));
518
+ formData.append('sign', '2959f1aea8db0f7fbba61f0f8474d0ef');
519
+ _superagent2['default'].post('' + urlCheckProgress).send(formData).withCredentials().end(function (err, res) {
520
+ if (err) {
521
+ var _state4 = _this3.state,
522
+ fileList = _state4.fileList,
523
+ currentFile = _state4.currentFile;
524
+
525
+ var index = fileList.indexOf(currentFile);
526
+ if (index >= 0) {
527
+ fileList.splice(index, 1);
528
+ _this3.setState((0, _extends3['default'])({}, _this3.state, {
529
+ fileList: fileList,
530
+ cancelStatus: true,
531
+ loading: false
532
+ }), function () {
533
+ _this3.setUploadValue(fileList);
534
+ });
535
+ }
536
+ if (err.timeout) {
537
+ _modal2['default'].error({
538
+ style: { top: '38%' },
539
+ content: '网络超时,上传失败,请检查网络后,重新续传。'
540
+ });
541
+ } else {
542
+ _modal2['default'].error({
543
+ style: { top: '38%' },
544
+ content: '服务请求异常,请重试'
545
+ });
546
+ }
547
+ return;
548
+ }
549
+ _this3.setState({ uploadRequest: false });
550
+ if (res.body.rspCode === '0000' && res.body.data) {
551
+ var _res$body$data = res.body.data,
552
+ uploadStatus = _res$body$data.uploadStatus,
553
+ uploadedSize = _res$body$data.uploadedSize,
554
+ fileId = _res$body$data.fileId,
555
+ uid = _res$body$data.uid;
556
+ var _fileList = _this3.state.fileList;
557
+
558
+ var fileInfo = {};
559
+ if (uploadStatus === '1') {
560
+ // 上传完成
561
+ var newList = _fileList.map(function (item) {
562
+ var tempData = item;
563
+ if (uid === item.uid) {
564
+ tempData.uid = fileId;
565
+ tempData.fileId = fileId;
566
+ tempData.url = '' + urlDownloadFile + fileId;
567
+ tempData.status = 'done';
568
+ tempData.fileName = tempData.name;
569
+ fileInfo = tempData;
570
+ }
571
+ return tempData;
572
+ });
573
+ _this3.setState((0, _extends3['default'])({}, _this3.state, {
574
+ uploadPercent: 100, // 不显示进度条
575
+ loading: false,
576
+ fileList: newList,
577
+ currentFile: null
578
+ }), function () {
579
+ _this3.setUploadValue(newList);
580
+ if (uploadDoneCallback) {
581
+ uploadDoneCallback(name, fileInfo, newList);
582
+ }
583
+ });
584
+ } else {
585
+ var uploadPercent = 0;
586
+ for (var _index = 0; _index < _fileList.length; _index += 1) {
587
+ var file = _fileList[_index];
588
+ if (uid === file.uid) {
589
+ var size = file.size;
590
+
591
+ var tempSize = Number(uploadedSize);
592
+ uploadPercent = Math.floor(tempSize / size * 100 * 10) / 10;
593
+ _this3.setState({
594
+ uploadPercent: uploadPercent,
595
+ CUSize: tempSize
596
+ }, function () {
597
+ setImmediate(_this3.handlePartUpload);
598
+ });
599
+ break;
600
+ }
601
+ }
602
+ }
603
+ } else if (res.body.rspMsg) {
604
+ _modal2['default'].error({
605
+ style: { top: '38%' },
606
+ content: res.body.rspMsg
607
+ });
608
+ var _state5 = _this3.state,
609
+ _fileList2 = _state5.fileList,
610
+ _currentFile = _state5.currentFile;
611
+
612
+ var _index2 = _fileList2.indexOf(_currentFile);
613
+ if (_index2 >= 0) {
614
+ _fileList2.splice(_index2, 1);
615
+ _this3.setState((0, _extends3['default'])({}, _this3.state, { fileList: _fileList2, loading: false }), function () {
616
+ _this3.setUploadValue(_fileList2);
617
+ });
618
+ }
619
+ }
620
+ });
621
+ };
622
+
623
+ this.handlePartUpload = function (sIndex, eIndex) {
624
+ try {
625
+ var _state6 = _this3.state,
626
+ currentFile = _state6.currentFile,
627
+ CUSize = _state6.CUSize,
628
+ cancelStatus = _state6.cancelStatus,
629
+ uploadData = _state6.uploadData,
630
+ loading = _state6.loading,
631
+ speed = _state6.speed;
632
+
633
+ if (cancelStatus) {
634
+ if (loading) {
635
+ _this3.setState((0, _extends3['default'])({}, _this3.state, { loading: false }));
636
+ }
637
+ return;
638
+ }
639
+ var uploadPercent = _this3.state.uploadPercent;
640
+
641
+ if (uploadPercent === 100) {
642
+ _this3.setState((0, _extends3['default'])({}, _this3.state, { loading: false }));
643
+ return;
644
+ }
645
+ var uploadFileReader = new FileReader();
646
+ var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
647
+ var chunkCheckErr = false;
648
+ var _props4 = _this3.props,
649
+ name = _props4.name,
650
+ limitChunkSize = _props4.limitChunkSize,
651
+ sendData = _props4.sendData,
652
+ uploadCallback = _props4.uploadCallback,
653
+ uploadDoneCallback = _props4.uploadDoneCallback,
654
+ urlUpBigFileGeneral = _props4.urlUpBigFileGeneral,
655
+ urlDownloadFile = _props4.urlDownloadFile;
656
+
657
+ var chunkSize = 0;
658
+ if (typeof limitChunkSize === 'string') {
659
+ if (limitChunkSize.toLowerCase().indexOf('k') !== -1) {
660
+ var temp = limitChunkSize.substring(0, limitChunkSize.toLowerCase().indexOf('k'));
661
+ chunkSize = Number(temp) * 1024;
662
+ } else if (limitChunkSize.toLowerCase().indexOf('m') !== -1) {
663
+ var _temp = limitChunkSize.substring(0, limitChunkSize.toLowerCase().indexOf('m'));
664
+ chunkSize = Number(_temp) * 1024 * 1024;
665
+ } else {
666
+ chunkSize = Number(limitChunkSize);
667
+ }
668
+ } else {
669
+ chunkSize = limitChunkSize;
670
+ }
671
+ var fileSize = currentFile.size;
672
+ var end = 0;
673
+ // 如果速率大于0 使用当前速率上传
674
+ if (speed > chunkSize) {
675
+ if (fileSize - CUSize > speed) {
676
+ end = CUSize + speed;
677
+ } else {
678
+ end = fileSize;
679
+ }
680
+ } else if (fileSize - CUSize > chunkSize) {
681
+ end = CUSize + chunkSize;
682
+ } else {
683
+ end = fileSize;
684
+ }
685
+ var start = CUSize;
686
+ if (sIndex && sIndex > 0 && eIndex && eIndex > 0) {
687
+ end = eIndex;
688
+ start = sIndex;
689
+ }
690
+ uploadFileReader.onload = function (e) {
691
+ if (chunkCheckErr) {
692
+ return;
693
+ }
694
+ var mainFileSpark = new _sparkMd2['default'].ArrayBuffer(); // 对arrayBuffer数据进行md5加密,产生一个md5字符串 主文件
695
+ mainFileSpark.append(e.target.result);
696
+ var chunkMD5 = mainFileSpark.end();
697
+ // 上传附件
698
+ var file = uploadData.file;
699
+
700
+ var formData = new FormData();
701
+ var authToken = (0, _Easy3wGetCookie2['default'])('userToken') || 'E3WSAFEAPPQWEFGHYI7I483S';
702
+ // const timeStr = new Date().getTime();
703
+ // if (AESFlag && AESFlag === '1') {
704
+ // authToken = Easy3wAESEncrypt(`${authToken}@#${timeStr}`, AESKey, AESIV);
705
+ // }
706
+ var blob = new Blob([e.target.result], { type: 'application/octet-stream' });
707
+ var postParam = (0, _extends3['default'])({ fileInfo: file }, sendData, { currentSize: end, startSize: start, chunkMD5: chunkMD5 });
708
+ formData.append('chunk', blob);
709
+ formData.append('sendTime', new Date().getTime());
710
+ formData.append('appType', '01');
711
+ formData.append('authToken', authToken);
712
+ formData.append('data', JSON.stringify(postParam));
713
+ formData.append('sign', '2959f1aea8db0f7fbba61f0f8474d0ef');
714
+ var startTime = new Date().getTime();
715
+ _superagent2['default'].post('' + urlUpBigFileGeneral).send(formData).withCredentials().end(function (err, res) {
716
+ if (err) {
717
+ var fileList = _this3.state.fileList;
718
+
719
+ var index = fileList.indexOf(currentFile);
720
+ if (index >= 0) {
721
+ fileList.splice(index, 1);
722
+ _this3.setState((0, _extends3['default'])({}, _this3.state, {
723
+ fileList: fileList,
724
+ cancelStatus: true,
725
+ loading: false
726
+ }), function () {
727
+ _this3.setUploadValue(fileList);
728
+ });
729
+ }
730
+ if (err.timeout) {
731
+ _modal2['default'].error({
732
+ style: { top: '38%' },
733
+ content: '网络超时,上传失败,请检查网络后,重新续传。'
734
+ });
735
+ } else {
736
+ _modal2['default'].error({
737
+ style: { top: '38%' },
738
+ content: '服务请求异常,请重试'
739
+ });
740
+ }
741
+ return;
742
+ }
743
+ var size = e.target.result.byteLength;
744
+ blob = null;
745
+ formData = null;
746
+ if (res && res.body.rspCode === '0000') {
747
+ var _res$body$data2 = res.body.data,
748
+ uploadStatus = _res$body$data2.uploadStatus,
749
+ fileId = _res$body$data2.fileId,
750
+ checkStatus = _res$body$data2.checkStatus,
751
+ uploadedSize = _res$body$data2.uploadedSize,
752
+ startIndex = _res$body$data2.startIndex,
753
+ endIndex = _res$body$data2.endIndex;
754
+
755
+ var useTime = (new Date().getTime() - startTime) / 1000; // 用时秒
756
+ var upSize = Number(uploadedSize);
757
+ // 1秒传输速率
758
+ var curSpeed = Math.floor(1 / useTime * size);
759
+ if (checkStatus && checkStatus === 'RETRY') {
760
+ _this3.setState((0, _extends3['default'])({}, _this3.state, {
761
+ speed: curSpeed
762
+ }), function () {
763
+ setImmediate(_this3.handlePartUpload, startIndex, endIndex);
764
+ });
765
+ return;
766
+ }
767
+ // 计算上传进度
768
+ uploadPercent = Math.floor(upSize / fileSize * 100 * 10) / 10;
769
+ if (checkStatus === '0') {
770
+ chunkCheckErr = true;
771
+ }
772
+ var chunkProgressStatus = 'active';
773
+ if (uploadPercent >= 100) {
774
+ var _fileList3 = _this3.state.fileList;
775
+
776
+ if (uploadStatus === '1' && checkStatus === '1') {
777
+ // 上传并验证完毕
778
+ var fileInfo = null;
779
+ chunkProgressStatus = 'active';
780
+ var newList = _fileList3.map(function (item) {
781
+ var tempData = item;
782
+ if (currentFile && currentFile.uid === item.uid) {
783
+ tempData.uid = fileId;
784
+ tempData.fileId = fileId;
785
+ tempData.url = '' + urlDownloadFile + fileId;
786
+ tempData.status = 'done';
787
+ tempData.fileName = tempData.name;
788
+ fileInfo = tempData;
789
+ }
790
+ return tempData;
791
+ });
792
+ _this3.setState((0, _extends3['default'])({}, _this3.state, {
793
+ uploadPercent: uploadPercent,
794
+ uploading: false,
795
+ loading: false,
796
+ chunkProgressStatus: chunkProgressStatus,
797
+ CUSize: upSize,
798
+ fileList: newList,
799
+ currentFile: null,
800
+ speed: curSpeed
801
+ }), function () {
802
+ _this3.setUploadValue(newList);
803
+ });
804
+ if (uploadCallback && typeof uploadCallback === 'function') {
805
+ uploadCallback(newList);
806
+ }
807
+ if (uploadDoneCallback) {
808
+ uploadDoneCallback(name, fileInfo, newList);
809
+ }
810
+ } else {
811
+ chunkProgressStatus = 'exception';
812
+ if (checkStatus !== '1') {
813
+ _modal2['default'].error({
814
+ style: { top: '38%' },
815
+ content: '附件完整性验证失败:可能由于网络丢包原因,您上传的附件未通过完整性校验,需要您重新上传。'
816
+ });
817
+ } else {
818
+ _modal2['default'].error({
819
+ style: { top: '38%' },
820
+ content: '上传失败'
821
+ });
822
+ }
823
+ var _index3 = _fileList3.indexOf(currentFile);
824
+ if (_index3 >= 0) {
825
+ _fileList3.splice(_index3, 1);
826
+ _this3.setState((0, _extends3['default'])({}, _this3.state, {
827
+ uploadPercent: uploadPercent,
828
+ uploading: false,
829
+ loading: false,
830
+ chunkProgressStatus: chunkProgressStatus,
831
+ CUSize: upSize,
832
+ fileList: _fileList3,
833
+ currentFile: null,
834
+ speed: curSpeed
835
+ }), function () {
836
+ _this3.setUploadValue(_fileList3);
837
+ });
838
+ }
839
+ }
840
+ } else {
841
+ _this3.setState((0, _extends3['default'])({}, _this3.state, {
842
+ uploadPercent: uploadPercent,
843
+ uploading: true,
844
+ loading: true,
845
+ chunkProgressStatus: chunkProgressStatus,
846
+ CUSize: upSize,
847
+ speed: curSpeed
848
+ }), function () {
849
+ setImmediate(_this3.handlePartUpload);
850
+ });
851
+ }
852
+ } else {
853
+ _modal2['default'].error({
854
+ style: { top: '38%' },
855
+ content: res && res.body.rspMsg ? res.body.rspMsg : '上传失败'
856
+ });
857
+ var _fileList4 = _this3.state.fileList;
858
+
859
+ var _index4 = _fileList4.indexOf(currentFile);
860
+ if (_index4 >= 0) {
861
+ _fileList4.splice(_index4, 1);
862
+ _this3.setState((0, _extends3['default'])({}, _this3.state, { loading: false, fileList: _fileList4 }), function () {
863
+ _this3.setUploadValue(_fileList4);
864
+ });
865
+ }
866
+ }
867
+ });
868
+ };
869
+ // console.log('读取文件', `文件大小:${currentFile.size}`, `已上传大小${start}`, `结束值${end}`, `切片大小${speed}`);
870
+ uploadFileReader.readAsArrayBuffer(blobSlice.call(currentFile, start, end));
871
+ } catch (error) {
872
+ _modal2['default'].error({
873
+ style: { top: '38%' },
874
+ content: error
875
+ });
876
+ var _state7 = _this3.state,
877
+ fileList = _state7.fileList,
878
+ _currentFile2 = _state7.currentFile;
879
+
880
+ var index = fileList.indexOf(_currentFile2);
881
+ if (index >= 0) {
882
+ fileList.splice(index, 1);
883
+ _this3.setState((0, _extends3['default'])({}, _this3.state, { fileList: fileList }), function () {
884
+ _this3.setUploadValue(fileList);
885
+ });
886
+ }
887
+ }
888
+ };
889
+
890
+ this.readFile = function (file) {
891
+ try {
892
+ var chunkReader = new FileReader();
893
+ var _props5 = _this3.props,
894
+ limitChunkSize = _props5.limitChunkSize,
895
+ readFileSize = _props5.readFileSize;
896
+ // ...对文件的预处理
897
+ // 兼容性的处理
898
+
899
+ var blobSlice = File.prototype.slice || File.prototype.mozSlice || File.prototype.webkitSlice;
900
+ var chunkSize = 0;
901
+ if (typeof limitChunkSize === 'string') {
902
+ if (limitChunkSize.toLowerCase().indexOf('k') !== -1) {
903
+ var temp = limitChunkSize.substring(0, limitChunkSize.toLowerCase().indexOf('k'));
904
+ chunkSize = Number(temp) * 1024;
905
+ } else if (limitChunkSize.toLowerCase().indexOf('m') !== -1) {
906
+ var _temp2 = limitChunkSize.substring(0, limitChunkSize.toLowerCase().indexOf('m'));
907
+ chunkSize = Number(_temp2) * 1024 * 1024;
908
+ } else {
909
+ chunkSize = Number(limitChunkSize);
910
+ }
911
+ } else {
912
+ chunkSize = limitChunkSize;
913
+ }
914
+ var tempreadFileSize = 0;
915
+ if (typeof readFileSize === 'string') {
916
+ if (readFileSize.toLowerCase().indexOf('k') !== -1) {
917
+ var _temp3 = readFileSize.substring(0, readFileSize.toLowerCase().indexOf('k'));
918
+ tempreadFileSize = Number(_temp3) * 1024;
919
+ } else if (readFileSize.toLowerCase().indexOf('m') !== -1) {
920
+ var _temp4 = readFileSize.substring(0, readFileSize.toLowerCase().indexOf('m'));
921
+ tempreadFileSize = Number(_temp4) * 1024 * 1024;
922
+ } else {
923
+ tempreadFileSize = Number(readFileSize);
924
+ }
925
+ } else {
926
+ tempreadFileSize = readFileSize;
927
+ }
928
+ if (tempreadFileSize < 5 * 1024 * 1024) {
929
+ tempreadFileSize = 5 * 1024 * 1024;
930
+ }
931
+ var sliceCount = 0;
932
+ if (chunkSize < tempreadFileSize) {
933
+ // 切片小于分段大小
934
+ sliceCount = Math.ceil(file.size / tempreadFileSize);
935
+ } else {
936
+ sliceCount = Math.ceil(file.size / chunkSize);
937
+ }
938
+ var mainFileSpark = new _sparkMd2['default'].ArrayBuffer(); // 对arrayBuffer数据进行md5加密,产生一个md5字符串 主文件
939
+ var params = { file: {} }; // 用于上传所有分片的md5信息
940
+ params.file.fileName = file.name;
941
+ params.file.fileSize = file.size;
942
+ params.file.uid = file.uid;
943
+ var sliceIndex = 0;
944
+ chunkReader.onload = function (e) {
945
+ mainFileSpark.append(e.target.result);
946
+ sliceIndex += 1;
947
+ if (sliceIndex < sliceCount) {
948
+ _this3.setState((0, _extends3['default'])({}, _this3.state, {
949
+ preUploading: true,
950
+ preUploadPercent: Number((sliceIndex / sliceCount * 100).toFixed(1))
951
+ }));
952
+ setImmediate(_loadNext, sliceIndex, tempreadFileSize);
953
+ } else {
954
+ var mainFileMD5 = mainFileSpark.end();
955
+ params.file.fileMd5 = mainFileMD5;
956
+ // 表示预处理结束,检验附件上传情况
957
+ _this3.setState((0, _extends3['default'])({}, _this3.state, {
958
+ preUploading: false,
959
+ preUploadPercent: 100,
960
+ uploadData: params
961
+ // loading: false
962
+ }), function () {
963
+ setImmediate(_this3.checkFile, params);
964
+ });
965
+ }
966
+ };
967
+ var _loadNext = function _loadNext(count, size) {
968
+ var cancelStatus = _this3.state.cancelStatus;
969
+
970
+ if (cancelStatus) {
971
+ return;
972
+ }
973
+ var start = count * size;
974
+ var end = start + size >= file.size ? file.size : start + size;
975
+ // console.log(`读取文件,文件大小${file.size},截取开始位置${start},结束位置${end}`);
976
+ chunkReader.readAsArrayBuffer(blobSlice.call(file, start, end));
977
+ };
978
+ _loadNext(sliceIndex, tempreadFileSize);
979
+ } catch (error) {
980
+ _modal2['default'].error({
981
+ style: { top: '38%' },
982
+ content: error
983
+ });
984
+ var _state8 = _this3.state,
985
+ fileList = _state8.fileList,
986
+ currentFile = _state8.currentFile;
987
+
988
+ var index = fileList.indexOf(currentFile);
989
+ if (index >= 0) {
990
+ fileList.splice(index, 1);
991
+ _this3.setState((0, _extends3['default'])({}, _this3.state, { fileList: fileList }), function () {
992
+ _this3.setUploadValue(fileList);
993
+ });
994
+ }
995
+ }
996
+ };
997
+
998
+ this.requiredFile = function (rule, value, callback) {
999
+ var required = _this3.props.required;
1000
+ var fileList = _this3.state.fileList;
1001
+
1002
+ if (required && (!fileList || fileList.length === 0)) {
1003
+ callback();
1004
+ return;
1005
+ }
1006
+ if (required) {
1007
+ for (var i = 0; i < fileList.length; i += 1) {
1008
+ var file = fileList[i];
1009
+ if (file.status !== 'done') {
1010
+ callback(' ');
1011
+ break;
1012
+ }
1013
+ }
1014
+ }
1015
+ callback();
1016
+ };
1017
+ };
1018
+
1019
+ exports['default'] = BigFileUpload;
1020
+ module.exports = exports['default'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "easy3wui",
3
- "version": "1.5.0",
3
+ "version": "1.5.4",
4
4
  "description": "easy3wui components for react",
5
5
  "keywords": [
6
6
  "react",