Page({ data: { webviewUrl: '', title: '' }, onLoad(options) { const { url, title } = options if (!url) { wx.showToast({ title: '缺少URL参数', icon: 'none' }) wx.navigateBack() return } const decodedUrl = decodeURIComponent(url) const decodedTitle = decodeURIComponent(title || '文档预览') this.setData({ webviewUrl: decodedUrl, title: decodedTitle }) // 设置导航栏标题 wx.setNavigationBarTitle({ title: decodedTitle }) console.log('WebView加载URL:', decodedUrl) }, onLoad() { console.log('WebView页面加载完成') }, onError(e) { console.error('WebView加载错误:', e.detail) wx.showModal({ title: '加载失败', content: '文档预览失败,请检查网络连接或尝试下载文件', showCancel: false, confirmText: '确定', success: () => { wx.navigateBack() } }) }, onMessage(e) { console.log('WebView消息:', e.detail) }, onShareAppMessage() { return { title: this.data.title, path: `/pages/webview/webview?url=${encodeURIComponent(this.data.webviewUrl)}&title=${encodeURIComponent(this.data.title)}` } } })