index.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  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. },
  66. lifetimes: {
  67. detached: function () {
  68. // 在组件实例被从页面节点树移除时执行
  69. },
  70. attached: async function () {
  71. // 在组件实例进入页面节点树时执行
  72. // 计算
  73. const systemInfo = wx.getSystemInfoSync();
  74. const statusBarHeight = systemInfo.statusBarHeight || 0;
  75. const screenHeight = systemInfo.screenHeight || 0;
  76. const custom = wx.getMenuButtonBoundingClientRect();
  77. const customHeight = custom.height + 10 + 2 || 0;
  78. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  79. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  80. const contentHeight = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  81. this.setData({
  82. statusBarHeight,
  83. screenHeight,
  84. customHeight,
  85. bottomNavHeight,
  86. contentHeight,
  87. contentpadding
  88. });
  89. console.log('123', contentpadding);
  90. this.gettarget()
  91. },
  92. },
  93. /**
  94. * 组件的方法列表
  95. */
  96. methods: {
  97. //跳转
  98. gourl(e) {
  99. const url = e.currentTarget.dataset.url
  100. const active = e.currentTarget.dataset.active
  101. if (active) {
  102. wx.navigateTo({
  103. url: `${url}?id=` + active // 目标页面的路径
  104. });
  105. console.log(active);
  106. } else {
  107. wx.navigateTo({
  108. url: `${url}` // 目标页面的路径
  109. });
  110. }
  111. },
  112. async gettarget() {
  113. const currentUser = Parse.User.current();
  114. let userquery = new Parse.Query('_User');
  115. userquery.equalTo('company', company);
  116. userquery.equalTo('objectId', currentUser.id);
  117. userquery.notEqualTo('isDeleted', true)
  118. let user = await userquery.find();
  119. let num = user.map(item => item.toJSON());
  120. if (num[0].num) {
  121. this.setData({
  122. target: num[0].num
  123. })
  124. console.log('当前步数',this.data.target);
  125. } else {
  126. const currentUser2 = Parse.User.current();
  127. let userquery2 = new Parse.Query('_User');
  128. userquery2.equalTo('company', company);
  129. userquery2.equalTo('objectId', currentUser2.id);
  130. userquery2.notEqualTo('isDeleted', true)
  131. let user2 = await userquery2.first();
  132. user2.set('num', 5000)
  133. try {
  134. let saveDate2 = await user2.save();
  135. console.log(saveDate2);
  136. this.setData({
  137. target: 5000
  138. })
  139. console.log("目标步数更改成功");
  140. } catch (error) {
  141. console.error("保存数据时出现错误:", error);
  142. }
  143. }
  144. },
  145. }
  146. })