util.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. const formatTime = date => {
  2. const year = date.getFullYear()
  3. const month = date.getMonth() + 1
  4. const day = date.getDate()
  5. const hour = date.getHours()
  6. const minute = date.getMinutes()
  7. const second = date.getSeconds()
  8. return `${[year, month, day].map(formatNumber).join('/')} ${[hour, minute, second].map(formatNumber).join(':')}`
  9. }
  10. const formatNumber = n => {
  11. n = n.toString()
  12. return n[1] ? n : `0${n}`
  13. }
  14. //获取url参数组成json
  15. const GetQueryJson = e => {
  16. if (e == 'undefined') {
  17. return {}
  18. } else {
  19. let url = e; //获取url
  20. let arr = []; //存储参数的数
  21. let res = {}; //存储最终JSON结果对象
  22. arr = url.split('?')[1].split('&'); //获取浏览器地址栏中的参数
  23. for (let i = 0; i < arr.length; i++) { //遍历参数
  24. if (arr[i].indexOf('=') != -1) { //如果参数中有值
  25. let str = arr[i].split('=');
  26. res[str[0]] = str[1];
  27. } else { //如果参数中无值
  28. res[arr[i]] = '';
  29. }
  30. };
  31. return res;
  32. }
  33. }
  34. module.exports = {
  35. formatTime,GetQueryJson
  36. }