index.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. // nova-werun/components/home/index.js
  2. const Parse = getApp().Parse;
  3. const company = getApp().globalData.company;
  4. let getSportData = require('../../service/getSportData')
  5. const uid = Parse.User.current()?.id
  6. Component({
  7. /**
  8. * 组件的属性列表
  9. */
  10. properties: {
  11. },
  12. /**
  13. * 组件的初始数据
  14. */
  15. data: {
  16. //屏幕高度
  17. statusBarHeight: 0, // 状态栏高度
  18. screenHeight: 0, // 屏幕高度
  19. customHeight: 0, // 自定义导航栏高度(如小程序右上角胶囊按钮)
  20. bottomNavHeight: 0, // 底部导航栏高度
  21. contentHeight: 0, // 可用内容高度
  22. contentpadding: 0, //顶部padding高度
  23. navheight: 0,
  24. percentage: 0,
  25. //选择
  26. rows: [{
  27. image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241225/r5j1uc041211788.png',
  28. text: '签到打卡',
  29. url: '../../pages/home/signin/index'
  30. },
  31. {
  32. image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241225/n1pin1040819673.png',
  33. text: '实时步行',
  34. url: '../../pages/home/sport/sport-home/index',
  35. },
  36. {
  37. image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241225/9vfr1l040831635.png',
  38. text: '转发分享',
  39. url: '../../pages/home/share/index'
  40. },
  41. {
  42. image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241225/it1rna040843179.png',
  43. text: '我的勋章',
  44. url: '../../pages/home/medal/index'
  45. },
  46. {
  47. image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241225/r5193r040853498.png',
  48. text: '我的统计',
  49. url: '../../pages/home/statistics/index'
  50. },
  51. // {
  52. // image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/v6p4fm041343296.png?imageView2/1/w/200/h/200',
  53. // text: '排行榜',
  54. // url: '../../pages/home/ranking/index'
  55. // },
  56. // {
  57. // image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/71svpg041343669.png?imageView2/1/w/200/h/200',
  58. // text: '跑步',
  59. // url: '../../pages/home/sport/sport-home/index',
  60. // active: 1
  61. // },
  62. // {
  63. // image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241104/k1q4no034958681.png?imageView2/1/w/200/h/200',
  64. // text: '积分',
  65. // url: '../../pages/home/integral/index'
  66. // },
  67. ],
  68. target: 0,
  69. sharList: [],
  70. address: "",
  71. //排行榜
  72. todayList: [],
  73. changetitle: 0,
  74. changetitleMap: {
  75. 0: '历史',
  76. 'today': '本日',
  77. 'toweek': '本周',
  78. 'tomonth': '本月',
  79. },
  80. steps: 0,
  81. //正序
  82. rank: 'DESC',
  83. meContinuousChick: 0, //当前用户连续打卡数
  84. },
  85. lifetimes: {
  86. detached: function () {
  87. // 在组件实例被从页面节点树移除时执行
  88. },
  89. attached: async function () {
  90. // getSportData.setEndSport("NwzxcVxCV1")
  91. // 在组件实例进入页面节点树时执行
  92. // 计算
  93. const systemInfo = wx.getSystemInfoSync();
  94. const statusBarHeight = systemInfo.statusBarHeight || 0;
  95. const screenHeight = systemInfo.screenHeight || 0;
  96. const custom = wx.getMenuButtonBoundingClientRect();
  97. const customHeight = custom.height + 10 + 2 || 0;
  98. const bottomNavHeight = systemInfo.screenHeight - systemInfo.safeArea.bottom || 0;
  99. const contentpadding = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  100. const contentHeight = (screenHeight - bottomNavHeight - 50 - statusBarHeight - customHeight) * 750 / systemInfo.windowWidth;
  101. const navheight = (statusBarHeight + customHeight) * 750 / systemInfo.windowWidth;
  102. this.setData({
  103. statusBarHeight,
  104. screenHeight: (screenHeight - 50 - bottomNavHeight) * 750 / systemInfo.windowWidth,
  105. customHeight,
  106. bottomNavHeight,
  107. contentHeight,
  108. contentpadding,
  109. navheight,
  110. });
  111. this.Getlocation()
  112. this.refersh()
  113. },
  114. },
  115. /**
  116. * 组件的方法列表
  117. */
  118. methods: {
  119. async refersh() {
  120. await this.gettarget()
  121. this.order()
  122. this.gettoday()
  123. this.getMeChick()
  124. },
  125. /**当前用户连续打卡数 */
  126. async getMeChick() {
  127. let meContinuousChick = await getSportData.getContinuousCount(uid, 'ActivityData') || 0
  128. this.setData({
  129. meContinuousChick
  130. })
  131. },
  132. //跳转
  133. gourl(e) {
  134. const url = e.currentTarget.dataset.url
  135. const active = e.currentTarget.dataset.active
  136. if (active) {
  137. wx.navigateTo({
  138. url: `${url}?id=` + active // 目标页面的路径
  139. });
  140. console.log(active);
  141. } else {
  142. wx.navigateTo({
  143. url: `${url}` // 目标页面的路径
  144. });
  145. }
  146. },
  147. //获取目标步数
  148. async gettarget() {
  149. const currentUser = Parse.User.current();
  150. let userquery = new Parse.Query('_User');
  151. userquery.equalTo('company', company);
  152. userquery.equalTo('objectId', currentUser?.id);
  153. userquery.notEqualTo('isDeleted', true)
  154. let user = await userquery.first();
  155. let num = user?.toJSON()
  156. if (num?.num) {
  157. this.setData({
  158. target: num?.num
  159. })
  160. console.log('当前步数', this.data.target);
  161. } else {
  162. const currentUser2 = Parse.User.current();
  163. let userquery2 = new Parse.Query('_User');
  164. userquery2.equalTo('company', company);
  165. userquery2.equalTo('objectId', currentUser2?.id);
  166. userquery2.notEqualTo('isDeleted', true)
  167. let user2 = await userquery2.first();
  168. user2.set('num', 5000)
  169. try {
  170. let saveDate2 = await user2.save();
  171. console.log(saveDate2);
  172. this.setData({
  173. target: 5000
  174. })
  175. console.log("目标步数更改成功");
  176. } catch (error) {
  177. console.error("保存数据时出现错误:", error);
  178. }
  179. }
  180. },
  181. /** 获取当天运动数据*/
  182. async order() {
  183. let steps = await getSportData.getwalk('steps')
  184. this.setData({
  185. steps,
  186. })
  187. this.getBackgroundColor()
  188. // console.log('sharList', steps);
  189. },
  190. /** 修改进度条*/
  191. getBackgroundColor() {
  192. console.log(this.data.steps, this.data.target)
  193. let percentage = (this.data.steps / this.data.target) * 100;
  194. if (percentage > 100) {
  195. percentage = 100;
  196. }
  197. this.setData({
  198. percentage: `conic-gradient(from 0deg, #015EEA ${percentage}%, white 0%)`,
  199. })
  200. console.log('百分比', this.data.percentage);
  201. },
  202. /** 获取当前位置信息*/
  203. Getlocation() {
  204. // 获取当前位置信息
  205. wx.getLocation({
  206. type: 'wgs84',
  207. success: (res) => {
  208. const {
  209. latitude,
  210. longitude
  211. } = res;
  212. //调用api解析地址
  213. wx.request({
  214. url: 'https://api.map.baidu.com/reverse_geocoding/v3/?ak=sHZTomd7grslfP7sPKB8tRgT49FK9TEu&output=json&coordtype=gcj02&location=' + latitude + ',' + longitude,
  215. data: {},
  216. header: {
  217. 'Content-Type': 'application/json'
  218. },
  219. success: (ops) => { // 使用箭头函数
  220. console.log(ops);
  221. // const address = ops.data.result.formatted_address;//详细地址
  222. const address = ops.data.result.addressComponent.city; //市
  223. this.setData({
  224. address: address,
  225. });
  226. console.log(this.data.address);
  227. },
  228. fail: function (resq) {
  229. wx.showModal({
  230. title: '信息提示',
  231. content: '请求失败',
  232. showCancel: false,
  233. confirmColor: '#f37938'
  234. });
  235. },
  236. complete: function () {}
  237. })
  238. },
  239. fail: (err) => {
  240. console.error(err);
  241. wx.showToast({
  242. title: '获取位置失败',
  243. icon: 'none'
  244. });
  245. }
  246. });
  247. },
  248. /** 切换 历史/本日/本周/本月*/
  249. change() {
  250. // 使用数组来简化切换逻辑
  251. const titles = [0, 'today', 'toweek', 'tomonth'];
  252. const currentIndex = titles.indexOf(this.data.changetitle); //获取index
  253. const nextIndex = (currentIndex + 1) % titles.length; // 循环切换
  254. this.setData({
  255. changetitle: titles[nextIndex]
  256. });
  257. this.gettoday()
  258. },
  259. /**获取排行榜 */
  260. async gettoday() {
  261. let {
  262. rank,
  263. changetitle
  264. } = this.data
  265. let data = await getSportData.getRanking('', changetitle, '', '', rank)
  266. let todayList = []
  267. for (let i in data) {
  268. let obj = data[i]
  269. obj.count = await getSportData.getChickCount(obj.user, 'ActivityData')
  270. todayList.push(obj)
  271. }
  272. this.setData({
  273. todayList
  274. });
  275. },
  276. /** 正序逆序*/
  277. async changeup() {
  278. if (this.data.rank == 'DESC') {
  279. await this.setData({
  280. rank: 'ASC'
  281. })
  282. } else {
  283. await this.setData({
  284. rank: 'DESC'
  285. })
  286. }
  287. this.gettoday()
  288. },
  289. }
  290. })