index.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777
  1. const Parse = getApp().Parse;
  2. const company = getApp().globalData.company;
  3. const login = require("../../../utils/login");
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. },
  10. data: {
  11. // 轮播图相关数据
  12. currentSwiperIndex: 0,
  13. },
  14. lifetimes: {
  15. created() {},
  16. attached: function () {
  17. // 页面加载时检查是否首次访问
  18. this.checkFirstVisit();
  19. // 在控制台显示当前登录用户信息
  20. this.showCurrentUser();
  21. },
  22. },
  23. /**
  24. * 组件的方法列表
  25. */
  26. methods: {
  27. /**
  28. * 在控制台显示当前登录用户信息
  29. */
  30. showCurrentUser() {
  31. const currentUser = Parse.User.current();
  32. console.log('===========================================');
  33. console.log('======= 当前登录用户信息 =======');
  34. console.log('===========================================');
  35. if (currentUser) {
  36. console.log('✅ 用户已登录');
  37. console.log('📱 用户ID:', currentUser.id);
  38. console.log('📞 手机号:', currentUser.get('mobile') || '未设置');
  39. console.log('👤 用户名:', currentUser.get('username') || '未设置');
  40. console.log('🔑 Session Token:', currentUser.getSessionToken());
  41. console.log('📧 邮箱:', currentUser.get('email') || '未设置');
  42. console.log('📦 完整用户对象:', currentUser);
  43. console.log('📋 所有属性:', currentUser.attributes);
  44. } else {
  45. console.log('❌ 当前没有登录用户');
  46. }
  47. console.log('===========================================');
  48. },
  49. /**
  50. * 检查是否首次访问
  51. */
  52. checkFirstVisit() {
  53. try {
  54. const hasVisited = wx.getStorageSync('hasVisitedWelcome');
  55. if (!hasVisited) {
  56. console.log('首次访问,显示引导页');
  57. } else {
  58. console.log('已访问过,可选择是否直接跳转');
  59. // 如果需要自动跳转到主页,可以在这里调用 this.navigateToHome()
  60. }
  61. } catch (e) {
  62. console.error('检查访问状态失败:', e);
  63. }
  64. },
  65. /**
  66. * 点击"立即开始探索"按钮
  67. */
  68. onStart() {
  69. console.log('===========================================');
  70. console.log('🚀 调用了 onStart 方法(立即开始探索)');
  71. console.log('===========================================');
  72. // 标记已访问
  73. wx.setStorageSync('hasVisitedWelcome', true);
  74. // 跳转到 H5 主页
  75. this.navigateToHome();
  76. },
  77. /**
  78. * 点击"跳过引导"按钮
  79. */
  80. onSkip() {
  81. // 标记已访问
  82. wx.setStorageSync('hasVisitedWelcome', true);
  83. // 跳转到 H5 主页
  84. this.navigateToHome();
  85. },
  86. /**
  87. * 点击"查看新手指南"
  88. */
  89. onGuide() {
  90. wx.showToast({
  91. title: '新手指南开发中',
  92. icon: 'none',
  93. duration: 2000
  94. });
  95. // TODO: 后续可以跳转到新手指南页面
  96. // wx.navigateTo({
  97. // url: '/pages/guide/index'
  98. // });
  99. },
  100. /**
  101. * 验证 token 是否有效
  102. */
  103. async validateToken(token) {
  104. try {
  105. console.log('🔍 开始验证 token 有效性...');
  106. // 使用 Parse.User.become() 验证 token
  107. const user = await Parse.User.become(token);
  108. if (user) {
  109. console.log('✅ Token 有效!用户:', user.id);
  110. return true;
  111. }
  112. console.log('⚠️ Token 验证返回空用户');
  113. return false;
  114. } catch (error) {
  115. console.error('❌ Token 验证失败:', error.message);
  116. return false;
  117. }
  118. },
  119. /**
  120. * 刷新用户 session token
  121. */
  122. async refreshToken() {
  123. try {
  124. console.log('🔄 开始刷新 token...');
  125. const currentUser = Parse.User.current();
  126. if (!currentUser) {
  127. console.error('❌ 当前没有登录用户,无法刷新 token');
  128. return null;
  129. }
  130. // 保存用户信息以触发 session token 刷新
  131. await currentUser.fetch();
  132. const newToken = currentUser.getSessionToken();
  133. console.log('✅ Token 刷新成功');
  134. console.log('🔑 新 Token (前20字符):', newToken.substring(0, 20));
  135. return newToken;
  136. } catch (error) {
  137. console.error('❌ Token 刷新失败:', error.message);
  138. return null;
  139. }
  140. },
  141. /**
  142. * 获取店铺 ID
  143. */
  144. async getStoreId() {
  145. try {
  146. console.log('🏪 开始获取店铺 ID...');
  147. const defaultStoreId = 'pkPdAnLAUZ'; // 超级门店ID
  148. const configuredStoreId =
  149. wx.getStorageSync('storeId') ||
  150. getApp().globalData.storeId ||
  151. defaultStoreId;
  152. console.log('✅ 使用店铺 ID:', configuredStoreId);
  153. return configuredStoreId;
  154. } catch (error) {
  155. console.error('❌ 获取店铺 ID 失败:', error);
  156. return null;
  157. }
  158. },
  159. /**
  160. * 获取店铺信息(id 与 名称)
  161. */
  162. async getStoreInfo() {
  163. try {
  164. const defaultStoreId = 'pkPdAnLAUZ'; // 超级门店ID
  165. const effectiveStoreId =
  166. wx.getStorageSync('storeId') ||
  167. getApp().globalData.storeId ||
  168. defaultStoreId;
  169. const query = new Parse.Query('ShopStore');
  170. query.equalTo('objectId', effectiveStoreId);
  171. const store = await query.first();
  172. if (store) {
  173. const name = store.get('storeName') || '';
  174. console.log('✅ 获取店铺信息:', { id: effectiveStoreId, name });
  175. return { id: effectiveStoreId, name };
  176. } else {
  177. console.log('⚠️ 未找到店铺,仅返回 ID');
  178. return { id: effectiveStoreId, name: '' };
  179. }
  180. } catch (e) {
  181. console.error('获取店铺信息失败:', e);
  182. return { id: wx.getStorageSync('storeId') || 'pkPdAnLAUZ', name: '' };
  183. }
  184. },
  185. /**
  186. * 跳转到 H5 主页
  187. */
  188. async navigateToHome() {
  189. console.log('===========================================');
  190. console.log('======= navigateToHome 被调用 =======');
  191. console.log('===========================================');
  192. const currentUser = Parse.User.current();
  193. let userInfo = wx.getStorageSync("userLogin");
  194. console.log('当前用户:', currentUser ? '已登录' : '未登录');
  195. console.log('userInfo:', userInfo);
  196. // 如果用户未登录,直接进入游客模式(简化流程)
  197. if (!currentUser || userInfo == '') {
  198. console.log('⚠️ 用户未登录,直接进入游客模式');
  199. // 直接进入游客模式,不显示提示框
  200. this.navigateToHomeAsGuest();
  201. return;
  202. }
  203. let token = currentUser.getSessionToken();
  204. if (!token) {
  205. console.error('❌ 无法获取 Session Token!');
  206. wx.showToast({
  207. title: '获取登录信息失败',
  208. icon: 'none'
  209. });
  210. return;
  211. }
  212. // 验证 token 是否有效
  213. const isValid = await this.validateToken(token);
  214. if (!isValid) {
  215. wx.showLoading({
  216. title: '正在刷新登录...'
  217. });
  218. // 尝试刷新 token
  219. const newToken = await this.refreshToken();
  220. wx.hideLoading();
  221. if (newToken) {
  222. token = newToken;
  223. } else {
  224. console.error('❌ Token 刷新失败,需要重新登录');
  225. wx.showModal({
  226. title: '提示',
  227. content: '登录已过期,请重新登录',
  228. showCancel: false,
  229. success: () => {
  230. wx.navigateTo({
  231. url: 'plugin://fm-plugin/fm-auth'
  232. });
  233. }
  234. });
  235. return;
  236. }
  237. } else {
  238. // token 验证通过
  239. }
  240. // 获取店铺信息
  241. const store = await this.getStoreInfo();
  242. const storeId = store && store.id ? store.id : null;
  243. const storeName = store && store.name ? store.name : '';
  244. // 构建 H5 URL(重要:storeId 和 token 作为查询参数)
  245. let h5Url = `https://app.fmode.cn/dev/pobingfeng/owner/nav/home?`;
  246. // 如果有 storeId,添加到 URL 中
  247. if (storeId) {
  248. h5Url += `storeId=${storeId}&`;
  249. }
  250. h5Url += `token=${token}`;
  251. console.log('🌐 H5 URL:', h5Url);
  252. console.log(' - URL 长度:', h5Url.length);
  253. if (storeId) {
  254. console.log(' - 店铺 ID:', storeId);
  255. }
  256. // 编码后的 URL
  257. const encodedUrl = encodeURIComponent(h5Url);
  258. console.log('📦 编码后的 URL:', encodedUrl.substring(0, 100) + '...');
  259. // 最终的小程序页面路径
  260. // 传递店铺信息给 web-view 页面,优先用于设置标题
  261. let webViewPath = `/common-page/pages/web-view/index?path=${encodedUrl}`;
  262. if (storeId) {
  263. webViewPath += `&storeId=${storeId}`;
  264. }
  265. if (storeName) {
  266. webViewPath += `&storeName=${encodeURIComponent(storeName)}`;
  267. }
  268. console.log('📄 web-view 页面路径:', webViewPath.substring(0, 100) + '...');
  269. console.log('===========================================');
  270. wx.navigateTo({
  271. url: webViewPath,
  272. success: () => {
  273. console.log('✅ 跳转成功');
  274. },
  275. fail: (err) => {
  276. console.error('❌ 跳转失败:', err);
  277. wx.showToast({
  278. title: '跳转失败,请重试',
  279. icon: 'none'
  280. });
  281. }
  282. });
  283. },
  284. /**
  285. * 游客模式跳转到主页
  286. */
  287. async navigateToHomeAsGuest() {
  288. try {
  289. console.log('===========================================');
  290. console.log('======= 游客模式访问 =======');
  291. console.log('===========================================');
  292. // 标记为游客模式
  293. wx.setStorageSync('isGuestMode', true);
  294. // ✅ 游客默认使用超级门店ID,确保有数据
  295. const superStoreId = 'pkPdAnLAUZ'; // 超级门店ID
  296. // 设置超级门店ID到存储
  297. wx.setStorageSync('storeId', superStoreId);
  298. getApp().globalData.storeId = superStoreId;
  299. console.log('✅ 游客使用超级门店ID:', superStoreId);
  300. // 获取店铺信息
  301. const store = await this.getStoreInfo();
  302. const storeId = store && store.id ? store.id : superStoreId;
  303. const storeName = store && store.name ? store.name : '超级门店';
  304. console.log('✅ 店铺信息:', { id: storeId, name: storeName });
  305. // 构建 H5 URL(游客模式,不传 token)
  306. let h5Url = `https://app.fmode.cn/dev/pobingfeng/owner/nav/home?`;
  307. h5Url += `storeId=${storeId}&`;
  308. // 添加游客模式标识
  309. h5Url += `guestMode=true`;
  310. console.log('🌐 游客模式 H5 URL:', h5Url);
  311. console.log('');
  312. console.log('⚠️⚠️⚠️ 重要提示 ⚠️⚠️⚠️');
  313. console.log('如果H5页面显示的不是超级门店,说明H5端没有正确使用URL中的storeId参数!');
  314. console.log('H5端需要确保:');
  315. console.log('1. 从URL中读取 storeId 参数');
  316. console.log('2. 优先使用URL传递的 storeId,不要被其他逻辑覆盖');
  317. console.log('3. 不要使用localStorage缓存的旧门店ID');
  318. console.log('');
  319. console.log('请复制以下URL在浏览器中测试:');
  320. console.log(h5Url);
  321. console.log('===========================================');
  322. // 编码后的 URL
  323. const encodedUrl = encodeURIComponent(h5Url);
  324. // 跳转
  325. let webViewPath = `/common-page/pages/web-view/index?path=${encodedUrl}`;
  326. webViewPath += `&storeId=${storeId}`;
  327. if (storeName) {
  328. webViewPath += `&storeName=${encodeURIComponent(storeName)}`;
  329. }
  330. console.log('📄 web-view 页面路径:', webViewPath.substring(0, 100) + '...');
  331. console.log('===========================================');
  332. wx.navigateTo({
  333. url: webViewPath,
  334. success: () => {
  335. console.log('✅ 游客模式跳转成功');
  336. },
  337. fail: (err) => {
  338. console.error('❌ 跳转失败:', err);
  339. wx.showToast({
  340. title: '跳转失败,请重试',
  341. icon: 'none'
  342. });
  343. }
  344. });
  345. } catch (error) {
  346. console.error('❌ 游客模式跳转失败:', error);
  347. wx.showToast({
  348. title: '加载失败,请重试',
  349. icon: 'none'
  350. });
  351. }
  352. },
  353. /**
  354. * 轮播图变化事件
  355. */
  356. onSwiperChange(e) {
  357. this.setData({
  358. currentSwiperIndex: e.detail.current
  359. });
  360. },
  361. /**
  362. * 跳转到案例展示页面
  363. */
  364. async navigateToCases() {
  365. console.log('===========================================');
  366. console.log('🏠 调用了 navigateToCases 方法(案例展示)');
  367. console.log('===========================================');
  368. // 案例展示允许游客访问,直接跳转
  369. const currentUser = Parse.User.current();
  370. if (!currentUser) {
  371. console.log('游客访问案例展示');
  372. wx.setStorageSync('isGuestMode', true);
  373. await this.navigateToH5PageAsGuest('owner/nav/cases');
  374. } else {
  375. await this.navigateToH5Page('owner/nav/cases');
  376. }
  377. },
  378. /**
  379. * 跳转到产品中心页面
  380. * @param {string} productId - 可选的产品ID,用于直接跳转到特定产品详情
  381. */
  382. async navigateToProducts(productId = null) {
  383. console.log('===========================================');
  384. console.log('📦 调用了 navigateToProducts 方法(产品中心)');
  385. console.log('===========================================');
  386. // 产品中心允许游客访问,直接跳转
  387. const currentUser = Parse.User.current();
  388. const params = productId ? { productId } : {};
  389. if (!currentUser) {
  390. console.log('游客访问产品中心');
  391. wx.setStorageSync('isGuestMode', true);
  392. await this.navigateToH5PageAsGuest('owner/nav/products', params);
  393. } else {
  394. await this.navigateToH5Page('owner/nav/products', params);
  395. }
  396. },
  397. /**
  398. * 跳转到方案定制/AI推荐页面
  399. */
  400. async navigateToConsultation() {
  401. console.log('===========================================');
  402. console.log('======= 点击咨询/方案定制 =======');
  403. console.log('===========================================');
  404. // 方案定制需要登录
  405. const currentUser = Parse.User.current();
  406. const isGuestMode = wx.getStorageSync('isGuestMode');
  407. console.log('当前用户:', currentUser ? '已登录' : '未登录');
  408. console.log('游客模式:', isGuestMode);
  409. if (!currentUser || isGuestMode) {
  410. console.log('⚠️ 游客尝试访问咨询功能,显示登录提示');
  411. wx.showModal({
  412. title: '需要登录',
  413. content: '方案定制和咨询功能需要登录后使用,是否立即登录?',
  414. confirmText: '立即登录',
  415. cancelText: '取消',
  416. success: (res) => {
  417. if (res.confirm) {
  418. console.log('用户选择:立即登录');
  419. login.loginNow();
  420. } else {
  421. console.log('用户选择:取消');
  422. // 用户取消,不做任何操作
  423. }
  424. }
  425. });
  426. // ✅ 重要:直接返回,不继续执行后面的跳转
  427. return;
  428. }
  429. console.log('✅ 用户已登录,跳转到咨询页面');
  430. await this.navigateToH5Page('owner/nav/consultation');
  431. },
  432. /**
  433. * 通用 H5 页面跳转方法
  434. * @param {string} pagePath - H5 页面路径(例如: 'owner/nav/cases')
  435. * @param {object} extraParams - 额外的URL参数对象(例如: { productId: 'xxx' })
  436. */
  437. async navigateToH5Page(pagePath, extraParams = {}) {
  438. console.log('===========================================');
  439. console.log(`======= 小程序跳转 H5: ${pagePath} =======`);
  440. console.log('===========================================');
  441. const currentUser = Parse.User.current();
  442. let userInfo = wx.getStorageSync("userLogin");
  443. // 检查是否是游客模式
  444. const isGuestMode = wx.getStorageSync('isGuestMode');
  445. // 定义允许游客访问的页面
  446. const guestAllowedPages = [
  447. 'owner/nav/home', // 首页
  448. 'owner/nav/products', // 产品中心
  449. 'owner/nav/cases' // 案例展示
  450. ];
  451. // 检查当前页面是否允许游客访问
  452. const isGuestAllowed = guestAllowedPages.some(page => pagePath.includes(page));
  453. if ((!currentUser || userInfo == '') && !isGuestMode) {
  454. // 未登录且不是游客模式,提示用户
  455. wx.showModal({
  456. title: '温馨提示',
  457. content: '登录后可以体验更多功能,是否立即登录?',
  458. confirmText: '立即登录',
  459. cancelText: '先随便看看',
  460. success: (res) => {
  461. if (res.confirm) {
  462. // 用户选择登录
  463. login.loginNow();
  464. } else {
  465. // 用户选择游客模式
  466. if (isGuestAllowed) {
  467. // 如果是允许游客访问的页面,继续访问
  468. wx.setStorageSync('isGuestMode', true);
  469. this.navigateToH5PageAsGuest(pagePath, extraParams);
  470. } else {
  471. // 如果不允许游客访问,提示需要登录
  472. wx.showToast({
  473. title: '此功能需要登录',
  474. icon: 'none'
  475. });
  476. }
  477. }
  478. }
  479. });
  480. return;
  481. }
  482. // 如果是游客模式,检查是否允许访问
  483. if (isGuestMode || !currentUser) {
  484. if (!isGuestAllowed) {
  485. // 游客不允许访问此页面
  486. wx.showModal({
  487. title: '需要登录',
  488. content: '此功能需要登录后使用,是否立即登录?',
  489. confirmText: '立即登录',
  490. cancelText: '取消',
  491. success: (res) => {
  492. if (res.confirm) {
  493. login.loginNow();
  494. }
  495. }
  496. });
  497. return;
  498. }
  499. // 游客访问允许的页面
  500. this.navigateToH5PageAsGuest(pagePath, extraParams);
  501. return;
  502. }
  503. let token = currentUser.getSessionToken();
  504. console.log('🔑 当前 Session Token:', token);
  505. console.log(' - Token 长度:', token ? token.length : 0);
  506. console.log(' - Token 前20个字符:', token ? token.substring(0, 20) : 'null');
  507. if (!token) {
  508. console.error('❌ 无法获取 Session Token!');
  509. wx.showToast({
  510. title: '获取登录信息失败',
  511. icon: 'none'
  512. });
  513. return;
  514. }
  515. // 验证 token 是否有效
  516. console.log('🔍 验证 token 有效性...');
  517. const isValid = await this.validateToken(token);
  518. if (!isValid) {
  519. console.log('⚠️ Token 已失效,尝试刷新...');
  520. wx.showLoading({
  521. title: '正在刷新登录...'
  522. });
  523. // 尝试刷新 token
  524. const newToken = await this.refreshToken();
  525. wx.hideLoading();
  526. if (newToken) {
  527. token = newToken;
  528. console.log('✅ 使用新的 token:', token.substring(0, 20));
  529. } else {
  530. console.error('❌ Token 刷新失败,需要重新登录');
  531. wx.showModal({
  532. title: '提示',
  533. content: '登录已过期,请重新登录',
  534. showCancel: false,
  535. success: () => {
  536. wx.navigateTo({
  537. url: 'plugin://fm-plugin/fm-auth'
  538. });
  539. }
  540. });
  541. return;
  542. }
  543. } else {
  544. console.log('✅ Token 验证通过');
  545. }
  546. // 获取店铺信息
  547. const store = await this.getStoreInfo();
  548. const storeId = store && store.id ? store.id : null;
  549. const storeName = store && store.name ? store.name : '';
  550. // 构建 H5 URL(重要:storeId 和 token 作为查询参数)
  551. let h5Url = `https://app.fmode.cn/dev/pobingfeng/${pagePath}?`;
  552. // 如果有 storeId,添加到 URL 中
  553. if (storeId) {
  554. h5Url += `storeId=${storeId}&`;
  555. }
  556. h5Url += `token=${token}`;
  557. // 添加额外的参数(如 productId)
  558. if (extraParams && Object.keys(extraParams).length > 0) {
  559. for (const [key, value] of Object.entries(extraParams)) {
  560. if (value) {
  561. h5Url += `&${key}=${encodeURIComponent(value)}`;
  562. console.log(` - 添加参数 ${key}:`, value);
  563. }
  564. }
  565. }
  566. // 编码后的 URL
  567. const encodedUrl = encodeURIComponent(h5Url);
  568. // 最终的小程序页面路径
  569. // 传递店铺信息给 web-view 页面,优先用于设置标题
  570. let webViewPath = `/common-page/pages/web-view/index?path=${encodedUrl}`;
  571. if (storeId) {
  572. webViewPath += `&storeId=${storeId}`;
  573. }
  574. if (storeName) {
  575. webViewPath += `&storeName=${encodeURIComponent(storeName)}`;
  576. }
  577. wx.navigateTo({
  578. url: webViewPath,
  579. success: () => {},
  580. fail: (err) => {
  581. console.error('❌ 跳转失败:', err);
  582. wx.showToast({
  583. title: '跳转失败,请重试',
  584. icon: 'none'
  585. });
  586. }
  587. });
  588. },
  589. /**
  590. * 游客模式跳转 H5 页面
  591. * @param {string} pagePath - H5 页面路径
  592. * @param {object} extraParams - 额外参数
  593. */
  594. async navigateToH5PageAsGuest(pagePath, extraParams = {}) {
  595. try {
  596. console.log('===========================================');
  597. console.log(`======= 游客模式跳转 H5: ${pagePath} =======`);
  598. console.log('===========================================');
  599. // ✅ 游客默认使用超级门店ID,确保有数据
  600. const superStoreId = 'pkPdAnLAUZ'; // 超级门店ID
  601. // 确保使用超级门店ID
  602. wx.setStorageSync('storeId', superStoreId);
  603. getApp().globalData.storeId = superStoreId;
  604. console.log('✅ 游客使用超级门店ID:', superStoreId);
  605. // 获取店铺信息
  606. const store = await this.getStoreInfo();
  607. const storeId = store && store.id ? store.id : superStoreId;
  608. const storeName = store && store.name ? store.name : '超级门店';
  609. console.log('✅ 店铺信息:', { id: storeId, name: storeName });
  610. // 构建 H5 URL(游客模式,不传 token)
  611. let h5Url = `https://app.fmode.cn/dev/pobingfeng/${pagePath}?`;
  612. h5Url += `storeId=${storeId}&`;
  613. // 添加游客模式标识
  614. h5Url += `guestMode=true`;
  615. // 添加额外的参数
  616. if (extraParams && Object.keys(extraParams).length > 0) {
  617. for (const [key, value] of Object.entries(extraParams)) {
  618. if (value) {
  619. h5Url += `&${key}=${encodeURIComponent(value)}`;
  620. console.log(` - 添加参数 ${key}:`, value);
  621. }
  622. }
  623. }
  624. console.log('🌐 游客模式 H5 URL:', h5Url);
  625. console.log('');
  626. console.log('⚠️ 如果H5显示的不是超级门店,请检查H5端是否正确读取了URL中的storeId参数');
  627. console.log('');
  628. // 编码后的 URL
  629. const encodedUrl = encodeURIComponent(h5Url);
  630. // 最终的小程序页面路径
  631. let webViewPath = `/common-page/pages/web-view/index?path=${encodedUrl}`;
  632. webViewPath += `&storeId=${storeId}`;
  633. if (storeName) {
  634. webViewPath += `&storeName=${encodeURIComponent(storeName)}`;
  635. }
  636. console.log('📄 web-view 页面路径:', webViewPath.substring(0, 100) + '...');
  637. console.log('===========================================');
  638. wx.navigateTo({
  639. url: webViewPath,
  640. success: () => {
  641. console.log('✅ 游客模式跳转成功');
  642. },
  643. fail: (err) => {
  644. console.error('❌ 跳转失败:', err);
  645. wx.showToast({
  646. title: '跳转失败,请重试',
  647. icon: 'none'
  648. });
  649. }
  650. });
  651. } catch (error) {
  652. console.error('❌ 游客模式跳转失败:', error);
  653. wx.showToast({
  654. title: '加载失败,请重试',
  655. icon: 'none'
  656. });
  657. }
  658. }
  659. }
  660. })