|
|
@@ -199,7 +199,9 @@ export default {
|
|
|
questionList: [],
|
|
|
showIndex: 1,
|
|
|
userId,
|
|
|
- countdownNotify: false
|
|
|
+ countdownNotify: false,
|
|
|
+ lastKey: '', // 存储上一次的按键
|
|
|
+ lastLastKey: '' // 存储上上次的按键
|
|
|
}
|
|
|
},
|
|
|
computed: {
|
|
|
@@ -417,21 +419,61 @@ export default {
|
|
|
return result.join(' ')
|
|
|
},
|
|
|
handleKeyPress (event) {
|
|
|
+ // console.log(event.keyCode, event.key)
|
|
|
+ // 这四种符号在中文模式下会自动补全 导致左右键混入的情况 《 “ {} 【 (
|
|
|
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') {
|
|
|
- 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.lastLastKey = this.lastKey
|
|
|
+ this.lastKey = event.key
|
|
|
},
|
|
|
handleBeforeUnload (event) {
|
|
|
const confirmationMessage = '离开将自动提交当前数据,确定要离开吗?';
|