|
|
@@ -113,53 +113,6 @@ Component({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
- /**
|
|
|
- * 检查 Company 的 isPublishing 状态
|
|
|
- * 只有 isPublishing == true 时才显示 AI 相关内容
|
|
|
- */
|
|
|
- async checkPublishingStatus() {
|
|
|
- try {
|
|
|
- // 先尝试从全局或缓存读取
|
|
|
- let isPublishing = getApp().globalData.isPublishing;
|
|
|
-
|
|
|
- if (isPublishing === undefined) {
|
|
|
- isPublishing = wx.getStorageSync('isPublishing');
|
|
|
- }
|
|
|
-
|
|
|
- // 如果缓存中没有,查询数据库
|
|
|
- if (isPublishing === undefined || isPublishing === '') {
|
|
|
- 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;
|
|
|
- } else {
|
|
|
- isPublishing = false;
|
|
|
- }
|
|
|
-
|
|
|
- // 保存到全局和缓存
|
|
|
- getApp().globalData.isPublishing = isPublishing;
|
|
|
- wx.setStorageSync('isPublishing', isPublishing);
|
|
|
- }
|
|
|
-
|
|
|
- console.log('📋 isPublishing 状态:', isPublishing);
|
|
|
- console.log('🤖 是否显示 AI:', isPublishing);
|
|
|
-
|
|
|
- // 更新组件数据
|
|
|
- this.setData({
|
|
|
- showAI: isPublishing === true
|
|
|
- });
|
|
|
- } catch (error) {
|
|
|
- console.error('❌ 检查 isPublishing 状态失败:', error);
|
|
|
- // 出错时默认不显示 AI
|
|
|
- this.setData({
|
|
|
- showAI: false
|
|
|
- });
|
|
|
- }
|
|
|
- },
|
|
|
-
|
|
|
/**
|
|
|
* 在控制台显示当前登录用户信息
|
|
|
*/
|
|
|
@@ -203,6 +156,58 @@ Component({
|
|
|
}
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * 检查登录状态(强制登录模式)
|
|
|
+ * 当 isPublishing != true 时,必须登录才能访问
|
|
|
+ * @returns {Promise<boolean>} 是否已登录或允许访问
|
|
|
+ */
|
|
|
+ async checkLoginRequired() {
|
|
|
+ // 获取 isPublishing 状态
|
|
|
+ const isPublishing = wx.getStorageSync('isPublishing');
|
|
|
+
|
|
|
+ console.log('🔐 检查登录要求...');
|
|
|
+ console.log(' isPublishing:', isPublishing);
|
|
|
+
|
|
|
+ // 如果 isPublishing == true,不需要强制登录,允许游客访问
|
|
|
+ if (isPublishing === true) {
|
|
|
+ console.log('✅ isPublishing == true,允许游客访问');
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('⚠️ isPublishing != true,需要强制登录');
|
|
|
+
|
|
|
+ // 检查用户是否已登录
|
|
|
+ const currentUser = Parse.User.current();
|
|
|
+ const userLogin = wx.getStorageSync('userLogin');
|
|
|
+ const isLoggedIn = currentUser && currentUser.get('mobile') && userLogin;
|
|
|
+
|
|
|
+ console.log(' 当前用户:', currentUser ? currentUser.id : '无');
|
|
|
+ console.log(' 手机号:', currentUser?.get('mobile') || '无');
|
|
|
+ console.log(' userLogin:', userLogin || '无');
|
|
|
+ console.log(' 登录状态:', isLoggedIn ? '已登录' : '未登录');
|
|
|
+
|
|
|
+ if (!isLoggedIn) {
|
|
|
+ console.log('❌ 用户未登录,显示登录提示');
|
|
|
+
|
|
|
+ wx.showModal({
|
|
|
+ title: '需要登录',
|
|
|
+ content: '请先登录后再使用此功能',
|
|
|
+ showCancel: false,
|
|
|
+ confirmText: '立即登录',
|
|
|
+ success: () => {
|
|
|
+ // 跳转到登录页面
|
|
|
+ console.log('🔄 跳转到登录页面');
|
|
|
+ login.loginNow();
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('✅ 用户已登录,允许访问');
|
|
|
+ return true;
|
|
|
+ },
|
|
|
+
|
|
|
/**
|
|
|
* 检查 Company 的 isPublishing 状态
|
|
|
* 用于控制是否显示 AI 相关内容
|
|
|
@@ -215,22 +220,38 @@ Component({
|
|
|
let isPublishing = wx.getStorageSync('isPublishing');
|
|
|
|
|
|
if (isPublishing === '' || isPublishing === null || isPublishing === undefined) {
|
|
|
- // 缓存中没有,查询 Company 表
|
|
|
- const companyQuery = new Parse.Query('Company');
|
|
|
- companyQuery.equalTo('objectId', getApp().globalData.company);
|
|
|
- companyQuery.select('isPublishing');
|
|
|
- const companyObj = await companyQuery.first();
|
|
|
+ console.log('📦 缓存中没有 isPublishing,尝试查询数据库...');
|
|
|
|
|
|
- if (companyObj) {
|
|
|
- isPublishing = companyObj.get('isPublishing') === true;
|
|
|
- console.log('📋 从数据库查询 isPublishing:', isPublishing);
|
|
|
+ try {
|
|
|
+ // 缓存中没有,查询 Company 表(使用 master key,不需要登录)
|
|
|
+ const companyQuery = new Parse.Query('Company');
|
|
|
+ companyQuery.equalTo('objectId', getApp().globalData.company);
|
|
|
+ companyQuery.select('isPublishing');
|
|
|
|
|
|
- // 保存到缓存
|
|
|
- wx.setStorageSync('isPublishing', isPublishing);
|
|
|
- getApp().globalData.isPublishing = isPublishing;
|
|
|
- } else {
|
|
|
- console.warn('⚠️ 未找到 Company 记录');
|
|
|
+ // 使用 find 而不是 first,避免 session token 问题
|
|
|
+ const results = await companyQuery.find();
|
|
|
+
|
|
|
+ if (results && results.length > 0) {
|
|
|
+ const companyObj = results[0];
|
|
|
+ isPublishing = companyObj.get('isPublishing') === true;
|
|
|
+ console.log('📋 从数据库查询 isPublishing:', isPublishing);
|
|
|
+
|
|
|
+ // 保存到缓存
|
|
|
+ wx.setStorageSync('isPublishing', isPublishing);
|
|
|
+ getApp().globalData.isPublishing = isPublishing;
|
|
|
+ } else {
|
|
|
+ console.warn('⚠️ 未找到 Company 记录,默认为 false');
|
|
|
+ isPublishing = false;
|
|
|
+ // 也保存到缓存,避免重复查询
|
|
|
+ wx.setStorageSync('isPublishing', false);
|
|
|
+ getApp().globalData.isPublishing = false;
|
|
|
+ }
|
|
|
+ } catch (queryError) {
|
|
|
+ console.error('❌ 查询 Company 失败:', queryError);
|
|
|
+ // 查询失败时,默认为 false(需要登录)
|
|
|
isPublishing = false;
|
|
|
+ wx.setStorageSync('isPublishing', false);
|
|
|
+ getApp().globalData.isPublishing = false;
|
|
|
}
|
|
|
} else {
|
|
|
console.log('📦 从缓存读取 isPublishing:', isPublishing);
|
|
|
@@ -247,21 +268,31 @@ Component({
|
|
|
console.log('===========================================');
|
|
|
} catch (error) {
|
|
|
console.error('❌ 检查 isPublishing 状态失败:', error);
|
|
|
- // 出错时默认不显示 AI
|
|
|
+ // 出错时默认不显示 AI(需要登录)
|
|
|
this.setData({
|
|
|
showAI: false
|
|
|
});
|
|
|
+ wx.setStorageSync('isPublishing', false);
|
|
|
}
|
|
|
},
|
|
|
|
|
|
/**
|
|
|
* 点击"立即开始探索"按钮
|
|
|
*/
|
|
|
- onStart() {
|
|
|
+ async onStart() {
|
|
|
console.log('===========================================');
|
|
|
console.log('🚀 调用了 onStart 方法(立即开始探索)');
|
|
|
console.log('===========================================');
|
|
|
|
|
|
+ // 检查 isPublishing 状态,如果不是 true,需要强制登录
|
|
|
+ const isPublishing = this.data.showAI; // showAI 就是 isPublishing 的状态
|
|
|
+
|
|
|
+ // 检查是否需要强制登录
|
|
|
+ const canAccess = await this.checkLoginRequired();
|
|
|
+ if (!canAccess) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// 标记已访问
|
|
|
wx.setStorageSync('hasVisitedWelcome', true);
|
|
|
|
|
|
@@ -272,7 +303,13 @@ Component({
|
|
|
/**
|
|
|
* 点击"跳过引导"按钮
|
|
|
*/
|
|
|
- onSkip() {
|
|
|
+ async onSkip() {
|
|
|
+ // 检查是否需要强制登录
|
|
|
+ const canAccess = await this.checkLoginRequired();
|
|
|
+ if (!canAccess) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// 标记已访问
|
|
|
wx.setStorageSync('hasVisitedWelcome', true);
|
|
|
|
|
|
@@ -692,7 +729,16 @@ Component({
|
|
|
console.log('🏠 调用了 navigateToCases 方法(案例展示)');
|
|
|
console.log('===========================================');
|
|
|
|
|
|
- // 案例展示允许游客访问,直接跳转
|
|
|
+ // 检查 isPublishing 状态,如果不是 true,需要强制登录
|
|
|
+ const isPublishing = this.data.showAI;
|
|
|
+
|
|
|
+ // 检查是否需要强制登录
|
|
|
+ const canAccess = await this.checkLoginRequired();
|
|
|
+ if (!canAccess) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 案例展示允许游客访问(当 isPublishing == true 时)
|
|
|
const currentUser = Parse.User.current();
|
|
|
|
|
|
if (!currentUser) {
|
|
|
@@ -703,7 +749,7 @@ Component({
|
|
|
await this.navigateToH5Page('owner/nav/cases');
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 跳转到产品中心页面
|
|
|
* @param {string} productId - 可选的产品ID,用于直接跳转到特定产品详情
|
|
|
@@ -713,7 +759,13 @@ Component({
|
|
|
console.log('📦 调用了 navigateToProducts 方法(产品中心)');
|
|
|
console.log('===========================================');
|
|
|
|
|
|
- // 产品中心允许游客访问,直接跳转
|
|
|
+ // 检查是否需要强制登录
|
|
|
+ const canAccess = await this.checkLoginRequired();
|
|
|
+ if (!canAccess) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 产品中心允许游客访问(当 isPublishing == true 时)
|
|
|
const currentUser = Parse.User.current();
|
|
|
const params = productId ? { productId } : {};
|
|
|
|
|
|
@@ -734,6 +786,15 @@ Component({
|
|
|
console.log('======= 点击咨询/方案定制 =======');
|
|
|
console.log('===========================================');
|
|
|
|
|
|
+ // 检查 isPublishing 状态,如果不是 true,需要强制登录
|
|
|
+ const isPublishing = this.data.showAI;
|
|
|
+
|
|
|
+ // 检查是否需要强制登录
|
|
|
+ const canAccess = await this.checkLoginRequired();
|
|
|
+ if (!canAccess) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
// 方案定制需要登录
|
|
|
let currentUser = Parse.User.current();
|
|
|
const isGuestMode = wx.getStorageSync('isGuestMode');
|
|
|
@@ -1012,6 +1073,49 @@ Component({
|
|
|
});
|
|
|
},
|
|
|
|
|
|
+ /**
|
|
|
+ * 检查登录状态
|
|
|
+ * @returns {boolean} 是否已登录
|
|
|
+ */
|
|
|
+ async checkLoginStatus() {
|
|
|
+ let currentUser = Parse.User.current();
|
|
|
+ let userLogin = wx.getStorageSync('userLogin');
|
|
|
+
|
|
|
+ // 如果有 Parse 用户但没有 userLogin,等待同步
|
|
|
+ if (currentUser && currentUser.get('mobile') && !userLogin) {
|
|
|
+ console.log('⏳ 等待登录状态同步...');
|
|
|
+ await new Promise(resolve => setTimeout(resolve, 500));
|
|
|
+
|
|
|
+ currentUser = Parse.User.current();
|
|
|
+ userLogin = wx.getStorageSync('userLogin');
|
|
|
+
|
|
|
+ if (currentUser && currentUser.get('mobile') && !userLogin) {
|
|
|
+ wx.setStorageSync("userLogin", currentUser.id);
|
|
|
+ userLogin = currentUser.id;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return currentUser && currentUser.get('mobile') && userLogin;
|
|
|
+ },
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 显示需要登录的提示
|
|
|
+ */
|
|
|
+ showLoginRequired() {
|
|
|
+ wx.showModal({
|
|
|
+ title: '需要登录',
|
|
|
+ content: '此功能需要登录后使用,请先完成登录',
|
|
|
+ confirmText: '立即登录',
|
|
|
+ cancelText: '取消',
|
|
|
+ success: (res) => {
|
|
|
+ if (res.confirm) {
|
|
|
+ console.log('用户选择:立即登录');
|
|
|
+ login.loginNow();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+
|
|
|
/**
|
|
|
* 游客模式跳转 H5 页面
|
|
|
* @param {string} pagePath - H5 页面路径
|