Explorar el Código

依赖微信sdk,开发定位demo

zwq hace 6 años
padre
commit
1e5482c72b
Se han modificado 2 ficheros con 58 adiciones y 4 borrados
  1. 3 2
      package.json
  2. 55 2
      src/view/user/index.vue

+ 3 - 2
package.json

@@ -10,13 +10,14 @@
     "lint": "vue-cli-service lint"
   },
   "dependencies": {
+    "axios": "^0.18.0",
     "core-js": "^3.4.3",
     "vant": "^2.2.0",
     "vue": "^2.6.10",
     "vue-router": "^3.0.5",
-    "axios": "^0.18.0",
     "vuex": "^3.0.1",
-    "vuex-class": "^0.3.1"
+    "vuex-class": "^0.3.1",
+    "weixin-jsapi": "^1.1.0"
   },
   "devDependencies": {
     "@vue/cli-plugin-babel": "^4.1.1",

+ 55 - 2
src/view/user/index.vue

@@ -21,7 +21,7 @@
     </van-row>
 
     <van-cell-group class="user-group">
-      <van-cell icon="records" title="全部订单" is-link />
+      <van-cell icon="records" title="全部订单" is-link @click="location"/>
     </van-cell-group>
 
     <van-cell-group>
@@ -33,7 +33,9 @@
 </template>
 
 <script>
-import { Row, Col, Icon, Cell, CellGroup } from 'vant';
+import { Row, Col, Icon, Cell, CellGroup,Toast } from 'vant';
+import {getAction} from '@/api/manage'
+import wx from 'weixin-jsapi'
 
 export default {
   components: {
@@ -43,10 +45,61 @@ export default {
     [Cell.name]: Cell,
     [CellGroup.name]: CellGroup
   },
+    data() {
+        return {
+            url: {
+                getJsapiConfig: '/f/api/wechat/getJsapiConfig',
+            }
+        };
+    },
     created(){
         //获取传入的参数
         var param = this.$route.query;
         console.log("ddf",param)
+        this.getJsapiConfig();
+    },
+    methods: {
+      getJsapiConfig(){
+          //获取微信js配置信息
+          getAction(this.url.getJsapiConfig, {fullUrl:encodeURIComponent(location.href.split('#')[0])})
+              .then((res) => {
+                  console.log("res",res);
+                  var _config = eval('(' + res.data.configValue + ')');
+                  console.log("12345====js", _config.appId)
+                  wx.config({
+                      debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
+                      appId: _config.appId, // 必填,公众号的唯一标识
+                      timestamp: _config.timeStamp, // 必填,生成签名的时间戳
+                      nonceStr: _config.nonceStr, // 必填,生成签名的随机串
+                      signature: _config.signature, // 必填,签名,见附录1
+                      jsApiList: ['chooseImage', 'previewImage', 'uploadImage', 'downloadImage', 'getLocation'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
+                  });
+                  wx.ready(function() {
+                      console.log("微信验证")
+                  });
+                  wx.error(function() {
+                      console.log("微信验证失败")
+                  })
+              })
+              .catch(() => {
+              });
+      },
+      location(){
+          wx.getLocation({
+              type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
+              success: function(res) {
+                  console.log(JSON.stringify(res))
+                  // var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
+                  // var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
+                  // var speed = res.speed; // 速度,以米/每秒计
+                  // var accuracy = res.accuracy; // 位置精度
+              },
+              cancel: function() {
+                  console.log("获取位置失败,请检查定位");
+                  Toast("获取位置失败,请检查定位")
+              }
+          });
+      }
     }
 };
 </script>