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 } }