123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- // 公共方法模块
- /**
- * 手机号校验
- * @param {手机号} tel
- * @param {区号} areaNum 默认86
- * @returns Boolean
- * 86 正常手机号校验
- * 非86 位数必须大于8位
- */
- export const telVerify = (tel, areaNum = 86) => {
- let flag = false;
- if (areaNum == 86 && /^1[3456789]\d{9}$/.test(tel)) {
- flag = true;
- }
- if (areaNum != 86 && tel.length > 8) {
- flag = true;
- }
- return flag;
- };
- /**
- * 邮箱校验
- * @param {邮箱} email
- * @returns Boolean
- */
- export const emailVerify = (email) => {
- let flag = false;
- let pattern = /^([A-Za-z0-9_\-\.])+@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
- let domains = ["qq.com", "163.com", "vip.163.com", "263.net", "yeah.net", "sohu.com", "sina.cn", "sina.com", "eyou.com", "gmail.com", "hotmail.com", "42du.cn"];
- if (pattern.test(email)) {
- var domain = email.substring(email.indexOf("@") + 1);
- for (var i = 0; i < domains.length; i++) {
- if (domain == domains[i]) {
- flag = true;
- }
- }
- }
- return flag;
- };
- /**
- * 校验是否有小程序新版本
- */
- export const hasUpdate = () => {
- const updateManager = uni.getUpdateManager();
- updateManager.onCheckForUpdate(function (res) {
- // 请求完新版本信息的回调
- console.log("是否有新版本", res.hasUpdate);
- });
- updateManager.onUpdateReady(function (res) {
- uni.showModal({
- title: "更新提示",
- content: "新版本已经准备好,是否重启应用?",
- success(res) {
- if (res.confirm) {
- // 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
- updateManager.applyUpdate();
- }
- },
- });
- });
- };
- /**
- *
- * 防抖
- */
- export const debounce = (fn,t=300) => {
- let timer = null;
- return function() {
- clearTimeout(timer);
- timer = setTimeout(_ => {
- fn.call(this, arguments);
- }, t);
- };
- }
|