// pages/browser/index.js Page({ data: { //h5Url: 'https://t1d.yixunpro.com/h5/', // 直接赋值真实链接,无需传参 //pageTitle: 'H5 页面', //isLoading: true }, onLoad() { wx.setNavigationBarTitle ({title: ''}) // 无需接收 options,直接使用硬编码链接 //console.log('加载 H5 链接:', this.data.h5Url); }, // H5 页面加载完成 handleWebLoad(e) { this.setData({ isLoading: false }); // 可选:同步 H5 页面标题(通过 web-view 加载完成的 url 解析,或 H5 主动发送消息) //wx.setNavigationBarTitle({ title: 'H5 页面' }); // 也可固定标题或动态解析 }, // H5 页面加载失败 handleWebError(e) { // this.setData({ isLoading: false }); wx.showToast({ title: '页面加载失败', icon: 'none' }); console.error('H5 加载失败:', e.detail); }, // 返回上一页(H5 历史记录) handleGoBack() { // 创建 web-view 上下文,控制 H5 历史回退 const webViewCtx = wx.createWebViewContext('web-view'); webViewCtx.navigateBack({ fail: () => { // 若 H5 无历史记录,返回小程序上一页 wx.navigateBack({ delta: 1 }); } }); }, // 刷新 H5 页面 handleRefresh() { this.setData({ isLoading: true }); // 通过添加时间戳强制刷新(避免缓存) const timestamp = Date.now(); const newUrl = this.data.h5Url.includes('?') ? `${this.data.h5Url}&t=${timestamp}` : `${this.data.h5Url}?t=${timestamp}`; this.setData({ h5Url: newUrl }); } });