index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const { buildConversationWebViewPath } = require('../../../utils/web-view-target');
  2. Component({
  3. properties: {},
  4. data: {
  5. loading: false,
  6. webViewPath: '',
  7. slides: [1, 2, 3, 5],
  8. activeSlide: 0,
  9. },
  10. lifetimes: {
  11. attached: function () {
  12. this.preloadCommonSubpackage();
  13. this.prepareWebViewPath();
  14. },
  15. },
  16. methods: {
  17. /**
  18. * 点击「立即体验」按钮
  19. * 直接跳转到 H5,不依赖 Parse/fm-plugin,让 H5 自行处理鉴权
  20. */
  21. onEnter() {
  22. if (this.data.loading) return;
  23. this.setData({ loading: true });
  24. try {
  25. const webViewPath = this.data.webViewPath || this.buildWebViewPath();
  26. wx.navigateTo({
  27. url: webViewPath,
  28. fail: (err) => {
  29. console.error('❌ 跳转失败:', err);
  30. wx.showToast({ title: '跳转失败,请重试', icon: 'none' });
  31. },
  32. complete: () => this.setData({ loading: false }),
  33. });
  34. } catch (err) {
  35. console.error('❌ onEnter 异常:', err);
  36. this.setData({ loading: false });
  37. wx.showToast({ title: '加载失败,请重试', icon: 'none' });
  38. }
  39. },
  40. onOpenServiceDesk() {
  41. wx.navigateTo({ url: '/yuban/pages/service-desk/index' });
  42. },
  43. onSwiperChange(e) {
  44. const current = Number(e?.detail?.current ?? 0);
  45. this.setData({ activeSlide: current });
  46. },
  47. preloadCommonSubpackage() {
  48. if (typeof wx.loadSubpackage !== 'function') return;
  49. wx.loadSubpackage({
  50. name: 'common'
  51. });
  52. },
  53. prepareWebViewPath() {
  54. const webViewPath = this.buildWebViewPath();
  55. this.setData({ webViewPath });
  56. },
  57. buildWebViewPath() {
  58. // H5 maintains its own SMS session. Native account data stays in the mini program.
  59. return buildConversationWebViewPath();
  60. },
  61. }
  62. })