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.
 
 
 

90 lines
2.1 KiB

function toArray(data) {
if (!data) return data
let arr = new Array()
if (data instanceof Array){
return data
} else {
return [data]
}
}
function generateUUID() {
const timestamp = new Date().getTime().toString(); // 获取当前时间戳
const random = Math.random().toString().substr(2, 8); // 生成8位随机数
const increment = Math.floor(Math.random() * 1000000000).toString().padStart(9, '0'); // 生成9位自增数
return timestamp + random + increment;
}
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){
console.log("verificationAll:", data);
if (!data){
uni.showToast({
title: '表单数据未填写',
icon: "error"
})
return true
}
for (let key in data) {
if (!data[key] || data[key] === "") {
console.log(key);
uni.showToast({
title: '必填数据未填写' + key,
icon: "error"
})
return true
}
}
return false
}
function getLocation(fn){
uni.getLocation({
type: 'wgs84',
geocode:true,//设置该参数为true可直接获取经纬度及城市信息
success(orientation) {
console.log('获取定位信息',orientation);
let data = {
latitude : orientation.latitude,//纬度
longitude : orientation.longitude,//经度
}
fn && fn(data)
},
fail(err) {
console.log("获取定位失败",err);
uni.showToast({
title: '获取地址失败,将导致部分功能不可用',
icon:'none'
});
}
});
}
export default {
toArray: toArray,
generateUUID: generateUUID,
verificationAll: verificationAll,
generateRandomColor: generateRandomColor,
generateLightRandomColor: generateLightRandomColor,
getLocation,
}