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.

74 lines
1.6 KiB

8 months ago
  1. function toArray(data) {
  2. if (!data) return data
  3. let arr = new Array()
  4. if (data instanceof Array){
  5. return data
  6. } else {
  7. return [data]
  8. }
  9. }
  10. function generateUUID() {
  11. return 'xxxxxxxxxxxx4xxxyxxxxxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
  12. var r = Math.random() * 16 | 0,
  13. v = c == 'x' ? r : (r & 0x3 | 0x8);
  14. return v.toString(16);
  15. });
  16. }
  17. function generateRandomColor() {
  18. const letters = '0123456789ABCDEF';
  19. let color = '#';
  20. for (let i = 0; i < 6; i++) {
  21. color += letters[Math.floor(Math.random() * 16)];
  22. }
  23. return color;
  24. }
  25. function generateLightRandomColor() {
  26. const min = 150;
  27. const range = 105;
  28. const r = Math.floor(Math.random() * range + min);
  29. const g = Math.floor(Math.random() * range + min);
  30. const b = Math.floor(Math.random() * range + min);
  31. const color = 'rgb(' + r + ',' + g + ',' + b + ')';
  32. return color;
  33. }
  34. function verificationAll(data){
  35. if (!data){
  36. uni.showToast({
  37. title: '表单数据未填写',
  38. icon: "error"
  39. })
  40. return true
  41. }
  42. for (let key in data) {
  43. if (!data[key] || data[key] === "") {
  44. uni.showToast({
  45. title: '必填数据未填写' + key,
  46. icon: "error"
  47. })
  48. return true
  49. }
  50. }
  51. return false
  52. }
  53. //验证手机号是否合法
  54. function verificationPhone(phone){
  55. 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)){
  56. return false
  57. }
  58. return true
  59. }
  60. export default {
  61. toArray: toArray,
  62. generateUUID: generateUUID,
  63. verificationAll: verificationAll,
  64. generateRandomColor: generateRandomColor,
  65. generateLightRandomColor: generateLightRandomColor,
  66. verificationPhone : verificationPhone
  67. }