fix(payment): guard ezpay redirect persistence

This commit is contained in:
2026-06-23 17:55:51 +08:00
parent c8881a33c6
commit a47038c46f
2 changed files with 64 additions and 43 deletions
+22 -17
View File
@@ -26,26 +26,14 @@ export function PwaInstallOverlay() {
let mounted = true;
const init = async () => {
// 0) PWA 支持 / 安装 双重门禁(两种环境都检查):
// isSupported() 检查 serviceWorker + windowSSR 安全)
// isInstalled() 检查 standalone display-mode(避免给已安装用户再弹)
if (!pwaUtil.isSupported()) return;
if (pwaUtil.isInstalled()) return;
if (BrowserDetector.isInAppBrowser()) return;
// const isDev = AppEnvUtil.isDevelopment();
const isDev = false;
const shouldShowDialog = await shouldShowPwaInstallDialog(isDev);
if (!shouldShowDialog) return;
// 提前挂 beforeinstallprompt 监听,避免用户点 OK 时事件已在更早时机丢失。
pwaUtil.prepareInstallPrompt();
const isDev = AppEnvUtil.isDevelopment();
if (!isDev) {
// 生产环境:每日只弹一次(防骚扰)
const lastResult = await SpAsyncUtil.getString(PWA_DIALOG_KEY);
if (!lastResult.success) return;
const today = new Date().toISOString().slice(0, 10);
if (lastResult.data === today) return; // 今天已显示过
}
// 开发环境:跳过"每日一次"门禁,每次进入都弹,方便 UI 测试
// 开发环境 1s 后弹(快);生产环境 3.5s 后弹(让用户先看到聊天内容)
const delay = isDev ? 1000 : 3500;
setTimeout(() => {
@@ -63,6 +51,23 @@ export function PwaInstallOverlay() {
return <div className={styles.hidden} aria-hidden="true" />;
}
async function shouldShowPwaInstallDialog(isDevelopment: boolean) {
// PWA 支持 / 安装 双重门禁(两种环境都检查)。
if (!pwaUtil.isSupported()) return false;
if (pwaUtil.isInstalled()) return false;
if (BrowserDetector.isInAppBrowser()) return false;
// 开发环境:跳过"每日一次"门禁,每次进入都弹,方便 UI 测试。
if (isDevelopment) return true;
// 生产环境:每日只弹一次(防骚扰)。
const lastResult = await SpAsyncUtil.getString(PWA_DIALOG_KEY);
if (!lastResult.success) return false;
const today = new Date().toISOString().slice(0, 10);
return lastResult.data !== today;
}
function showPwaDialog() {
if (typeof document === "undefined") return;
// 记录显示时间