| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- // 直接进入 H5 首页(对应 H5 路由 /home),用于跳过 H5 的启动页。
- const H5_BASE = 'https://www.yuban.co/home';
- Component({
- properties: {},
- data: {
- loading: false,
- },
- lifetimes: {
- attached: function () {
- console.log('✅ 语伴首页加载完成');
- },
- },
- methods: {
- /**
- * 点击「立即体验」按钮
- * 直接跳转到 H5,不依赖 Parse/fm-plugin,让 H5 自行处理鉴权
- */
- onEnter() {
- if (this.data.loading) return;
- this.setData({ loading: true });
- try {
- // 尝试从 Parse 获取 token(插件未授权时会是 null,不影响跳转)
- let token = null;
- try {
- const app = getApp();
- if (app && app.Parse) {
- const currentUser = app.Parse.User.current();
- token = currentUser ? currentUser.getSessionToken() : null;
- }
- } catch (e) {
- console.warn('⚠️ Parse 不可用,以游客模式跳转 H5');
- }
- let h5Url = H5_BASE;
- if (token) {
- h5Url += `?token=${token}`;
- }
- const encodedUrl = encodeURIComponent(h5Url);
- const webViewPath = `/common-page/pages/web-view/index?path=${encodedUrl}&skipAuth=true`;
- wx.navigateTo({
- url: webViewPath,
- success: () => console.log('✅ 跳转 H5 成功:', h5Url),
- 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' });
- }
- },
- }
- })
|