Browse Source

home page

邹能昇 1 week ago
parent
commit
f2eb5cb79b

+ 113 - 4
nova-werun/components/home/index.js

@@ -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);
+                }
+            }
+        }
     }
     }
 })
 })

+ 1 - 1
nova-werun/components/home/index.wxml

@@ -10,7 +10,7 @@
         <view class="runbox">
         <view class="runbox">
             <view class="run">
             <view class="run">
                 <view class="tody-steps">今日步数</view>
                 <view class="tody-steps">今日步数</view>
-                <view class="step-num">{{sharList[0].steps}}</view>
+                <view class="step-num">{{sharList[0].steps||0}}</view>
                 <view class="objective">
                 <view class="objective">
                     <image src="https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/q12pc1114226514.png?imageView2/1/w/200/h/200" alt="" />
                     <image src="https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/q12pc1114226514.png?imageView2/1/w/200/h/200" alt="" />
                     <view class="ob-num">目标:{{target}}</view>
                     <view class="ob-num">目标:{{target}}</view>

+ 2 - 2
nova-werun/pages/home/share/index.wxml

@@ -19,12 +19,12 @@
             </view>
             </view>
             <view class="num-tex">
             <view class="num-tex">
                 <view class="nu-nam">今日步数</view>
                 <view class="nu-nam">今日步数</view>
-                <view class="num">{{sharList[0].steps}}</view>
+                <view class="num">{{sharList[0].steps||0}}</view>
             </view>
             </view>
             <view class="num-tex">
             <view class="num-tex">
                 <view class="nu-nam">公里数</view>
                 <view class="nu-nam">公里数</view>
                 <view class="num">
                 <view class="num">
-                    <view class="num-num">{{sharList[0].distance}}</view>
+                    <view class="num-num">{{sharList[0].distance||0}}</view>
                     <view class="num-km">km</view>
                     <view class="num-km">km</view>
                 </view>
                 </view>
             </view>
             </view>

+ 9 - 9
nova-werun/pages/home/statistics/index.wxml

@@ -3,7 +3,7 @@
 <view class="all" style="height: {{contentHeight}}rpx;" wx:if="{{active==0}}">
 <view class="all" style="height: {{contentHeight}}rpx;" wx:if="{{active==0}}">
     <view class="number">
     <view class="number">
         <view class="num">
         <view class="num">
-            <view class="num-num">{{sharList[0].burnCalories}}</view>
+            <view class="num-num">{{sharList[0].burnCalories||0}}</view>
             <view class="num-text">
             <view class="num-text">
                 <image src="https://file-cloud.fmode.cn/qpFbRRSZrO/20241113/f1p6rn032449318.png?imageView2/1/w/200/h/200"></image>
                 <image src="https://file-cloud.fmode.cn/qpFbRRSZrO/20241113/f1p6rn032449318.png?imageView2/1/w/200/h/200"></image>
                 卡路里
                 卡路里
@@ -11,7 +11,7 @@
         </view>
         </view>
         <view class="num">
         <view class="num">
             <view class="num-num">
             <view class="num-num">
-                {{sharList[0].sportDate}}
+                {{sharList[0].sportDate||0}}
                 <view class="numtext">分钟</view>
                 <view class="numtext">分钟</view>
             </view>
             </view>
             <view class="num-text">
             <view class="num-text">
@@ -20,7 +20,7 @@
             </view>
             </view>
         </view>
         </view>
         <view class="num">
         <view class="num">
-            <view class="num-num">{{sharList[0].distance}}</view>
+            <view class="num-num">{{sharList[0].distance||0}}</view>
             <view class="num-text">
             <view class="num-text">
                 <image src="https://file-cloud.fmode.cn/qpFbRRSZrO/20241113/i12ut1032603507.png?imageView2/1/w/200/h/200"></image>
                 <image src="https://file-cloud.fmode.cn/qpFbRRSZrO/20241113/i12ut1032603507.png?imageView2/1/w/200/h/200"></image>
                 公里
                 公里
@@ -59,22 +59,22 @@
             <view>|</view>
             <view>|</view>
             生涯合计
             生涯合计
         </view>
         </view>
-        <view class="card1-in">自{{stardate}}开始,共{{daysDifference}}天,您走了</view>
+        <view class="card1-in">自{{stardate||0}}开始,共{{daysDifference||0}}天,您走了</view>
         <view class="card1-card">
         <view class="card1-card">
-            <view class="card1card-number">{{totalSteps}}</view>
+            <view class="card1card-number">{{totalSteps||0}}</view>
             <view class="card1card-text">步,相当于</view>
             <view class="card1card-text">步,相当于</view>
         </view>
         </view>
         <view class="card1-card2">
         <view class="card1-card2">
             <view class="card1-c2c">
             <view class="card1-c2c">
-                <view class="card1-c2cnum">{{totalBurnCalories}}</view>
+                <view class="card1-c2cnum">{{totalBurnCalories||0}}</view>
                 <view class="card1-c2ctex">卡路里</view>
                 <view class="card1-c2ctex">卡路里</view>
             </view>
             </view>
             <view class="card1-c2c">
             <view class="card1-c2c">
-                <view class="card1-c2cnum">{{totalsportDate}}</view>
+                <view class="card1-c2cnum">{{totalsportDate||0}}</view>
                 <view class="card1-c2ctex">时间</view>
                 <view class="card1-c2ctex">时间</view>
             </view>
             </view>
             <view class="card1-c2c">
             <view class="card1-c2c">
-                <view class="card1-c2cnum">{{totalDistance}}</view>
+                <view class="card1-c2cnum">{{totalDistance||0}}</view>
                 <view class="card1-c2ctex">公里</view>
                 <view class="card1-c2ctex">公里</view>
             </view>
             </view>
 
 
@@ -86,7 +86,7 @@
                 <view>|</view>
                 <view>|</view>
                 生涯合计
                 生涯合计
             </view>
             </view>
-            <view class="card2-title2">今日{{sharList[0].steps}}步</view>
+            <view class="card2-title2">今日{{sharList[0].steps||0}}步</view>
         </view>
         </view>
         <view class="card2-bottom">
         <view class="card2-bottom">
             <view class="card2-bottom1">今日步数已超过</view>
             <view class="card2-bottom1">今日步数已超过</view>