liyongli 2 years ago
parent
commit
ed0e0ea41b

+ 3 - 2
src/view/allMedia/AIeditor/components/image.vue

@@ -32,10 +32,11 @@
 // 图片
 import image from '@/assets/img/image.png';
 import { textImageMatch } from '@/api/aleditor.js';
-import { ref } from 'vue';
+import { ref, defineEmits } from 'vue';
 const is_status = ref('none');
 const input = ref('');
 const oriD = ref({});
+const emits = defineEmits(['closeType', 'setHtml', 'getImage', 'setImage']);
 const search = () => {
   is_status.value = 'load';
   textImageMatch({
@@ -55,7 +56,7 @@ const search = () => {
 };
 
 const saveImg = item => {
-    console.log(item.url)
+    emits('setImage', [item.url]);
 }
 </script>
 

+ 18 - 6
src/view/allMedia/AIeditor/index.vue

@@ -134,6 +134,7 @@
             <component
               @saveData="saveData"
               @closeType="closeType"
+              @setImage="setImage"
               :headTitle="titleh1"
               :html="() => editorRef.getHtml()"
               :text="() => editorRef.getText()"
@@ -307,7 +308,6 @@ const btnType = ref('short');
 
 const getSidFun = () => {
   getSID().then(r => {
-    console.log(r);
     localStorage.setItem('fileId', r.fileId);
     localStorage.setItem('sid', r.sid);
   });
@@ -357,10 +357,14 @@ const editorConfig = {
   },
 };
 
-const contentChange = e =>{
-    console.log(e.getHtml());
-    // 编辑器修改
-}
+const contentChange = () => {
+  //   const s = window.getSelection().getRangeAt(0);
+  //   const offset = s.startOffset;
+  //   const innerText = s.startContainer.innerText;
+  //   const T = e.getHtml().split(innerText);
+  //   console.log(T, innerText , offset, s);
+  // 编辑器修改
+};
 
 // 组件销毁时,也及时销毁编辑器
 onBeforeUnmount(() => {
@@ -422,7 +426,15 @@ const setHtml = html => {
 };
 // 右侧生成图片
 const setImage = imgs => {
-  console.log(imgs);
+  const ot = editorRef.value.getHtml();
+  if (typeof imgs == 'string') {
+    editorRef.value.setHtml(ot + `<img src="${imgs}" />`);
+  } else if (Array.isArray(imgs)) {
+    for (let i = 0; i < imgs.length; i++) {
+      const v = imgs[i];
+      editorRef.value.setHtml(ot + `<img src="${v}" />`);
+    }
+  }
 };
 const setTitle = text => {
   titleh1.value = text;