|
@@ -42,6 +42,9 @@ Page({
|
|
|
distance: 0,
|
|
|
calorie: 0,
|
|
|
pace: 0,
|
|
|
+
|
|
|
+ //
|
|
|
+ activitdateid: '',
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -76,6 +79,8 @@ Page({
|
|
|
await this.Getlocation();
|
|
|
//开启后台定位
|
|
|
this.startbackgroumd()
|
|
|
+ //创建开始数据
|
|
|
+ this.startdate()
|
|
|
},
|
|
|
|
|
|
/**
|
|
@@ -235,6 +240,8 @@ Page({
|
|
|
icon: 'success',
|
|
|
duration: 500
|
|
|
});
|
|
|
+ this.enddate() //结束数据
|
|
|
+ this.endActivitydate()
|
|
|
setTimeout(() => {
|
|
|
this.onConfirm()
|
|
|
}, 500)
|
|
@@ -287,6 +294,7 @@ Page({
|
|
|
wx.navigateBack({
|
|
|
delta: 1 // 返回的页面层数,1 表示返回上一页
|
|
|
});
|
|
|
+ this.stopBackgroundLocation()// 停止后台定位和位置监听
|
|
|
},
|
|
|
//开始计时或继续计时
|
|
|
startTimer: function () {
|
|
@@ -308,6 +316,8 @@ Page({
|
|
|
// 这里可以处理位置变化的逻辑
|
|
|
console.log('位置已更新:', res);
|
|
|
});
|
|
|
+ that.progressdate()
|
|
|
+ that.progressActivitydate()
|
|
|
}, 1000);
|
|
|
|
|
|
this.setData({
|
|
@@ -346,7 +356,6 @@ Page({
|
|
|
// 这里需要调用你的后端接口进行解密
|
|
|
// 假设你有一个解密函数 decryptData
|
|
|
this.decryptData(encryptedData, iv, session_key).then(async steps => {
|
|
|
- await this.progressdate(steps)
|
|
|
console.log('再次赋值');
|
|
|
await this.setData({
|
|
|
startsteps: steps,
|
|
@@ -373,7 +382,6 @@ Page({
|
|
|
// 这里需要调用你的后端接口进行解密
|
|
|
// 假设你有一个解密函数 decryptData
|
|
|
this.decryptData(encryptedData, iv, session_key).then(async steps => {
|
|
|
- await this.progressdate(steps)
|
|
|
console.log('再次赋值');
|
|
|
await this.setData({
|
|
|
steps: steps,
|
|
@@ -439,32 +447,6 @@ Page({
|
|
|
date.getMonth() === today.getMonth() &&
|
|
|
date.getDate() === today.getDate();
|
|
|
},
|
|
|
- //创建过程数据
|
|
|
- async progressdate(steps) {
|
|
|
- if (steps == this.data.steps) {
|
|
|
- console.log('步数没变');
|
|
|
- return
|
|
|
- }
|
|
|
- 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 query = new Parse.Object('ActivityRunLog');
|
|
|
- query.set('user', user.toPointer())
|
|
|
- query.set('company', companyPointer)
|
|
|
- query.set('stage', 'progress ')
|
|
|
- query.set('steps', this.data.steps)
|
|
|
- try {
|
|
|
- // let saveDate2 = await Comment.save();
|
|
|
- console.log("新数据保存成功");
|
|
|
- } catch (error) {
|
|
|
- console.error("保存数据时出现错误:", error);
|
|
|
- }
|
|
|
- },
|
|
|
// 开启后台定位
|
|
|
startbackgroumd() {
|
|
|
wx.startLocationUpdateBackground({
|
|
@@ -596,7 +578,179 @@ Page({
|
|
|
console.log('卡路里为', Calorie);
|
|
|
return parseFloat(Calorie.toFixed(2)); // 保留两位小数并转换为数字
|
|
|
|
|
|
- }
|
|
|
+ },
|
|
|
+ //创建开始数据
|
|
|
+ async startdate() {
|
|
|
+ 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 query = new Parse.Object('ActivityRunLog');
|
|
|
+ query.set('user', user.toPointer())
|
|
|
+ query.set('company', companyPointer)
|
|
|
+ query.set('stage', 'start ')
|
|
|
+ query.set('steps', 0) //步数
|
|
|
+ query.set('distance', 0) //距离
|
|
|
+ query.set('matchSpeed', 0) //配速
|
|
|
+ query.set('sportDate', 0) //运动时间
|
|
|
+ query.set('burnCalories', 0) //卡路里
|
|
|
+ try {
|
|
|
+ let saveDate2 = await query.save();
|
|
|
+ console.log(saveDate2);
|
|
|
+ const id = saveDate2.id
|
|
|
+ await this.startActivitdate(id)
|
|
|
+ console.log("新数据保存成功");
|
|
|
+ } catch (error) {
|
|
|
+ console.error("保存数据时出现错误:", error);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //创建ActivityData数据
|
|
|
+ async startActivitdate(objectId) {
|
|
|
+ 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 Activitdate = new Parse.Query('ActivityRunLog');
|
|
|
+ Activitdate.equalTo('objectId', objectId);
|
|
|
+ Activitdate.notEqualTo('isDeleted', true)
|
|
|
+ let Activit = await Activitdate.first();
|
|
|
|
|
|
+ let companyPointer = Parse.Object.extend('Company').createWithoutData(company);
|
|
|
+ let query = new Parse.Object('ActivityData');
|
|
|
+ query.set('user', user.toPointer())
|
|
|
+ query.set('company', companyPointer)
|
|
|
+ query.set('runlog', Activit.toPointer())
|
|
|
+ try {
|
|
|
+ let saveDate2 = await query.save();
|
|
|
+ this.setData({
|
|
|
+ activitdateid: saveDate2.id
|
|
|
+ })
|
|
|
+ console.log("ActivityData数据", this.data.activitdate);
|
|
|
+ } catch (error) {
|
|
|
+ console.error("保存数据时出现错误:", error);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //创建过程数据
|
|
|
+ async progressdate() {
|
|
|
+ if (this.data.totalSeconds % 4 != 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ 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 query = new Parse.Object('ActivityRunLog');
|
|
|
+ query.set('user', user.toPointer())
|
|
|
+ query.set('company', companyPointer)
|
|
|
+ query.set('stage', 'progress ')
|
|
|
+ query.set('steps', this.data.defferentstep) //步数
|
|
|
+ query.set('distance', this.data.distance) //距离
|
|
|
+ query.set('matchSpeed', this.data.pace) //配速
|
|
|
+ query.set('sportDate', this.data.totalSeconds) //运动时间
|
|
|
+ query.set('burnCalories', this.data.calorie) //卡路里
|
|
|
+ try {
|
|
|
+ console.log('上传成功', this.data.defferentstep, this.data.distance, this.data.pace, this.data.totalSeconds, this.data.calorie);
|
|
|
+ let saveDate2 = await query.save();
|
|
|
+ console.log("新数据保存成功");
|
|
|
+ } catch (error) {
|
|
|
+ console.error("保存数据时出现错误:", error);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //上传ActivityData过程数据
|
|
|
+ async progressActivitydate() {
|
|
|
+ if (this.data.totalSeconds % 4 != 0) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let query = new Parse.Query('ActivityData');
|
|
|
+ query.equalTo('objectId', this.data.activitdateid);
|
|
|
+ query.notEqualTo('isDeleted', true)
|
|
|
+ let Activit = await query.first();
|
|
|
+ console.log('Activit',Activit);
|
|
|
+ if (Activit) {
|
|
|
+ Activit.set('steps', this.data.defferentstep) //步数
|
|
|
+ Activit.set('distance', this.data.distance) //距离
|
|
|
+ Activit.set('matchSpeed', this.data.pace) //配速
|
|
|
+ Activit.set('sportDate', this.data.totalSeconds) //运动时间
|
|
|
+ Activit.set('burnCalories', this.data.calorie) //卡路里
|
|
|
+ try {
|
|
|
+ let saveDate2 = await Activit.save();
|
|
|
+ console.log("ActivityData过程数据数据");
|
|
|
+ } catch (error) {
|
|
|
+ console.error("保存数据时出现错误:", error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ //创建结束数据
|
|
|
+ async enddate() {
|
|
|
+ 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 query = new Parse.Object('ActivityRunLog');
|
|
|
+ query.set('user', user.toPointer())
|
|
|
+ query.set('company', companyPointer)
|
|
|
+ query.set('stage', 'end ')
|
|
|
+ query.set('steps', this.data.defferentstep) //步数
|
|
|
+ query.set('distance', this.data.distance) //距离
|
|
|
+ query.set('matchSpeed', this.data.pace) //配速
|
|
|
+ query.set('sportDate', this.data.totalSeconds) //运动时间
|
|
|
+ query.set('burnCalories', this.data.calorie) //卡路里
|
|
|
+ try {
|
|
|
+ console.log('上传成功', this.data.defferentstep, this.data.distance, this.data.pace, this.data.totalSeconds, this.data.calorie);
|
|
|
+ let saveDate2 = await query.save();
|
|
|
+ console.log("新数据保存成功");
|
|
|
+ } catch (error) {
|
|
|
+ console.error("保存数据时出现错误:", error);
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //上传ActivityData结束数据
|
|
|
+ async endActivitydate() {
|
|
|
+ let query = new Parse.Query('ActivityData');
|
|
|
+ query.equalTo('objectId', this.data.activitdateid);
|
|
|
+ query.notEqualTo('isDeleted', true)
|
|
|
+ let Activit = await query.first();
|
|
|
+ if (Activit) {
|
|
|
+ Activit.set('steps', this.data.defferentstep) //步数
|
|
|
+ Activit.set('distance', this.data.distance) //距离
|
|
|
+ Activit.set('matchSpeed', this.data.pace) //配速
|
|
|
+ Activit.set('sportDate', this.data.totalSeconds) //运动时间
|
|
|
+ Activit.set('burnCalories', this.data.calorie) //卡路里
|
|
|
+ try {
|
|
|
+ let saveDate2 = await Activit.save();
|
|
|
+ console.log("ActivityData结束数据数据");
|
|
|
+ } catch (error) {
|
|
|
+ console.error("保存数据时出现错误:", error);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ },
|
|
|
+ // 停止后台定位和位置监听
|
|
|
+ stopBackgroundLocation() {
|
|
|
+ wx.stopLocationUpdate({
|
|
|
+ success: (res) => {
|
|
|
+ console.log('后台定位已停止');
|
|
|
+ },
|
|
|
+ fail: (res) => {
|
|
|
+ console.error('停止后台定位失败', res);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ wx.offLocationChange(); // 停止监听位置变化
|
|
|
+ },
|
|
|
|
|
|
})
|