pass.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. Page({
  2. data: {
  3. year: 0,
  4. month: 0,
  5. date: ['日', '一', '二', '三', '四', '五', '六'],
  6. dateArr: [],
  7. isToday: 0,
  8. isTodayWeek: false,
  9. todayIndex: 0
  10. },
  11. onLoad: function () {
  12. wx.showLoading({
  13. title: '正在加载',
  14. })
  15. let now = new Date();
  16. let year = now.getFullYear();
  17. let month = now.getMonth() + 1;
  18. this.dateInit();
  19. this.req(year + '-' + month + '-' + now.getDate())
  20. this.setData({
  21. year: year,
  22. month: month,
  23. isToday: '' + year + month + now.getDate()
  24. })
  25. },
  26. dateInit: function (setYear, setMonth) {
  27. //全部时间的月份都是按0~11基准,显示月份才+1
  28. let dateArr = []; //需要遍历的日历数组数据
  29. let arrLen = 0; //dateArr的数组长度
  30. let now = setYear ? new Date(setYear, setMonth) : new Date();
  31. let year = setYear || now.getFullYear();
  32. let nextYear = 0;
  33. let month = setMonth || now.getMonth(); //没有+1方便后面计算当月总天数
  34. let nextMonth = (month + 1) > 11 ? 1 : (month + 1);
  35. let startWeek = new Date(year + '/' + (month + 1) + '/' + 1).getDay();
  36. // let startWeek = new Date(year + ',' + (month + 1) + ',' + 1).getDay(); //目标月1号对应的星期
  37. let dayNums = new Date(year, nextMonth, 0).getDate(); //获取目标月有多少天
  38. let obj = {};
  39. let num = 0;
  40. if (month + 1 > 11) {
  41. nextYear = year + 1;
  42. dayNums = new Date(nextYear, nextMonth, 0).getDate();
  43. }
  44. arrLen = startWeek + dayNums;
  45. for (let i = 0; i < arrLen; i++) {
  46. if (i >= startWeek) {
  47. num = i - startWeek + 1;
  48. obj = {
  49. isToday: '' + year + (month + 1) + num,
  50. dateNum: num,
  51. weight: 5
  52. }
  53. } else {
  54. obj = {};
  55. }
  56. dateArr[i] = obj;
  57. }
  58. this.setData({
  59. dateArr: dateArr
  60. })
  61. let nowDate = new Date();
  62. let nowYear = nowDate.getFullYear();
  63. let nowMonth = nowDate.getMonth() + 1;
  64. let nowWeek = nowDate.getDay();
  65. let getYear = setYear || nowYear;
  66. let getMonth = setMonth >= 0 ? (setMonth + 1) : nowMonth;
  67. if (nowYear == getYear && nowMonth == getMonth) {
  68. this.setData({
  69. isTodayWeek: true,
  70. todayIndex: nowWeek
  71. })
  72. } else {
  73. this.setData({
  74. isTodayWeek: false,
  75. todayIndex: -1
  76. })
  77. }
  78. },
  79. lastMonth: function () {
  80. //全部时间的月份都是按0~11基准,显示月份才+1
  81. let year = this.data.month - 2 < 0 ? this.data.year - 1 : this.data.year;
  82. let month = this.data.month - 2 < 0 ? 11 : this.data.month - 2;
  83. this.setData({
  84. year: year,
  85. month: (month + 1)
  86. })
  87. this.dateInit(year, month);
  88. },
  89. nextMonth: function () {
  90. //全部时间的月份都是按0~11基准,显示月份才+1
  91. let year = this.data.month > 11 ? this.data.year + 1 : this.data.year;
  92. let month = this.data.month > 11 ? 0 : this.data.month;
  93. this.setData({
  94. year: year,
  95. month: (month + 1)
  96. })
  97. this.dateInit(year, month);
  98. },
  99. check(e){
  100. wx.showLoading({
  101. title: '正在加载',
  102. })
  103. this.setData({
  104. isToday: e.currentTarget.dataset.year + '' + e.currentTarget.dataset.month + '' + e.currentTarget.dataset.day
  105. })
  106. this.req(e.currentTarget.dataset.year + '-' + e.currentTarget.dataset.month + '-' + e.currentTarget.dataset.day)
  107. },
  108. req(time){
  109. let that=this
  110. wx.request({
  111. url: 'http://192.168.100.234:8080/oneportal/access/getAccessInfo.if',
  112. method: 'GET',
  113. data: { 'loginId': wx.getStorageSync('loginId'), 'time': time },
  114. success(res) {
  115. wx.hideLoading()
  116. console.log(res)
  117. }
  118. })
  119. }
  120. })