Bladeren bron

修复扫码报错提示的问题

zuypeng 1 jaar geleden
bovenliggende
commit
664d448d5e
4 gewijzigde bestanden met toevoegingen van 58 en 35 verwijderingen
  1. 3 2
      src/App.vue
  2. 20 4
      src/pages-wash/device/index.vue
  3. 28 22
      src/pages/index/index.vue
  4. 7 7
      src/utils/auth.ts

+ 3 - 2
src/App.vue

@@ -10,13 +10,14 @@ export default <any>{
     },
     isLogin: false,
     last:{},
-    device: null,
+    device: {},
+    deviceId:null,
     manualLogout:false
   },
   onLaunch() {
     uni.getSystemInfo({
       success: (res) => {
-        this.globalData.device = res;
+        // this.globalData.device = res;
       },
     });
 

+ 20 - 4
src/pages-wash/device/index.vue

@@ -43,6 +43,7 @@ import {onHide, onLoad, onShow} from "@dcloudio/uni-app";
 import {reactive, ref} from "vue";
 import {debounce, fmtDictName} from "@/utils/common";
 import {get, post} from "@/utils/https";
+import {tryLogin} from "@/utils/auth";
 
 const initState = () => ({
   device: {
@@ -74,10 +75,24 @@ onLoad((options: any) => {
     }
   }
   state.device = getApp<any>().globalData.last.device;
-  loadDeviceDetail(id);
+  tryLogin().then(() => {
+    setTimeout(() => {
+      loadDeviceDetail(id);
+    }, 200)
+  })
 });
 
 
+onShow(() => {
+  if (!state.device?.id) {
+    console.log(getApp<any>().globalData.deviceId)
+    let deviceId = getApp<any>().globalData.deviceId;
+    if (deviceId) {
+      loadDeviceDetail(deviceId);
+    }
+  }
+})
+
 const loadDeviceDetail = (id: number) => {
   get(`/wash-device/queryDevice/${id}`).then((res: any) => {
     if (res.currentUserId && res.currentUserId != getApp<any>().globalData.user.id) {
@@ -86,13 +101,14 @@ const loadDeviceDetail = (id: number) => {
         icon: 'error'
       })
       setTimeout(() => {
-        uni.redirectTo({
+        uni.switchTab({
           url: '/pages/index/index'
         })
       }, 2000)
     }
     res.functionList = res.functions?.split("|") || []
     state.device = res;
+    getApp<any>().globalData.deviceId = id;
   }).catch(e => {
     console.error(e)
   })
@@ -123,7 +139,7 @@ const handleClickDevice = () => {
             uni.showToast({
               title: '设备启动成功'
             })
-            state.device.state ='busy'
+            state.device.state = 'busy'
           })
         } else {
           uni.showLoading({
@@ -135,7 +151,7 @@ const handleClickDevice = () => {
             uni.showToast({
               title: '设备停机成功'
             })
-            state.device.state ='idle'
+            state.device.state = 'idle'
           })
         }
       }

+ 28 - 22
src/pages/index/index.vue

@@ -32,8 +32,8 @@
     <view class="menu-content w100">
       <uv-grid :border="false" :col="4">
         <uv-grid-item v-for="(item,index) in state.menuList" :key="index" @click="handleMenuClick(item)">
-          <image :src="item.icon"  mode="widthFit"  style="width: 48rpx;height: 48rpx"></image>
-<!--          <uv-icon :customStyle="{paddingTop:20+'rpx'}" :name="item.name" :size="22"></uv-icon>-->
+          <image :src="item.icon" mode="widthFit" style="width: 48rpx;height: 48rpx"></image>
+          <!--          <uv-icon :customStyle="{paddingTop:20+'rpx'}" :name="item.name" :size="22"></uv-icon>-->
           <text class="grid-text" style="font-size: 14px;">{{ item.title }}</text>
         </uv-grid-item>
       </uv-grid>
@@ -77,13 +77,12 @@ const change = () => {
 
 const initState = () => ({
   bannerList: [],
-  swiperList: [
-  ],
+  swiperList: [],
   menuList: [
-    {name: "photo", title: "洗车",icon:'/static/iconfont/default/fastwash.svg'},
-    {name: "lock", title: "充值",icon:'/static/iconfont/default/chongzhi_1.svg'},
-    {name: "star", title: "卡券",icon:'/static/iconfont/default/coupon.svg'},
-    {name: "red-packet", title: "停车",icon:'/static/iconfont/default/parking.svg'},
+    {name: "photo", title: "洗车", icon: '/static/iconfont/default/fastwash.svg'},
+    {name: "lock", title: "充值", icon: '/static/iconfont/default/chongzhi_1.svg'},
+    {name: "star", title: "卡券", icon: '/static/iconfont/default/coupon.svg'},
+    {name: "red-packet", title: "停车", icon: '/static/iconfont/default/parking.svg'},
   ],
   qrcodeOption: {
     style: 'round',
@@ -123,29 +122,29 @@ onLoad((e: any) => {
 
 onShow(() => {
   let token = fetchToken();
-  if(token){
+  if (token) {
     getApp<any>().globalData.token = token;
     getApp<any>().globalData.isLogin = true;
     isLogin.value = true;
     loadUserInfo();
-  }else{
+  } else {
     //主动退出的不自动登录
     let manualLogout = getApp<any>().globalData.manualLogout;
-    if(manualLogout){
+    if (manualLogout) {
       return;
     }
-    tryLogin().then(token=>{
+    tryLogin().then(token => {
       getApp<any>().globalData.token = token;
       getApp<any>().globalData.isLogin = true;
       isLogin.value = true;
-    }).catch(e=>{
+    }).catch(e => {
       console.error(e)
     })
   }
- /* const userData = getApp<any>().globalData.user;
-  if (userData && userData.id) {
-    isLogin.value = true;
-  }*/
+  /* const userData = getApp<any>().globalData.user;
+   if (userData && userData.id) {
+     isLogin.value = true;
+   }*/
 
   console.log("show index>>>>", isLogin.value, state.stationList, state.location)
   let locationData = getApp<any>().globalData.location;
@@ -155,7 +154,10 @@ onShow(() => {
     state.location = locationData;
     loadWashStationList();
   }
-  loadBannerList();
+
+  if (isLogin.value) {
+    loadBannerList();
+  }
 
   addListener();
 
@@ -169,6 +171,9 @@ onHide(() => {
 const addListener = () => {
   uni.$on('login', function (data) {
     isLogin.value = data.isLogin;
+    if(!state.bannerList|| state.bannerList.length===0){
+      loadBannerList();
+    }
   })
 
   uni.$on('logout', function (data) {
@@ -206,10 +211,10 @@ const handleMenuClick = (menu: any) => {
       uni.navigateTo({
         url: '/pages-user/wallet/recharge'
       })
-    }else{
+    } else {
       uni.showToast({
-        icon:'none',
-        title:'敬请期待',
+        icon: 'none',
+        title: '敬请期待',
       })
     }
   })
@@ -280,9 +285,10 @@ const handleNavStation = (station: any) => {
 </script>
 
 <style scoped lang="scss">
-page{
+page {
   background: #fafafa;
 }
+
 .content {
   width: 100%;
   display: flex;

+ 7 - 7
src/utils/auth.ts

@@ -83,10 +83,10 @@ export function login(e: any): Promise<string> {
                         _resolveTokenQueue(satoken);
                         setToken(satoken);
                         loadUserInfo();
-                 
+
                     } else {
                         _resolveTokenQueue({
-                            errMsg:  `${JSON.stringify(res)}`,
+                            errMsg: `${JSON.stringify(res)}`,
                         });
                     }
                 }).catch(e => {
@@ -124,7 +124,7 @@ export  function tryLogin(){
                     reject(e)
                 })
             },
-            fail: function (){
+            fail: function () {
                 reject('fail')
             },
         });
@@ -135,7 +135,7 @@ export  function tryLogin(){
 export function checkLogin() {
     return new Promise((resolve, reject) => {
         let user = getApp<any>().globalData.user;
-        if (!user||!user.id) {
+        if (!user || !user.id) {
             uni.showToast({
                 icon: "none",
                 title: "请先登录",
@@ -158,7 +158,7 @@ export function loadUserInfo() {
 
 export function refresh(): Promise<string> {
     return new Promise((resolve, reject) => {
-        uni.getStorage({key:"token"}).then((token) => {
+        uni.getStorage({key: "token"}).then((token) => {
             if (!token) {
                 clearToken();
                 reject({
@@ -215,8 +215,8 @@ export function setToken(token: string) {
 
 export function clearToken() {
     getApp<any>().globalData.token = "";
-    getApp<any>().globalData.isLong =false;
-    getApp<any>().globalData.user ={};
+    getApp<any>().globalData.isLong = false;
+    getApp<any>().globalData.user = {};
     uni.$emit('logout')
     uni.removeStorageSync("token")
 }