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.
 
 
 
 
 

75 lines
1.6 KiB

function toArray(data) {
if (!data) return data
let arr = new Array()
if (data instanceof Array){
return data
} else {
return [data]
}
}
function generateUUID() {
return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0,
v = c == 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
function generateRandomColor() {
const letters = '0123456789ABCDEF';
let color = '#';
for (let i = 0; i < 6; i++) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
function generateLightRandomColor() {
const min = 150;
const range = 105;
const r = Math.floor(Math.random() * range + min);
const g = Math.floor(Math.random() * range + min);
const b = Math.floor(Math.random() * range + min);
const color = 'rgb(' + r + ',' + g + ',' + b + ')';
return color;
}
function verificationAll(data){
if (!data){
uni.showToast({
title: '表单数据未填写',
icon: "error"
})
return true
}
for (let key in data) {
if (!data[key] || data[key] === "") {
uni.showToast({
title: '必填数据未填写' + key,
icon: "error"
})
return true
}
}
return false
}
//验证手机号是否合法
function verificationPhone(phone){
if(!/^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/.test(phone)){
return false
}
return true
}
export default {
toArray: toArray,
generateUUID: generateUUID,
verificationAll: verificationAll,
generateRandomColor: generateRandomColor,
generateLightRandomColor: generateLightRandomColor,
verificationPhone : verificationPhone
}