From 0598f5b566873cf6f6d703723252157f2fce3dc1 Mon Sep 17 00:00:00 2001 From: Karlcarlo Date: Tue, 8 Sep 2026 10:52:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=B1=E4=BA=AB=E5=BA=93=20goMall=20?= =?UTF-8?q?=E5=8A=A0=E7=8E=AF=E5=A2=83=E5=88=A4=E5=AE=9A=E7=9F=A9=E9=98=B5?= =?UTF-8?q?(=E4=B8=8E=E6=8E=88=E6=9D=83=E5=90=8C=E6=AC=BE):=20=E9=9D=9Eweb?= =?UTF-8?q?view=E6=8F=90=E7=A4=BA=E3=80=8C=E8=AF=B7=E5=9C=A8=E5=B0=8F?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E4=B8=AD=E6=89=93=E5=BC=80=E5=95=86=E5=9F=8E?= =?UTF-8?q?=E3=80=8D;=20demo=E5=8A=A0switchTab=E5=9F=8B=E7=82=B9=20(v26090?= =?UTF-8?q?810)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- js/wx-auth.js | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/js/wx-auth.js b/js/wx-auth.js index 9b20665..ecc9e16 100644 --- a/js/wx-auth.js +++ b/js/wx-auth.js @@ -87,9 +87,30 @@ } }, /* ⑤ 跳小程序商城(tabBar 页用 switchTab;非 tabBar 用 navigateTo) */ + /* ⑤ 跳商城:环境判定与 requestProfile 同一套 —— 仅小程序 webview 内 switchTab, + UA 非微信/微信内非 webview(或 getEnv 不回调)都提示「请在小程序中打开商城」。 */ goMall: function (url) { - if (!(window.wx && window.wx.miniProgram)) { this.toast('请在微信小程序中打开商城'); return; } - window.wx.miniProgram.switchTab({ url: url || '/pages/goods_cate/goods_cate' }); + var self = this; + function go() { + window.wx.miniProgram.switchTab({ url: url || '/pages/goods_cate/goods_cate' }); + } + if (!/MicroMessenger/i.test(navigator.userAgent)) { + this.toast('请在小程序中打开商城'); + return; + } + if (window.wx && window.wx.miniProgram) { + var responded = false; + window.wx.miniProgram.getEnv(function (r) { + responded = true; + if (r && r.miniprogram) go(); + else self.toast('请在小程序中打开商城'); + }); + setTimeout(function () { + if (!responded) self.toast('请在小程序中打开商城'); + }, 800); + } else { + this.toast('请在小程序中打开商城'); + } }, /* ⑥ 展示授权结果到指定元素(可选便捷方法) */ fillAuth: function (nameEl, avatarEl) {