wenbobowen 4 år sedan
förälder
incheckning
582a20a409
2 ändrade filer med 39 tillägg och 15 borttagningar
  1. 6 6
      src/components/input/normalArea.vue
  2. 33 9
      src/components/input/textArea.vue

+ 6 - 6
src/components/input/normalArea.vue

@@ -125,13 +125,13 @@ export default {
         this.inputValue = newV
       },
       immediate: true
-    },
-    inputValue: {
-      handler(newV, oldV) {
-        this.resetImgSrc(newV)
-      },
-      immediate: true
     }
+    // inputValue: {
+    //   handler(newV, oldV) {
+    //     this.resetImgSrc(newV)
+    //   },
+    //   immediate: true
+    // }
   },
   mounted() {
     tinymce.init({ selector: `#tinymce_${this.id}` })

+ 33 - 9
src/components/input/textArea.vue

@@ -124,13 +124,13 @@ export default {
         this.inputValue = newV
       },
       immediate: true
-    },
-    inputValue: {
-      handler(newV, oldV) {
-        this.resetImgSrc(newV)
-      },
-      immediate: true
     }
+    // inputValue: {
+    //   handler(newV, oldV) {
+    //     this.resetImgSrc(newV)
+    //   },
+    //   immediate: true
+    // }
   },
   mounted() {
     // 失去焦点保存功能
@@ -143,7 +143,6 @@ export default {
     //     document.getElementById(`inputUpload_${this.id}`).click()
     //   }
     // })
-    console.log(this.value)
     tinymce.init({ selector: `.tinymce_${this.id}` })
   },
   methods: {
@@ -167,6 +166,30 @@ export default {
         }
       })
     },
+    async resetImgSrcAll(str) {
+      if (!str) return
+      let newStr = str
+      const imgReg = /<img.*?(?:>|\/>)/gi
+      const srcReg = /src=[\'\"]?([^\'\"]*)[\'\"]?/i
+      const imgArr = newStr.match(imgReg)
+      let val = this.inputValue
+      imgArr && imgArr.map(async t => {
+        const src = t.match(srcReg)
+        if (src[1] && src[1].includes('data:image')) {
+          const newImgUrl = await uploadImg(src[1])
+          console.log(newImgUrl)
+          newStr = newStr.replace(src[1], newImgUrl)
+          val = newStr
+          // // 光标最后
+          // this.$nextTick(() => {
+          //   const ifra = document.getElementById(`tinymce_${this.id}_ifr`)
+          //   keepLastIndex(ifra.contentWindow.document.getElementById(`tinymce`), ifra.contentWindow)
+          // })
+        }
+      })
+      console.log(val)
+      return val
+    },
     ImmediateAddition() { // 立即添加(编辑)
       this.edit = true
     },
@@ -184,8 +207,9 @@ export default {
         }
         this.loading = false
         this.edit = false
-        this.$emit('update:value', this.inputValue)
-        this.$emit('change', this.inputValue)
+        const val = await this.resetImgSrcAll(this.inputValue)
+        this.$emit('update:value', val)
+        this.$emit('change', val)
       }
     },
     handlerText(val) {