|
|
@@ -101,6 +101,10 @@ Page({
|
|
|
console.log('✅ 入口页已设置店铺 ID:', storeId)
|
|
|
}
|
|
|
if (company) getApp().globalData.toCompany = true;
|
|
|
+
|
|
|
+ // 检查是否是扫码进入(需要统计扫码次数)
|
|
|
+ this.checkAndHandleScan(options);
|
|
|
+
|
|
|
plugin.init(config, wx.getStorageSync('invite'))
|
|
|
},
|
|
|
|
|
|
@@ -155,6 +159,13 @@ Page({
|
|
|
if (!await this.getCompanyServerExpire(url)) {
|
|
|
return
|
|
|
}
|
|
|
+
|
|
|
+ // 检查是否需要跳转到扫码统计页面
|
|
|
+ if (this.shouldRedirectToScanPage()) {
|
|
|
+ await this.redirectToScanPage();
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
wx.redirectTo({
|
|
|
url: url,
|
|
|
});
|
|
|
@@ -261,5 +272,93 @@ Page({
|
|
|
obj[key] = val
|
|
|
})
|
|
|
return obj
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 检查并处理扫码参数
|
|
|
+ * 如果 URL 中包含 scanCount 和 partnerId,保存到临时存储
|
|
|
+ */
|
|
|
+ checkAndHandleScan(options) {
|
|
|
+ const { scanCount, partnerId, storeId } = options;
|
|
|
+
|
|
|
+ // 如果存在 scanCount 和 partnerId,说明是扫码进入
|
|
|
+ if (scanCount !== undefined && partnerId) {
|
|
|
+ console.log('===========================================');
|
|
|
+ console.log('======= 检测到扫码参数 =======');
|
|
|
+ console.log('partnerId:', partnerId);
|
|
|
+ console.log('storeId:', storeId);
|
|
|
+ console.log('scanCount:', scanCount);
|
|
|
+ console.log('===========================================');
|
|
|
+
|
|
|
+ // 保存到临时存储,用于后续跳转
|
|
|
+ wx.setStorageSync('scan_partnerId', partnerId);
|
|
|
+ wx.setStorageSync('scan_storeId', storeId);
|
|
|
+ wx.setStorageSync('scan_scanCount', scanCount);
|
|
|
+ wx.setStorageSync('need_scan_redirect', true);
|
|
|
+ }
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否需要跳转到扫码统计页面
|
|
|
+ */
|
|
|
+ shouldRedirectToScanPage() {
|
|
|
+ return wx.getStorageSync('need_scan_redirect') === true;
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 跳转到扫码统计页面
|
|
|
+ * 构建完整的 H5 URL 并跳转到 web-view 页面
|
|
|
+ */
|
|
|
+ async redirectToScanPage() {
|
|
|
+ try {
|
|
|
+ const partnerId = wx.getStorageSync('scan_partnerId');
|
|
|
+ const storeId = wx.getStorageSync('scan_storeId');
|
|
|
+ const scanCount = wx.getStorageSync('scan_scanCount');
|
|
|
+
|
|
|
+ // 清除临时存储
|
|
|
+ wx.removeStorageSync('scan_partnerId');
|
|
|
+ wx.removeStorageSync('scan_storeId');
|
|
|
+ wx.removeStorageSync('scan_scanCount');
|
|
|
+ wx.removeStorageSync('need_scan_redirect');
|
|
|
+
|
|
|
+ if (!partnerId || !storeId) {
|
|
|
+ console.error('❌ 缺少必要参数,无法跳转');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取当前用户的 sessionToken
|
|
|
+ const currentUser = Parse.User.current();
|
|
|
+ const token = currentUser ? currentUser.getSessionToken() : '';
|
|
|
+
|
|
|
+ // 构建 H5 URL
|
|
|
+ const h5Url = `https://pwa.fmode.cn/gomini/pmd/`;
|
|
|
+
|
|
|
+ // 手动构建查询参数(兼容小程序环境)
|
|
|
+ const params = [];
|
|
|
+ params.push(`scanCount=${scanCount || '1'}`);
|
|
|
+ params.push(`storeId=${storeId}`);
|
|
|
+ params.push(`partnerId=${partnerId}`);
|
|
|
+
|
|
|
+ if (token) {
|
|
|
+ params.push(`token=${encodeURIComponent(token)}`);
|
|
|
+ }
|
|
|
+
|
|
|
+ const fullUrl = `${h5Url}?${params.join('&')}`;
|
|
|
+
|
|
|
+ console.log('===========================================');
|
|
|
+ console.log('======= 跳转到扫码统计页面 =======');
|
|
|
+ console.log('完整 URL:', fullUrl);
|
|
|
+ console.log('===========================================');
|
|
|
+
|
|
|
+ // 跳转到 web-view 页面
|
|
|
+ wx.redirectTo({
|
|
|
+ url: `/common-page/pages/web-view/index?path=${encodeURIComponent(fullUrl)}`,
|
|
|
+ fail: (err) => {
|
|
|
+ console.error('❌ 跳转失败:', err);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ console.error('❌ 跳转到扫码页面失败:', error);
|
|
|
+ }
|
|
|
}
|
|
|
});
|