| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- // 直接进入 H5 首页(对应 H5 路由 /home),用于跳过 H5 的启动页。
- const H5_BASE = 'https://www.yuban.co/home';
- Component({
- properties: {},
- data: {
- loading: false,
- webViewPath: '',
- },
- lifetimes: {
- attached: function () {
- this.preloadCommonSubpackage();
- this.prepareWebViewPath();
- },
- },
- methods: {
- /**
- * 点击「立即体验」按钮
- * 直接跳转到 H5,不依赖 Parse/fm-plugin,让 H5 自行处理鉴权
- */
- onEnter() {
- if (this.data.loading) return;
- this.setData({ loading: true });
- try {
- const webViewPath = this.data.webViewPath || this.buildWebViewPath();
- wx.navigateTo({
- url: webViewPath,
- fail: (err) => {
- console.error('❌ 跳转失败:', err);
- wx.showToast({ title: '跳转失败,请重试', icon: 'none' });
- },
- complete: () => this.setData({ loading: false }),
- });
- } catch (err) {
- console.error('❌ onEnter 异常:', err);
- this.setData({ loading: false });
- wx.showToast({ title: '加载失败,请重试', icon: 'none' });
- }
- },
- preloadCommonSubpackage() {
- if (typeof wx.loadSubpackage !== 'function') return;
- wx.loadSubpackage({
- name: 'common'
- });
- },
- prepareWebViewPath() {
- const webViewPath = this.buildWebViewPath();
- this.setData({ webViewPath });
- },
- buildWebViewPath() {
- let token = null;
- try {
- const app = getApp();
- if (app && app.Parse) {
- const currentUser = app.Parse.User.current();
- token = currentUser ? currentUser.getSessionToken() : null;
- }
- } catch (e) {
- // Parse 不可用时直接游客模式进入 H5
- }
- const h5Url = token ? `${H5_BASE}?token=${token}` : H5_BASE;
- const encodedUrl = encodeURIComponent(h5Url);
- return `/common-page/pages/web-view/index?path=${encodedUrl}&skipAuth=true`;
- }
- }
- })
|