index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. const WXAPI = require('apifm-wxapi')
  2. const AUTH = require('../../utils/auth')
  3. Page({
  4. data: {
  5. minDate: new Date().getTime(),
  6. maxDate: new Date().getTime(),
  7. formatter(day) {
  8. return day;
  9. },
  10. },
  11. onLoad: function(options) {
  12. this.scoreSignLogs()
  13. },
  14. onShow: function() {
  15. AUTH.checkHasLogined().then(isLogined => {
  16. if (!isLogined) {
  17. AUTH.login(this)
  18. }
  19. })
  20. },
  21. async scoreSignLogs() {
  22. const res = await WXAPI.scoreSignLogs({
  23. token: wx.getStorageSync('token')
  24. })
  25. if (res.code == 0) {
  26. this.setData({
  27. scoreSignLogs: res.data.result,
  28. formatter(day) {
  29. const _log = res.data.result.find(ele => {
  30. const year = day.date.getYear() + 1900
  31. let month = day.date.getMonth() + 1
  32. month = month + ''
  33. if (month.length == 1) {
  34. month = '0' + month
  35. }
  36. let date = day.date.getDate() + ''
  37. if (date.length == 1) {
  38. date = '0' + date
  39. }
  40. return ele.dateAdd.indexOf(`${year}-${month}-${date}`) == 0
  41. })
  42. if (_log) {
  43. day.bottomInfo = '已签到'
  44. }
  45. return day;
  46. }
  47. })
  48. }
  49. },
  50. async sign() {
  51. const res = await WXAPI.scoreSign(wx.getStorageSync('token'))
  52. if (res.code == 10000) {
  53. wx.showToast({
  54. title: '签到成功',
  55. icon: 'success'
  56. })
  57. this.scoreSignLogs()
  58. return
  59. }
  60. if (res.code != 0) {
  61. wx.showToast({
  62. title: res.msg,
  63. icon: 'none'
  64. })
  65. } else {
  66. wx.showToast({
  67. title: '签到成功',
  68. icon: 'success'
  69. })
  70. this.scoreSignLogs()
  71. }
  72. },
  73. })