邹能昇 3 gün önce
ebeveyn
işleme
279cb98d40

+ 73 - 11
nova-werun/pages/home/ranking/index.js

@@ -1,4 +1,6 @@
 // nova-werun/pages/home/ranking/index.js
+const Parse = getApp().Parse;
+const company = getApp().globalData.company;
 Page({
 
     /**
@@ -14,7 +16,10 @@ Page({
         contentHeight2: 0,
         contentpadding: 0, //顶部padding高度
         //
-        changetitle:'yundong'
+        changetitle:'today',
+        //本日排行
+        todayList:[],
+        myList:[]
     },
 
     /**
@@ -39,6 +44,7 @@ Page({
             contentpadding,
             contentHeight
         });
+        this.gettoday()
     },
 
     /**
@@ -89,16 +95,72 @@ Page({
     onShareAppMessage: function () {
 
     },
-    change(){
-        if(this.data.changetitle=='yundong'){
-            this.setData({
-                changetitle:'zhaijia'
-            })
-        }else{
+    change() {
+        // 使用数组来简化切换逻辑
+        const titles = ['today', 'weekdday', 'month'];
+        const currentIndex = titles.indexOf(this.data.changetitle);//获取index
+        const nextIndex = (currentIndex + 1) % titles.length; // 循环切换
+        this.setData({
+            changetitle: titles[nextIndex]
+        });
+        if(this.data.changetitle=='today'){
+            this.gettoday()
+        }
+        if(this.data.changetitle=='weekdday'){
+           console.log('weekdday');
+        }
+        if(this.data.changetitle=='month'){
+            console.log('month');
+         }
+    },
+    // 获取本日排行
+    async gettoday() {
+        const currentUser = Parse.User.current();
+        let ActivityDataquery = new Parse.Query('ActivityData');
+        ActivityDataquery.equalTo('company', company);
+        ActivityDataquery.equalTo('type', "today");
+        ActivityDataquery.notEqualTo('isDeleted', true);
+        
+        // 获取今天的日期
+        const today = new Date();
+        const todayStart = new Date(today.getFullYear(), today.getMonth(), today.getDate()); // 今天的开始时间
+        const todayEnd = new Date(todayStart);
+        todayEnd.setHours(23, 59, 59, 999); // 今天的结束时间
+    
+        // 在查询条件中添加对 createdAt 的限制
+        ActivityDataquery.greaterThanOrEqualTo('createdAt', todayStart);
+        ActivityDataquery.lessThanOrEqualTo('createdAt', todayEnd);
+        
+        // 根据 steps 字段进行降序排序
+        ActivityDataquery.descending('steps');
+        ActivityDataquery.include('user');
+    
+        try {
+            let P = await ActivityDataquery.find();
+            let todayList = P.map(item => item.toJSON());
+    
+            // 初始化 myList
+            let myList = [];
+            
+            // 找到当前用户的数据并计算排名
+            todayList.forEach((item, index) => {
+                if (item.user.objectId === currentUser.id) {
+                    myList.push({
+                        ...item, // 包含用户数据
+                        rank: index + 1 // 计算排名(index 从 0 开始,所以加 1)
+                    });
+                }
+            });
+    
+            // 更新页面数据
             this.setData({
-                changetitle:'yundong'
-            })
+                todayList,
+                myList
+            });
+    
+            console.log(this.data.todayList, this.data.myList);
+        } catch (error) {
+            console.error('Error fetching today\'s data:', error);
         }
-
-    }
+    },
 })

+ 10 - 0
nova-werun/pages/home/ranking/index.less

@@ -56,6 +56,16 @@
             border-radius: 10rpx;
             background-color: white;
             left: 7%;
+            .paiming{
+                width: 60rpx;
+                height: 60rpx;
+                margin-right: 10rpx;
+                font-size: 36rpx;
+                display: flex;
+                justify-content: center;
+                align-items: center;
+                color: red;
+            }
             image{
                 width: 60rpx;
                 height: 60rpx;

+ 13 - 12
nova-werun/pages/home/ranking/index.wxml

@@ -3,18 +3,19 @@
 <view class="all" style="height: {{contentHeight}}rpx;">
     <view class="textbox">
         <view class="textobx2">
-            <view class="text" wx:if="{{changetitle=='yundong'}}" >运动排行榜</view>
-            <view class="text" wx:if="{{changetitle=='zhaijia'}}" >宅家排行榜</view>
+            <view class="text" wx:if="{{changetitle=='today'}}" >本日排行榜</view>
+            <view class="text" wx:if="{{changetitle=='weekdday'}}" >本周排行榜</view>
+            <view class="text" wx:if="{{changetitle=='month'}}" >本月排行榜</view>
             <view class="switch" bindtap="change">
                 <image src="https://file-cloud.fmode.cn/qpFbRRSZrO/20241111/8ic78m043647360.png?imageView2/1/w/200/h/200"></image>
                 <view class="switch-text">切换</view>
             </view>
         </view>
         <view class="cardbox">
-            <image></image>
-            <image class="avarter" src="https://file-cloud.fmode.cn//tmp/sBX4tFxdGjkk1fea2c9db35cbd67b50b01dd3bae1592.png?imageView2/1/w/200/h/200"></image>
-            <view class="name">超级无敌暴龙战士</view>
-            <view class="num">20569步</view>
+            <view class="paiming" >{{myList[0].rank}}</view>
+            <image class="avarter" src="{{myList[0].user.avatar}}"></image>
+            <view class="name">{{myList[0].user.nickname}}</view>
+            <view class="num">{{myList[0].steps}}步</view>
             <view class="good">
                 <view class="good-num">77</view>
                 <van-icon name="good-job-o" />
@@ -22,13 +23,13 @@
         </view>
     </view>
     <view class="rankbox">
-        <block wx:for="{{10}}"> 
+        <block wx:for="{{todayList}}" wx:key="index"> 
             <view class="cardbox">
-                <image wx:if="{{item<3}}" src="https://file-cloud.fmode.cn/qpFbRRSZrO/20241111/je1q5i052857833.png?imageView2/1/w/200/h/200"></image>
-                <view class="paiming" wx:if="{{item>=3}}">{{item+1}}</view>
-                <image class="avarter" src="https://file-cloud.fmode.cn//tmp/sBX4tFxdGjkk1fea2c9db35cbd67b50b01dd3bae1592.png?imageView2/1/w/200/h/200"></image>
-                <view class="name">超级无敌暴龙战士</view>
-                <view class="num">20569步</view>
+                <image wx:if="{{index<3}}" src="https://file-cloud.fmode.cn/qpFbRRSZrO/20241111/je1q5i052857833.png?imageView2/1/w/200/h/200"></image>
+                <view class="paiming" wx:if="{{index>=3}}">{{index+1}}</view>
+                <image class="avarter" src="{{item.user.avatar}}"></image>
+                <view class="name">{{item.user.nickname}}</view>
+                <view class="num">{{item.steps}}步</view>
                 <view class="good">
                     <view class="good-num">77</view>
                     <van-icon name="good-job-o" />

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 0
nova-werun/pages/home/ranking/index.wxss


Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor