Bladeren bron

修改wx引入方式,获取定位方法统一封装

zhujindu 1 jaar geleden
bovenliggende
commit
118e978905
7 gewijzigde bestanden met toevoegingen van 566 en 532 verwijderingen
  1. 2 1
      package.json
  2. 2 2
      public/index.html
  3. 523 514
      src/api/index.js
  4. 2 0
      src/main.js
  5. 9 2
      src/utils/getPosition.js
  6. 19 8
      src/views/storeManagement/storeDetail.vue
  7. 9 5
      src/views/storeManagement/storeEdit.vue

+ 2 - 1
package.json

@@ -24,7 +24,8 @@
     "vue-baidu-map": "^0.21.22",
     "vue-jsonp": "^2.0.0",
     "vue-router": "^3.5.3",
-    "watermark-dom": "^2.3.0"
+    "watermark-dom": "^2.3.0",
+    "weixin-js-sdk": "^1.6.5"
   },
   "devDependencies": {
     "@vue/cli-plugin-babel": "~4.5.0",

+ 2 - 2
public/index.html

@@ -29,8 +29,8 @@
         return null;
     }
 </script>
-<script src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
-<script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js"></script>
+<!-- <script src="//res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
+<script src="https://open.work.weixin.qq.com/wwopen/js/jwxwork-1.0.0.js"></script> -->
 <!--生产、uat-->
 <script charset="utf-8" src="https://map.qq.com/api/gljs?v=1.exp&libraries=service,tools&key=Y7SBZ-PI5K5-FOJIT-ILHLY-PN66T-HKB4A"></script>
 </body>

File diff suppressed because it is too large
+ 523 - 514
src/api/index.js


+ 2 - 0
src/main.js

@@ -30,6 +30,8 @@ import ElPopover from "element-ui/lib/popover";
 import "element-ui/lib/theme-chalk/table-column.css";
 import "element-ui/lib/theme-chalk/popover.css";
 import Vconsole from "vconsole";
+import wx from "weixin-js-sdk";
+
 Vue.use(ElTable);
 Vue.use(ElTableColumn);
 Vue.use(ElPopover);

+ 9 - 2
src/utils/getPosition.js

@@ -1,7 +1,10 @@
+import Vue from "vue";
 import { getTicket } from "@/api/index";
 import { toastLoading } from "@/utils/commonVant";
 import { CJ02BD, gcj02BD } from "@/utils/index";
 import { jsonp } from "vue-jsonp";
+// 微信JSSDK实例
+const wx = Vue.prototype.wx;
 // 腾讯位置服务 key
 const TxMapKey = "WLCBZ-HRM6L-YOMPV-ME62B-AQOG6-JUBW6";
 
@@ -26,7 +29,7 @@ export function getPosition() {
       //  获取签名
       getTicket({ url: url }).then((res) => {
         console.log("url=" + url);
-        // toastLoading().clear();
+        toastLoading().clear();
         if (res.status == 200) {
           let qiyeData = res.data.data;
           wx.config({
@@ -59,10 +62,14 @@ export function getPosition() {
               },
             });
           });
-          wx.error((res) => {
+          wx.error((err) => {
             toastLoading().clear();
+            console.log(err);
             reject("定位失败,请开启企微定位权限");
           });
+        } else {
+          toastLoading().clear();
+          reject("获取签名失败");
         }
       });
     }

+ 19 - 8
src/views/storeManagement/storeDetail.vue

@@ -524,7 +524,7 @@ export default {
         ]);
         that.maplist = [];
         // 地点搜索 获取500米范围poi点
-        getMapPoi({ latitude: this.pLat, longitude: this.pLot }).then((res) => {
+        getMapPoi({ latitude: val.location.lat, longitude: val.location.lng }).then((res) => {
           console.log(res);
           that.maplist = res.data;
           that.marker.setGeometries([]);
@@ -599,14 +599,17 @@ export default {
       console.log(this.maplist);
       console.log(this.addresssb);
       if (this.addresssb > -1) {
-        this.list.addressLine = this.maplist[this.addresssb].address;
+        let checkedPoint = this.maplist[this.addresssb];
+        // 坐标转换
+        let TXisBD = this.CJ02BD(checkedPoint.location.lat, checkedPoint.location.lng);
+        this.list.addressLine = checkedPoint.address;
         this.lon = this.myLat;
         this.lat = this.myLon;
-        this.poiAddress = this.maplist[this.addresssb].address;
-        this.poiLat = this.maplist[this.addresssb].location.lat;
-        this.poiLon = this.maplist[this.addresssb].location.lng;
-        this.poiId = this.maplist[this.addresssb].id;
-        this.poiName = this.maplist[this.addresssb].title;
+        this.poiAddress = checkedPoint.address;
+        this.poiLat = TXisBD.lat;
+        this.poiLon = TXisBD.lon;
+        this.poiId = checkedPoint.id;
+        this.poiName = checkedPoint.title;
         this.showmap = false;
       }
     },
@@ -807,6 +810,13 @@ export default {
       map.removeControl(TMap.constants.DEFAULT_CONTROL_ID.SCALE); //移除比例尺控件
       map.removeControl(TMap.constants.DEFAULT_CONTROL_ID.ROTATION); //移除旋转控件
       map.removeControl(TMap.constants.DEFAULT_CONTROL_ID.ZOOM); //移除控件缩放
+      this.map.on("click", this.clickMap);
+    },
+    // 点击事件处理方法
+    clickMap(evt) {
+      var lat = evt.latLng.getLat().toFixed(6);
+      var lng = evt.latLng.getLng().toFixed(6);
+      console.log(evt);
     },
     initMap(map) {
       // 监听地图平移开始
@@ -1174,7 +1184,8 @@ export default {
           valid({ storeId: that.list.storeId }).then((res) => {
             loading1.clear();
             if (res.code == 200) {
-              window.location.replace(window.location.origin + "/mobile/storeAddress");
+              that.$router.go(-1);
+              // window.location.replace(window.location.origin + "/mobile/storeAddress");
             }
           });
         });

+ 9 - 5
src/views/storeManagement/storeEdit.vue

@@ -801,14 +801,18 @@ export default {
     },
     confirmMap() {
       if (this.addresssb > -1) {
-        this.fromValue.addressLine = this.maplist[this.addresssb].address;
+        let checkedPoint = this.maplist[this.addresssb];
+        // 坐标转换
+        let TXisBD = this.CJ02BD(checkedPoint.location.lat, checkedPoint.location.lng);
+        this.fromValue.addressLine = checkedPoint.address;
         var location = this.CJ02BD(this.pLat, this.pLot);
         this.fromValue.lat = location.lat;
         this.fromValue.lon = location.lon;
-        this.fromValue.poiAddress = this.maplist[this.addresssb].address;
-        this.fromValue.poiLat = this.maplist[this.addresssb].location.lat;
-        this.fromValue.poiLon = this.maplist[this.addresssb].location.lng;
-        this.fromValue.poiId = this.maplist[this.addresssb].id;
+        this.fromValue.poiAddress = checkedPoint.address;
+        this.fromValue.poiLat = TXisBD.lat;
+        this.fromValue.poiLon = TXisBD.lon;
+        this.fromValue.poiId = checkedPoint.id;
+        this.fromValue.poiName = checkedPoint.title;
       }
       this.showmap = false;
     },