index.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. address:"",
  67. },
  68. lifetimes: {
  69. detached: function () {
  70. // 在组件实例被从页面节点树移除时执行
  71. },
  72. attached: async function () {
  73. // 在组件实例进入页面节点树时执行
  74. // 计算
  75. const systemInfo = wx.getSystemInfoSync();
  76. const statusBarHeight = systemInfo.statusBarHeight || 0;
  77. const screenHeight = systemInfo.screenHeight || 0;
  78. const custom = wx.getMenuButtonBoundingClientRect();
  79. const customHeight = custom.height + 10 + 2 || 0;
  80. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  81. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  82. const contentHeight = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  83. this.setData({
  84. statusBarHeight,
  85. screenHeight,
  86. customHeight,
  87. bottomNavHeight,
  88. contentHeight,
  89. contentpadding
  90. });
  91. console.log('123', contentpadding);
  92. this.gettarget()
  93. this.order()
  94. this.Getlocation()
  95. },
  96. },
  97. /**
  98. * 组件的方法列表
  99. */
  100. methods: {
  101. //跳转
  102. gourl(e) {
  103. const url = e.currentTarget.dataset.url
  104. const active = e.currentTarget.dataset.active
  105. if (active) {
  106. wx.navigateTo({
  107. url: `${url}?id=` + active // 目标页面的路径
  108. });
  109. console.log(active);
  110. } else {
  111. wx.navigateTo({
  112. url: `${url}` // 目标页面的路径
  113. });
  114. }
  115. },
  116. async gettarget() {
  117. const currentUser = Parse.User.current();
  118. let userquery = new Parse.Query('_User');
  119. userquery.equalTo('company', company);
  120. userquery.equalTo('objectId', currentUser.id);
  121. userquery.notEqualTo('isDeleted', true)
  122. let user = await userquery.find();
  123. let num = user.map(item => item.toJSON());
  124. if (num[0].num) {
  125. this.setData({
  126. target: num[0].num
  127. })
  128. console.log('当前步数', this.data.target);
  129. } else {
  130. const currentUser2 = Parse.User.current();
  131. let userquery2 = new Parse.Query('_User');
  132. userquery2.equalTo('company', company);
  133. userquery2.equalTo('objectId', currentUser2.id);
  134. userquery2.notEqualTo('isDeleted', true)
  135. let user2 = await userquery2.first();
  136. user2.set('num', 5000)
  137. try {
  138. let saveDate2 = await user2.save();
  139. console.log(saveDate2);
  140. this.setData({
  141. target: 5000
  142. })
  143. console.log("目标步数更改成功");
  144. } catch (error) {
  145. console.error("保存数据时出现错误:", error);
  146. }
  147. }
  148. },
  149. //获取当天运动数据
  150. async order() {
  151. const currentUser = Parse.User.current();
  152. let ActivityDataquery = new Parse.Query('ActivityData');
  153. ActivityDataquery.equalTo('user', currentUser.id);
  154. ActivityDataquery.equalTo('company', company);
  155. ActivityDataquery.equalTo('type', 'today');
  156. ActivityDataquery.notEqualTo('isDeleted', true);
  157. // 获取今天的日期
  158. const today = new Date();
  159. const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // 今天的开始时间
  160. const todayEnd = new Date(todayStart);
  161. todayEnd.setHours(23, 59, 59, 999); // 今天的结束时间
  162. // 在查询条件中添加对 createdAt 的限制
  163. ActivityDataquery.greaterThanOrEqualTo('createdAt', todayStart);
  164. ActivityDataquery.lessThanOrEqualTo('createdAt', todayEnd);
  165. ActivityDataquery.include('user');
  166. let r = await ActivityDataquery.find();
  167. let sharList = r.map(item => item.toJSON());
  168. this.setData({
  169. sharList
  170. });
  171. console.log(this.data.sharList);
  172. },
  173. //获取当前位置信息
  174. Getlocation() {
  175. // 获取当前位置信息
  176. wx.getLocation({
  177. type: 'wgs84',
  178. success: (res) => {
  179. const {
  180. latitude,
  181. longitude
  182. } = res;
  183. //调用api解析地址
  184. wx.request({
  185. url: 'https://api.map.baidu.com/reverse_geocoding/v3/?ak=sHZTomd7grslfP7sPKB8tRgT49FK9TEu&output=json&coordtype=gcj02&location=' + latitude + ',' + longitude,
  186. data: {},
  187. header: {
  188. 'Content-Type': 'application/json'
  189. },
  190. success: (ops) => { // 使用箭头函数
  191. console.log(ops);
  192. const address = ops.data.result.formatted_address;
  193. this.setData({
  194. address: address,
  195. });
  196. console.log(this.data.address);
  197. },
  198. fail: function (resq) {
  199. wx.showModal({
  200. title: '信息提示',
  201. content: '请求失败',
  202. showCancel: false,
  203. confirmColor: '#f37938'
  204. });
  205. },
  206. complete: function () {}
  207. })
  208. },
  209. fail: (err) => {
  210. console.error(err);
  211. wx.showToast({
  212. title: '获取位置失败',
  213. icon: 'none'
  214. });
  215. }
  216. });
  217. },
  218. }
  219. })