⚠️⚠️⚠️⚠️⚠️⚠️注意。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
// this.ctrlf = !this.ctrlf
// 关闭搜索时 返回表格全部数据
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)) {
// mac 和 windows有区别
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)
}
},
}