浏览代码

home page

邹能昇 2 周之前
父节点
当前提交
bc245d6106

+ 50 - 1
nova-werun/components/home/index.js

@@ -67,7 +67,9 @@ Component({
             },
         ],
         target: 0,
-        sharList:[],
+        sharList: [],
+
+        address:"",
 
     },
     lifetimes: {
@@ -98,6 +100,7 @@ Component({
             console.log('123', contentpadding);
             this.gettarget()
             this.order()
+            this.Getlocation()
         },
     },
 
@@ -182,5 +185,51 @@ Component({
             });
             console.log(this.data.sharList);
         },
+        //获取当前位置信息
+        Getlocation() {
+            // 获取当前位置信息
+            wx.getLocation({
+                type: 'wgs84',
+                success: (res) => {
+                    const {
+                        latitude,
+                        longitude
+                    } = res;
+                    //调用api解析地址
+                    wx.request({
+                        url: 'https://api.map.baidu.com/reverse_geocoding/v3/?ak=sHZTomd7grslfP7sPKB8tRgT49FK9TEu&output=json&coordtype=gcj02&location=' + latitude + ',' + longitude,
+                        data: {},
+                        header: {
+                            'Content-Type': 'application/json'
+                        },
+                        success: (ops) => { // 使用箭头函数
+                            console.log(ops);
+                            const address = ops.data.result.formatted_address;
+                            this.setData({
+                                address: address,
+                            });
+                            console.log(this.data.address);
+                        },
+                        fail: function (resq) {
+                            wx.showModal({
+                                title: '信息提示',
+                                content: '请求失败',
+                                showCancel: false,
+                                confirmColor: '#f37938'
+                            });
+                        },
+                        complete: function () {}
+                    })
+
+                },
+                fail: (err) => {
+                    console.error(err);
+                    wx.showToast({
+                        title: '获取位置失败',
+                        icon: 'none'
+                    });
+                }
+            });
+        },
     }
 })

+ 6 - 0
nova-werun/components/home/index.less

@@ -17,6 +17,12 @@
             display: flex;
             margin-top: 16rpx;
             align-items: center;
+            .addressbox-text{
+                width: 80%;
+                white-space: nowrap;
+                overflow: hidden;
+                text-overflow: ellipsis;
+            }
         }
         .runbox{
             width: 350rpx;

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

@@ -5,7 +5,7 @@
     <view class="clockinbox">
         <view class="addressbox">
             <van-icon name="location-o" size='20px' />
-            <view>江西脑控科技有限公司</view>
+            <view class="addressbox-text">{{address}}</view>
         </view>
         <view class="runbox">
             <view class="run">

文件差异内容过多而无法显示
+ 0 - 0
nova-werun/components/home/index.wxss


部分文件因为文件数量过多而无法显示