Browse Source

fix:如果url没有http协议,自动增加,主要防止web这边访问有问题

adam 4 years ago
parent
commit
c805ebae04
1 changed files with 14 additions and 2 deletions
  1. 14
    2
      src/RichTextEditor.js

+ 14
- 2
src/RichTextEditor.js View File

@@ -444,7 +444,13 @@ export default class RichTextEditor extends Component {
444 444
   }
445 445
 
446 446
   insertLink(url, title) {
447
-    this._sendAction(actions.insertLink, {url, title: title || url});
447
+    // 不填写标题,则采用链接作为url
448
+    title = title || url;
449
+    // 如果前没有http://,则需要加入
450
+    if (!(/^(http:\/\/|https:\/\/)/.test(url))) {
451
+      url = `http://${url}`;
452
+    }
453
+    this._sendAction(actions.insertLink, {url, title});
448 454
     // if (/^(http:\/\/|https:\/\/)/.test(url)) {
449 455
     //   this._sendAction(actions.insertLink, {url, title: title || url});
450 456
     // } else {
@@ -453,7 +459,13 @@ export default class RichTextEditor extends Component {
453 459
   }
454 460
 
455 461
   updateLink(url, title) {
456
-    this._sendAction(actions.updateLink, {url, title: title || url});
462
+    // 不填写标题,则采用链接作为url
463
+    title = title || url;
464
+    // 如果前没有http://,则需要加入
465
+    if (!(/^(http:\/\/|https:\/\/)/.test(url))) {
466
+      url = `http://${url}`;
467
+    }
468
+    this._sendAction(actions.updateLink, {url, title});
457 469
     // if (/^(http:\/\/|https:\/\/)/.test(url)) {
458 470
     //   this._sendAction(actions.updateLink, {url, title: title || url});
459 471
     // } else {