首页
壁纸
统计
友联
留言
Search
1
飞牛NAS社区自动打卡签到
31 阅读
2
飞牛NAS部署宝塔面板
19 阅读
3
Deepin V25安装 1Panel启动失败的问题修复办法
16 阅读
4
Debain终端语言报错问题解决办法
13 阅读
5
123云盘资源分享链接
13 阅读
飞牛Nas
青龙面板
编程开发
Python
Java
Go
PHP
JavaScript
Typecho
系统问题
Linux
Windows
Debain
Deepin
资源分享
登录
/
注册
Search
标签搜索
飞牛NAS
Python
宝塔面板
PHP
函数
Linux
Docker
青龙面板
JavaScript
Typecho
伪静态
Nginx
Debain
123云盘
123Pan
资源
Deepin
1Panel
Windows
Xbox Game Bar
AiWeiYi
累计撰写
14
篇文章
累计收到
1
条评论
首页
栏目
飞牛Nas
青龙面板
编程开发
Python
Java
Go
PHP
JavaScript
Typecho
系统问题
Linux
Windows
Debain
Deepin
资源分享
页面
壁纸
统计
友联
留言
搜索到
1
篇与
的结果
2025-03-27
网上收集到的一些常用函数
/** * @description: 校验身份证 * @param {*} * @return {*} */ export const validateIDCard = value => /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(value); /** * @description: 校验支付宝账号 * @param {*} * @return {*} */ export const validateAlipay = value => /^1\d{10}$|^[a-zA-Z\d._-]*\@[a-zA-Z\d.-]{1,10}\.[a-zA-Z\d]{1,20}$/.test(value); /** * @description: 校验银行卡 * @param {*} * @return {*} */ export const validateBankCode = value => /^\d{13,19}$/.test(value); /** * @description: 校验手机号 * @param {*} * @return {*} */ export const validatePhone = value => /^1\d{10}$/.test(value); /** * @description: 函数节流 * @param {*} * @return {*} */ export const throttle = function (fn, delay = 1000) { let prev = 0; return function () { const now = Date.now(); if (now - prev > delay) { fn.apply(this, arguments); prev = Date.now(); } } } /** * @description: 获取随机字符串 * @param {*} * @return {*} */ export const randomString = () => Math.random().toString(36).substr(2); /** * @description: 将 BASE64 转换文件 * @param {*} * @return {*} */ export const dataURLtoFile = (dataurl, filename) => { const arr = dataurl.split(','); const mime = arr[0].match(/:(.*?);/)[1]; if (!filename) filename = `${Date.parse(new Date())}.jpg`; const bstr = window.atob(arr[1]); let n = bstr.length; const u8arr = new Uint8Array(n); while (n--) { u8arr[n] = bstr.charCodeAt(n); } return new File([u8arr], filename, { type: mime }); } /** * @description: 压缩图片 * @param {*} * @return {*} */ export const compressImg = file => { const fileSize = parseFloat(Number.parseInt(file.size, 10) / 1024 / 1024).toFixed(2); const reader = new FileReader(); reader.readAsDataURL(file); return new Promise((resolve) => { reader.onload = e => { const img = new Image(); img.src = e.target.result; img.onload = () => { const w = img.width; const h = img.height; const canvas = document.createElement('canvas'); const ctx = canvas.getContext('2d'); let base64; canvas.setAttribute('width', w); canvas.setAttribute('height', h); ctx.drawImage(img, 0, 0, w, h); if (fileSize <= 1) { base64 = canvas.toDataURL(file.type, 1); } else if (fileSize <= 3) { base64 = canvas.toDataURL(file.type, 0.8); } else if (fileSize <= 5) { base64 = canvas.toDataURL(file.type, 0.5); } else { base64 = canvas.toDataURL(file.type, 0.1); } let fileName = file.name; fileName = fileName.replace(/^(.+)\.(.+)$/, (fullName, name, suffix) => name + Math.floor(Math.random() * (9999 - 1000) + 1000) + '.' + suffix); resolve(dataURLtoFile(base64, fileName)); }; }; }); }
2025年03月27日
6 阅读
0 评论
0 点赞