index.js 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. // nova-werun/components/home/index.js
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company;
  4. Component({
  5. /**
  6. * 组件的属性列表
  7. */
  8. properties: {
  9. },
  10. /**
  11. * 组件的初始数据
  12. */
  13. data: {
  14. //屏幕高度
  15. statusBarHeight: 0, // 状态栏高度
  16. screenHeight: 0, // 屏幕高度
  17. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  18. bottomNavHeight: 0, // 底部导航栏高度
  19. contentHeight: 0, // 可用内容高度
  20. contentpadding: 0, //顶部padding高度
  21. //选择
  22. rows: [{
  23. image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/3l5p1v041343137.png?imageView2/1/w/200/h/200',
  24. text: '签到打卡',
  25. url: '../../pages/home/signin/index'
  26. },
  27. {
  28. image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/v6p4fm041343296.png?imageView2/1/w/200/h/200',
  29. text: '排行榜',
  30. url: '../../pages/home/ranking/index'
  31. },
  32. {
  33. image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/mcu488041343362.png?imageView2/1/w/200/h/200',
  34. text: '转发分享',
  35. url: '../../pages/home/share/index'
  36. },
  37. {
  38. image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/pqln61041343428.png?imageView2/1/w/200/h/200',
  39. text: '我的勋章',
  40. url: '../../pages/home/medal/index'
  41. },
  42. {
  43. image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/9crt85041343498.png?imageView2/1/w/200/h/200',
  44. text: '步行',
  45. url: '../../pages/home/sport/sport-home/index',
  46. },
  47. {
  48. image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/71svpg041343669.png?imageView2/1/w/200/h/200',
  49. text: '跑步',
  50. url: '../../pages/home/sport/sport-home/index',
  51. active: 1
  52. },
  53. {
  54. image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/uk13u1041343733.png?imageView2/1/w/200/h/200',
  55. text: '我的统计',
  56. url: '../../pages/home/statistics/index'
  57. },
  58. {
  59. image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241104/k1q4no034958681.png?imageView2/1/w/200/h/200',
  60. text: '积分',
  61. url: '../../pages/home/integral/index'
  62. },
  63. ],
  64. target: 0,
  65. sharList:[],
  66. },
  67. lifetimes: {
  68. detached: function () {
  69. // 在组件实例被从页面节点树移除时执行
  70. },
  71. attached: async function () {
  72. // 在组件实例进入页面节点树时执行
  73. // 计算
  74. const systemInfo = wx.getSystemInfoSync();
  75. const statusBarHeight = systemInfo.statusBarHeight || 0;
  76. const screenHeight = systemInfo.screenHeight || 0;
  77. const custom = wx.getMenuButtonBoundingClientRect();
  78. const customHeight = custom.height + 10 + 2 || 0;
  79. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  80. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  81. const contentHeight = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  82. this.setData({
  83. statusBarHeight,
  84. screenHeight,
  85. customHeight,
  86. bottomNavHeight,
  87. contentHeight,
  88. contentpadding
  89. });
  90. console.log('123', contentpadding);
  91. this.gettarget()
  92. this.order()
  93. },
  94. },
  95. /**
  96. * 组件的方法列表
  97. */
  98. methods: {
  99. //跳转
  100. gourl(e) {
  101. const url = e.currentTarget.dataset.url
  102. const active = e.currentTarget.dataset.active
  103. if (active) {
  104. wx.navigateTo({
  105. url: `${url}?id=` + active // 目标页面的路径
  106. });
  107. console.log(active);
  108. } else {
  109. wx.navigateTo({
  110. url: `${url}` // 目标页面的路径
  111. });
  112. }
  113. },
  114. async gettarget() {
  115. const currentUser = Parse.User.current();
  116. let userquery = new Parse.Query('_User');
  117. userquery.equalTo('company', company);
  118. userquery.equalTo('objectId', currentUser.id);
  119. userquery.notEqualTo('isDeleted', true)
  120. let user = await userquery.find();
  121. let num = user.map(item => item.toJSON());
  122. if (num[0].num) {
  123. this.setData({
  124. target: num[0].num
  125. })
  126. console.log('当前步数', this.data.target);
  127. } else {
  128. const currentUser2 = Parse.User.current();
  129. let userquery2 = new Parse.Query('_User');
  130. userquery2.equalTo('company', company);
  131. userquery2.equalTo('objectId', currentUser2.id);
  132. userquery2.notEqualTo('isDeleted', true)
  133. let user2 = await userquery2.first();
  134. user2.set('num', 5000)
  135. try {
  136. let saveDate2 = await user2.save();
  137. console.log(saveDate2);
  138. this.setData({
  139. target: 5000
  140. })
  141. console.log("目标步数更改成功");
  142. } catch (error) {
  143. console.error("保存数据时出现错误:", error);
  144. }
  145. }
  146. },
  147. //获取当天运动数据
  148. async order() {
  149. const currentUser = Parse.User.current();
  150. let ActivityDataquery = new Parse.Query('ActivityData');
  151. ActivityDataquery.equalTo('user', currentUser.id);
  152. ActivityDataquery.equalTo('company', company);
  153. ActivityDataquery.equalTo('type', 'today');
  154. ActivityDataquery.notEqualTo('isDeleted', true);
  155. // 获取今天的日期
  156. const today = new Date();
  157. const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // 今天的开始时间
  158. const todayEnd = new Date(todayStart);
  159. todayEnd.setHours(23, 59, 59, 999); // 今天的结束时间
  160. // 在查询条件中添加对 createdAt 的限制
  161. ActivityDataquery.greaterThanOrEqualTo('createdAt', todayStart);
  162. ActivityDataquery.lessThanOrEqualTo('createdAt', todayEnd);
  163. ActivityDataquery.include('user');
  164. let r = await ActivityDataquery.find();
  165. let sharList = r.map(item => item.toJSON());
  166. this.setData({
  167. sharList
  168. });
  169. console.log(this.data.sharList);
  170. },
  171. }
  172. })