|
@@ -69,8 +69,7 @@ Component({
|
|
target: 0,
|
|
target: 0,
|
|
sharList: [],
|
|
sharList: [],
|
|
|
|
|
|
- address:"",
|
|
|
|
-
|
|
|
|
|
|
+ address: "",
|
|
},
|
|
},
|
|
lifetimes: {
|
|
lifetimes: {
|
|
|
|
|
|
@@ -98,9 +97,11 @@ Component({
|
|
contentpadding
|
|
contentpadding
|
|
});
|
|
});
|
|
console.log('123', contentpadding);
|
|
console.log('123', contentpadding);
|
|
|
|
+ this.getWeRunData()
|
|
this.gettarget()
|
|
this.gettarget()
|
|
- this.order()
|
|
|
|
- this.Getlocation()
|
|
|
|
|
|
+ // this.order()
|
|
|
|
+ this.Getlocation()
|
|
|
|
+
|
|
},
|
|
},
|
|
},
|
|
},
|
|
|
|
|
|
@@ -124,6 +125,7 @@ Component({
|
|
}
|
|
}
|
|
|
|
|
|
},
|
|
},
|
|
|
|
+ //获取目标步数
|
|
async gettarget() {
|
|
async gettarget() {
|
|
const currentUser = Parse.User.current();
|
|
const currentUser = Parse.User.current();
|
|
let userquery = new Parse.Query('_User');
|
|
let userquery = new Parse.Query('_User');
|
|
@@ -231,5 +233,112 @@ Component({
|
|
}
|
|
}
|
|
});
|
|
});
|
|
},
|
|
},
|
|
|
|
+ //获取微信步数
|
|
|
|
+ getWeRunData() {
|
|
|
|
+ wx.getWeRunData({
|
|
|
|
+ success: (res) => {
|
|
|
|
+ // 获取到的加密数据
|
|
|
|
+ const encryptedData = res.encryptedData;
|
|
|
|
+ const iv = res.iv;
|
|
|
|
+ // 这里需要调用你的后端接口进行解密
|
|
|
|
+ // 假设你有一个解密函数 decryptData
|
|
|
|
+ // this.decryptData(encryptedData, iv).then(steps => {
|
|
|
|
+ // this.setData({
|
|
|
|
+ // steps: `${steps}`
|
|
|
|
+ // });
|
|
|
|
+ // console.log('用户步数:', this.data.steps);
|
|
|
|
+ // }).catch(err => {
|
|
|
|
+ // console.error('解密失败:', err);
|
|
|
|
+ // });
|
|
|
|
+ const steps = this.decryptData(encryptedData, iv)
|
|
|
|
+ console.log(steps);
|
|
|
|
+ this.updatetoday(steps)
|
|
|
|
+ },
|
|
|
|
+ fail: (err) => {
|
|
|
|
+ console.error('获取运动数据失败:', err);
|
|
|
|
+ }
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ decryptData(encryptedData, iv) {
|
|
|
|
+ // return new Promise((resolve, reject) => {
|
|
|
|
+ // // 发送请求到后端进行解密
|
|
|
|
+ // wx.request({
|
|
|
|
+ // url: '', // 替换为你的后端解密接口
|
|
|
|
+ // method: 'POST',
|
|
|
|
+ // data: {
|
|
|
|
+ // encryptedData: encryptedData,
|
|
|
|
+ // iv: iv,
|
|
|
|
+ // // 需要传递 session_key,通常在用户登录时获取
|
|
|
|
+ // session_key: wx.getStorageSync('session_key') // 假设你已经存储了 session_key
|
|
|
|
+ // },
|
|
|
|
+ // success: (res) => {
|
|
|
|
+ // if (res.data && res.data.steps) {
|
|
|
|
+ // // resolve(res.data.steps); // 返回步数
|
|
|
|
+ // const steps = 123456
|
|
|
|
+ // resolve(steps);
|
|
|
|
+ // } else {
|
|
|
|
+ // reject('解密返回数据格式错误');
|
|
|
|
+ // }
|
|
|
|
+ // },
|
|
|
|
+ // fail: (err) => {
|
|
|
|
+ // reject(err);
|
|
|
|
+ // }
|
|
|
|
+ // });
|
|
|
|
+ // });
|
|
|
|
+ const steps = 323456
|
|
|
|
+ return steps
|
|
|
|
+ },
|
|
|
|
+ //更新今日步数
|
|
|
|
+ async updatetoday(steps) {
|
|
|
|
+ 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); // 今天的结束时间
|
|
|
|
+
|
|
|
|
+ // 在查询条件中添加对 createdAt 的限制
|
|
|
|
+ ActivityDataquery.greaterThanOrEqualTo('createdAt', todayStart);
|
|
|
|
+ ActivityDataquery.lessThanOrEqualTo('createdAt', todayEnd);
|
|
|
|
+
|
|
|
|
+ let r = await ActivityDataquery.first();
|
|
|
|
+ if (r) {
|
|
|
|
+ r.set('steps', steps)
|
|
|
|
+ try {
|
|
|
|
+ let saveDate = await r.save();
|
|
|
|
+ this.order()
|
|
|
|
+ console.log("步数修改成功");
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error("保存数据时出现错误:", error);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ const currentUser = Parse.User.current();
|
|
|
|
+ let userquery = new Parse.Query('_User');
|
|
|
|
+ userquery.equalTo('company', company);
|
|
|
|
+ userquery.equalTo('objectId', currentUser.id);
|
|
|
|
+ userquery.notEqualTo('isDeleted', true)
|
|
|
|
+ let user = await userquery.first();
|
|
|
|
+
|
|
|
|
+ let companyPointer = Parse.Object.extend('Company').createWithoutData(company);
|
|
|
|
+ let Comment = new Parse.Object('ActivityData');
|
|
|
|
+ Comment.set('company', companyPointer);
|
|
|
|
+ Comment.set('type', 'today');
|
|
|
|
+ Comment.set('user', user.toPointer());
|
|
|
|
+ Comment.set('steps', steps);
|
|
|
|
+ try {
|
|
|
|
+ let saveDate2 = await Comment.save();
|
|
|
|
+ this.order()
|
|
|
|
+ // console.log(saveDate2);
|
|
|
|
+ console.log("步数保存成功");
|
|
|
|
+ } catch (error) {
|
|
|
|
+ console.error("保存数据时出现错误:", error);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
})
|
|
})
|