wx-h5-demo: scenario1 '去小程序授权' in webview → wx.miniProgram.navigateTo(/pages/demo/auth); browser → configurable LAUNCH_SCHEME; clarify README

This commit is contained in:
2026-09-07 17:38:30 +08:00
parent eaaf2b6773
commit bc3531e83c
2 changed files with 14 additions and 6 deletions

View File

@@ -86,13 +86,18 @@
}
// 场景1:跳小程序授权(wx-open-launch-weapp 或 URL Scheme) → 小程序授权页
var LAUNCH_PATH = '/pages/demo/auth'; // 小程序授权页路径(场景1 的授权页,见 miniapp/scenario1-auth-bridge.*)
var LAUNCH_SCHEME = ''; // 微信浏览器用的 URL Scheme(后端用 appid+path 生成,见 README);留空则走 webview navigateTo
function jumpToMiniAuth() {
if (MODE === 'browser') { toast('请在微信内打开'); return; }
// 方式A:公众号/网页 JSSDK `<wx-open-launch-weapp>`(需 jsapi 签名 + 微信内打开)
// 方式B:小程序 URL Scheme(后端用 appid+path 换 scheme,形如 weixin://dl/business/?t=xxx)
var scheme = $('#launchPath') && $('#launchPath').value; // 你可在下面填 scheme 或 path
if (scheme) { location.href = scheme; return; }
toast('请在此填入小程序授权页的 scheme/launch 入口(见 README)');
// 小程序 web-view 内:用 wx.miniProgram.navigateTo 跳到授权页(场景1 在 webview 里的做法)
if (window.wx && window.wx.miniProgram && inWebview) {
window.wx.miniProgram.navigateTo({ url: LAUNCH_PATH });
return;
}
// 微信浏览器(非 web-view):优先 URL Scheme;否则提示用 <wx-open-launch-weapp>(需 jsapi 签名)
if (LAUNCH_SCHEME) { location.href = LAUNCH_SCHEME; return; }
toast('请配置小程序 URL Scheme(后端生成)或用 <wx-open-launch-weapp> 跳授权页');
}
// 场景2:postMessage 请求 web-view 宿主弹授权面板