Просмотр исходного кода

不能设置笔记与收藏文本不显示笔记与收藏按钮栏

zq 3 недель назад
Родитель
Сommit
5895299aa9
1 измененных файлов с 12 добавлено и 9 удалено
  1. 12 9
      src/views/book/courseware/preview/CoursewarePreview.vue

+ 12 - 9
src/views/book/courseware/preview/CoursewarePreview.vue

@@ -155,6 +155,7 @@ export default {
         top: 0,
       },
       selectedInfo: null,
+      selectHandleInfo: null,
     };
   },
   watch: {
@@ -443,7 +444,14 @@ export default {
 
         const selectedText = selection.toString().trim();
         const range = selection.getRangeAt(0);
-        console.info(selectedText, range);
+        this.selectedInfo = {
+          text: selectedText,
+          range,
+        };
+        let selectHandleInfo = this.getSelectionInfo();
+        if (!selectHandleInfo || !selectHandleInfo.text) return;
+        this.selectHandleInfo = selectHandleInfo;
+
         this.showToolbar = true;
         const container = document.querySelector('.courserware');
         const boxRect = container.getBoundingClientRect();
@@ -452,21 +460,15 @@ export default {
           left: `${Math.round(selectRect.left - boxRect.left + selectRect.width / 2 - 63)}px`,
           top: `${Math.round(selectRect.top - boxRect.top + selectRect.height)}px`, // 向上偏移10px
         };
-
-        this.selectedInfo = {
-          text: selectedText,
-          range,
-        };
       }, 100);
     },
     // 笔记
     setNote() {
       this.showToolbar = false;
       this.oldRichData = {};
-      let info = this.getSelectionInfo();
+      let info = this.selectHandleInfo;
       if (!info) return;
       info.coursewareId = this.courseware_id;
-
       this.$emit('editNote', info);
       this.selectedInfo = null;
     },
@@ -474,7 +476,7 @@ export default {
     setCollect() {
       this.showToolbar = false;
 
-      let info = this.getSelectionInfo();
+      let info = this.selectHandleInfo;
       if (!info) return;
       info.coursewareId = this.courseware_id;
 
@@ -485,6 +487,7 @@ export default {
     handLocation(item) {
       this.scrollToDataId(item.blockId);
     },
+
     getSelectionInfo() {
       if (!this.selectedInfo) return;
       const range = this.selectedInfo.range;