Przeglądaj źródła

fix: v2.4.6 三轮测试修复

wzl 3 miesięcy temu
rodzic
commit
707b955536

+ 10 - 8
packages/core/src/editor/add_image.js

@@ -9,6 +9,7 @@ export default class AddImage {
     tool,
     color,
     container,
+    pageViewer,
     viewport,
     page,
     eventBus,
@@ -18,6 +19,7 @@ export default class AddImage {
     this._tool = tool
     this.color = color
     this.container = container
+    this.pageViewer = pageViewer
     this.viewport = viewport
     this.page = page
     this.eventBus = eventBus
@@ -100,8 +102,8 @@ export default class AddImage {
     const initEndPoint = this.initEndPoint
 
     if (initEndPoint && initStartPoint.x !== initEndPoint.x && initStartPoint.y !== initEndPoint.y) { // 绘制区域
-      const start = getInitialPoint(initStartPoint, this.viewport, this.viewport.scale)
-      const end = getInitialPoint(initEndPoint, this.viewport, this.viewport.scale)
+      const start = getInitialPoint(initStartPoint, this.pageViewer.viewport, this.pageViewer.viewport.scale)
+      const end = getInitialPoint(initEndPoint, this.pageViewer.viewport, this.pageViewer.viewport.scale)
       
       const newStart = {
         x: Math.min(start.x, end.x),
@@ -158,9 +160,9 @@ export default class AddImage {
           console.error(error)
         })
     } else { // 单击区域
-      const centerPoint = getInitialPoint(initStartPoint, this.viewport, this.viewport.scale)
-      const pageWidth = this.viewport.viewBox[2]
-      const pageHeight = this.viewport.viewBox[3]
+      const centerPoint = getInitialPoint(initStartPoint, this.pageViewer.viewport, this.pageViewer.viewport.scale)
+      const pageWidth = this.pageViewer.viewport.viewBox[2]
+      const pageHeight = this.pageViewer.viewport.viewBox[3]
       const fixedWidth = pageWidth / 2
       const fixedHeight = pageHeight / 2
 
@@ -237,8 +239,8 @@ export default class AddImage {
 
   handleMouseMove (event) {
     let { x, y } = getAbsoluteCoordinate(this.container, event)
-    const { width, height } = this.viewport
-    const scale = this.viewport.scale
+    const { width, height } = this.pageViewer.viewport
+    const scale = this.pageViewer.viewport.scale
     x = Math.min(width, x)
     x = Math.max(0, x)
     y = Math.min(height, y)
@@ -295,7 +297,7 @@ export default class AddImage {
 
   calculate (start, end) {
     const initRect = this.rectCalc({ start, end })
-    const actualbdwidth = 1 * this.viewport.scale
+    const actualbdwidth = 1 * this.pageViewer.viewport.scale
 
     return {
       top: initRect.top - actualbdwidth,

+ 7 - 5
packages/core/src/editor/add_text.js

@@ -10,6 +10,7 @@ export default class AddText {
     tool,
     color,
     container,
+    pageViewer,
     viewport,
     page,
     eventBus,
@@ -18,6 +19,7 @@ export default class AddText {
     this._tool = tool
     this.color = color
     this.container = container
+    this.pageViewer = pageViewer
     this.viewport = viewport
     this.page = page
     this.eventBus = eventBus
@@ -95,8 +97,8 @@ export default class AddText {
     let initStartPoint = this.initStartPoint
     let initEndPoint = this.initEndPoint
     if (initEndPoint && initStartPoint.x !== initEndPoint.x && initStartPoint.y !== initEndPoint.y) {
-      let start = getInitialPoint(initStartPoint, this.viewport, this.viewport.scale)
-      let end = getInitialPoint(initEndPoint, this.viewport, this.viewport.scale)
+      let start = getInitialPoint(initStartPoint, this.pageViewer.viewport, this.pageViewer.viewport.scale)
+      let end = getInitialPoint(initEndPoint, this.pageViewer.viewport, this.pageViewer.viewport.scale)
       
       const newStart = {
         x: Math.min(start.x, end.x),
@@ -146,8 +148,8 @@ export default class AddText {
 
   handleMouseMove (event) {
     let { x, y } = getAbsoluteCoordinate(this.container, event)
-    const { width, height } = this.viewport
-    const scale = this.viewport.scale
+    const { width, height } = this.pageViewer.viewport
+    const scale = this.pageViewer.viewport.scale
     x = Math.min(width, x)
     x = Math.max(0, x)
     y = Math.min(height, y)
@@ -204,7 +206,7 @@ export default class AddText {
 
   calculate (start, end) {
     const initRect = this.rectCalc({ start, end });
-    const actualbdwidth = 1 * this.viewport.scale
+    const actualbdwidth = 1 * this.pageViewer.viewport.scale
 
     return {
       top: initRect.top - actualbdwidth,

+ 54 - 44
packages/core/src/editor/content_container.js

@@ -18,6 +18,7 @@ export class ContentContainer {
 
     this.destroyed = false
     this.rendered = false
+    this.isRendering = false
     this.frameEditorList = []
     this.tool = this.pageViewer.tool || ''
     this.color = this.pageViewer.color || ''
@@ -62,6 +63,8 @@ export class ContentContainer {
     if (this.contentContainer) {
       return;
     }
+    const rendering = this.isRendering
+    this.isRendering = true
 
     const contentContainer = document.createElement('div')
     contentContainer.className = 'contentContainer'
@@ -75,54 +78,59 @@ export class ContentContainer {
     })
     this.frameEditorList.length = 0
 
-    const editAreaCount = await this.messageHandler.sendWithPromise('GetEditAreaCount', this.editPagePtr)
-    
-    for (let i = 0; i < editAreaCount; i++) {
-      const editAreaPtr = await this.messageHandler.sendWithPromise('GetEditArea', {
-        editPagePtr: this.editPagePtr,
-        index: i
-      })
-      if (!editAreaPtr) continue
-
-      const isTextPtr = await this.messageHandler.sendWithPromise('IsTextArea', editAreaPtr)
-      if (isTextPtr) {
-        const frameEditor = new TextEditor({
-          eventBus: this.eventBus,
-          contentContainer: this,
-          container: this.contentContainer,
-          pagePtr: this.pagePtr,
-          editPagePtr: this.editPagePtr,
-          editAreaPtr,
-          editAreaIndex: i,
-          viewport: this.pageViewer.viewport,
-          scale: this.pageViewer.scale,
-          messageHandler: this.messageHandler,
-          pageViewer: this.pageViewer,
-          hidden: this.tool === 'addImage'
-        })
-        this.frameEditorList.push(frameEditor)
-        continue
-      }
+    try {
+      const editAreaCount = await this.messageHandler.sendWithPromise('GetEditAreaCount', this.editPagePtr)
+      for (let i = 0; i < editAreaCount; i++) {
+        if (rendering) break
 
-      const isImagePtr = await this.messageHandler.sendWithPromise('IsImageArea', editAreaPtr)
-      if (isImagePtr) {
-        const frameEditor = new ImageEditor({
-          eventBus: this.eventBus,
-          contentContainer: this,
-          container: this.contentContainer,
-          pagePtr: this.pagePtr,
+        const editAreaPtr = await this.messageHandler.sendWithPromise('GetEditArea', {
           editPagePtr: this.editPagePtr,
-          editAreaPtr,
-          editAreaIndex: i,
-          viewport: this.pageViewer.viewport,
-          scale: this.pageViewer.scale,
-          messageHandler: this.messageHandler,
-          pageViewer: this.pageViewer,
-          $t: this.$t,
-          hidden: this.tool === 'addText'
+          index: i
         })
-        this.frameEditorList.push(frameEditor)
+        if (!editAreaPtr) continue
+
+        const isTextPtr = await this.messageHandler.sendWithPromise('IsTextArea', editAreaPtr)
+        if (isTextPtr) {
+          const frameEditor = new TextEditor({
+            eventBus: this.eventBus,
+            contentContainer: this,
+            container: this.contentContainer,
+            pagePtr: this.pagePtr,
+            editPagePtr: this.editPagePtr,
+            editAreaPtr,
+            editAreaIndex: i,
+            viewport: this.pageViewer.viewport,
+            scale: this.pageViewer.scale,
+            messageHandler: this.messageHandler,
+            pageViewer: this.pageViewer,
+            hidden: this.tool === 'addImage'
+          })
+          this.frameEditorList.push(frameEditor)
+          continue
+        }
+
+        const isImagePtr = await this.messageHandler.sendWithPromise('IsImageArea', editAreaPtr)
+        if (isImagePtr) {
+          const frameEditor = new ImageEditor({
+            eventBus: this.eventBus,
+            contentContainer: this,
+            container: this.contentContainer,
+            pagePtr: this.pagePtr,
+            editPagePtr: this.editPagePtr,
+            editAreaPtr,
+            editAreaIndex: i,
+            viewport: this.pageViewer.viewport,
+            scale: this.pageViewer.scale,
+            messageHandler: this.messageHandler,
+            pageViewer: this.pageViewer,
+            $t: this.$t,
+            hidden: this.tool === 'addText'
+          })
+          this.frameEditorList.push(frameEditor)
+        }
       }
+    } finally {
+      this.isRendering = false
     }
 
     if (this.tool === 'addText') {
@@ -243,6 +251,7 @@ export class ContentContainer {
         tool: this.tool,
         color: this.color,
         container: this.pageDiv,
+        pageViewer: this.pageViewer,
         viewport: this.pageViewer.viewport,
         scale: this.pageViewer.scale,
         page: this.page,
@@ -260,6 +269,7 @@ export class ContentContainer {
         tool: this.tool,
         color: this.color,
         container: this.pageDiv,
+        pageViewer: this.pageViewer,
         viewport: this.pageViewer.viewport,
         scale: this.pageViewer.scale,
         page: this.page,

+ 2 - 2
packages/core/src/editor/text_editor.js

@@ -147,7 +147,7 @@ export class TextEditor {
     this.textContainer.append(textarea)
     this.textarea = textarea
     let text = await this.getText()
-    this.textarea.innerHTML = text
+    this.textarea.value = text
 
     this.frameContainer?.append(this.textContainer)
 
@@ -592,7 +592,7 @@ export class TextEditor {
       
       if (this.mouseMoved) {
         endPoint = this.endPoint
-        this.cursor.style.display = 'block'
+        this.cursor && (this.cursor.style.display = 'block')
       }
       if (!this.startPoint) {
         this.startPoint = endPoint

+ 1 - 1
packages/webview/src/components/Measure/MeasurePop.vue

@@ -76,10 +76,10 @@ import { useViewerStore } from '@/stores/modules/viewer'
     color: rgb(36, 42, 51);
     box-sizing: border-box;
     outline: none;
+    -moz-appearance: textfield;
     &::-webkit-inner-spin-button {
       -webkit-appearance: none;
     }
-    -moz-appearance: textfield;
   }
   .measure-pop select {
     width: 45px;