|
|
- 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
- }
-
-
-
- export default {
- toArray: toArray,
- generateUUID: generateUUID,
- verificationAll: verificationAll,
- generateRandomColor: generateRandomColor,
- generateLightRandomColor: generateLightRandomColor
- }
|