wenbobowen 4 years ago
parent
commit
a55ce0aa50
1 changed files with 22 additions and 1 deletions
  1. 22 1
      src/components/input/textArea.vue

+ 22 - 1
src/components/input/textArea.vue

@@ -120,7 +120,8 @@ export default {
   watch: {
     value: {
       handler(newV, oldV) {
-        this.inputValue = newV
+        // this.inputValue = newV
+        this.resetImgSrc(newV)
       },
       immediate: true
     }
@@ -139,6 +140,26 @@ export default {
     tinymce.init({ selector: `.tinymce_${this.id}` })
   },
   methods: {
+    async resetImgSrc(str) {
+      let newStr = str
+      const imgReg = /<img.*?(?:>|\/>)/gi
+      const srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i
+      const imgArr = newStr.match(imgReg)
+      imgArr && imgArr.map(async t => {
+        var src = t.match(srcReg)
+        if (src[1] && src[1].includes('data:image')) {
+          const newImgUrl = await uploadImg(src[1])
+          newStr = newStr.replace(src[1], newImgUrl)
+          console.log('newStr', newStr)
+          this.inputValue = newStr
+          // 光标最后
+          this.$nextTick(() => {
+            var ifra = document.getElementById(`tinymce_${this.id}_ifr`)
+            keepLastIndex(ifra.contentWindow.document.getElementById(`tinymce`), ifra.contentWindow)
+          })
+        }
+      })
+    },
     ImmediateAddition() { // 立即添加(编辑)
       this.edit = true
     },