Browse Source

add default show upload props with timeout

Roxas 3 years ago
parent
commit
1226c385fd
3 changed files with 36 additions and 30 deletions
  1. 30
    26
      lib/components/Editor/index.js
  2. 1
    1
      lib/components/Editor/index.js.map
  3. 5
    3
      src/components/Editor/index.js

+ 30
- 26
lib/components/Editor/index.js View File

@@ -148,6 +148,8 @@ var Editor = function (_React$Component) {
148 148
   _createClass(Editor, [{
149 149
     key: "componentDidMount",
150 150
     value: function componentDidMount() {
151
+      var _this2 = this;
152
+
151 153
       var _props = this.props,
152 154
           app = _props.app,
153 155
           onRef = _props.onRef,
@@ -162,9 +164,11 @@ var Editor = function (_React$Component) {
162 164
       if (uploadDefaultShow) {
163 165
         var uploadFileList = this.props.fileList || this.state.fileList;
164 166
         if (uploadFileList.length > 0) {
165
-          this.setState({
166
-            uploadVisible: true
167
-          });
167
+          setTimeout(function () {
168
+            _this2.setState({
169
+              uploadVisible: true
170
+            });
171
+          }, 1000);
168 172
         }
169 173
       }
170 174
     }
@@ -299,7 +303,7 @@ var Editor = function (_React$Component) {
299 303
   }, {
300 304
     key: "handlePaste",
301 305
     value: function handlePaste(e) {
302
-      var _this2 = this;
306
+      var _this3 = this;
303 307
 
304 308
       if (this.state.fileList.length >= this.props.maxUpload) {
305 309
         return;
@@ -322,21 +326,21 @@ var Editor = function (_React$Component) {
322 326
       reader.readAsDataURL(file);
323 327
       reader.onloadend = function () {
324 328
         // DRIVER_LICENSE_PATH oss 的存储路径位置
325
-        UploadToOss(_this2.props.app.oss, _constant.DRIVER_LICENSE_PATH, file).then(function (data) {
326
-          var fileList = _this2.state.fileList.concat({
329
+        UploadToOss(_this3.props.app.oss, _constant.DRIVER_LICENSE_PATH, file).then(function (data) {
330
+          var fileList = _this3.state.fileList.concat({
327 331
             url: _constant.OSS_LINK + data.name,
328 332
             thumbUrl: _constant.OSS_LINK + data.name,
329 333
             type: file.type,
330 334
             uid: new Date().valueOf()
331 335
           });
332
-          _this2.invokeFileListChange(fileList);
336
+          _this3.invokeFileListChange(fileList);
333 337
         }).catch(function (e) {
334 338
           var msg = e.message || _constant.ERROR_DEFAULT;
335
-          if (_this2.props.showError) {
339
+          if (_this3.props.showError) {
336 340
             _message3.default.error(msg);
337 341
           }
338
-          if (_this2.props.onError) {
339
-            _this2.props.onError(msg, { response: e.response });
342
+          if (_this3.props.onError) {
343
+            _this3.props.onError(msg, { response: e.response });
340 344
           }
341 345
         });
342 346
       };
@@ -351,7 +355,7 @@ var Editor = function (_React$Component) {
351 355
   }, {
352 356
     key: "handleSubmit",
353 357
     value: function handleSubmit() {
354
-      var _this3 = this;
358
+      var _this4 = this;
355 359
 
356 360
       var maxLength = this.props.maxLength;
357 361
       var _state = this.state,
@@ -380,19 +384,19 @@ var Editor = function (_React$Component) {
380 384
       if (this.props.beforeSubmit) {
381 385
         Promise.resolve(this.props.beforeSubmit({ text: value, files: files })).then(function (res) {
382 386
           if (!(res === false)) {
383
-            _this3.props.onSubmit({ text: value, files: files }, function (res, action) {
384
-              _this3.resetState();
385
-              if (action === "comment" && _this3.props.onCommentSuccess) {
386
-                _this3.props.onCommentSuccess(res);
387
+            _this4.props.onSubmit({ text: value, files: files }, function (res, action) {
388
+              _this4.resetState();
389
+              if (action === "comment" && _this4.props.onCommentSuccess) {
390
+                _this4.props.onCommentSuccess(res);
387 391
               }
388 392
             });
389 393
           }
390 394
         });
391 395
       } else {
392 396
         this.props.onSubmit({ text: value, files: files }, function (res, action) {
393
-          _this3.resetState();
394
-          if (action === "comment" && _this3.props.onCommentSuccess) {
395
-            _this3.props.onCommentSuccess(res);
397
+          _this4.resetState();
398
+          if (action === "comment" && _this4.props.onCommentSuccess) {
399
+            _this4.props.onCommentSuccess(res);
396 400
           }
397 401
         });
398 402
       }
@@ -456,7 +460,7 @@ var Editor = function (_React$Component) {
456 460
   }, {
457 461
     key: "render",
458 462
     value: function render() {
459
-      var _this4 = this;
463
+      var _this5 = this;
460 464
 
461 465
       var _props4 = this.props,
462 466
           value = _props4.value,
@@ -503,7 +507,7 @@ var Editor = function (_React$Component) {
503 507
             _react2.default.createElement(TextArea, {
504 508
               value: inputValue,
505 509
               onChange: function onChange(e) {
506
-                _this4.handleChange(e.target.value);
510
+                _this5.handleChange(e.target.value);
507 511
               },
508 512
               rows: rows,
509 513
               placeholder: placeholder,
@@ -532,7 +536,7 @@ var Editor = function (_React$Component) {
532 536
                       _react2.default.createElement(_Emoji2.default, {
533 537
                         onClick: this.handleClickEmoji,
534 538
                         ref: function ref(node) {
535
-                          _this4.emoji = node;
539
+                          _this5.emoji = node;
536 540
                         },
537 541
                         emojiList: this.props.app.emojiList
538 542
                       })
@@ -552,7 +556,7 @@ var Editor = function (_React$Component) {
552 556
                     autoAdjustOverflow: false,
553 557
                     overlayStyle: { zIndex: 9999 },
554 558
                     onVisibleChange: function onVisibleChange(visible) {
555
-                      _this4.setState({
559
+                      _this5.setState({
556 560
                         uploadVisible: visible
557 561
                       });
558 562
                     },
@@ -561,7 +565,7 @@ var Editor = function (_React$Component) {
561 565
                       { className: "comment-img-popover" },
562 566
                       _react2.default.createElement(_Upload2.default, {
563 567
                         onRef: function onRef(node) {
564
-                          return _this4.uploadRef = node;
568
+                          return _this5.uploadRef = node;
565 569
                         },
566 570
                         multiple: multiple,
567 571
                         onChangeFileList: this.handleChangeFileList,
@@ -592,14 +596,14 @@ var Editor = function (_React$Component) {
592 596
                   },
593 597
                   imageToolIcon ? _react2.default.cloneElement(imageToolIcon, {
594 598
                     onClick: function onClick() {
595
-                      return _this4.handleShowUpload(true);
599
+                      return _this5.handleShowUpload(true);
596 600
                     }
597 601
                   }) : _react2.default.createElement(_icon2.default, {
598 602
                     type: "picture",
599 603
                     className: "comment-toolbar-icon",
600 604
                     style: { marginLeft: 20 },
601 605
                     onClick: function onClick() {
602
-                      return _this4.handleShowUpload(true);
606
+                      return _this5.handleShowUpload(true);
603 607
                     }
604 608
                   })
605 609
                 ) : null
@@ -613,7 +617,7 @@ var Editor = function (_React$Component) {
613 617
                   _button2.default,
614 618
                   {
615 619
                     onClick: function onClick() {
616
-                      return _this4.handleSubmit();
620
+                      return _this5.handleSubmit();
617 621
                     },
618 622
                     type: "primary",
619 623
                     loading: btnLoading,

+ 1
- 1
lib/components/Editor/index.js.map
File diff suppressed because it is too large
View File


+ 5
- 3
src/components/Editor/index.js View File

@@ -88,9 +88,11 @@ class Editor extends React.Component {
88 88
     if (uploadDefaultShow) {
89 89
       const uploadFileList = this.props.fileList || this.state.fileList;
90 90
       if (uploadFileList.length > 0) {
91
-        this.setState({
92
-          uploadVisible: true,
93
-        });
91
+        setTimeout(() => {
92
+          this.setState({
93
+            uploadVisible: true
94
+          });
95
+        }, 1000);
94 96
       }
95 97
     }
96 98
   }