Ver Fonte

fix:修复中文符号自动补全导致左右键功能异常的问题

luoaoxuan há 1 ano atrás
pai
commit
0c77b8173d
1 ficheiros alterados com 52 adições e 10 exclusões
  1. 52 10
      src/views/platform/examination/questionBank/test.vue

+ 52 - 10
src/views/platform/examination/questionBank/test.vue

@@ -199,7 +199,9 @@ export default {
             questionList: [],
             questionList: [],
             showIndex: 1,
             showIndex: 1,
             userId,
             userId,
-            countdownNotify: false
+            countdownNotify: false,
+            lastKey: '', // 存储上一次的按键
+            lastLastKey: '' // 存储上上次的按键
         }
         }
     },
     },
     computed: {
     computed: {
@@ -417,21 +419,61 @@ export default {
             return result.join(' ')
             return result.join(' ')
         },
         },
         handleKeyPress (event) {
         handleKeyPress (event) {
+            // console.log(event.keyCode, event.key)
+            // 这四种符号在中文模式下会自动补全 导致左右键混入的情况  《 “ {} 【  (
             if (event.keyCode === 37 || event.key === 'ArrowLeft') {
             if (event.keyCode === 37 || event.key === 'ArrowLeft') {
-                if (this.showIndex === 1) {
-                    this.$message.warning('已经是第一题了!')
-                    return
+                const ignoreConditions = [
+                    ['(', 'Shift'],
+                    ['{', 'Shift'],
+                    ['<', 'Shift'],
+                    ['9', 'Shift'],
+                    ['[', 'Shift'],
+                    ['Process', '['],
+                    ['Process', '9'],
+                    ['Process', ','],
+                    ['Process', "'"],
+                    ['ArrowLeft', 'Shift'],
+                    ['[', 'ArrowLeft'],
+                    ['ArrowLeft', '['],
+                    ['[', '['],
+                    ["'", '['],
+                    [',', 'Shift']
+                ]
+
+                if (!ignoreConditions.some(([llk, lk]) => this.lastLastKey === llk && this.lastKey === lk)) {
+                    if (this.showIndex === 1) {
+                        this.$message.warning('已经是第一题了!')
+                    } else {
+                        this.showIndex--
+                    }
                 }
                 }
-                this.showIndex--
             } else if (event.keyCode === 39 || event.key === 'ArrowRight') {
             } else if (event.keyCode === 39 || event.key === 'ArrowRight') {
-                if (this.showIndex === this.questionList.length) {
-                    this.$message.warning('已经是最后一题了!')
-                    return
+                const ignoreConditions = [
+                    ['[', 'ArrowLeft'],
+                    ["'", 'ArrowLeft'],
+                    ['ArrowLeft', 'Shift'],
+                    ['Process', 'ArrowLeft'],
+                    ['ArrowLeft', '['],
+                    ['{', 'Shift'],
+                    ['<', 'Shift'],
+                    ['(', 'Shift'],
+                    ['9', 'Shift']
+                ]
+
+                if (!ignoreConditions.some(([llk, lk]) => this.lastLastKey === llk && this.lastKey === lk)) {
+                    if (this.showIndex === this.questionList.length) {
+                        this.$message.warning('已经是最后一题了!')
+                    } else {
+                        this.showIndex++
+                    }
                 }
                 }
-                this.showIndex++
-            } else if (event.keyCode === 27 || event.key === 'Esc') {
+            } else if (event.keyCode === 27 || event.key === 'Escape') {
                 this.handleCancel()
                 this.handleCancel()
             }
             }
+
+            // 更新键盘状态
+            this.lastLastKey = this.lastKey
+            this.lastKey = event.key
         },
         },
         handleBeforeUnload (event) {
         handleBeforeUnload (event) {
             const confirmationMessage = '离开将自动提交当前数据,确定要离开吗?';
             const confirmationMessage = '离开将自动提交当前数据,确定要离开吗?';