Sfoglia il codice sorgente

修复首次进入首页强制跳转登陆页及站点列表未显示的问题

zuy 7 mesi fa
parent
commit
664d904cd1

+ 0 - 7
src/components/login-bar/index.vue

@@ -53,13 +53,6 @@ const removeListener = () => {
   uni.$off('login');
 }
 
-const handleGetPhone = (e:any) => {
-  console.log(e)
-  login(e).then((token: string) => {
-    console.log(">>>>>>>>>",token)
-      state.isLogin =true;
-  })
-}
 
 const handleGotoLoginPage = () => {
   tryLogin().then((token)=>{

+ 3 - 11
src/pages-user/login/index.vue

@@ -50,7 +50,8 @@ import {onLoad} from "@dcloudio/uni-app";
 
 const isAgreePrivacy = ref([])
 const redirectUrl =ref ("")
-const shortId =ref ("")
+const shortId =ref (null)
+const stationId =ref (null)
 
 
 
@@ -58,6 +59,7 @@ onLoad((options:any)=>{
   console.log(options)
   redirectUrl.value = options?.redirectUrl
   shortId.value = options?.shortId
+  stationId.value = options?.stationId
 })
 // 处理微信登录
 const handleWechatLogin = () => {
@@ -97,16 +99,6 @@ const handleGetPhone = (e:any) => {
   login(e).then((token: string) => {
     console.log(">>>>>>>>>",token)
     uni.navigateBack()
-    // if(redirectUrl.value){
-    //   uni.redirectTo({
-    //     url:redirectUrl.value+"?shortId="+shortId.value
-    //   })
-    // }else{
-    //   uni.navigateBack()
-    //   // uni.switchTab({
-    //   //   url:"/pages/index/index"
-    //   // })
-    // }
   })
 }
 </script>

+ 5 - 2
src/pages-wash/device/index.vue

@@ -71,7 +71,8 @@ const initState = () => ({
   },
   time: "00:00:00",
   start: new Date(),
-  deviceId: null
+  deviceId: null,
+  stationId: null
 })
 
 const state = reactive(initState())
@@ -86,6 +87,7 @@ onLoad((options: any) => {
   // })
   console.log("device onLoad>>>>", options)
   let id = options?.shortId;
+  state.stationId = options?.stationId;
   if (!id) {
     let query = decodeURIComponent(options.q);
     let scanTime = options.scancode_time;
@@ -98,6 +100,7 @@ onLoad((options: any) => {
     }
   }
   getApp<any>().globalData.deviceId = id;
+  state.deviceId = id;
   state.device = getApp<any>().globalData.last.device;
   checkLogin().then((token) => {
     state.isLogin =true;
@@ -139,7 +142,7 @@ onShow((options:any) => {
     console.error("校验登录失败,自动跳转登录页")
     setTimeout(()=>{
       uni.navigateTo({
-        url: `/pages-user/login/index?shortId=${state.deviceId}&redirectUrl=/pages-wash/device/index`
+        url: `/pages-user/login/index?shortId=${!!state.deviceId?state.deviceId:''}&stationId=${!!state.stationId?state.stationId:''}&redirectUrl=/pages-wash/device/index`
       })
     },1000)
 

+ 1 - 1
src/pages-wash/station/index.vue

@@ -144,7 +144,7 @@ const handleClickDevice = (device: any) => {
   }
   getApp<any>().globalData.last.device = device;
   uni.navigateTo({
-    url: '/pages-wash/device/index?shortId=' + device.shortId
+    url: '/pages-wash/device/index?shortId=' + device.shortId+'&stationId='+device.stationId
   })
 }
 

+ 27 - 47
src/pages/index/index.vue

@@ -33,10 +33,10 @@
 
     <!--    站点清单  start-->
     <view class="w100 content_station">
-      <template v-if="isLogin">
+<!--      <template v-if="isLogin">-->
         <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
-      </template>
-      <uv-empty v-else mode="order" text="请先登录" :marginTop="100" @click="gotoLogin"></uv-empty>
+<!--      </template>-->
+<!--      <uv-empty v-if="!isLogin" mode="order" text="请先登录" :marginTop="100" @click="gotoLogin"></uv-empty>-->
     </view>
 <!--
     <movable-area class="mov-area">
@@ -142,23 +142,6 @@ onLoad((e: any) => {
     width: '100%',
     height: `${(height - rpxToPx(60)) / 4}px`
   };
-  /*  if (query) {
-      uni.showToast({
-        title: query,
-        duration: 5000
-      })
-    }*/
-
-})
-
-onShow(() => {
-  let height = uni.getWindowInfo().windowHeight;
-  // const bound = uni.getMenuButtonBoundingClientRect();
-  // width: 100%;height:170px;
-  state.customStyle = {
-    width: '100%',
-    height: `${(height - rpxToPx(60)) / 4}px`
-  };
 
   let token = fetchToken();
   if (token) {
@@ -186,45 +169,45 @@ onShow(() => {
       })
     }
   }
-  /* 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;
-  // if(isLogin.value) {
-    if (!locationData || !locationData.longitude) {
-      loadCurrentLocation();
-    } else {
-      state.location = locationData;
-      loadWashStationList();
-    }
-
-  // }
-
-  loadBannerList();
 
   if (!isLogin.value) {
     addListener();
   }
+})
 
+onShow(() => {
+  let height = uni.getWindowInfo().windowHeight;
+  // const bound = uni.getMenuButtonBoundingClientRect();
+  // width: 100%;height:170px;
+  state.customStyle = {
+    width: '100%',
+    height: `${(height - rpxToPx(60)) / 4}px`
+  };
 
+  loadInitData()
 });
 
 onHide(() => {
-  // Object.assign(state, initState());
   removeListener();
 })
 
+
+const loadInitData = () => {
+  console.log("show index>>>>", isLogin.value, state.stationList, state.location)
+  let locationData = getApp<any>().globalData.location;
+  if (!locationData || !locationData.longitude) {
+    loadCurrentLocation();
+  } else {
+    state.location = locationData;
+    loadWashStationList();
+  }
+
+  loadBannerList();
+}
+
 const addListener = () => {
   uni.$on('login', function (data) {
     isLogin.value = data.isLogin;
-    // if (!state.bannerList || state.bannerList.length === 0) {
-    //   loadBannerList();
-    // }
-    // loadWashStationList();
-
   })
 
   uni.$on('logout', function (data) {
@@ -327,9 +310,6 @@ const loadCurrentLocation = () => {
 }
 
 const loadWashStationList = () => {
-  if (state.stationList && state.stationList.length > 0) {
-    return;
-  }
   post(`/wash-station/listStation`, {pageSize: 5}).then((res: any) => {
     let {list, total} = res;
     list.forEach((station: any) => {