You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
268 lines
5.6 KiB
268 lines
5.6 KiB
const u_check = uni.$u.test;
|
|
var com = {
|
|
|
|
/**************uview集成********************************/
|
|
/**
|
|
* 验证检测
|
|
*
|
|
* @param array || obj || ... value 需要验证的值(可以是 array || obj || ... )
|
|
* @param string type 需要验证的类型(可以是 array || obj || ...)
|
|
*/
|
|
check:function(value,type)
|
|
{
|
|
switch(type) {
|
|
//数组
|
|
case 'array':
|
|
return u_check.array(value);
|
|
break;
|
|
//json字符串
|
|
case 'json':
|
|
return u_check.jsonString(value);
|
|
break;
|
|
//object对象
|
|
case 'object':
|
|
return u_check.object(value);
|
|
break;
|
|
//email 邮箱号
|
|
case 'email':
|
|
return u_check.email(value);
|
|
break;
|
|
//mobile 手机号
|
|
case 'mobile':
|
|
return u_check.mobile(value);
|
|
break;
|
|
//url 地址
|
|
case 'url':
|
|
return u_check.url(value);
|
|
break;
|
|
//empty 是否为空
|
|
case 'empty':
|
|
return u_check.isEmpty(value);
|
|
break;
|
|
//注解
|
|
//总的来说,年月日之间可以用"/"或者"-"分隔(不能用中文分隔),时分秒之间用":"分隔,数值不能超出范围,如月份不能为13,则检验成功,否则失败。
|
|
//date 日期时间
|
|
case 'date':
|
|
return u_check.date(value);
|
|
break;
|
|
//number 是否十进制数值
|
|
case 'number':
|
|
return u_check.number(value);
|
|
break;
|
|
//digits 是否整数
|
|
case 'digits':
|
|
return u_check.digits(value);
|
|
break;
|
|
//idCard 是否身份证号
|
|
case 'id_card':
|
|
return u_check.idCard(value);
|
|
break;
|
|
//是否车牌号 (例:京A88888)
|
|
case 'car_no':
|
|
return u_check.carNo(value);
|
|
break;
|
|
//amount 金额字符串
|
|
case 'amount':
|
|
return u_check.amount(value);
|
|
break;
|
|
//zh 是否汉字
|
|
case 'zh':
|
|
return u_check.chinese(value);
|
|
break;
|
|
//en 是否字母 letter
|
|
case 'en':
|
|
return u_check.letter(value);
|
|
break;
|
|
//str 是否字母或者数字
|
|
case 'str':
|
|
return u_check.enOrNum(value);
|
|
break;
|
|
default:
|
|
return false;
|
|
}
|
|
},
|
|
//是否为空
|
|
isNull:function(value)
|
|
{
|
|
if(value != null || value != 'null')
|
|
{
|
|
return u_check.isEmpty(value);
|
|
}
|
|
else
|
|
{
|
|
return true;
|
|
}
|
|
},
|
|
|
|
/********************反馈信息****************************************************/
|
|
alert: function(info) {
|
|
uni.showModal({
|
|
title: '提示',
|
|
content: info,
|
|
showCancel: false
|
|
});
|
|
},
|
|
|
|
alertDo: function(info, callback) {
|
|
uni.showModal({
|
|
title: '提示',
|
|
content: info,
|
|
showCancel: false,
|
|
success() {
|
|
callback();
|
|
}
|
|
});
|
|
},
|
|
confirm: function(info, callback, title) {
|
|
uni.showModal({
|
|
title: title ? title : '提示',
|
|
content: info,
|
|
success: function(res) {
|
|
if (res.confirm) {
|
|
callback();
|
|
}
|
|
}
|
|
});
|
|
},
|
|
|
|
// 加载信息,带遮罩
|
|
showLoading: function(title = '', mask = true) {
|
|
uni.showLoading({
|
|
title,
|
|
mask
|
|
});
|
|
},
|
|
|
|
// 隐藏遮罩
|
|
hideLoading:function () {
|
|
uni.hideLoading();
|
|
},
|
|
|
|
showSuccess: function(info) {
|
|
uni.showToast({
|
|
title: info,
|
|
icon: 'success',
|
|
duration: 3000
|
|
});
|
|
},
|
|
showError: function(info) {
|
|
uni.showToast({
|
|
title: info,
|
|
icon: 'none',
|
|
duration: 3000
|
|
});
|
|
},
|
|
showSuccessDo: function(info, time, callback) {
|
|
uni.showToast({
|
|
title: info,
|
|
icon: 'success',
|
|
duration: time,
|
|
success: function() {
|
|
callback();
|
|
}
|
|
});
|
|
},
|
|
/******************加减乘除****************************************************/
|
|
/**
|
|
* 加法精度计算
|
|
*
|
|
* @param {Object} number 数字
|
|
*/
|
|
bcadd: function(a, b){
|
|
var c, d, e;
|
|
try {
|
|
c = a.toString().split(".")[1].length
|
|
} catch(f) {
|
|
c = 0
|
|
}
|
|
try {
|
|
d = b.toString().split(".")[1].length
|
|
} catch(f) {
|
|
d = 0
|
|
}
|
|
return e = Math.pow(10, Math.max(c, d)),(this.bcmul(a, e) + this.bcmul(b, e)) / e
|
|
},
|
|
|
|
/**
|
|
* 减法精度计算
|
|
*
|
|
* @param {Object} number 数字
|
|
*/
|
|
bcsub: function(a, b){
|
|
var c, d, e;
|
|
try {
|
|
c = a.toString().split(".")[1].length
|
|
} catch(f) {
|
|
c = 0
|
|
}
|
|
try {
|
|
d = b.toString().split(".")[1].length
|
|
} catch(f) {
|
|
d = 0
|
|
}
|
|
return e = Math.pow(10, Math.max(c, d)),(this.bcmul(a, e) - this.bcmul(b, e)) / e
|
|
},
|
|
|
|
/**
|
|
* 乘法精度计算
|
|
*
|
|
* @param {Object} number 数字
|
|
*/
|
|
bcmul: function(a, b){
|
|
var c = 0,
|
|
d = a.toString(),
|
|
e = b.toString();
|
|
try {
|
|
c += d.split(".")[1].length
|
|
} catch(f) {}
|
|
try {
|
|
c += e.split(".")[1].length
|
|
} catch(f) {}
|
|
return Number(d.replace(".", "")) * Number(e.replace(".", "")) / Math.pow(10, c)
|
|
},
|
|
|
|
/**
|
|
* 除法精度计算
|
|
*
|
|
* @param {Object} number 数字
|
|
*/
|
|
bcdiv: function(a, b){
|
|
var c, d, e = 0,
|
|
f = 0;
|
|
try {
|
|
e = a.toString().split(".")[1].length
|
|
} catch(g) {}
|
|
try {
|
|
f = b.toString().split(".")[1].length
|
|
} catch(g) {}
|
|
return c = Number(a.toString().replace(".", "")),d = Number(b.toString().replace(".", "")),this.bcmul(c / d, Math.pow(10, f - e))
|
|
},
|
|
|
|
/**
|
|
* 隐藏手机号
|
|
* @param phone string 数值1
|
|
*/
|
|
hidephone:function (phone){
|
|
var reg = /^(\d{3})\d{4}(\d{4})$/;
|
|
return phone.replace(reg, "$1****$2")
|
|
},
|
|
|
|
removeObserver(arr) {
|
|
return arr.map((item) => {
|
|
if (Array.isArray(item)) return removeObserver(item)
|
|
else if (typeof item === 'object') {
|
|
const target = {}
|
|
for (let key in item) {
|
|
if (key !== '__ob__') {
|
|
target[key] = item[key]
|
|
}
|
|
}
|
|
return target
|
|
}
|
|
return item
|
|
})
|
|
},
|
|
|
|
}
|
|
|
|
module.exports = com |