methods-util.js 938 B

1234567891011121314151617181920212223242526272829303132333435
  1. //获取url的参数params
  2. export const getParams = () => {
  3. let str = location.href;
  4. let num = str.indexOf('?');
  5. const param = {};
  6. str = str.substr(num + 1);
  7. //history模式使用这个
  8. // let num2 = str.indexOf('#');
  9. // console.log(num2);
  10. // let str2 = '';
  11. // if (num2 > 0) {
  12. // str2 = str.substr(0, num2);
  13. // } else {
  14. // num2 = str.indexOf('/');
  15. // str2 = str.substr(0, num2);
  16. // console.log(str2);
  17. // }
  18. const arr = str.split('&');
  19. for (let i = 0; i < arr.length; i++) {
  20. num = arr[i].indexOf('=');
  21. if (num > 0) {
  22. const name = arr[i].substring(0, num);
  23. const value = arr[i].substr(num + 1);
  24. param[name] = decodeURI(value);
  25. }
  26. }
  27. return param;
  28. };
  29. //判断信息是否过期
  30. export const isDateOff = dataDate => {
  31. const now = new Date(new Date().getTime() - 24 * 60 * 60 * 1000);
  32. dataDate = new Date(dataDate);
  33. return now.getTime() <= dataDate.getTime();
  34. };