邹能昇 hace 3 meses
padre
commit
b5f7382cf1
Se han modificado 1 ficheros con 38 adiciones y 23 borrados
  1. 38 23
      nova-werun/pages/home/statistics/index.js

+ 38 - 23
nova-werun/pages/home/statistics/index.js

@@ -43,18 +43,18 @@ Page({
         percent: '',
 
         //排名百分比
-        percebtage:0,
+        percebtage: 0,
         //
-        average:0,
-        totle:0,
+        average: 0,
+        totle: 0,
 
         //显示日历
-        minDate: new Date(2025, 0, 1).getTime(),
-        maxDate: new Date(2025, 0, 31).getTime(),
-        formatter(day) {        
-            day.topInfo = '11111'    
+        minDate: null,
+        maxDate: null,
+        formatter(day) {
+            day.topInfo = '11111'
             return day;
-          },
+        },
     },
 
     /**
@@ -159,17 +159,17 @@ Page({
             return dayOfMonth
         })
         daylist.reverse()
-        const dayindex = daylist.length-1
+        const dayindex = daylist.length - 1
         if (daylist.length < 7) {
             for (let i = daylist.length; i < 7; i++) {
                 const lastDay = daylist[daylist.length - 1];
                 daylist.push(lastDay + (i - daylist.length + 1)); // 补充后续日期
             }
         }
-        const dates =  daylist.map(item=>{
+        const dates = daylist.map(item => {
             return `${item}号`
         })
-        return index === dayindex ? '今天'+'\n' + '\n' + dates[index] : value + '\n' + '\n' + dates[index];
+        return index === dayindex ? '今天' + '\n' + '\n' + dates[index] : value + '\n' + '\n' + dates[index];
     },
     /**
      * 生命周期函数--监听页面初次渲染完成
@@ -233,6 +233,7 @@ Page({
             this.setData({
                 day: '30',
             })
+            this.gettodaydate()
         } else {
             this.setData({
                 day: '7'
@@ -410,12 +411,12 @@ Page({
         });
         stepsData.reverse()
         //总计,平均
-        let totle=0
-        for(let i = 0;i<resultList.length;i++){
-            totle=totle+ Number(resultList[i].steps)
+        let totle = 0
+        for (let i = 0; i < resultList.length; i++) {
+            totle = totle + Number(resultList[i].steps)
         }
-        const average = totle/resultList.length
-        console.log('totle',totle,average);
+        const average = totle / resultList.length
+        console.log('totle', totle, average);
         this.setData({
             resultList,
             stepsData,
@@ -450,24 +451,38 @@ Page({
         try {
             let P = await ActivityDataquery.find();
             let todayList = P.map(item => item.toJSON());
-            console.log('todayList',todayList);
+            console.log('todayList', todayList);
             let rank = 0
             // 更新页面数据
-            todayList.forEach((item,index)=>{
-                if(item.user.objectId==currentUser.id){
-                    rank = index+1;
+            todayList.forEach((item, index) => {
+                if (item.user.objectId == currentUser.id) {
+                    rank = index + 1;
                     return
                 }
             })
 
-            var ranper =100 - (rank/todayList.length)*100
+            var ranper = 100 - (rank / todayList.length) * 100
             ranper = parseFloat(ranper.toFixed(2));
             this.setData({
-                percebtage:ranper
+                percebtage: ranper
             })
-            console.log('percebtage',this.data.percebtage);
+            console.log('percebtage', this.data.percebtage);
         } catch (error) {
             console.error('Error fetching today\'s data:', error);
         }
     },
+    //获取当月第一天日期和最后一天日期
+    gettodaydate() {
+
+        // 获取今天的日期
+        const today = new Date();
+        // 获取当月第一天的日期
+        const startOfMonth = new Date(today.getFullYear(), today.getMonth(), 1).getTime();
+        // 获取当月最后一天的日期
+        const endOfMonth = new Date(today.getFullYear(), today.getMonth() + 1, 0).getTime();
+        this.setData({
+            minDate:startOfMonth,
+            maxDate:endOfMonth
+        })
+    }
 })