Browse Source

避免点击导致的focus的朗读。

任一存 3 years ago
parent
commit
64a1f19e02
2 changed files with 28 additions and 11 deletions
  1. 2 1
      web/src/utils.js
  2. 26 10
      web/src/views/accessibility.vue

+ 2 - 1
web/src/utils.js

@@ -94,7 +94,8 @@ function extractTextForMagnify(e, allowRepeatd = false) {
 
   return {
     elemType,
-    elemDisc
+    elemDisc,
+    ariaNode: meaningfulNode,
   }
 }
 

+ 26 - 10
web/src/views/accessibility.vue

@@ -474,6 +474,9 @@ export default {
       navigationAreaNum: null,
       viewportAreaNum: null,
       interactionAreaNum: null,
+
+      focusedNode: null,
+      focudedNodeTimeoutId: null,
     }
   },
   watch: {
@@ -833,7 +836,12 @@ export default {
         this.elemType = extractedText.elemType
         this.elemDisc = extractedText.elemDisc
 
-        this.planToPlayAudio()
+        if (extractedText.ariaNode === this.focusedNode) {
+          console.log('已经由于(可能是点击导致的)focus而朗读了,不用再因为hover而朗读了');
+          return
+        } else {
+          this.planToPlayAudio()
+        }
       }
     }, 500),
     onMouseOverForContinueRead(e) {
@@ -876,15 +884,23 @@ export default {
       }
     },
     onFocusIn(e) {
-        if (!this.ariaSettings.isCompActive) {
-          return
-        }
-        const extractedText = utils.extractTextForMagnify(e, true)
-        if (extractedText) {
-          this.elemType = extractedText.elemType
-          this.elemDisc = extractedText.elemDisc
-          this.planToPlayAudio(this.continueReadTaskId)
-        }
+      if (!this.ariaSettings.isCompActive) {
+        return
+      }
+      const extractedText = utils.extractTextForMagnify(e, true)
+      if (extractedText) {
+        this.elemType = extractedText.elemType
+        this.elemDisc = extractedText.elemDisc
+
+        this.focusedNode = extractedText.ariaNode
+        clearTimeout(this.focusedNodeTimeoutId)
+        this.focusedNodeTimeoutId = setTimeout(() => {
+          this.focusedNode = null
+          this.focudedNodeTimeoutId = null
+        }, 1000);
+
+        this.planToPlayAudio(this.continueReadTaskId)
+      }
     },
     reset() {
       const copy = { ...defaultAriaSettings }