|
@@ -242,33 +242,87 @@ Component({
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取店铺 ID
|
|
* 获取店铺 ID
|
|
|
|
|
+ * 优先级:
|
|
|
|
|
+ * 1. 扫码进入的 storeId(最高优先级)
|
|
|
|
|
+ * 2. 用户历史访问的 storeId
|
|
|
|
|
+ * 3. 超级门店 ID(默认值)
|
|
|
|
|
+ *
|
|
|
|
|
+ * 注意:如果需要切换店铺(非扫码),请先调用:
|
|
|
|
|
+ * wx.removeStorageSync('storeId_from_scan')
|
|
|
*/
|
|
*/
|
|
|
async getStoreId() {
|
|
async getStoreId() {
|
|
|
try {
|
|
try {
|
|
|
console.log('🏪 开始获取店铺 ID...');
|
|
console.log('🏪 开始获取店铺 ID...');
|
|
|
const defaultStoreId = 'pkPdAnLAUZ'; // 超级门店ID
|
|
const defaultStoreId = 'pkPdAnLAUZ'; // 超级门店ID
|
|
|
- const configuredStoreId =
|
|
|
|
|
- wx.getStorageSync('storeId') ||
|
|
|
|
|
- getApp().globalData.storeId ||
|
|
|
|
|
- defaultStoreId;
|
|
|
|
|
- console.log('✅ 使用店铺 ID:', configuredStoreId);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 检查是否是扫码进入
|
|
|
|
|
+ const isFromScan = wx.getStorageSync('storeId_from_scan');
|
|
|
|
|
+ const storedStoreId = wx.getStorageSync('storeId');
|
|
|
|
|
+ const globalStoreId = getApp().globalData.storeId;
|
|
|
|
|
+
|
|
|
|
|
+ let configuredStoreId;
|
|
|
|
|
+
|
|
|
|
|
+ if (isFromScan && storedStoreId) {
|
|
|
|
|
+ // 优先级1:扫码进入的店铺(最高优先级)
|
|
|
|
|
+ configuredStoreId = storedStoreId;
|
|
|
|
|
+ console.log('🎯 使用扫码进入的店铺 ID:', configuredStoreId);
|
|
|
|
|
+ } else if (storedStoreId) {
|
|
|
|
|
+ // 优先级2:用户历史访问的店铺
|
|
|
|
|
+ configuredStoreId = storedStoreId;
|
|
|
|
|
+ console.log('📍 使用历史访问的店铺 ID:', configuredStoreId);
|
|
|
|
|
+ } else if (globalStoreId) {
|
|
|
|
|
+ // 优先级3:全局设置的店铺
|
|
|
|
|
+ configuredStoreId = globalStoreId;
|
|
|
|
|
+ console.log('🌐 使用全局店铺 ID:', configuredStoreId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 优先级4:默认超级门店
|
|
|
|
|
+ configuredStoreId = defaultStoreId;
|
|
|
|
|
+ console.log('⭐ 使用默认超级门店 ID:', configuredStoreId);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ console.log('✅ 最终使用店铺 ID:', configuredStoreId);
|
|
|
return configuredStoreId;
|
|
return configuredStoreId;
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
console.error('❌ 获取店铺 ID 失败:', error);
|
|
console.error('❌ 获取店铺 ID 失败:', error);
|
|
|
- return null;
|
|
|
|
|
|
|
+ return 'pkPdAnLAUZ';
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 获取店铺信息(id 与 名称)
|
|
* 获取店铺信息(id 与 名称)
|
|
|
|
|
+ * 优先级:
|
|
|
|
|
+ * 1. 扫码进入的 storeId(最高优先级)
|
|
|
|
|
+ * 2. 用户历史访问的 storeId
|
|
|
|
|
+ * 3. 超级门店 ID(默认值)
|
|
|
*/
|
|
*/
|
|
|
async getStoreInfo() {
|
|
async getStoreInfo() {
|
|
|
try {
|
|
try {
|
|
|
const defaultStoreId = 'pkPdAnLAUZ'; // 超级门店ID
|
|
const defaultStoreId = 'pkPdAnLAUZ'; // 超级门店ID
|
|
|
- const effectiveStoreId =
|
|
|
|
|
- wx.getStorageSync('storeId') ||
|
|
|
|
|
- getApp().globalData.storeId ||
|
|
|
|
|
- defaultStoreId;
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 检查是否是扫码进入
|
|
|
|
|
+ const isFromScan = wx.getStorageSync('storeId_from_scan');
|
|
|
|
|
+ const storedStoreId = wx.getStorageSync('storeId');
|
|
|
|
|
+ const globalStoreId = getApp().globalData.storeId;
|
|
|
|
|
+
|
|
|
|
|
+ let effectiveStoreId;
|
|
|
|
|
+
|
|
|
|
|
+ if (isFromScan && storedStoreId) {
|
|
|
|
|
+ // 优先级1:扫码进入的店铺(最高优先级)
|
|
|
|
|
+ effectiveStoreId = storedStoreId;
|
|
|
|
|
+ console.log('🎯 使用扫码进入的店铺 ID:', effectiveStoreId);
|
|
|
|
|
+ } else if (storedStoreId) {
|
|
|
|
|
+ // 优先级2:用户历史访问的店铺
|
|
|
|
|
+ effectiveStoreId = storedStoreId;
|
|
|
|
|
+ console.log('📍 使用历史访问的店铺 ID:', effectiveStoreId);
|
|
|
|
|
+ } else if (globalStoreId) {
|
|
|
|
|
+ // 优先级3:全局设置的店铺
|
|
|
|
|
+ effectiveStoreId = globalStoreId;
|
|
|
|
|
+ console.log('🌐 使用全局店铺 ID:', effectiveStoreId);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ // 优先级4:默认超级门店
|
|
|
|
|
+ effectiveStoreId = defaultStoreId;
|
|
|
|
|
+ console.log('⭐ 使用默认超级门店 ID:', effectiveStoreId);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
const query = new Parse.Query('ShopStore');
|
|
const query = new Parse.Query('ShopStore');
|
|
|
query.equalTo('objectId', effectiveStoreId);
|
|
query.equalTo('objectId', effectiveStoreId);
|
|
@@ -284,7 +338,8 @@ Component({
|
|
|
}
|
|
}
|
|
|
} catch (e) {
|
|
} catch (e) {
|
|
|
console.error('获取店铺信息失败:', e);
|
|
console.error('获取店铺信息失败:', e);
|
|
|
- return { id: wx.getStorageSync('storeId') || 'pkPdAnLAUZ', name: '' };
|
|
|
|
|
|
|
+ const fallbackId = wx.getStorageSync('storeId') || 'pkPdAnLAUZ';
|
|
|
|
|
+ return { id: fallbackId, name: '' };
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
@@ -296,17 +351,40 @@ Component({
|
|
|
console.log('======= navigateToHome 被调用 =======');
|
|
console.log('======= navigateToHome 被调用 =======');
|
|
|
console.log('===========================================');
|
|
console.log('===========================================');
|
|
|
|
|
|
|
|
- const currentUser = Parse.User.current();
|
|
|
|
|
|
|
+ let currentUser = Parse.User.current();
|
|
|
let userInfo = wx.getStorageSync("userLogin");
|
|
let userInfo = wx.getStorageSync("userLogin");
|
|
|
|
|
|
|
|
- console.log('当前用户:', currentUser ? '已登录' : '未登录');
|
|
|
|
|
- console.log('userInfo:', userInfo);
|
|
|
|
|
|
|
+ console.log('当前用户:', currentUser ? currentUser.id : '无');
|
|
|
|
|
+ console.log('用户手机号:', currentUser?.get('mobile') || '无');
|
|
|
|
|
+ console.log('userInfo:', userInfo || '无');
|
|
|
|
|
|
|
|
- // 如果用户未登录,直接进入游客模式(简化流程)
|
|
|
|
|
- if (!currentUser || userInfo == '') {
|
|
|
|
|
- console.log('⚠️ 用户未登录,直接进入游客模式');
|
|
|
|
|
|
|
+ // 如果有 Parse 用户但没有 userInfo,可能是刚登录,等待同步
|
|
|
|
|
+ if (currentUser && currentUser.get('mobile') && !userInfo) {
|
|
|
|
|
+ console.log('⏳ 检测到刚登录,等待状态同步...');
|
|
|
|
|
+
|
|
|
|
|
+ // 等待 500ms
|
|
|
|
|
+ await new Promise(resolve => setTimeout(resolve, 500));
|
|
|
|
|
|
|
|
- // 直接进入游客模式,不显示提示框
|
|
|
|
|
|
|
+ // 重新获取
|
|
|
|
|
+ currentUser = Parse.User.current();
|
|
|
|
|
+ userInfo = wx.getStorageSync("userLogin");
|
|
|
|
|
+
|
|
|
|
|
+ // 如果还是没有,手动设置
|
|
|
|
|
+ if (currentUser && currentUser.get('mobile') && !userInfo) {
|
|
|
|
|
+ wx.setStorageSync("userLogin", currentUser.id);
|
|
|
|
|
+ userInfo = currentUser.id;
|
|
|
|
|
+ console.log('✅ 手动设置 userLogin:', userInfo);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 重新检查登录状态
|
|
|
|
|
+ const isLoggedIn = currentUser && currentUser.get('mobile') && userInfo;
|
|
|
|
|
+
|
|
|
|
|
+ console.log('最终登录状态:', isLoggedIn ? '已登录' : '未登录');
|
|
|
|
|
+
|
|
|
|
|
+ // 如果用户未登录,进入游客模式
|
|
|
|
|
+ if (!isLoggedIn) {
|
|
|
|
|
+ console.log('⚠️ 用户未登录,进入游客模式');
|
|
|
this.navigateToHomeAsGuest();
|
|
this.navigateToHomeAsGuest();
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -603,42 +681,20 @@ Component({
|
|
|
if (res.confirm) {
|
|
if (res.confirm) {
|
|
|
console.log('用户选择:立即登录');
|
|
console.log('用户选择:立即登录');
|
|
|
|
|
|
|
|
- // 显示加载提示
|
|
|
|
|
- wx.showLoading({
|
|
|
|
|
- title: '准备登录...',
|
|
|
|
|
- mask: true
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // 不要清除登录状态,因为可能用户刚登录成功只是状态没同步
|
|
|
|
|
+ // 直接跳转到登录页面
|
|
|
|
|
+ console.log('准备调用 login.loginNow()');
|
|
|
|
|
|
|
|
- try {
|
|
|
|
|
- // 强制清除所有登录相关的缓存
|
|
|
|
|
- console.log('🧹 清除旧的登录状态...');
|
|
|
|
|
- await clearLogin.clearAllLoginState();
|
|
|
|
|
-
|
|
|
|
|
- // 等待一下,确保状态清除完成
|
|
|
|
|
- await new Promise(resolve => setTimeout(resolve, 300));
|
|
|
|
|
-
|
|
|
|
|
- wx.hideLoading();
|
|
|
|
|
-
|
|
|
|
|
- console.log('准备调用 login.loginNow()');
|
|
|
|
|
-
|
|
|
|
|
- // 直接调用登录方法
|
|
|
|
|
- const loginResult = login.loginNow();
|
|
|
|
|
- console.log('login.loginNow() 返回值:', loginResult);
|
|
|
|
|
-
|
|
|
|
|
- // 如果返回 false,说明已经跳转到登录页面
|
|
|
|
|
- if (!loginResult) {
|
|
|
|
|
- console.log('✅ 已跳转到登录页面');
|
|
|
|
|
- // 设置待处理的跳转,登录成功后自动跳转到咨询页面
|
|
|
|
|
- wx.setStorageSync('pendingNavigation', 'consultation');
|
|
|
|
|
- console.log('📌 已设置待处理跳转: consultation');
|
|
|
|
|
- }
|
|
|
|
|
- } catch (error) {
|
|
|
|
|
- wx.hideLoading();
|
|
|
|
|
- console.error('❌ 登录准备失败:', error);
|
|
|
|
|
- wx.showToast({
|
|
|
|
|
- title: '登录准备失败,请重试',
|
|
|
|
|
- icon: 'none'
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ // 直接调用登录方法
|
|
|
|
|
+ const loginResult = login.loginNow();
|
|
|
|
|
+ console.log('login.loginNow() 返回值:', loginResult);
|
|
|
|
|
+
|
|
|
|
|
+ // 如果返回 false,说明已经跳转到登录页面
|
|
|
|
|
+ if (!loginResult) {
|
|
|
|
|
+ console.log('✅ 已跳转到登录页面');
|
|
|
|
|
+ // 设置待处理的跳转,登录成功后自动跳转到咨询页面
|
|
|
|
|
+ wx.setStorageSync('pendingNavigation', 'consultation');
|
|
|
|
|
+ console.log('📌 已设置待处理跳转: consultation');
|
|
|
}
|
|
}
|
|
|
} else {
|
|
} else {
|
|
|
console.log('用户选择:取消');
|
|
console.log('用户选择:取消');
|