Bladeren bron

防止多个接口401重复定向到登录页面的问题

zaijin 1 jaar geleden
bovenliggende
commit
71bd844165
3 gewijzigde bestanden met toevoegingen van 60 en 36 verwijderingen
  1. 5 2
      common/http.interceptor.js
  2. 44 19
      pages/parkingInformation/parkingInformation.vue
  3. 11 15
      pages/parkingLists/parkingLists.vue

+ 5 - 2
common/http.interceptor.js

@@ -7,7 +7,7 @@ const install = (Vue, vm) => {
     originalData: true,
     dataType: 'text'
   });
-
+  let isRefreshing = false
   // 请求拦截,配置Token等参数
   Vue.prototype.$u.http.interceptor.request = (config) => {
     if (vm.vuex_token) {
@@ -34,7 +34,10 @@ const install = (Vue, vm) => {
     if (res.code == 200) {
       return res;
     } else if (res.code == 401 || (res.code == 400 && res.msg == '令牌不能为空')) {
-      login(vm);
+      if (!isRefreshing) {
+        login(vm);
+        isRefreshing = true;
+      }
       return false
     } else {
       // 用来判断时候需要使用当前提示框

+ 44 - 19
pages/parkingInformation/parkingInformation.vue

@@ -1,7 +1,7 @@
 <template>
   <view class="parking-information">
     <view class="parking-information-slider">
-      <image src="../../static/img/parking-info-bg.png" mode=""></image>
+      <image src="/static/img/parking-info-bg.png" mode=""></image>
     </view>
     <view class="parking-information-content">
       <view class="parking-information-content-title">
@@ -10,7 +10,7 @@
           <view class="subtitle">{{ roadInfo.roadName }}</view>
         </view>
         <view class="pict-right" @click="navigation(roadInfo.latitude, roadInfo.longitude, roadInfo.areaName)">
-          <image src="../../static/img/distance-icon.png" mode=""></image>
+          <image src="/static/img/distance-icon.png" mode=""></image>
           <view class="m">{{ roadInfo.distance | kmUnit }}</view>
         </view>
       </view>
@@ -70,14 +70,50 @@ export default {
     };
   },
   onLoad(page) {
-    this.roadInfo = JSON.parse(page.roadInfo);
-    const { latitude, longitude, roadInfo } = page;
-    this.latitude = latitude;
-    this.longitude = longitude;
-    this.roadInfo = JSON.parse(roadInfo);
-    console.log('this.roadInfo', this.roadInfo);
+    const { current, id, longitude, latitude } = page;
+    if (id) {
+      const obj = {
+        0: 'getNearRoadsl',
+        1: 'getParkingLotList'
+      };
+      this[obj[current]](id, longitude, latitude);
+      this.latitude = latitude;
+      this.longitude = longitude;
+    }
   },
   methods: {
+    /**
+     *获取路段列表
+     * @date 2021-08-10
+     * @param {String} longitude
+     * @param {String} latitude
+     * @param {String} id
+     * @returns {any}
+     */
+    async getNearRoadsl(id, longitude, latitude) {
+      try {
+        const { code, data } = await this.$u.api.nearRoadsl({ latitude, longitude });
+        if (code === 200) {
+          this.roadInfo = data.find((item) => item.id === id);
+        }
+      } catch (error) {}
+    },
+    /**
+     * @description: 获取停车场列表
+     * @param {*} id
+     * @param {*} longitude
+     * @param {*} latitude
+     * @return {*}
+     */
+    async getParkingLotList(id, longitude, latitude) {
+      try {
+        const { code, data } = await this.$u.api.nearParkingLot({ status: 1, latitude, longitude });
+        if (code === 200) {
+          this.roadInfo = data?.rows.find((item) => item.id === id);
+          console.log(this.roadInfo);
+        }
+      } catch (error) {}
+    },
     /**
      * 跳转停车标准页面
      * {roadNo} 路段编码
@@ -114,14 +150,6 @@ export default {
       const name = item[0].label;
       switch (name) {
         case '腾讯地图':
-          // uni.navigateTo({
-          //   url:
-          //     '/pages/parkingLists/map_web_view/map_web_view?url=https://3gimg.qq.com/lightmap/v1/marker/?marker=coord:' +
-          //     this.currentPositionHover.latitude +
-          //     ',' +
-          //     this.currentPositionHover.longitude +
-          //     '&referer=myApp&key=BOGBZ-2BZ33-O4L32-Y3QJR-PGN66-RFFEL'
-          // });
           location.href = `https://apis.map.qq.com/uri/v1/routeplan?type=drive&from=我的位置&fromcoord=${this.latitude},${this.longitude}&to=${this.currentPositionHover.areaName}&tocoord=${this.currentPositionHover.latitude},${this.currentPositionHover.longitude}&policy=1&referer=BOGBZ-2BZ33-O4L32-Y3QJR-PGN66-RFFEL`;
           break;
         case '百度地图':
@@ -130,9 +158,6 @@ export default {
 			&output=html&src=webapp.baidu.openAPIdemo`;
           break;
         case '高德地图':
-          console.log(this.longitude);
-          // const gdurl = `https://uri.amap.com/navigation?from=${this.currentPosition.longitude},${this.currentPosition.latitude},起点&to=${this.currentPositionHover.longitude},${this.currentPositionHover.latitude},终点&mode=car&policy=1&src=mypage&coordinate=gaode&callnative=0`;
-          // window.location.href = gdurl;
           location.href = `https://uri.amap.com/navigation?from=${this.longitude},${this.latitude},我的位置&to=${this.currentPositionHover.longitude},${this.currentPositionHover.latitude},${this.currentPositionHover.areaName}&mode=car&policy=1&src=mypage&coordinate=gaode&callnative=0`;
           break;
       }

+ 11 - 15
pages/parkingLists/parkingLists.vue

@@ -96,14 +96,14 @@
         </view>
         <view class="pali-right" v-if="currentPosition.latitude && currentPosition.longitude">
           <image
-            src="../../static/img/distance-icon.png"
+            src="/static/img/distance-icon.png"
             mode=""
             @click.stop="navigation(item.latitude, item.longitude, item.roadName || item.parkName)"
           ></image>
           <view>路线</view>
         </view>
         <view class="pali-right" v-else>
-          <image src="../../static/img/distance-icon.png" mode="" @click.stop="disabledNavigation"></image>
+          <image src="/static/img/distance-icon.png" mode="" @click.stop="disabledNavigation"></image>
           <view>路线</view>
         </view>
       </view>
@@ -316,9 +316,9 @@ export default {
     getNearRoadsl(lon, lat) {
       this.$u.api
         .nearRoadsl({
-          latitude: this.currentPosition.latitude,
-          longitude: this.currentPosition.longitude,
-          roadName: this.searchContent
+          latitude: this.currentPosition.latitude || undefined,
+          longitude: this.currentPosition.longitude || undefined,
+          roadName: this.searchContent || undefined
         })
         .then((res) => {
           const nearParkingList = []; // 附近停车场列表
@@ -372,9 +372,9 @@ export default {
       this.$u.api
         .nearParkingLot({
           status: 1,
-          latitude: this.currentPosition.latitude,
-          longitude: this.currentPosition.longitude,
-          parkName: this.searchContent
+          latitude: this.currentPosition.latitude || undefined,
+          longitude: this.currentPosition.longitude || undefined,
+          parkName: this.searchContent || undefined
         })
         .then((res) => {
           const nearParkingList = []; // 附近停车场列表
@@ -489,16 +489,12 @@ export default {
         this.$u.route({
           url: 'pages/parkingInformation/parkingInformation',
           params: {
-            roadInfo: JSON.stringify(item),
             longitude: this.currentPosition.longitude,
-            latitude: this.currentPosition.latitude
+            latitude: this.currentPosition.latitude,
+            id: item.id,
+            current: this.tabObj.current
           }
         });
-      } else {
-        this.$refs.uToast.show({
-          title: '该停车点不能包月!',
-          type: 'warning'
-        });
       }
     },
     /**