فهرست منبع

feat:富文本编辑器bug修改1.多次点击撤销后内容清空问题;2.ai改写插入未生效;3.导出文本使用微软雅黑字体;4.扩写,缩写加入要求输入,已经按钮初始禁用状态;5.保存状态文本修改;

韩洋 10 ماه پیش
والد
کامیت
dec04c9bf9
4فایلهای تغییر یافته به همراه48 افزوده شده و 17 حذف شده
  1. 2 7
      src/modules/report/AIModal.vue
  2. 20 5
      src/modules/report/Editor.vue
  3. 1 1
      src/utils/get-user-id.js
  4. 25 4
      src/views/report/ReportDetail.vue

+ 2 - 7
src/modules/report/AIModal.vue

@@ -31,12 +31,7 @@
         </div>
       </div>
       <div class="section-input">
-        <a-input
-          v-model="input_txt"
-          :disabled="input_disabled"
-          @keyup.enter="toSubmit"
-          placeholder="你有什么其他要求告诉我哦~"
-        />
+        <a-input v-model="input_txt" @keyup.enter="toSubmit" placeholder="你有什么其他要求告诉我哦~" />
         <img class="icon" @click="toSubmit" v-if="!chat_status" :src="submit_normal" alt="" />
         <img class="icon" @click="toStop" v-if="chat_status" :src="submit_ing" alt="" />
         <!-- <img class="icon" v-if="false" src="../../assets/submit_disabled.png" alt="" /> -->
@@ -168,7 +163,7 @@ const is_empty = computed(() => {
 });
 
 const disabled = computed(() => {
-  return chat_status.value;
+  return chat_status.value || is_empty.value;
 });
 
 const input_disabled = computed(() => {

+ 20 - 5
src/modules/report/Editor.vue

@@ -90,6 +90,9 @@ const toolbarConfig = {
 };
 const editorConfig = {
   placeholder: '请输入内容...',
+  fontFamily: {
+    items: ['微软雅黑', 'Arial', '宋体', '黑体', '楷体']
+  },
   MENU_CONF: {
     editImage: {
       hideLinkImg: true // 隐藏图片链接按钮
@@ -148,7 +151,7 @@ onBeforeUnmount(() => {
 
 const handleCreated = (editor) => {
   editorRef.value = editor; // 记录 editor 实例,重要!
-  // console.log(editor);
+  console.log(editor, editor.cmd);
   // 修改工具栏配置,保留图片上传按钮
   toolbarConfig.excludeKeys = [
     'insertImage',
@@ -416,10 +419,16 @@ const insertPElement = (obj) => {
     const editor = editorRef.value;
     const targetP = editorContentRef.value.$el.querySelector(`p#${obj.pid}`);
     if (targetP) {
-      // targetP.innerHTML += obj.content.innerHTML;
-      // console.log(obj);
+      console.log(targetP, 1111);
+      console.log(obj, 11);
+      // 创建一个临时Range来选中整个p元素
+      const range = document.createRange();
+      range.selectNodeContents(targetP);
+
+      // 将DOM范围转换为编辑器选区
+      editor.restoreSelection(range);
       editor.dangerouslyInsertHtml(obj.content.innerHTML);
-      editor.updateView();
+      // editor.updateView();
       // console.log(editor.getHtml());
     }
   }
@@ -527,9 +536,15 @@ watch(
 watch(
   () => props.html_content,
   (newValue) => {
+    // editorRef.value.setHtml(newValue);
     valueHtml.value = newValue;
-    pre_html_content.value = valueHtml.value;
+    pre_html_content.value = newValue;
     toAlginCenterByH1();
+    // 初始化历史记录,避免redo回滚到空
+    nextTick(() => {
+      const editor = editorRef.value;
+      editor.history.undos = []; //保证每次接口返回数据后点击撤销操作会会清空数据
+    });
   }
 );
 defineExpose({

+ 1 - 1
src/utils/get-user-id.js

@@ -2,7 +2,7 @@
 
 
 export const getUserId = async () => {
-  let user_id = window.top?.getUserId ? window.top.getUserId() : ''
+  let user_id = window.top?.getUserId ? window.top.getUserId() : '6e0dc82686b54f069494d4c1f83ad042'
   return user_id
 }
 

+ 25 - 4
src/views/report/ReportDetail.vue

@@ -14,13 +14,17 @@
               <div class="title">{{ report_title }}</div>
               <div class="save" v-if="save_status == -1"></div>
               <div class="save" v-if="save_status == 0">
-                未保存
+                <icon-check-circle class="save_icon" />
+                上次修改发生在:{{ last_save_time }}
                 <a-tooltip content="使用Ctrl+S快捷键保存">
                   <span class="shortcut-hint" @click="saveHtmlFunc">(Ctrl+S)</span>
                 </a-tooltip>
               </div>
               <div class="save" v-if="save_status == 1"><a-spin />保存中</div>
-              <div class="save" v-if="save_status == 2">已保存{{ save_time }}</div>
+              <div class="save" v-if="save_status == 2">
+                <icon-check-circle class="save_icon" />
+                已保存
+              </div>
             </div>
             <div class="tools-right">
               <a-tooltip content="复制">
@@ -95,6 +99,8 @@ const is_loading = ref(false);
 const save_status = ref(-1);
 // 保存时间
 const save_time = ref('10:20');
+// 上次保存事件
+const last_save_time = ref('');
 // 定时器,定时保存文本内容
 let timeout_interval = null;
 
@@ -113,7 +119,7 @@ const changeSaveStatus = () => {
   }
   timeout_interval = setTimeout(() => {
     saveHtmlFunc();
-  }, 1000 * 10);
+  }, 1000 * 30);
 };
 const itemClick = (item) => {
   target_active_item.value = item;
@@ -143,12 +149,18 @@ const toDownload = (item) => {
     <html lang="en">
     <head>
       <meta charset="UTF-8">
+      <style>
+        body {
+          font-family: "Microsoft YaHei", "微软雅黑", sans-serif;
+        }
+      </style>
       <title>Document</title>
     </head>
     <body>
       ${fullHtml}
     </body>
     </html>`;
+  console.log(htmlString);
   try {
     asBlob(htmlString).then((data) => {
       // console.log(data);
@@ -174,6 +186,15 @@ const getReportHtml = async (record_id) => {
       if (res.data?.title) {
         report_title.value = res.data.title;
       }
+      if (res.data?.updated_at) {
+        let timeStr = res.data.updated_at;
+        console.log(timeStr);
+        last_save_time.value = timeStr.slice(0, 16);
+        console.log(last_save_time.value);
+      } else {
+        last_save_time.value = getCurrentTime();
+      }
+
       // console.log(html_content.value, report_title.value, 99);
     }
   } catch (e) {
@@ -211,7 +232,7 @@ const saveHtmlFunc = async () => {
     id: id.value,
     title: report_title.value,
     record_id: target_record_id.value,
-    html_content: my_editor.value.getHtml()
+    html_content: my_editor.value?.getHtml()
   };
   try {
     const res = await saveHtml(data);