new-cashier/jeepay-ui-uapp-agent/hooks/useBackPress.js

32 lines
835 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import onceVar from '@/util/onceVar.js'
import { onBackPress } from '@dcloudio/uni-app'
import {nextTick} from 'vue'
/*
本函数用于阻断返回操作当页面开启图片预览与选择框时app上的返回操作会直接返回到上一级页面不符合正常的体验。 所以触发返回事件,优先关闭图片预览与其他弹窗
参数fun 为具体使用页面的关闭弹窗函数,需要在这里执行一次
onceVar 为全局唯一变量,保存在内存中。 可用vuex代替
*/
export default function (fun) {
onBackPress((option) => {
if (onceVar.imgView()) {
nextTick(() => {
fun()
inactive()
})
return true
}
return false
})
const active = () => onceVar.imgView(true)
const inactive = () => onceVar.imgView(false)
return { active, inactive }
}