Jelajahi Sumber

:update map

0235699曾露 1 hari lalu
induk
melakukan
bf15d2eb86
3 mengubah file dengan 132 tambahan dan 69 penghapusan
  1. 37 15
      common-page/pages/web-view/index.js
  2. 23 8
      nova-pbf/pages/index/index.js
  3. 72 46
      utils/login.js

+ 37 - 15
common-page/pages/web-view/index.js

@@ -169,14 +169,19 @@ Page({
             currentTitle: title
         });
 
-        // 调用微信 API 设置标题
-        wx.setNavigationBarTitle({
-            title: title,
-            success: () => {},
-            fail: (err) => {
-                console.error('❌ 标题设置失败:', err);
-            }
-        });
+        // 延迟调用微信 API 设置标题,确保页面已准备好
+        setTimeout(() => {
+            wx.setNavigationBarTitle({
+                title: title,
+                success: () => {
+                    console.log('✅ web-view 标题设置成功:', title);
+                },
+                fail: (err) => {
+                    console.warn('⚠️ web-view 标题设置失败(可忽略):', err.errMsg);
+                    // 不影响主流程,静默失败
+                }
+            });
+        }, 100);
     },
 
     startTitlePolling: function () {
@@ -195,29 +200,46 @@ Page({
      */
     loadAndSetStoreTitle: async function (storeId = '', storeName = '') {
         try {
-            let finalName = storeName;
+            let finalTitle = storeName;
 
-            if (!finalName) {
+            if (!finalTitle) {
                 // 如果没有传入名字,按传入的 storeId 精确查询;再不行按 company 兜底
                 if (storeId) {
                     const q = new Parse.Query('ShopStore');
                     const s = await q.get(storeId);
-                    if (s) finalName = s.get('storeName') || '';
+                    if (s) {
+                        // 优先使用门店地址,如果没有地址则使用门店名称
+                        const address = s.get('address');
+                        const name = s.get('storeName');
+                        finalTitle = address || name || '';
+                        
+                        console.log('📍 web-view 门店信息:', {
+                            id: storeId,
+                            name: name,
+                            address: address,
+                            displayTitle: finalTitle
+                        });
+                    }
                 }
-                if (!finalName) {
+                if (!finalTitle) {
                     const storeQuery = new Parse.Query('ShopStore');
                     storeQuery.equalTo('company', company);
                     storeQuery.ascending('score');
                     storeQuery.limit(1);
                     const store = await storeQuery.first();
-                    if (store) finalName = store.get('storeName') || '';
+                    if (store) {
+                        // 优先使用门店地址,如果没有地址则使用门店名称
+                        const address = store.get('address');
+                        const name = store.get('storeName');
+                        finalTitle = address || name || '';
+                    }
                 }
             }
 
-            if (!finalName) return;
+            if (!finalTitle) return;
 
             // 使用统一的设置标题方法
-            this.setNavigationTitle(finalName);
+            this.setNavigationTitle(finalTitle);
         } catch (e) {
             console.error('设置 web-view 标题失败:', e);
         }

+ 23 - 8
nova-pbf/pages/index/index.js

@@ -121,17 +121,32 @@ Page({
       const store = await storeQuery.first();
       
       if (store) {
+        // 优先使用门店地址,如果没有地址则使用门店名称
+        const storeAddress = store.get('address');
         const storeName = store.get('storeName');
+        const title = storeAddress || storeName;
         
-        if (storeName) {
-          // ✅ 立即同步设置导航栏标题
-          wx.setNavigationBarTitle({
-            title: storeName,
-            success: () => {},
-            fail: (err) => {
-              console.error('❌❌❌ 引导页标题设置失败:', err);
-            }
+        if (title) {
+          console.log('📍 门店信息:', {
+            id: effectiveStoreId,
+            name: storeName,
+            address: storeAddress,
+            displayTitle: title
           });
+          
+          // 延迟设置标题,确保页面已完全加载
+          setTimeout(() => {
+            wx.setNavigationBarTitle({
+              title: title,
+              success: () => {
+                console.log('✅ 引导页标题设置成功:', title);
+              },
+              fail: (err) => {
+                console.warn('⚠️ 引导页标题设置失败(可忽略):', err.errMsg);
+                // 不影响主流程,静默失败
+              }
+            });
+          }, 300);
         }
       }
     } catch (error) {

+ 72 - 46
utils/login.js

@@ -29,57 +29,83 @@ function loginNow(authPage = 'plugin://fm-plugin/fm-auth') {
   }
   
   // 跳转到授权页面
-  console.log('🔄 跳转到授权页面');
+  console.log('🔄 准备跳转到授权页面:', authPage);
   
   // 检查页面栈
   const pages = getCurrentPages();
   console.log('当前页面栈层数:', pages.length);
+  console.log('当前页面路径:', pages[pages.length - 1]?.route);
   
-  if (pages.length >= 10) {
-    // 页面栈已满,使用 redirectTo
-    console.log('⚠️ 页面栈已满,使用 redirectTo');
-    wx.redirectTo({
-      url: authPage,
-      success: () => {
-        console.log('✅ redirectTo 跳转成功');
-      },
-      fail: (err) => {
-        console.error('❌ redirectTo 失败:', err);
-        wx.showToast({
-          title: '跳转失败,请重试',
-          icon: 'none'
-        });
-      }
-    });
-  } else {
-    // 使用 navigateTo
-    console.log('📱 使用 navigateTo 跳转');
-    wx.navigateTo({
-      url: authPage,
-      success: () => {
-        console.log('✅ navigateTo 跳转成功');
-      },
-      fail: (err) => {
-        console.error('❌ navigateTo 失败:', err);
-        console.log('⚠️ 尝试使用 redirectTo');
-        
-        // 降级使用 redirectTo
-        wx.redirectTo({
-          url: authPage,
-          success: () => {
-            console.log('✅ redirectTo 跳转成功');
-          },
-          fail: (err2) => {
-            console.error('❌ redirectTo 也失败:', err2);
-            wx.showToast({
-              title: '跳转失败,请重试',
-              icon: 'none'
-            });
-          }
-        });
-      }
-    });
-  }
+  // 添加短暂延迟,确保 UI 渲染完成
+  setTimeout(() => {
+    if (pages.length >= 9) {
+      // 页面栈接近满,使用 redirectTo
+      console.log('⚠️ 页面栈接近满,使用 redirectTo');
+      wx.redirectTo({
+        url: authPage,
+        success: () => {
+          console.log('✅ redirectTo 跳转成功');
+        },
+        fail: (err) => {
+          console.error('❌ redirectTo 失败:', err);
+          console.error('错误详情:', JSON.stringify(err));
+          wx.showToast({
+            title: '跳转失败,请重试',
+            icon: 'none',
+            duration: 2000
+          });
+        }
+      });
+    } else {
+      // 使用 navigateTo
+      console.log('📱 使用 navigateTo 跳转');
+      wx.navigateTo({
+        url: authPage,
+        success: () => {
+          console.log('✅ navigateTo 跳转成功');
+        },
+        fail: (err) => {
+          console.error('❌ navigateTo 失败:', err);
+          console.error('错误详情:', JSON.stringify(err));
+          console.log('⚠️ 尝试使用 redirectTo');
+          
+          // 降级使用 redirectTo
+          wx.redirectTo({
+            url: authPage,
+            success: () => {
+              console.log('✅ redirectTo 跳转成功');
+            },
+            fail: (err2) => {
+              console.error('❌ redirectTo 也失败:', err2);
+              console.error('错误详情:', JSON.stringify(err2));
+              
+              // 最后尝试使用 reLaunch
+              console.log('⚠️ 尝试使用 reLaunch');
+              wx.reLaunch({
+                url: '/index',
+                success: () => {
+                  console.log('✅ reLaunch 到首页成功,请重新点击登录');
+                  wx.showToast({
+                    title: '请重新点击登录',
+                    icon: 'none',
+                    duration: 2000
+                  });
+                },
+                fail: (err3) => {
+                  console.error('❌ reLaunch 也失败:', err3);
+                  wx.showToast({
+                    title: '跳转失败,请重启小程序',
+                    icon: 'none',
+                    duration: 3000
+                  });
+                }
+              });
+            }
+          });
+        }
+      });
+    }
+  }, 100);
   
   console.log('===========================================');
   return false;