0235699曾露 пре 11 часа
родитељ
комит
7aeec23dc0
2 измењених фајлова са 283 додато и 39 уклоњено
  1. 92 25
      index.js
  2. 191 14
      nova-pbf/components/home/index.js

+ 92 - 25
index.js

@@ -183,15 +183,18 @@ Page({
 
       let currentUser = Parse.User.current()
       console.log(Parse.User.current())
+      
+      // 修改:不强制登录,允许游客访问
       if (!currentUser || force) {
-        // let data = await wxLogin()
-        // if (data.statusCode == 200) {
-         let r = await checkAuth(true)
-         console.log(r);
-        //  getApp().Parse = Parse
-        //  getApp().checkAuth = checkAuth
-         if(!r) return
-        // }
+        // 尝试静默登录(不强制授权)
+        let r = await checkAuth(false)  // 改为 false,不强制授权
+        console.log(r);
+        
+        // 即使登录失败,也允许继续访问
+        if(!r) {
+          console.log('⚠️ 用户未登录或拒绝授权,允许游客访问');
+          // 不要 return,继续执行后面的跳转逻辑
+        }
       } else {
         this.updateUser(currentUser.id)
       }
@@ -213,8 +216,44 @@ Page({
         return;
       }
       
+      console.log('✅ 准备跳转到:', url);
+      
       wx.redirectTo({
-          url: url,
+        url: url,
+        success: () => {
+          console.log('✅ redirectTo 跳转成功');
+        },
+        fail: (err) => {
+          console.error('❌ redirectTo 失败:', err);
+          console.log('⚠️ 尝试使用 reLaunch');
+          
+          // 降级:尝试使用 reLaunch
+          wx.reLaunch({
+            url: url,
+            success: () => {
+              console.log('✅ reLaunch 跳转成功');
+            },
+            fail: (err2) => {
+              console.error('❌ reLaunch 也失败:', err2);
+              // 显示错误提示
+              this.setData({ loading: false });
+              wx.showModal({
+                title: '温馨提示',
+                content: '页面加载失败,请检查网络后重试。',
+                showCancel: true,
+                cancelText: '退出',
+                confirmText: '重试',
+                success: (result) => {
+                  if (result.confirm) {
+                    this.review(true);
+                  } else {
+                    wx.exitMiniProgram();
+                  }
+                }
+              });
+            }
+          });
+        }
       });
     }
     catch (err) {
@@ -228,22 +267,50 @@ Page({
         this.review(true)
         return
       }
-      this.setData({
-        loading:false
-      })
-      wx.showModal({
-        title: '温馨提示',
-        content: '服务器正在升级,请稍后重试。',
-        showCancel: false,
-        cancelText: '取消',
-        cancelColor: '#000000',
-        confirmText: '确定',
-        confirmColor: '#3CC51F',
-        success: (result) => {
-          if (result.confirm) {
-            wx.exitMiniProgram()
-          }
-        },
+      
+      // 如果出错,尝试继续跳转到主页(游客模式)
+      console.log('⚠️ 登录出错,尝试游客模式访问');
+      
+      let url = getApp().globalData.rootPage || getApp().globalData.defaultTabBar.list[0].pagePath;
+      if (this.data.options) {
+        let objArr = Object.keys(this.data.options)
+        if (objArr && objArr.length > 0) {
+          let parms = '?'
+          objArr.forEach((o, index) => {
+            if (index > 0) {
+              parms += '&' + o + '=' + this.data.options[o]
+            } else {
+              parms += o + '=' + this.data.options[o]
+            }
+          })
+          url += parms
+        }
+      }
+      
+      wx.redirectTo({
+        url: url,
+        fail: () => {
+          // 如果跳转失败,显示错误提示
+          this.setData({
+            loading:false
+          })
+          wx.showModal({
+            title: '温馨提示',
+            content: '页面加载失败,请检查网络后重试。',
+            showCancel: true,
+            cancelText: '退出',
+            confirmText: '重试',
+            success: (result) => {
+              if (result.confirm) {
+                // 用户选择重试
+                this.review(true)
+              } else {
+                // 用户选择退出
+                wx.exitMiniProgram()
+              }
+            },
+          });
+        }
       });
     }
   },

+ 191 - 14
nova-pbf/components/home/index.js

@@ -215,13 +215,27 @@ Component({
     async navigateToHome() {
       const currentUser = Parse.User.current();
       let userInfo = wx.getStorageSync("userLogin");
-      if (userInfo == '') {
-        // wx.showToast({
-        //   title: '请先登录',
-        //   icon: 'none'
-        // });
-        login.loginNow()
-        return
+      
+      // 如果用户未登录,显示提示让用户选择
+      if (!currentUser || userInfo == '') {
+        console.log('⚠️ 用户未登录,显示登录提示');
+        
+        wx.showModal({
+          title: '温馨提示',
+          content: '登录后可以体验更多功能,是否立即登录?',
+          confirmText: '立即登录',
+          cancelText: '先随便看看',
+          success: (res) => {
+            if (res.confirm) {
+              // 用户选择登录
+              login.loginNow();
+            } else {
+              // 用户选择稍后登录,跳转到游客模式
+              this.navigateToHomeAsGuest();
+            }
+          }
+        });
+        return;
       }
       
       let token = currentUser.getSessionToken();
@@ -319,6 +333,72 @@ Component({
         }
       });
     },
+    
+    /**
+     * 游客模式跳转到主页
+     */
+    async navigateToHomeAsGuest() {
+      try {
+        console.log('===========================================');
+        console.log('======= 游客模式访问 =======');
+        console.log('===========================================');
+        
+        // 标记为游客模式
+        wx.setStorageSync('isGuestMode', true);
+        
+        // 获取店铺信息
+        const store = await this.getStoreInfo();
+        const storeId = store && store.id ? store.id : null;
+        const storeName = store && store.name ? store.name : '';
+        
+        // 构建 H5 URL(游客模式,不传 token)
+        let h5Url = `https://app.fmode.cn/dev/pobingfeng/owner/nav/home?`;
+        
+        if (storeId) {
+          h5Url += `storeId=${storeId}&`;
+        }
+        
+        // 添加游客模式标识
+        h5Url += `guestMode=true`;
+        
+        console.log('🌐 游客模式 H5 URL:', h5Url);
+        
+        // 编码后的 URL
+        const encodedUrl = encodeURIComponent(h5Url);
+        
+        // 跳转
+        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'
+            });
+          }
+        });
+      } catch (error) {
+        console.error('❌ 游客模式跳转失败:', error);
+        wx.showToast({
+          title: '加载失败,请重试',
+          icon: 'none'
+        });
+      }
+    },
 
     /**
      * 轮播图变化事件
@@ -364,13 +444,35 @@ Component({
       
       const currentUser = Parse.User.current();
       let userInfo = wx.getStorageSync("userLogin");
-      if (userInfo == '') {
-        // wx.showToast({
-        //   title: '请先登录',
-        //   icon: 'none'
-        // });
-        login.loginNow()
-        return
+      
+      // 检查是否是游客模式
+      const isGuestMode = wx.getStorageSync('isGuestMode');
+      
+      if ((!currentUser || userInfo == '') && !isGuestMode) {
+        // 未登录且不是游客模式,提示用户
+        wx.showModal({
+          title: '温馨提示',
+          content: '登录后可以体验更多功能,是否立即登录?',
+          confirmText: '立即登录',
+          cancelText: '先随便看看',
+          success: (res) => {
+            if (res.confirm) {
+              // 用户选择登录
+              login.loginNow();
+            } else {
+              // 用户选择游客模式,继续访问
+              wx.setStorageSync('isGuestMode', true);
+              this.navigateToH5PageAsGuest(pagePath, extraParams);
+            }
+          }
+        });
+        return;
+      }
+      
+      // 如果是游客模式,使用游客访问
+      if (isGuestMode || !currentUser) {
+        this.navigateToH5PageAsGuest(pagePath, extraParams);
+        return;
       }
       
       let token = currentUser.getSessionToken();
@@ -472,6 +574,81 @@ Component({
           });
         }
       });
+    },
+    
+    /**
+     * 游客模式跳转 H5 页面
+     * @param {string} pagePath - H5 页面路径
+     * @param {object} extraParams - 额外参数
+     */
+    async navigateToH5PageAsGuest(pagePath, extraParams = {}) {
+      try {
+        console.log('===========================================');
+        console.log(`======= 游客模式跳转 H5: ${pagePath} =======`);
+        console.log('===========================================');
+        
+        // 获取店铺信息
+        const store = await this.getStoreInfo();
+        const storeId = store && store.id ? store.id : null;
+        const storeName = store && store.name ? store.name : '';
+        
+        // 构建 H5 URL(游客模式,不传 token)
+        let h5Url = `https://app.fmode.cn/dev/pobingfeng/${pagePath}?`;
+        
+        if (storeId) {
+          h5Url += `storeId=${storeId}&`;
+        }
+        
+        // 添加游客模式标识
+        h5Url += `guestMode=true`;
+        
+        // 添加额外的参数
+        if (extraParams && Object.keys(extraParams).length > 0) {
+          for (const [key, value] of Object.entries(extraParams)) {
+            if (value) {
+              h5Url += `&${key}=${encodeURIComponent(value)}`;
+              console.log(`   - 添加参数 ${key}:`, value);
+            }
+          }
+        }
+        
+        console.log('🌐 游客模式 H5 URL:', h5Url);
+        
+        // 编码后的 URL
+        const encodedUrl = encodeURIComponent(h5Url);
+        
+        // 最终的小程序页面路径
+        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'
+            });
+          }
+        });
+      } catch (error) {
+        console.error('❌ 游客模式跳转失败:', error);
+        wx.showToast({
+          title: '加载失败,请重试',
+          icon: 'none'
+        });
+      }
     }
   }
 })