import { POLICY_CONSENT_VERSION, STORAGE_KEY_POLICY_CONSENT, } from '@/utils/policy-config.js' import { eventBus } from '@/utils/event-bus' let policyHostVm = null let privacyResolve = null let lastTabbarBlocked = false let pendingHomeRefreshAfterPolicy = false /** 用户刚同意协议,首页需在登录后补拉数据 */ export function markHomeRefreshAfterPolicy() { pendingHomeRefreshAfterPolicy = true } export function consumeHomeRefreshAfterPolicy() { const need = pendingHomeRefreshAfterPolicy pendingHomeRefreshAfterPolicy = false return need } function hideNativeTabBar() { uni.hideTabBar({ animation: false, fail: () => {}, }) } function showNativeTabBar() { uni.showTabBar({ animation: false, fail: () => {}, }) } /** * 协议/隐私弹窗期间隐藏原生 tabBar(小程序内 cover-view 无法可靠拦截 tabBar 点击) */ export function setTabbarBlockedState(blocked) { const next = !!blocked lastTabbarBlocked = next if (next) { hideNativeTabBar() } else { showNativeTabBar() } eventBus.emit('tabbarBlockChange', next) } /** Tab 切换回显时重新应用 tabBar 显隐 */ export function syncTabbarBlockedState() { if (lastTabbarBlocked) { hideNativeTabBar() } else { showNativeTabBar() } } export function getTabbarBlockedState() { return lastTabbarBlocked } export function isPolicyConsented() { return uni.getStorageSync(STORAGE_KEY_POLICY_CONSENT) === POLICY_CONSENT_VERSION } /** 未同意业务协议前,禁止展示分享减价/加价等活动弹窗 */ export function shouldBlockMarketingPopup() { const app = getApp() if (app && app.globalData && app.globalData.needPolicyConsent) { return true } return !isPolicyConsented() } export function setPolicyConsented() { uni.setStorageSync(STORAGE_KEY_POLICY_CONSENT, POLICY_CONSENT_VERSION) } export function registerPolicyHost(vm) { policyHostVm = vm const app = getApp() if (app && app.globalData && app.globalData.needPolicyConsent) { vm.tryOpenPolicyModal() } if (app && app.globalData && app.globalData.needPrivacyPopup) { vm.tryOpenPrivacyPopup() } } export function unregisterPolicyHost(vm) { if (policyHostVm === vm) { policyHostVm = null } } export function requestShowPolicyModal() { const app = getApp() if (app && app.globalData) { app.globalData.needPolicyConsent = true } if (policyHostVm) { policyHostVm.tryOpenPolicyModal() } } export function requestShowPrivacyPopup(resolve) { privacyResolve = resolve const app = getApp() if (app && app.globalData) { app.globalData.needPrivacyPopup = true } if (policyHostVm) { policyHostVm.tryOpenPrivacyPopup() } } export function getPrivacyResolve() { return privacyResolve } export function clearPrivacyResolve() { privacyResolve = null } export function clearPrivacyPopupFlag() { const app = getApp() if (app && app.globalData) { app.globalData.needPrivacyPopup = false } }