共享库 goMall 加环境判定矩阵(与授权同款): 非webview提示「请在小程序中打开商城」; demo加switchTab埋点 (v26090810)

This commit is contained in:
2026-09-08 10:52:13 +08:00
parent f7691c540f
commit 0598f5b566

View File

@@ -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) {