checkInShare.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // checkInShare.js
  2. Page({
  3. data: {
  4. checkInList: [],
  5. userInfo: {}
  6. },
  7. onLoad() {
  8. const userInfo = wx.getStorageSync('userInfo');
  9. if (userInfo) {
  10. this.setData({
  11. userInfo
  12. });
  13. }
  14. const logs = wx.getStorageSync('logs') || [];
  15. const checkInList = logs.map(log => {
  16. return {
  17. userInfo: this.data.userInfo,
  18. date: log.date,
  19. cate: this.getCateText(log.cate),
  20. time: log.time
  21. };
  22. });
  23. this.setData({
  24. checkInList
  25. });
  26. },
  27. getCateText(cateIndex) {
  28. const cateArr = [
  29. {
  30. icon: 'work',
  31. text: '工作'
  32. },
  33. {
  34. icon: 'study',
  35. text: "学习"
  36. },
  37. {
  38. icon: 'think',
  39. text: '思考'
  40. },
  41. {
  42. icon: 'write',
  43. text: '写作'
  44. },
  45. {
  46. icon: 'sport',
  47. text: '运动'
  48. },
  49. {
  50. icon: 'read',
  51. text: "阅读"
  52. }
  53. ];
  54. return cateArr[cateIndex].text;
  55. },
  56. publishCheckIn() {
  57. const logs = wx.getStorageSync('logs') || [];
  58. const lastLog = logs[0];
  59. const newCheckIn = {
  60. userInfo: this.data.userInfo,
  61. date: lastLog.date,
  62. cate: this.getCateText(lastLog.cate),
  63. time: lastLog.time
  64. };
  65. const checkInList = [newCheckIn, ...this.data.checkInList];
  66. this.setData({
  67. checkInList
  68. });
  69. wx.showToast({
  70. title: '打卡发布成功',
  71. icon: 'success'
  72. });
  73. }
  74. });