index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.openLoginDialog()
  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. processLogin(e) {
  74. if (!e.detail.userInfo) {
  75. wx.showToast({
  76. title: '已取消',
  77. icon: 'none',
  78. })
  79. return;
  80. }
  81. AUTH.register(this);
  82. },
  83. })