邹能昇 il y a 3 mois
Parent
commit
3ecf402c7a

+ 45 - 7
nova-werun/components/home/index.js

@@ -1,4 +1,6 @@
 // nova-werun/components/home/index.js
+const Parse = getApp().Parse;
+const company = getApp().globalData.company;
 Component({
     /**
      * 组件的属性列表
@@ -33,7 +35,7 @@ Component({
                 image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/mcu488041343362.png?imageView2/1/w/200/h/200',
                 text: '转发分享',
                 url: '../../pages/home/share/index'
-                
+
             },
             {
                 image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/pqln61041343428.png?imageView2/1/w/200/h/200',
@@ -44,14 +46,14 @@ Component({
                 image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/9crt85041343498.png?imageView2/1/w/200/h/200',
                 text: '步行',
                 url: '../../pages/home/sport/sport-home/index',
-               
+
             },
 
             {
                 image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/71svpg041343669.png?imageView2/1/w/200/h/200',
                 text: '跑步',
                 url: '../../pages/home/sport/sport-home/index',
-                active:1
+                active: 1
             },
             {
                 image: 'https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/uk13u1041343733.png?imageView2/1/w/200/h/200',
@@ -63,7 +65,9 @@ Component({
                 text: '积分',
                 url: '../../pages/home/integral/index'
             },
-        ]
+        ],
+        target: 0
+
     },
     lifetimes: {
 
@@ -91,6 +95,7 @@ Component({
                 contentpadding
             });
             console.log('123', contentpadding);
+            this.gettarget()
         },
     },
 
@@ -102,17 +107,50 @@ Component({
         gourl(e) {
             const url = e.currentTarget.dataset.url
             const active = e.currentTarget.dataset.active
-            if(active){
+            if (active) {
                 wx.navigateTo({
-                    url: `${url}?id=`+active // 目标页面的路径
+                    url: `${url}?id=` + active // 目标页面的路径
                 });
                 console.log(active);
-            }else{
+            } else {
                 wx.navigateTo({
                     url: `${url}` // 目标页面的路径
                 });
             }
 
         },
+        async gettarget() {
+            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.find();
+            let num = user.map(item => item.toJSON());
+            if (num[0].num) {
+                this.setData({
+                    target: num[0].num
+                })
+                console.log('当前步数',this.data.target);
+            } else {
+                const currentUser2 = Parse.User.current();
+                let userquery2 = new Parse.Query('_User');
+                userquery2.equalTo('company', company);
+                userquery2.equalTo('objectId', currentUser2.id);
+                userquery2.notEqualTo('isDeleted', true)
+                let user2 = await userquery2.first();
+                user2.set('num', 5000)
+                try {
+                    let saveDate2 = await user2.save();
+                    console.log(saveDate2);
+                    this.setData({
+                        target: 5000
+                    })
+                    console.log("目标步数更改成功");
+                } catch (error) {
+                    console.error("保存数据时出现错误:", error);
+                }
+            }
+        },
     }
 })

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

@@ -13,7 +13,7 @@
                 <view class="step-num">18000</view>
                 <view class="objective">
                     <image src="https://file-cloud.fmode.cn/qpFbRRSZrO/20241102/q12pc1114226514.png?imageView2/1/w/200/h/200" alt="" />
-                    <view class="ob-num">目标:200000</view>
+                    <view class="ob-num">目标:{{target}}</view>
                 </view>
             </view>
         </view>

+ 2 - 1
nova-werun/pages/home/share/index.js

@@ -86,5 +86,6 @@ Page({
      */
     onShareAppMessage: function () {
 
-    }
+    },
+    
 })