2 Комити 12a3f90bc5 ... 85b3bb0aaa

Аутор SHA1 Порука Датум
  敖欣乐 85b3bb0aaa u пре 1 месец
  敖欣乐 d4ec7db607 u пре 1 месец
4 измењених фајлова са 118 додато и 56 уклоњено
  1. 16 3
      common-page/pages/web-view/index.js
  2. 99 0
      index.js
  3. 2 25
      nova-pbf/components/home/index.js
  4. 1 28
      nova-pbf/pages/index/index.js

+ 16 - 3
common-page/pages/web-view/index.js

@@ -126,6 +126,21 @@ Page({
             return;
         }
 
+        // 若与当前标题一致则跳过,避免频繁触发
+        if (title === this.data.currentTitle) {
+            return;
+        }
+
+        // 简单节流:500ms 内重复更新跳过
+        if (!this._lastTitleUpdateTs) {
+            this._lastTitleUpdateTs = 0;
+        }
+        const now = Date.now();
+        if (now - this._lastTitleUpdateTs < 500) {
+            return;
+        }
+        this._lastTitleUpdateTs = now;
+
         // 更新当前标题记录
         this.setData({
             currentTitle: title
@@ -134,9 +149,7 @@ Page({
         // 调用微信 API 设置标题
         wx.setNavigationBarTitle({
             title: title,
-            success: () => {
-                console.log('✅ 标题已更新:', title);
-            },
+            success: () => {},
             fail: (err) => {
                 console.error('❌ 标题设置失败:', err);
             }

+ 99 - 0
index.js

@@ -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);
+    }
   }
 });

+ 2 - 25
nova-pbf/components/home/index.js

@@ -213,12 +213,7 @@ Component({
      * 跳转到 H5 主页
      */
     async navigateToHome() {
-      console.log('===========================================');
-      console.log('======= 小程序跳转 H5 =======');
-      console.log('===========================================');
-      
       const currentUser = Parse.User.current();
-      console.log('📱 当前用户:', currentUser);
       const isAuth = login.loginNow()
       
       if (!currentUser || !isAuth) {
@@ -235,9 +230,6 @@ Component({
       }
       
       let token = currentUser.getSessionToken();
-      console.log('🔑 当前 Session Token:', token);
-      console.log('   - Token 长度:', token ? token.length : 0);
-      console.log('   - Token 前20个字符:', token ? token.substring(0, 20) : 'null');
       
       if (!token) {
         console.error('❌ 无法获取 Session Token!');
@@ -249,11 +241,9 @@ Component({
       }
       
       // 验证 token 是否有效
-      console.log('🔍 验证 token 有效性...');
       const isValid = await this.validateToken(token);
       
       if (!isValid) {
-        console.log('⚠️ Token 已失效,尝试刷新...');
         wx.showLoading({
           title: '正在刷新登录...'
         });
@@ -265,7 +255,6 @@ Component({
         
         if (newToken) {
           token = newToken;
-          console.log('✅ 使用新的 token:', token.substring(0, 20));
         } else {
           console.error('❌ Token 刷新失败,需要重新登录');
           wx.showModal({
@@ -281,7 +270,7 @@ Component({
           return;
         }
       } else {
-        console.log('✅ Token 验证通过');
+        // token 验证通过
       }
       
       // 获取店铺信息
@@ -457,16 +446,8 @@ Component({
       
       h5Url += `token=${token}`;
       
-      console.log('🌐 H5 URL:', h5Url);
-      console.log('   - URL 长度:', h5Url.length);
-      console.log('   - 页面路径:', pagePath);
-      if (storeId) {
-        console.log('   - 店铺 ID:', storeId);
-      }
-      
       // 编码后的 URL
       const encodedUrl = encodeURIComponent(h5Url);
-      console.log('📦 编码后的 URL:', encodedUrl.substring(0, 100) + '...');
       
       // 最终的小程序页面路径
       // 传递店铺信息给 web-view 页面,优先用于设置标题
@@ -477,14 +458,10 @@ Component({
       if (storeName) {
         webViewPath += `&storeName=${encodeURIComponent(storeName)}`;
       }
-      console.log('📄 web-view 页面路径:', webViewPath.substring(0, 100) + '...');
-      console.log('===========================================');
       
       wx.navigateTo({
         url: webViewPath,
-        success: () => {
-          console.log('✅ 跳转成功');
-        },
+        success: () => {},
         fail: (err) => {
           console.error('❌ 跳转失败:', err);
           wx.showToast({

+ 1 - 28
nova-pbf/pages/index/index.js

@@ -111,58 +111,31 @@ Page({
    */
   loadAndSetStoreTitle: async function () {
     try {
-      console.log('===========================================');
-      console.log('======= 引导页:开始设置页面标题 =======');
-      console.log('===========================================');
-      
       // 计算当前有效的店铺 ID
       const defaultStoreId = 'Zr65KGWXHx';
       const effectiveStoreId = wx.getStorageSync('storeId') || getApp().globalData.storeId || defaultStoreId;
-      console.log('🏪 使用店铺 ID:', effectiveStoreId);
       
       // 查询指定的店铺
       const storeQuery = new Parse.Query('ShopStore');
       storeQuery.equalTo('objectId', effectiveStoreId);
-      
-      console.log('🔍 正在查询 ShopStore 表...');
       const store = await storeQuery.first();
       
       if (store) {
         const storeName = store.get('storeName');
-        console.log('🏪 查询到店铺信息:', {
-          storeId: store.id,
-          storeName: storeName
-        });
         
         if (storeName) {
           // ✅ 立即同步设置导航栏标题
-          console.log('🎯 立即设置标题为:', storeName);
           wx.setNavigationBarTitle({
             title: storeName,
-            success: () => {
-              console.log('✅✅✅ 引导页标题设置成功:', storeName);
-              console.log('===========================================');
-            },
+            success: () => {},
             fail: (err) => {
               console.error('❌❌❌ 引导页标题设置失败:', err);
-              console.log('===========================================');
             }
           });
-        } else {
-          console.warn('⚠️ 店铺信息中没有 storeName 字段');
-          console.log('📋 店铺所有字段:', store.attributes);
-          console.log('===========================================');
         }
-      } else {
-        console.warn('⚠️ 未找到指定店铺信息 (ID:', effectiveStoreId, ')');
-        console.log('💡 请检查:');
-        console.log('   1. ShopStore 表中是否存在该店铺');
-        console.log('   2. 店铺 ID 是否正确:', effectiveStoreId);
-        console.log('===========================================');
       }
     } catch (error) {
       console.error('❌ 加载店铺信息失败:', error);
-      console.log('===========================================');
     }
   }
 })