Pārlūkot izejas kodu

设备详情页未反显设备编号问题修复

zuypeng 1 gadu atpakaļ
vecāks
revīzija
366a6da559

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

@@ -62,9 +62,6 @@ const handleGetPhone = (e:any) => {
 }
 
 const handleGotoLoginPage = () => {
-/*  uni.navigateTo({
-    url: '/pages-user/login/index'
-  })*/
   tryLogin().then((token)=>{
     console.log(">>>>>>>>>",token)
 

+ 13 - 12
src/pages-user/login/index.vue

@@ -56,8 +56,8 @@ const shortId =ref ("")
 
 onLoad((options:any)=>{
   console.log(options)
-  redirectUrl.value = options?.query?.redirectUrl
-  shortId.value = options?.query?.shortId
+  redirectUrl.value = options?.redirectUrl
+  shortId.value = options?.shortId
 })
 // 处理微信登录
 const handleWechatLogin = () => {
@@ -104,16 +104,17 @@ const handleGetPhone = (e:any) => {
   }
   login(e).then((token: string) => {
     console.log(">>>>>>>>>",token)
-    if(redirectUrl.value){
-      uni.redirectTo({
-        url:redirectUrl.value+"?shortId="+shortId.value
-      })
-    }else{
-      uni.navigateBack()
-      // uni.switchTab({
-      //   url:"/pages/index/index"
-      // })
-    }
+    uni.navigateBack()
+    // if(redirectUrl.value){
+    //   uni.redirectTo({
+    //     url:redirectUrl.value+"?shortId="+shortId.value
+    //   })
+    // }else{
+    //   uni.navigateBack()
+    //   // uni.switchTab({
+    //   //   url:"/pages/index/index"
+    //   // })
+    // }
   })
 }
 </script>

+ 25 - 10
src/pages-wash/device/index.vue

@@ -10,13 +10,13 @@
         </view>
       </view>
       <view class="device-header_fun">
-        <uv-tags plain size="mini" type="primary" :text="fmtDictName('WashDevice.state',state.device.state)"></uv-tags>
+        <uv-tags plain size="mini" type="primary" :text="fmtDictName('WashDevice.state',state.device?.state)"></uv-tags>
       </view>
 
     </view>
     <view class="device-body">
       <view class="device-body_ops" @click="debounceStartStopDevice">
-        <text v-if="state.device.state==='idle'">启动设备</text>
+        <text v-if="state.device?.state==='idle'">启动设备</text>
         <text v-else>停止设备</text>
       </view>
 
@@ -37,9 +37,10 @@
 
       <view class="device-body_recharge">
         <uv-button
+            v-if="state.isLogin"
             type="default"
             color="#19A497"
-            @click="handleGotoRechage">充值
+            @click="handleGotoRechage">余额¥ {{ fmtMoney(state.balance)  }},去充值
         </uv-button>
       </view>
     </view>
@@ -55,9 +56,12 @@ import {reactive, ref} from "vue";
 import {debounce, fmtDictName} from "@/utils/common";
 import {get, post} from "@/utils/https";
 import {checkLogin, fetchToken, tryLogin} from "@/utils/auth";
+import {fmtMoney} from "@/utils/common";
 import LoginBar from "@/components/login-bar/index.vue";
 
 const initState = () => ({
+  isLogin:false,
+  balance:0,
   device: {
     functions: [],
     deviceName: '',
@@ -92,21 +96,25 @@ onLoad((options: any) => {
       return;
     }
   }
+  getApp<any>().globalData.deviceId = id;
   state.device = getApp<any>().globalData.last.device;
   checkLogin().then((token) => {
+    state.isLogin =true;
     setTimeout(() => {
       loadDeviceDetail(id);
+      state.balance = getApp<any>().globalData.user.balance
     }, 200)
   }).catch(e => {
     console.error("onLoad 校验登录失败,自动跳转登录页")
-    uni.navigateTo({
-      url: `/pages-user/login/index?shortId=${state.deviceId}&redirectUrl=/pages-wash/device/index`
-    })
+    // uni.navigateTo({
+    //   url: `/pages-user/login/index?shortId=${state.deviceId}&redirectUrl=/pages-wash/device/index`
+    // })
   })
 });
 
 
-onShow(() => {
+onShow((options:any) => {
+  console.log(options)
   addListener();
   // uni.showToast({
   //   title:'onShow,'
@@ -116,7 +124,7 @@ onShow(() => {
     //   title:'onShow,loaded'
     // })
     if (!state.deviceId) {
-      console.log("deviceId", getApp<any>().globalData.deviceId)
+      console.log("device page deviceId", getApp<any>().globalData.deviceId)
       let deviceId = getApp<any>().globalData.deviceId;
       if (deviceId) {
         loadDeviceDetail(deviceId);
@@ -124,11 +132,16 @@ onShow(() => {
     } else {
       loadDeviceDetail(state.deviceId);
     }
+    state.isLogin =true;
+    state.balance = getApp<any>().globalData.user.balance
   }).catch(e => {
     console.error("校验登录失败,自动跳转登录页")
-    uni.navigateTo({
-      url: `/pages-user/login/index?shortId=${state.deviceId}&redirectUrl=/pages-wash/device/index`
+    setTimeout(()=>{
+      uni.navigateTo({
+        url: `/pages-user/login/index?shortId=${state.deviceId}&redirectUrl=/pages-wash/device/index`
+      },100)
     })
+
   })
 
 
@@ -137,8 +150,10 @@ onShow(() => {
 
 const addListener = () => {
   uni.$on('login', function (data) {
+    state.isLogin =true;
     if (state.deviceId && data.isLogin) {
       loadDeviceDetail(state.deviceId);
+      state.balance = getApp<any>().globalData.user.balance
     }
   })