/** * 显示消息提示框 * @param content 提示的标题 */ export function toast(content) { uni.showToast({ icon: 'none', title: content }) } /** * 显示模态弹窗 * @param content 提示的标题 */ export function showConfirm(content) { return new Promise((resolve, reject) => { uni.showModal({ title: '提示', content: content, cancelText: '取消', confirmText: '确定', success: function(res) { resolve(res) } }) }) } /** * 参数处理 * @param params 参数 */ export function tansParams(params) { let result = '' // FIXME 拼接参数 return result } export function getStaticUrl(url) { let result = ''; // #ifdef H5 result = `/mdist/${url}` // #endif // #ifdef APP-PLUS result = url // #endif return result; } /************* 将时间格式化成 年月+日 ***********/ export function formatDateToYearMonthDay(dateStr) { let date = new Date(dateStr.replace(/-/g, '/')); let dataStr1 = `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')}` const yearMonth = dataStr1.substring(0, 7); // "2025-06" const day = dataStr1.substring(8); // "01" return [yearMonth, day] } export function getStringByHtml3(html) { return html ? html.replace(//g, '') .replace(/<(style|script|iframe)[^>]*?>[\s\S]+?<\/\1\s*>/gi, '') .replace(/<[^>]+?>/g, '') .replace(/\s+/g, ' ') .replace(/ /g, ' ') .replace(/>/g, ' ') .replace(/]*>/g, '') .replace(/]*>.*?<\/video>/gi, '') : ''; } // 在页面/组件的 onReady 或 mounted 生命周期中添加 export function addClassToWebViewIframe() { const targetSrc = "/hybrid/html/web/viewer.html"; // 替换为你的 WebView URL const className = "custom-iframe-class"; // 要添加的类名 // 检查是否已存在目标 iframe const existingIframe = Array.from(document.querySelectorAll('iframe')).find( iframe => iframe.src.includes(targetSrc) ); if (existingIframe) { existingIframe.classList.add(className); return; } // 使用 MutationObserver 监听新增 iframe const observer = new MutationObserver(mutations => { mutations.forEach(mutation => { mutation.addedNodes.forEach(node => { if (node.tagName === 'IFRAME' && node.src.includes(targetSrc)) { node.classList.add(className); observer.disconnect(); // 找到后停止监听 } }); }); }); // 监听整个 body 的子元素变化 observer.observe(document.body, { childList: true, subtree: false }); // 设置超时停止监听(防止内存泄漏) setTimeout(() => observer.disconnect(), 5000); }