|
|
@@ -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'
|
|
|
+ });
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
})
|