From 440b4ab9d4278d3f9c13b004d2c2289f45254cbc Mon Sep 17 00:00:00 2001
From: Liuyi <candymxq888@outlook.com>
Date: 星期二, 19 十一月 2024 17:29:06 +0800
Subject: [PATCH] 添加积分记录,修改位置获取

---
 unpackage/dist/dev/mp-weixin/pages/index/index.js |   69 +++++++++++++++++++++++++++++++++-
 1 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/unpackage/dist/dev/mp-weixin/pages/index/index.js b/unpackage/dist/dev/mp-weixin/pages/index/index.js
index 18cf45a..656a757 100644
--- a/unpackage/dist/dev/mp-weixin/pages/index/index.js
+++ b/unpackage/dist/dev/mp-weixin/pages/index/index.js
@@ -33,6 +33,7 @@
     async function getVipInfo() {
       await api_index.getVipInfoApi().then((res) => {
         if (res.code == 200 && res.data.id) {
+          console.log("获取会员卡返回响应-首页", res);
           cardInfo.value.waterCardNumber = res.data.cardNumber;
           cardInfo.value.cardType = res.data.cardType;
           cardInfo.value.state = res.data.state == 2 ? true : false;
@@ -190,9 +191,73 @@
         icon: "none"
       });
     }
+    let userLocation = {
+      lat: "",
+      lon: ""
+    };
+    function getUserLocation() {
+      common_vendor.index.authorize({
+        scope: "scope.userLocation",
+        success() {
+          console.log("成功授权位置信息1");
+          storageLocation();
+        },
+        fail() {
+          console.log("用户拒绝授权位置信息,再次提示用户授权");
+          showToast();
+        }
+      });
+      function storageLocation() {
+        common_vendor.index.getLocation({
+          type: "gcj02",
+          isHighAccuracy: true,
+          success: (res) => {
+            userLocation.lat = res.latitude;
+            userLocation.lon = res.longitude;
+            common_vendor.index.setStorageSync("userLocation", JSON.stringify(userLocation));
+          },
+          fail: () => {
+            showToast();
+          }
+        });
+      }
+      function showToast() {
+        common_vendor.index.showModal({
+          title: "请求授权当前位置",
+          content: "请求获取您的位置,加载附近饮水设备信息!",
+          confirmText: "前往设置",
+          success: (res) => {
+            if (res.confirm) {
+              common_vendor.index.openSetting({
+                success: (res1) => {
+                  if (res1.authSetting["scope.userLocation"]) {
+                    console.log("用户二次授权成功");
+                    setTimeout(() => {
+                      storageLocation();
+                    }, 1e3);
+                  } else {
+                    showToast();
+                    console.log("用户拒绝授权");
+                  }
+                }
+              });
+            } else {
+              common_vendor.index.showToast({
+                title: "请先授权!",
+                duration: 2e3,
+                icon: "none"
+              });
+              showToast();
+            }
+          }
+        });
+      }
+    }
     common_vendor.onMounted(async () => {
       getTopHeight();
       await getInfo();
+      await getUserLocation();
+      console.log("进入首页了");
     });
     common_vendor.onShow(async () => {
       getTopHeight();
@@ -214,13 +279,13 @@
       }, cardInfo.value.headImg ? {
         b: common_vendor.unref(config_baseUrl.BASE_URL) + "/upload" + cardInfo.value.headImg
       } : {
-        c: common_assets.headImg
+        c: common_assets._imports_0$3
       }, {
         d: common_vendor.t(cardInfo.value.userName),
         e: common_vendor.o(($event) => navTo("/pages/userInfo/index")),
         f: common_vendor.o(($event) => navTo("/pages/userInfo/index")),
         g: common_assets._imports_1$1,
-        h: common_assets._imports_0$1,
+        h: common_assets._imports_0$2,
         i: isShareCard.value
       }, isShareCard.value ? {
         j: common_vendor.t(cardInfo.value.waterCardNumber)

--
Gitblit v1.9.3