修复小程序生成前订阅授权体验
生成前订阅授权页自动弹出微信授权框 授权返回或跳过后继续执行拼图生成提交 避免订阅页改写上一页 web-view URL 导致回首页 更新订阅消息生成前授权与终态发送文档口径
This commit is contained in:
@@ -3,6 +3,7 @@ import { isWechatMiniProgramRuntime } from './payment/paymentPlatform';
|
||||
const WECHAT_JS_SDK_URL = 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js';
|
||||
const SUBSCRIBE_RESULT_HASH_KEY = 'wx_subscribe_result';
|
||||
const SUBSCRIBE_RESULT_TIMEOUT_MS = 30_000;
|
||||
const SUBSCRIBE_RESULT_RETURN_FALLBACK_MS = 800;
|
||||
|
||||
function clearSubscribeResultHash() {
|
||||
const rawHash = window.location.hash.replace(/^#/, '');
|
||||
@@ -39,6 +40,7 @@ function waitSubscribeResultFromHash(timeoutMs = SUBSCRIBE_RESULT_TIMEOUT_MS) {
|
||||
|
||||
return new Promise<string | null>((resolve) => {
|
||||
let timer: number | null = null;
|
||||
let resumeFallbackTimer: number | null = null;
|
||||
const cleanup = () => {
|
||||
window.removeEventListener('hashchange', handleHashChange);
|
||||
window.removeEventListener('focus', handleResume);
|
||||
@@ -47,6 +49,9 @@ function waitSubscribeResultFromHash(timeoutMs = SUBSCRIBE_RESULT_TIMEOUT_MS) {
|
||||
if (timer !== null) {
|
||||
window.clearTimeout(timer);
|
||||
}
|
||||
if (resumeFallbackTimer !== null) {
|
||||
window.clearTimeout(resumeFallbackTimer);
|
||||
}
|
||||
};
|
||||
const finish = (result: string | null) => {
|
||||
cleanup();
|
||||
@@ -70,7 +75,17 @@ function waitSubscribeResultFromHash(timeoutMs = SUBSCRIBE_RESULT_TIMEOUT_MS) {
|
||||
) {
|
||||
return;
|
||||
}
|
||||
consume();
|
||||
if (consume()) {
|
||||
return;
|
||||
}
|
||||
// 中文注释:订阅授权只影响后续通知,不应阻断生成;原生页返回但没有 hash
|
||||
// 回灌时,按已返回处理,让原本的生成提交流程继续执行。
|
||||
if (resumeFallbackTimer === null) {
|
||||
resumeFallbackTimer = window.setTimeout(
|
||||
() => finish('returned'),
|
||||
SUBSCRIBE_RESULT_RETURN_FALLBACK_MS,
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
window.addEventListener('hashchange', handleHashChange);
|
||||
@@ -142,7 +157,7 @@ export async function requestGenerationResultSubscribePermission() {
|
||||
const requestId = `subscribe_generation_result_${Date.now()}`;
|
||||
const navigated = await new Promise<boolean>((resolve) => {
|
||||
miniProgram.navigateTo?.({
|
||||
url: `/pages/subscribe-message/index?requestId=${encodeURIComponent(requestId)}&scene=generation-result`,
|
||||
url: `/pages/subscribe-message/index?requestId=${encodeURIComponent(requestId)}&scene=generation-result&autoRequest=1`,
|
||||
success() {
|
||||
resolve(true);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user