Commit e4ec3511 authored by 郭志伟's avatar 郭志伟

Merge branch 'fix/goods' into 'master'

fix: 键盘监听事件优化

See merge request !104
parents e2dfd947 e3996abd
......@@ -35,7 +35,7 @@
const LEFT_BTN_CLICK_EVENT = "leftClick";
const RIGHT_BTN_CLICK_EVENT = "click";
import settings from "@/api/settings";
import { onKeyboardStateChange, offKeyboardStateChange } from "@/service/utils";
import { onKeyboardStateChange } from "@/service/utils";
export default {
name: "GoodAction",
props: {
......@@ -67,7 +67,7 @@ export default {
});
},
destroyed() {
offKeyboardStateChange();
onKeyboardStateChange(() => {}, true);
},
methods: {
leftClick() {
......
......@@ -247,10 +247,11 @@ export function getBirthDate(idCard) {
/**
* @description: 移动端监听软键盘弹起或收起,IOS,android
* @param {Boolean} off 是否销毁
* @return {Function} callback 软键盘弹起或收取回调, true => 弹起, false => 隐藏
*/
export function onKeyboardStateChange(callback = () => {}) {
export function onKeyboardStateChange(callback = () => {}, off = false) {
if (isIOS) {
let isReset = true; //是否归位
......@@ -269,9 +270,14 @@ export function onKeyboardStateChange(callback = () => {}) {
}
}, 30);
};
if (off) {
document.body.removeEventListener("focusin", focusinHandler);
document.body.removeEventListener("focusout", focusoutHandler);
} else {
document.body.addEventListener("focusin", focusinHandler);
document.body.addEventListener("focusout", focusoutHandler);
}
}
if (isAndroid) {
const originHeight = document.documentElement.clientHeight || document.body.clientHeight;
......@@ -294,33 +300,10 @@ export function onKeyboardStateChange(callback = () => {}) {
callback(false);
}
};
if (off) {
window.removeEventListener("resize", resizeHandler);
} else {
window.addEventListener("resize", resizeHandler);
}
}
/**
* @description: 销毁软键盘监听
*/
export function offKeyboardStateChange(callback = () => {}) {
if (isIOS) {
const focusinHandler = () => {
console.log("focusin已卸载");
callback();
};
const focusoutHandler = () => {
console.log("focusout已卸载");
callback();
};
document.body.removeEventListener("focusin", focusinHandler);
document.body.removeEventListener("focusout", focusoutHandler);
}
if (isAndroid) {
const resizeHandler = () => {
console.log("resize已卸载");
callback();
};
window.removeEventListener("resize", resizeHandler);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment