const api = require('../../utils/api'); // 允许加载的域名白名单 const ALLOWED_HOSTS = ['m.muguaclub.cn', 'muguaclub.cn']; function isAllowedUrl(url) { if (!url) return false; try { // 简单解析 hostname const match = url.match(/^https?:\/\/([^/:?#]+)/i); if (!match) return false; const host = match[1].toLowerCase(); return ALLOWED_HOSTS.some((h) => host === h || host.endsWith('.' + h)); } catch (e) { return false; } } Page({ data: { url: '', invalid: false }, onLoad(options) { if (!options.url) { this.setData({ invalid: true }); return; } const url = decodeURIComponent(options.url); if (!isAllowedUrl(url)) { console.warn('[webview] blocked url:', url); this.setData({ invalid: true, url: '' }); return; } this.setData({ url, invalid: false }); }, onRetry() { if (this.data.url) { // 触发重新加载 this.setData({ url: '' }); setTimeout(() => { this.setData({ url: this.data._url || '' }); }, 50); } }, // ---- 分享 ---- onShareAppMessage() { return { title: '明缘云道场', path: '/pages/home/home' }; }, onShareTimeline() { return { title: '明缘云道场 · 学习成长,每日精进', query: 'from=timeline' }; } });