敖欣乐 6 päivää sitten
vanhempi
commit
225cce180f
3 muutettua tiedostoa jossa 209 lisäystä ja 43 poistoa
  1. 185 21
      nova-pbf/components/home/index.js
  2. 15 15
      nova-pbf/components/home/index.wxml
  3. 9 7
      nova-pbf/pages/index/index.js

+ 185 - 21
nova-pbf/components/home/index.js

@@ -168,22 +168,27 @@ Component({
       try {
         console.log('🏪 开始获取店铺 ID...');
         
-        // 查询 ShopStore 表,获取第一个店铺
-        const storeQuery = new Parse.Query('ShopStore');
-        storeQuery.equalTo('company', company);
-        storeQuery.ascending('score');
-        storeQuery.limit(1);
+        // 默认使用固定的店铺 ID
+        const defaultStoreId = 'Zr65KGWXHx';
+        console.log('✅ 使用默认店铺 ID:', defaultStoreId);
+        return defaultStoreId;
         
-        const store = await storeQuery.first();
-        
-        if (store) {
-          const storeId = store.id;
-          console.log('✅ 获取店铺 ID 成功:', storeId);
-          return storeId;
-        } else {
-          console.log('⚠️ 未找到店铺,将不带 storeId 参数');
-          return null;
-        }
+        // 原有的查询逻辑(已注释)
+        // const storeQuery = new Parse.Query('ShopStore');
+        // storeQuery.equalTo('company', company);
+        // storeQuery.ascending('score');
+        // storeQuery.limit(1);
+        // 
+        // const store = await storeQuery.first();
+        // 
+        // if (store) {
+        //   const storeId = store.id;
+        //   console.log('✅ 获取店铺 ID 成功:', storeId);
+        //   return storeId;
+        // } else {
+        //   console.log('⚠️ 未找到店铺,将不带 storeId 参数');
+        //   return null;
+        // }
       } catch (error) {
         console.error('❌ 获取店铺 ID 失败:', error);
         return null;
@@ -195,16 +200,25 @@ Component({
      */
     async getStoreInfo() {
       try {
+        // 默认使用固定的店铺 ID
+        const defaultStoreId = 'Zr65KGWXHx';
+        
+        // 尝试获取该店铺的名称
         const query = new Parse.Query('ShopStore');
-        query.equalTo('company', company);
-        query.ascending('score');
-        query.limit(1);
+        query.equalTo('objectId', defaultStoreId);
         const store = await query.first();
-        if (!store) return null;
-        return { id: store.id, name: store.get('storeName') || '' };
+        
+        if (store) {
+          console.log('✅ 获取到默认店铺信息:', { id: defaultStoreId, name: store.get('storeName') || '' });
+          return { id: defaultStoreId, name: store.get('storeName') || '' };
+        } else {
+          console.log('⚠️ 未找到默认店铺,仅返回 ID');
+          return { id: defaultStoreId, name: '' };
+        }
       } catch (e) {
         console.error('获取店铺信息失败:', e);
-        return null;
+        // 即使出错也返回默认 ID
+        return { id: 'Zr65KGWXHx', name: '' };
       }
     },
 
@@ -342,6 +356,156 @@ Component({
       this.setData({
         currentSwiperIndex: e.detail.current
       });
+    },
+
+    /**
+     * 跳转到案例展示页面
+     */
+    async navigateToCases() {
+      await this.navigateToH5Page('owner/nav/cases');
+    },
+
+    /**
+     * 跳转到产品中心页面
+     */
+    async navigateToProducts() {
+      await this.navigateToH5Page('owner/nav/products');
+    },
+
+    /**
+     * 跳转到方案定制/AI推荐页面
+     */
+    async navigateToConsultation() {
+      await this.navigateToH5Page('owner/nav/consultation');
+    },
+
+    /**
+     * 通用 H5 页面跳转方法
+     * @param {string} pagePath - H5 页面路径(例如: 'owner/nav/cases')
+     */
+    async navigateToH5Page(pagePath) {
+      console.log('===========================================');
+      console.log(`======= 小程序跳转 H5: ${pagePath} =======`);
+      console.log('===========================================');
+      
+      const currentUser = Parse.User.current();
+      console.log('📱 当前用户:', currentUser);
+      const isAuth = login.loginNow()
+      
+      if (!currentUser || !isAuth) {
+        console.error('❌ 当前没有登录用户!');
+        wx.showToast({
+          title: '请先登录',
+          icon: 'none'
+        });
+        // 跳转到登录页
+        wx.navigateTo({
+          url: 'plugin://fm-plugin/fm-auth'
+        });
+        return;
+      }
+      
+      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!');
+        wx.showToast({
+          title: '获取登录信息失败',
+          icon: 'none'
+        });
+        return;
+      }
+      
+      // 验证 token 是否有效
+      console.log('🔍 验证 token 有效性...');
+      const isValid = await this.validateToken(token);
+      
+      if (!isValid) {
+        console.log('⚠️ Token 已失效,尝试刷新...');
+        wx.showLoading({
+          title: '正在刷新登录...'
+        });
+        
+        // 尝试刷新 token
+        const newToken = await this.refreshToken();
+        
+        wx.hideLoading();
+        
+        if (newToken) {
+          token = newToken;
+          console.log('✅ 使用新的 token:', token.substring(0, 20));
+        } else {
+          console.error('❌ Token 刷新失败,需要重新登录');
+          wx.showModal({
+            title: '提示',
+            content: '登录已过期,请重新登录',
+            showCancel: false,
+            success: () => {
+              wx.navigateTo({
+                url: 'plugin://fm-plugin/fm-auth'
+              });
+            }
+          });
+          return;
+        }
+      } else {
+        console.log('✅ Token 验证通过');
+      }
+      
+      // 获取店铺信息
+      const store = await this.getStoreInfo();
+      const storeId = store && store.id ? store.id : null;
+      const storeName = store && store.name ? store.name : '';
+      
+      // 构建 H5 URL(重要:storeId 和 token 作为查询参数)
+      let h5Url = `https://app.fmode.cn/dev/pobingfeng/${pagePath}?`;
+      
+      // 如果有 storeId,添加到 URL 中
+      if (storeId) {
+        h5Url += `storeId=${storeId}&`;
+      }
+      
+      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 页面,优先用于设置标题
+      let webViewPath = `/common-page/pages/web-view/index?path=${encodedUrl}`;
+      if (storeId) {
+        webViewPath += `&storeId=${storeId}`;
+      }
+      if (storeName) {
+        webViewPath += `&storeName=${encodeURIComponent(storeName)}`;
+      }
+      console.log('📄 web-view 页面路径:', webViewPath.substring(0, 100) + '...');
+      console.log('===========================================');
+      
+      wx.navigateTo({
+        url: webViewPath,
+        success: () => {
+          console.log('✅ 跳转成功');
+        },
+        fail: (err) => {
+          console.error('❌ 跳转失败:', err);
+          wx.showToast({
+            title: '跳转失败,请重试',
+            icon: 'none'
+          });
+        }
+      });
     }
   }
 })

+ 15 - 15
nova-pbf/components/home/index.wxml

@@ -76,28 +76,28 @@
   <view class="value-section">
     <view class="value-title">核心功能</view>
     <view class="value-cards">
-      <view class="value-card">
+      <view class="value-card" bindtap="navigateToCases">
         <view class="card-icon">🏠</view>
-        <view class="card-title">案例浏览</view>
-        <view class="card-desc">精选案例</view>
+        <view class="card-title">案例展示</view>
+        <view class="card-desc">海量案例</view>
       </view>
       
-      <view class="value-card">
-        <view class="card-icon">📋</view>
-        <view class="card-title">方案定制</view>
-        <view class="card-desc">专属设计</view>
+      <view class="value-card" bindtap="navigateToProducts">
+        <view class="card-icon">📦</view>
+        <view class="card-title">产品中心</view>
+        <view class="card-desc">精选产品</view>
       </view>
       
-      <view class="value-card">
-        <view class="card-icon">🛠️</view>
-        <view class="card-title">安装预约</view>
-        <view class="card-desc">上门服务</view>
+      <view class="value-card" bindtap="navigateToConsultation">
+        <view class="card-icon">📝</view>
+        <view class="card-title">方案定制</view>
+        <view class="card-desc">专属设计</view>
       </view>
       
-      <view class="value-card">
-        <view class="card-icon">💬</view>
-        <view class="card-title">咨询服务</view>
-        <view class="card-desc">在线客服</view>
+      <view class="value-card" bindtap="navigateToConsultation">
+        <view class="card-icon">🤖</view>
+        <view class="card-title">AI推荐</view>
+        <view class="card-desc">智能匹配</view>
       </view>
     </view>
   </view>

+ 9 - 7
nova-pbf/pages/index/index.js

@@ -85,11 +85,13 @@ Page({
       console.log('======= 引导页:开始设置页面标题 =======');
       console.log('===========================================');
       
-      // 查询 ShopStore 表,获取第一个店铺
+      // 默认使用固定的店铺 ID
+      const defaultStoreId = 'Zr65KGWXHx';
+      console.log('🏪 使用默认店铺 ID:', defaultStoreId);
+      
+      // 查询指定的店铺
       const storeQuery = new Parse.Query('ShopStore');
-      storeQuery.equalTo('company', company);
-      storeQuery.ascending('score');
-      storeQuery.limit(1);
+      storeQuery.equalTo('objectId', defaultStoreId);
       
       console.log('🔍 正在查询 ShopStore 表...');
       const store = await storeQuery.first();
@@ -121,10 +123,10 @@ Page({
           console.log('===========================================');
         }
       } else {
-        console.warn('⚠️ 未找到店铺信息');
+        console.warn('⚠️ 未找到指定店铺信息 (ID:', defaultStoreId, ')');
         console.log('💡 请检查:');
-        console.log('   1. ShopStore 表是否有数据');
-        console.log('   2. company 是否正确:', company);
+        console.log('   1. ShopStore 表中是否存在该店铺');
+        console.log('   2. 店铺 ID 是否正确:', defaultStoreId);
         console.log('===========================================');
       }
     } catch (error) {