柒零 пре 1 година
родитељ
комит
e90749c762
2 измењених фајлова са 75 додато и 15 уклоњено
  1. 0 11
      app.js
  2. 75 4
      pages/index/index.js

+ 0 - 11
app.js

@@ -96,17 +96,6 @@ App({
   onShow() {
     wx.hideTabBar()
   },
-  handleStartupParams(options) {
-    if (options.scene === 1047 || options.scene === 1048) { // 扫码场景
-      const scene = decodeURIComponent(options.query.scene);
-      switch (scene) {
-        case 'page1':
-          wx.navigateTo({ url: '/pages/page1/page1' });
-          break;
-        // 添加更多页面
-      }
-    }
-  },
   onHide: function () {
     wx.setStorageSync('userName', '');
     wx.setStorageSync('isLogin', false);

+ 75 - 4
pages/index/index.js

@@ -14,6 +14,8 @@ Page({
     avatarUrl: defaultAvatarUrl,
     nickName: "用户登录",
     phoneNumber: "",
+    latitude: null,
+    longitude: null,
     menuCardList: [{
       icon: "../../static/index/icon/ic_fjkz.png",
       bgIcon: "../../static/index/bg/bg_fjkz.png",
@@ -87,10 +89,79 @@ Page({
     }]
 
   },
-  onCloseTipsDialog() { 
+  getLocation() {
+    const that = this;
+    var hasAuth = wx.getStorageSync("hasAuth");
+    if (!hasAuth) {
+      return
+    }
+    wx.getSetting({
+      success(res) {
+        if (res.authSetting['scope.userLocation']) {
+          // 用户已经授权  
+          wx.getLocation({
+            type: 'gcj02', // 返回可以用于wx.openLocation的经纬度  
+            success(locationRes) {
+              that.setData({
+                latitude: locationRes.latitude,
+                longitude: locationRes.longitude,
+              });
+              console.log('纬度:', locationRes.latitude);
+              console.log('经度:', locationRes.longitude);
+              that.savehotelnew();
+            },
+            fail(err) {
+              that.setData({
+                latitude: null,
+                longitude: null,
+                error: err.message
+              });
+              console.error('获取位置失败:', err.message);
+            }
+          });
+        } else {
+          // 用户未授权  
+          // wx.authorize({
+          //   scope: 'scope.userLocation',
+          //   success() {
+          //     // 用户同意授权后再次获取位置  
+          //     that.savehotelnew();
+          //   },
+          //   fail() {
+          //     // 用户拒绝授权  
+          //     that.setData({
+          //       latitude: null,
+          //       longitude: null,
+          //       error: '用户拒绝授权获取地理位置'
+          //     });
+          //     console.error('用户拒绝授权获取地理位置');
+          //   }
+          // });
+        }
+      }
+    });
+  },
+  savehotelnew() {
+    const that = this;
+    wx.request({
+      url: 'https://aipush.aidsleep.cn/savehotelnew',
+      method: 'POST',
+      data: {
+        token: "89835e65993fee4a6a6cbbe4c271da51e5521822934e13769e61cadabaed72c3" || wx.getStorageSync('token'),
+        unionid: wx.getStorageSync('unionid'),
+        longandlat: that.data.longitude + "|" + that.data.latitude
+      },
+      success: (res) => {
+
+      },
+      fail: () => {
+      }
+    });
+  },
+  onCloseTipsDialog() {
     this.setData({
       showTipsA: false,
-      showTipsB:false
+      showTipsB: false
     })
   },
   onMenuClick(e) {
@@ -156,7 +227,7 @@ Page({
             var hasHotelAuth = wx.getStorageSync("hasHotelAuth");
             if (!hasHotelAuth) {
               this.setData({
-                showTipsB:true
+                showTipsB: true
               })
               return
             }
@@ -230,8 +301,8 @@ Page({
    * 生命周期函数--监听页面初次渲染完成
    */
   onReady() {
-
     wx.hideTabBar()
+    this.getLocation();
   },
 
   /**