|
|
@@ -194,12 +194,37 @@ Page({
|
|
|
console.log('force 参数:', force);
|
|
|
console.log('===========================================');
|
|
|
|
|
|
- // 修改:不强制登录,允许游客访问
|
|
|
+ // 查询 Company 的 isPublishing 字段
|
|
|
+ let isPublishing = false;
|
|
|
+ try {
|
|
|
+ const companyQuery = new Parse.Query('Company');
|
|
|
+ companyQuery.equalTo('objectId', getApp().globalData.company);
|
|
|
+ companyQuery.select('isPublishing');
|
|
|
+ const companyObj = await companyQuery.first();
|
|
|
+
|
|
|
+ if (companyObj) {
|
|
|
+ isPublishing = companyObj.get('isPublishing') === true;
|
|
|
+ console.log('📋 Company isPublishing:', isPublishing);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 保存到全局,供其他页面使用
|
|
|
+ getApp().globalData.isPublishing = isPublishing;
|
|
|
+ wx.setStorageSync('isPublishing', isPublishing);
|
|
|
+ } catch (error) {
|
|
|
+ console.error('❌ 查询 Company isPublishing 失败:', error);
|
|
|
+ // 查询失败时,默认为 false(强制登录)
|
|
|
+ isPublishing = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 根据 isPublishing 决定是否强制登录
|
|
|
if (!currentUser || force) {
|
|
|
console.log('🔄 开始调用 checkAuth...');
|
|
|
|
|
|
- // 尝试静默登录(不强制授权)
|
|
|
- let r = await checkAuth(false) // 改为 false,不强制授权
|
|
|
+ // isPublishing == true 时不强制授权,否则强制授权
|
|
|
+ const forceAuth = !isPublishing;
|
|
|
+ console.log('🔐 是否强制登录:', forceAuth);
|
|
|
+
|
|
|
+ let r = await checkAuth(forceAuth);
|
|
|
|
|
|
console.log('===========================================');
|
|
|
console.log('======= checkAuth 返回结果 =======');
|
|
|
@@ -212,7 +237,64 @@ Page({
|
|
|
console.log('checkAuth 后的 Session Token:', currentUser?.getSessionToken()?.substring(0, 20) || '无');
|
|
|
console.log('===========================================');
|
|
|
|
|
|
- // 即使登录失败,也允许继续访问
|
|
|
+ // 如果强制登录但用户未登录,不允许继续访问
|
|
|
+ if (forceAuth && !r) {
|
|
|
+ console.log('❌ 强制登录模式,用户未登录,停止访问');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 即使登录失败,也允许继续访问(仅在非强制登录模式下)
|
|
|
+ if(!r) {
|
|
|
+ console.log('⚠️ 用户未登录或拒绝授权,允许游客访问');
|
|
|
+ // 不要 return,继续执行后面的跳转逻辑
|
|
|
+ } else {
|
|
|
+ // 登录成功,设置 userLogin
|
|
|
+ if (currentUser && currentUser.get('mobile')) {
|
|
|
+ wx.setStorageSync("userLogin", currentUser.id);
|
|
|
+ console.log('✅ 授权登录成功,已设置 userLogin:', currentUser.id);
|
|
|
+ console.log('✅ 用户手机号:', currentUser.get('mobile'));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查是否有待记录的扫码信息
|
|
|
+ await this.checkAndRecordPendingScan();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 用户已登录,确保 userLogin 已设置
|
|
|
+ if (currentUser.get('mobile')) {
|
|
|
+ wx.setStorageSync("userLogin", currentUser.id);
|
|
|
+ }
|
|
|
+ this.updateUser(currentUser.id)
|
|
|
+ // 用户已登录,检查是否有待记录的扫码信息
|
|
|
+ await this.checkAndRecordPendingScan();
|
|
|
+ }
|
|
|
+ // 游客模式(isPublishing == true)
|
|
|
+ if (!currentUser || force) {
|
|
|
+ console.log('🔄 游客模式,开始调用 checkAuth(false)...');
|
|
|
+
|
|
|
+ // 尝试静默登录(不强制授权)
|
|
|
+ let r = await checkAuth(false); // 不强制授权
|
|
|
+
|
|
|
+ console.log('===========================================');
|
|
|
+ console.log('======= checkAuth 返回结果 =======');
|
|
|
+ console.log('返回值:', r);
|
|
|
+
|
|
|
+ // 重新获取用户信息
|
|
|
+ currentUser = Parse.User.current();
|
|
|
+ console.log('checkAuth 后的用户:', currentUser ? currentUser.id : '无');
|
|
|
+ console.log('checkAuth 后的手机号:', currentUser?.get('mobile') || '无');
|
|
|
+ console.log('checkAuth 后的 Session Token:', currentUser?.getSessionToken()?.substring(0, 20) || '无');
|
|
|
+ console.log('===========================================');
|
|
|
+
|
|
|
+ // 即使登录失败,也允许继续访问
|
|
|
+ if(!r) {
|
|
|
+ console.log('⚠️ 用户未登录或拒绝授权,允许游客访问');
|
|
|
+ // 不要 return,继续执行后面的跳转逻辑
|
|
|
+ } else {
|
|
|
+ // 登录成功,设置 userLogin❌ 强制登录模式,用户未登录,停止访问');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 即使登录失败,也允许继续访问(仅在非强制登录模式下)
|
|
|
if(!r) {
|
|
|
console.log('⚠️ 用户未登录或拒绝授权,允许游客访问');
|
|
|
// 不要 return,继续执行后面的跳转逻辑
|