⚠️⚠️⚠️⚠️⚠️⚠️注意。mac、win、上面监听按键是有差异的,比如(e.key === ‘Meta’) || (e.key === ‘Control’),谷歌浏览器和qq浏览器、edge浏览器也有差异e.key === ‘f’ || e.key === ‘F’。,大小写
created() {
window.addEventListener('keydown', this.keydown)
window.addEventListener('keyup', this.keyup)
window.addEventListener('dblclick', this.doubleClick)
},
methods: {
keydown(e) {
if (ROUTER_PATH.includes(this.$route.path)) {
if ((e.key === 'Meta') || (e.key === 'Control')) this.CONTROL = 1
if (e.key === 'f' || e.key === 'F') this.F = 1
console.log(this.CONTROL, this.F, 'sss')
if (this.CONTROL === 1 && this.F === 1) {
this.ctrlf = true
if (this.ctrlf) {
this.doubleClick()
this.searchBill()
} else {
this.searchName = ''
}
e.preventDefault()
}
} else {
window.removeEventListener('keydown', this.keydown, true)
}
},
keyup(e) {
if (ROUTER_PATH.includes(this.$route.path)) {
const isMac = /macintosh|mac os x/i.test(navigator.userAgent)
if (isMac) {
this.CONTROL = 0
this.F = 0
} else {
if (e.key === 'Control') this.CONTROL = 0
if (e.key === 'f') this.F = 0
}
} else {
window.removeEventListener('keyup', this.keyup, true)
}
},
}