|
@@ -28,7 +28,9 @@ Page({
|
|
|
|
|
|
uptokenURL: '',
|
|
|
domain: '',
|
|
|
- uploadURL: ''
|
|
|
+ uploadURL: '',
|
|
|
+
|
|
|
+ userList:[],
|
|
|
|
|
|
},
|
|
|
|
|
@@ -54,6 +56,7 @@ Page({
|
|
|
contentpadding,
|
|
|
contentHeight
|
|
|
});
|
|
|
+ this.getuser()
|
|
|
this.order()
|
|
|
this.showRandomImage()
|
|
|
},
|
|
@@ -110,49 +113,88 @@ Page({
|
|
|
async order() {
|
|
|
const currentUser = Parse.User.current();
|
|
|
let ActivityDataquery = new Parse.Query('ActivityData');
|
|
|
- // ActivityDataquery.equalTo('user', currentUser.id);
|
|
|
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); // 今天的结束时间
|
|
|
-
|
|
|
+ console.log(todayStart, todayEnd);
|
|
|
+
|
|
|
// 在查询条件中添加对 createdAt 的限制
|
|
|
ActivityDataquery.greaterThanOrEqualTo('createdAt', todayStart);
|
|
|
ActivityDataquery.lessThanOrEqualTo('createdAt', todayEnd);
|
|
|
- ActivityDataquery.include('user');
|
|
|
-
|
|
|
+
|
|
|
// 根据 steps 字段进行降序排序
|
|
|
- ActivityDataquery.descending('steps');
|
|
|
-
|
|
|
- let r = await ActivityDataquery.find();
|
|
|
- let todayList = r.map(item => {
|
|
|
- let itemData = item.toJSON();
|
|
|
- // 获取当前时间并格式化
|
|
|
- const now = new Date();
|
|
|
- const formattedTime = `${now.getFullYear()}/${String(now.getMonth() + 1).padStart(2, '0')}/${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
|
|
|
- itemData.currentTime = formattedTime; // 将当前时间添加到 item 中
|
|
|
- return itemData;
|
|
|
- });
|
|
|
- let sharList = []
|
|
|
- todayList.forEach((item, index) => {
|
|
|
- if (item.user.objectId == currentUser.id) {
|
|
|
- sharList.push({
|
|
|
- ...item, // 包含用户数据
|
|
|
- rank: index + 1 // 计算排名(index 从 0 开始,所以加 1)
|
|
|
- });
|
|
|
+ ActivityDataquery.include('user');
|
|
|
+
|
|
|
+ try {
|
|
|
+ let P = await ActivityDataquery.find();
|
|
|
+ let todayList = P.map(item => {
|
|
|
+ let itemData = item.toJSON();
|
|
|
+ // 获取当前时间并格式化
|
|
|
+ const now = new Date();
|
|
|
+ const formattedTime = `${now.getFullYear()}/${String(now.getMonth() + 1).padStart(2, '0')}/${String(now.getDate()).padStart(2, '0')} ${String(now.getHours()).padStart(2, '0')}:${String(now.getMinutes()).padStart(2, '0')}`;
|
|
|
+ itemData.currentTime = formattedTime; // 将当前时间添加到 item 中
|
|
|
+ return itemData;
|
|
|
+ });
|
|
|
+
|
|
|
+ // 创建一个对象来存储用户的总步数
|
|
|
+ const userStepsMap = {};
|
|
|
+
|
|
|
+ // 遍历数据,累加相同用户的步数
|
|
|
+ todayList.forEach(item => {
|
|
|
+ const userId = item.user.objectId;
|
|
|
+ const steps = item.steps;
|
|
|
+ const distance = item.distance||0;
|
|
|
+ if (steps) {
|
|
|
+ if (!userStepsMap[userId]) {
|
|
|
+ userStepsMap[userId] = {
|
|
|
+ ...item.user, // 包含用户信息
|
|
|
+ currentTime: item.currentTime,
|
|
|
+ totalSteps: 0, // 初始化总步数
|
|
|
+ totaldistance:0,
|
|
|
+ };
|
|
|
+ }
|
|
|
+ userStepsMap[userId].totalSteps += steps;
|
|
|
+ userStepsMap[userId].totaldistance += distance; // 累加步数
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ // 将对象转换为数组
|
|
|
+ const aggregatedList = Object.values(userStepsMap);
|
|
|
+
|
|
|
+ // 按总步数降序排序
|
|
|
+ aggregatedList.sort((a, b) => b.totalSteps - a.totalSteps);
|
|
|
+
|
|
|
+ // 添加排名
|
|
|
+ let currentRank = 1; // 当前排名
|
|
|
+ for (let i = 0; i < aggregatedList.length; i++) {
|
|
|
+ if (i > 0 && aggregatedList[i].totalSteps === aggregatedList[i - 1].totalSteps) {
|
|
|
+ // 如果步数相同,排名相同
|
|
|
+ aggregatedList[i].rank = aggregatedList[i - 1].rank;
|
|
|
+ } else {
|
|
|
+ // 否则,更新当前排名
|
|
|
+ aggregatedList[i].rank = currentRank;
|
|
|
+ }
|
|
|
+ currentRank++;
|
|
|
}
|
|
|
- })
|
|
|
-
|
|
|
- this.setData({
|
|
|
- sharList
|
|
|
- });
|
|
|
- this.saveImage()
|
|
|
- console.log(this.data.sharList);
|
|
|
+ console.log('aggregatedList',aggregatedList);
|
|
|
+ aggregatedList.forEach(item=>{
|
|
|
+ if(item.objectId == currentUser.id){
|
|
|
+ this.setData({
|
|
|
+ sharList:item,
|
|
|
+ });
|
|
|
+ console.log('sharList',this.data.sharList);
|
|
|
+ this.saveImage()
|
|
|
+ }
|
|
|
+ })
|
|
|
+
|
|
|
+ } catch (error) {
|
|
|
+ console.error('Error fetching today\'s data:', error);
|
|
|
+ }
|
|
|
},
|
|
|
//随机展示图片
|
|
|
showRandomImage: function () {
|
|
@@ -183,6 +225,20 @@ Page({
|
|
|
});
|
|
|
})
|
|
|
},
|
|
|
+ //获取用户信息
|
|
|
+ async getuser(){
|
|
|
+ const currentUser = Parse.User.current();
|
|
|
+ let user = new Parse.Query('_User');
|
|
|
+ user.equalTo('company', company);
|
|
|
+ user.notEqualTo('isDeleted', true);
|
|
|
+ user.equalTo('objectId', currentUser.id);
|
|
|
+ let P = await user.find();
|
|
|
+ let userList = P.map(item => item.toJSON());
|
|
|
+ this.setData({
|
|
|
+ userList,
|
|
|
+ })
|
|
|
+ console.log('userList',this.data.userList);
|
|
|
+ },
|
|
|
//rpx
|
|
|
async saveImage() {
|
|
|
// console.log('运行了');
|
|
@@ -241,11 +297,11 @@ Page({
|
|
|
}
|
|
|
|
|
|
// 绘制昵称和时间
|
|
|
- const nickname = this.data.sharList[0].user.nickname;
|
|
|
- const currentTime = this.data.sharList[0].currentTime;
|
|
|
- const rank = this.data.sharList[0].rank;
|
|
|
- const steps = this.data.sharList[0].steps || 0;
|
|
|
- const distance = this.data.sharList[0].distance || 0;
|
|
|
+ const nickname = this.data.userList[0].nickname;
|
|
|
+ const currentTime = this.data.sharList.currentTime;
|
|
|
+ const rank = this.data.sharList.rank;
|
|
|
+ const steps = this.data.sharList.totalSteps || 0;
|
|
|
+ const distance = this.data.sharList.totaldistance || 0;
|
|
|
|
|
|
canvas.setFontSize(this.rpxToPx(30));
|
|
|
canvas.fillText(nickname, this.rpxToPx(140), this.rpxToPx(580)); // 昵称位置
|