Quellcode durchsuchen

pc端无定位依然支持访问

zhujindu vor 1 Jahr
Ursprung
Commit
d5aa1c8709
4 geänderte Dateien mit 248 neuen und 194 gelöschten Zeilen
  1. 18 33
      src/utils/TXApiFun.js
  2. 158 113
      src/views/deviceOutside/index.vue
  3. 34 23
      src/views/deviceWithin/index.vue
  4. 38 25
      src/views/home/login.vue

+ 18 - 33
src/utils/TXApiFun.js

@@ -27,36 +27,27 @@ export function getPosition() {
       toastLoading().clear();
       resolve({ TXisBD, resData });
     } else {
-      // let url = window.location.href;
-      // //  获取签名
-      // getTicket({ url: url }).then((response) => {
-      //   console.log(response);
-      //   toastLoading().clear();
-      //   if (response.code == 200) {
-      //     let qiyeData = response.data;
-      //     wx.config({
-      //       beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
-      //       debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
-      //       appId: qiyeData.appId, // 必填,企业微信的corpID
-      //       timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
-      //       nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
-      //       signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
-      //       jsApiList: ["ready", "getLocation"], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
-      //     });
       wx.ready(() => {
         wx.getLocation({
           type: 'gcj02',
           success: (resData) => {
             toastLoading().clear();
-            console.log('处理前');
-            console.log(resData.latitude, resData.longitude);
-            // 定位坐标转换 腾讯转百度
-            let TXisBD = CJ02BD(resData.latitude, resData.longitude);
-            console.log('处理后');
-            console.log(TXisBD);
-            localStorage.setItem('lat', TXisBD.lat);
-            localStorage.setItem('lon', TXisBD.lon);
-            resolve({ TXisBD, resData });
+            // resData.errmsg == fail_no permission 没有权限依会走success
+            if (resData.latitude) {
+              console.log('处理前');
+              console.log(resData.latitude, resData.longitude);
+              // 定位坐标转换 腾讯转百度
+              let TXisBD = CJ02BD(resData.latitude, resData.longitude);
+              console.log('处理后');
+              console.log(TXisBD);
+              localStorage.setItem('lat', TXisBD.lat);
+              localStorage.setItem('lon', TXisBD.lon);
+              resolve({ TXisBD, resData });
+            } else {
+              localStorage.setItem('lat', '');
+              localStorage.setItem('lon', '');
+              reject('定位失败,请开启企微定位权限');
+            }
           },
           fail: () => {
             toastLoading().clear();
@@ -70,16 +61,10 @@ export function getPosition() {
       wx.error((err) => {
         toastLoading().clear();
         console.log(err);
-        let isMobile = localStorage.getItem('isMobile');
-        // // 人、
-        // if( isMobile )
+        localStorage.setItem('lat', '');
+        localStorage.setItem('lon', '');
         reject('定位失败,请开启企微定位权限');
       });
-      // } else {
-      //   toastLoading().clear();
-      //   reject("获取签名失败");
-      // }
-      // });
     }
   });
 }

+ 158 - 113
src/views/deviceOutside/index.vue

@@ -938,99 +938,120 @@ export default {
     // 范围
     rangeStoreFn() {
       localStorage.setItem('tabVal', this.tabVal);
-      let loading1 = this.$toast.loading({
-        duration: 0,
-        message: '加载中...',
-        forbidClick: true,
-      });
-      let url = window.location.href;
-      let wx = this.wx;
-      var that = this;
-      // that.$router.push({path: "/rangeStore", query: {
-      //     lon:"112.45359397440227",
-      //     lat:"34.62171814576471",
-      //     tabVal:that.tabVal
-      //   }
-      // })
-      let qiyeData;
-      const instance = axios.create();
-      instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
-      instance
-        .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
-          params: {
-            url: url,
-          },
+      getPosition()
+        .then((res) => {
+          let { TXisBD } = res;
+          this.lat = TXisBD.lat;
+          this.lon = TXisBD.lon;
+          let name = this.tabVal != 1 ? '销售部' : '我的';
+          this.buryingPoint({
+            systemModel: '计划外',
+            buryingPointType: 3,
+            buryingPointValue: name,
+            buryingPointName: '计划外',
+            buryingPointPosition: '进入地图',
+          });
+          this.$router.push({
+            path: '/rangeStore',
+            query: {
+              lat: '',
+              lon: '',
+              tabVal: this.tabVal,
+            },
+          });
         })
-        .then((response) => {
-          if (response.status == 200) {
-            this.cont = 5;
-            var flat = true;
-            var times = setInterval(() => {
-              this.cont--;
-              if (this.cont == '0') {
-                if (flat) {
-                  loading1.clear();
-                  clearInterval(times);
-                  that.$dialog.alert({
-                    message: '定位失败,请开启企微定位权限',
-                  });
-                } else {
-                  clearInterval(times);
-                }
-              }
-            }, 1000);
-            qiyeData = response.data.data;
-            wx.config({
-              beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
-              debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
-              appId: qiyeData.appId, // 必填,企业微信的corpID
-              timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
-              nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
-              signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
-              jsApiList: ['ready', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
-            });
-            wx.ready(function () {
-              wx.getLocation({
-                type: 'gcj02',
-                success: function (res) {
-                  flat = false;
-                  loading1.clear();
-                  var name = '我的';
-                  if (that.tabVal != 1) {
-                    name = '销售部';
-                  }
-                  that.buryingPoint({
-                    systemModel: '计划外',
-                    buryingPointType: 3,
-                    buryingPointValue: name,
-                    buryingPointName: '计划外',
-                    buryingPointPosition: '进入地图',
-                  });
-                  that.$router.push({
-                    path: '/rangeStore',
-                    query: {
-                      lat: '',
-                      lon: '',
-                      tabVal: that.tabVal,
-                    },
-                  });
-                },
-                fail: function () {
-                  loading1.clear();
-                  that.$dialog.alert({
-                    message: 'GPS未开启',
-                  });
-                },
-              });
-            });
-            wx.error(function (res) {
-              loading1.clear();
-              that.$dialog.alert({
-                message: '定位失败,请开启企微定位权限',
-              });
-            });
-          }
+        .catch((error) => {
+          this.$dialog.alert({
+            message: error,
+          });
         });
+      // let loading1 = this.$toast.loading({
+      //   duration: 0,
+      //   message: '加载中...',
+      //   forbidClick: true,
+      // });
+      // let url = window.location.href;
+      // let wx = this.wx;
+      // var that = this;
+      // let qiyeData;
+      // const instance = axios.create();
+      // instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
+      // instance
+      //   .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
+      //     params: {
+      //       url: url,
+      //     },
+      //   })
+      //   .then((response) => {
+      //     if (response.status == 200) {
+      //       this.cont = 5;
+      //       var flat = true;
+      //       var times = setInterval(() => {
+      //         this.cont--;
+      //         if (this.cont == '0') {
+      //           if (flat) {
+      //             loading1.clear();
+      //             clearInterval(times);
+      //             that.$dialog.alert({
+      //               message: '定位失败,请开启企微定位权限',
+      //             });
+      //           } else {
+      //             clearInterval(times);
+      //           }
+      //         }
+      //       }, 1000);
+      //       qiyeData = response.data.data;
+      //       wx.config({
+      //         beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
+      //         debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
+      //         appId: qiyeData.appId, // 必填,企业微信的corpID
+      //         timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
+      //         nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
+      //         signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
+      //         jsApiList: ['ready', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
+      //       });
+      //       wx.ready(function () {
+      //         wx.getLocation({
+      //           type: 'gcj02',
+      //           success: function (res) {
+      //             flat = false;
+      //             loading1.clear();
+      //             var name = '我的';
+      //             if (that.tabVal != 1) {
+      //               name = '销售部';
+      //             }
+      //             that.buryingPoint({
+      //               systemModel: '计划外',
+      //               buryingPointType: 3,
+      //               buryingPointValue: name,
+      //               buryingPointName: '计划外',
+      //               buryingPointPosition: '进入地图',
+      //             });
+      //             that.$router.push({
+      //               path: '/rangeStore',
+      //               query: {
+      //                 lat: '',
+      //                 lon: '',
+      //                 tabVal: that.tabVal,
+      //               },
+      //             });
+      //           },
+      //           fail: function () {
+      //             loading1.clear();
+      //             that.$dialog.alert({
+      //               message: 'GPS未开启',
+      //             });
+      //           },
+      //         });
+      //       });
+      //       wx.error(function (res) {
+      //         loading1.clear();
+      //         that.$dialog.alert({
+      //           message: '定位失败,请开启企微定位权限',
+      //         });
+      //       });
+      //     }
+      //   });
     },
     //取消搜索
     cancelSearch() {
@@ -1114,22 +1135,40 @@ export default {
       });
     },
     positionFn(val) {
-      getPosition().then((res) => {
-        let { TXisBD } = res;
-        this.lat = TXisBD.lat;
-        this.lon = TXisBD.lon;
-        localStorage.setItem('lat', TXisBD.lat);
-        localStorage.setItem('lon', TXisBD.lon);
-        if (val == 1) {
-          if (this.tabVal == 1) {
+      getPosition()
+        .then((res) => {
+          let { TXisBD } = res;
+          this.lat = TXisBD.lat;
+          this.lon = TXisBD.lon;
+          if (val == 1) {
+            if (this.tabVal == 1) {
+              this.getUserOutPlaListFun();
+            } else {
+              this.getUserOrgStoreList();
+            }
+          } else {
             this.getUserOutPlaListFun();
+          }
+        })
+        .catch((error) => {
+          // PC端没有定位权限依然可以访问
+          let isMobile = localStorage.getItem('isMobile');
+          if (!isMobile) {
+            this.$dialog.alert({
+              message: error,
+            });
           } else {
-            this.getUserOrgStoreList();
+            if (val == 1) {
+              if (this.tabVal == 1) {
+                this.getUserOutPlaListFun();
+              } else {
+                this.getUserOrgStoreList();
+              }
+            } else {
+              this.getUserOutPlaListFun();
+            }
           }
-        } else {
-          this.getUserOutPlaListFun();
-        }
-      });
+        });
       // // 本地开发 test 环境时 时跳过获取定位功能
       // if (process.env.NODE_ENV === 'test') {
       //   this.lat = 34.62188103091605;
@@ -1460,15 +1499,21 @@ export default {
                   },
                 });
               } else {
-                getPosition().then((res) => {
-                  let { TXisBD, resData } = res;
-                  this.lat = TXisBD.lat;
-                  this.lon = TXisBD.lon;
-                  localStorage.setItem('lat', this.lat);
-                  localStorage.setItem('lon', this.lon);
-                  // var location = this.CJ02BD(res.latitude, res.longitude);
-                  this.checkStoreAddressByStoreCodeFun(val, TXisBD, resData);
-                });
+                getPosition()
+                  .then((res) => {
+                    let { TXisBD, resData } = res;
+                    this.lat = TXisBD.lat;
+                    this.lon = TXisBD.lon;
+                    localStorage.setItem('lat', this.lat);
+                    localStorage.setItem('lon', this.lon);
+                    // var location = this.CJ02BD(res.latitude, res.longitude);
+                    this.checkStoreAddressByStoreCodeFun(val, TXisBD, resData);
+                  })
+                  .catch((error) => {
+                    this.$dialog.alert({
+                      message: error,
+                    });
+                  });
                 // // 本地开发 test 环境时 跳过获取定位功能
                 // if (process.env.NODE_ENV === 'test') {
                 //   let res = {

+ 34 - 23
src/views/deviceWithin/index.vue

@@ -654,34 +654,45 @@ export default {
       }
       this.storeType = localStorage.getItem('storeType');
       this.endShow = false;
-      let loading1 = this.$toast.loading({
-        duration: 0,
-        message: '加载中...',
-        forbidClick: true,
-      });
+      this.toastLoading(0, '加载中...', true);
       localStorage.removeItem('visitId');
-      getPosition().then((res) => {
-        let { TXisBD } = res;
-        getUserInPlanList({
-          storeName: this.storeName.trim(),
-          genDate: this.genDate,
-          lat: TXisBD.lat,
-          lon: TXisBD.lon,
-        }).then((res) => {
-          loading1.clear();
-          if (res.code == 200) {
-            this.list = res.data;
-            this.list.forEach((item) => {
-              if (item.stateString.indexOf('拜访中') != -1) {
-                this.endShow = true;
-                this.visitEndId = item.visitId;
-                return;
-              }
+      getPosition()
+        .then((res) => {
+          let { TXisBD } = res;
+          this.getUserInPlanListFun(TXisBD);
+        })
+        .catch((error) => {
+          // PC端没有定位权限依然可以访问
+          let isMobile = localStorage.getItem('isMobile');
+          if (!isMobile) {
+            this.$dialog.alert({
+              message: error,
             });
           } else {
-            this.$toast.fail(res.msg);
+            this.getUserInPlanListFun({ lat: '', lon: '' });
           }
         });
+    },
+    getUserInPlanListFun(TXisBD) {
+      getUserInPlanList({
+        storeName: this.storeName.trim(),
+        genDate: this.genDate,
+        lat: TXisBD.lat,
+        lon: TXisBD.lon,
+      }).then((res) => {
+        this.toastLoading().clear();
+        if (res.code == 200) {
+          this.list = res.data;
+          this.list.forEach((item) => {
+            if (item.stateString.indexOf('拜访中') != -1) {
+              this.endShow = true;
+              this.visitEndId = item.visitId;
+              return;
+            }
+          });
+        } else {
+          this.$toast.fail(res.msg);
+        }
       });
     },
     storeVisit(val) {

+ 38 - 25
src/views/home/login.vue

@@ -1,35 +1,42 @@
 <template>
   <div class="logins">
-    <br><br><br><br><br><br><br><br><br><br><br>
-    <div class="avsd" >门点拜访登录</div>
-    <br><br>
-    <br><br>
-    <van-field v-model="name" label="账号" placeholder="请输入账号"/>
-    <br><br><br><br>
-    <van-button type="info" size="small" plain class="Btn100" @click="login" style="margin:0 auto;">登录</van-button>
+    <br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
+    <div class="avsd">门点拜访登录</div>
+    <br /><br />
+    <br /><br />
+    <van-field v-model="name" label="账号" placeholder="请输入账号" />
+    <br /><br /><br /><br />
+    <van-button type="info" size="small" plain class="Btn100" @click="login" style="margin: 0 auto"
+      >登录</van-button
+    >
   </div>
 </template>
 <script>
 export default {
-  name: "login",
+  name: 'login',
   data() {
     return {
-      name: ""
-    }
+      name: '',
+    };
   },
   methods: {
     login() {
       localStorage.clear();
-      if (this.name.trim() != "") {
-        localStorage.setItem('loginName', this.name)
-        localStorage.removeItem('loginType')
-        this.$router.push("/")
+      if (this.name.trim() != '') {
+        // 是否为移动端
+        let isMobile = window.navigator.userAgent.match(
+          /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i
+        );
+        localStorage.setItem('isMobile', !!isMobile);
+        localStorage.setItem('loginName', this.name);
+        localStorage.removeItem('loginType');
+        this.$router.push('/');
       } else {
-        this.$toast("账号不能为空")
+        this.$toast('账号不能为空');
       }
-    }
-  }
-}
+    },
+  },
+};
 </script>
 
 <style scoped>
@@ -47,17 +54,23 @@ export default {
   height: 44px;
   font-size: 16px;
 }
-.avsd{
+.avsd {
   margin: 0 auto;
   width: 112px;
   font-size: 18px;
-  color:#0057ba;
+  color: #0057ba;
   animation: jump 3s ease infinite;
 }
-@keyframes jump{
-  0%{ transform:translateY(0) scale(1,1);}
+@keyframes jump {
+  0% {
+    transform: translateY(0) scale(1, 1);
+  }
   /* 中间状态图片位移并且拉伸 */
-  50%{transform:translateY(-20px) scale(0.97,1.03);}
-  100%{transform:translateY(0) scale(1,1);}
+  50% {
+    transform: translateY(-20px) scale(0.97, 1.03);
+  }
+  100% {
+    transform: translateY(0) scale(1, 1);
+  }
 }
-</style>
+</style>