123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- /**
- * 显示消息提示框
- * @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(/<img [^.]*">/g, '')
- .replace(/<(style|script|iframe)[^>]*?>[\s\S]+?<\/\1\s*>/gi, '')
- .replace(/<[^>]+?>/g, '')
- .replace(/\s+/g, ' ')
- .replace(/ /g, ' ')
- .replace(/>/g, ' ')
- .replace(/<?img[^>]*>/g, '')
- .replace(/<video[^>]*>.*?<\/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);
- }
-
-
- /**
- * 验证中国大陆身份证号码
- * @param {string} idCard - 身份证号码
- * @returns {boolean} - 是否有效
- */
- export function validateIdCard(idCard) {
- // 基本格式验证
- if (!/^\d{17}[\dXx]$/.test(idCard)) {
- return false;
- }
-
- // 校验码计算
- const factors = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
- const checkCodes = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
-
- let sum = 0;
- for (let i = 0; i < 17; i++) {
- sum += parseInt(idCard[i]) * factors[i];
- }
-
- const mod = sum % 11;
- const checkCode = checkCodes[mod];
-
- return idCard[17].toUpperCase() === checkCode;
- }
-
- /**
- * 验证中国大陆手机号码
- * @param {string} phone - 手机号码
- * @returns {boolean} - 是否有效
- */
- export function validatePhone(phone) {
- // 正则表达式验证
- return /^1[3-9]\d{9}$/.test(phone);
- }
|