学员端小程序
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.

50 lines
1.2 KiB

1 year ago
1 year ago
1 year ago
1 year ago
  1. export function checkToken(vm) {
  2. let expiresTime = vm.$store.state.user.vuex_loginInfo.expiresTime
  3. let nowTime = new Date() * 1
  4. console.log('超时了')
  5. console.log(expiresTime)
  6. if (nowTime > expiresTime * 1) {
  7. vm.$store.commit('goLogin')
  8. // 如果小于20分钟就刷新一下token &&
  9. } else if ((expiresTime * 1 - nowTime) / 60000 < 30) {
  10. vm.$store.dispatch('refreshToken')
  11. }
  12. }
  13. function dateRangeFn(dateRange) {
  14. let tmp = []
  15. let dateArr = []
  16. dateRange.forEach((date) => {
  17. let dateStr = date.toISOString().split('T')[0]
  18. let dd = dateStr.split('-')[2]
  19. const daysOfWeek = ['日', '一', '二', '三', '四', '五', '六'];
  20. const dayOfWeek = date.getDay();
  21. const weekName = daysOfWeek[dayOfWeek];
  22. console.log(dateStr)
  23. console.log(weekName)
  24. if (tmp.length == 0) {
  25. dateArr.push(tmp)
  26. }
  27. let obj = {
  28. week: weekName,
  29. num: dd,
  30. date: dateStr
  31. }
  32. tmp.push(obj)
  33. if (tmp.length == 5) {
  34. tmp = []
  35. }
  36. });
  37. console.log(dateArr)
  38. return dateArr
  39. }
  40. export function getDates(startDate, endDate) {
  41. const dates = [];
  42. let currentDate = new Date(startDate);
  43. while (currentDate <= endDate) {
  44. dates.push(new Date(currentDate));
  45. currentDate.setDate(currentDate.getDate() + 1);
  46. }
  47. return dateRangeFn(dates)
  48. }