Explorar o código

扫码页修改

zuypeng hai 1 ano
pai
achega
c2258b2be4
Modificáronse 4 ficheiros con 54 adicións e 26 borrados
  1. 1 1
      src/App.vue
  2. 31 4
      src/pages-wash/device/index.vue
  3. 3 9
      src/pages-wash/scan/index.vue
  4. 19 12
      src/pages/index/index.vue

+ 1 - 1
src/App.vue

@@ -17,7 +17,7 @@ export default <any>{
   onLaunch() {
     uni.getSystemInfo({
       success: (res) => {
-        // this.globalData.device = res;
+        this.globalData.device = res;
       },
     });
 

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

@@ -35,6 +35,8 @@
       </view>
       <!--      <view class="device-body_ops-time">{{ state.time }}</view>-->
     </view>
+
+    <login-bar class="w100 text-center"></login-bar>
   </view>
 </template>
 
@@ -44,6 +46,7 @@ import {reactive, ref} from "vue";
 import {debounce, fmtDictName} from "@/utils/common";
 import {get, post} from "@/utils/https";
 import {tryLogin} from "@/utils/auth";
+import LoginBar from "@/components/login-bar/index.vue";
 
 const initState = () => ({
   device: {
@@ -52,7 +55,8 @@ const initState = () => ({
     state: ''
   },
   time: "00:00:00",
-  start: new Date()
+  start: new Date(),
+  deviceId:null
 })
 
 const state = reactive(initState())
@@ -69,7 +73,8 @@ onLoad((options: any) => {
     let scanTime = options.scancode_time;
     console.log(query, scanTime)
     if (query) {
-      id = query.split("#")[1]
+      id = query.split("#")[1].split("?")[0]
+      state.deviceId =id;
     } else {
       return;
     }
@@ -84,16 +89,38 @@ onLoad((options: any) => {
 
 
 onShow(() => {
-  if (!state.device?.id) {
+  addListener();
+  if (!state.deviceId) {
     console.log(getApp<any>().globalData.deviceId)
     let deviceId = getApp<any>().globalData.deviceId;
     if (deviceId) {
       loadDeviceDetail(deviceId);
     }
   }
+
 })
 
-const loadDeviceDetail = (id: number) => {
+
+
+const addListener = () => {
+  uni.$on('login', function (data) {
+      if(state.deviceId){
+        loadDeviceDetail(state.deviceId);
+      }
+  })
+
+  uni.$on('logout', function (data) {
+  })
+}
+
+const removeListener = () => {
+  uni.$off('logout');
+  uni.$off('login');
+}
+
+
+const loadDeviceDetail = (id: any) => {
+  state.deviceId =id;
   get(`/wash-device/queryDevice/${id}`).then((res: any) => {
     if (res.currentUserId && res.currentUserId != getApp<any>().globalData.user.id) {
       uni.showToast({

+ 3 - 9
src/pages-wash/scan/index.vue

@@ -1,11 +1,5 @@
 <template>
   <view class="page flex-column">
-    <cover-image
-      class="page_back"
-      :style="backStyle"
-      src="/static/scan/scan-camera-back.png"
-      @click="back"
-    ></cover-image>
     <view class="page_camera flex-grow">
       <camera
         v-if="!isDevTool"
@@ -54,7 +48,7 @@
         >
       </cover-view>
       <view class="flex">
-        <view
+<!--        <view
           class="flex-center flex-column"
           @click="redirect('/pages-charge/codeing/codeing')"
         >
@@ -63,8 +57,8 @@
             mode="widthFix"
             src="/static/scan/scan-code-input.png"
           ></image>
-<!--          <view class="fs-24 color-fff mt-20">输入充电桩编码</view>-->
-        </view>
+&lt;!&ndash;          <view class="fs-24 color-fff mt-20">输入充电桩编码</view>&ndash;&gt;
+        </view>-->
         <view class="flex-center flex-column" @click="chooseImage">
           <image
             class="width-96"

+ 19 - 12
src/pages/index/index.vue

@@ -43,7 +43,10 @@
 
     <!--    站点清单  start-->
     <view class="w100 content_station">
-      <WashStation v-for="item in state.stationList" :key="item.id" :item="item"></WashStation>
+      <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="请先登录"></uv-empty>
     </view>
     <!--    站点清单  end-->
 
@@ -171,9 +174,11 @@ onHide(() => {
 const addListener = () => {
   uni.$on('login', function (data) {
     isLogin.value = data.isLogin;
-    if(!state.bannerList|| state.bannerList.length===0){
+    if (!state.bannerList || state.bannerList.length === 0) {
       loadBannerList();
     }
+    loadWashStationList();
+
   })
 
   uni.$on('logout', function (data) {
@@ -250,17 +255,19 @@ const loadCurrentLocation = () => {
 }
 
 const loadWashStationList = () => {
-  post(`/wash-station/listStation`, {pageSize: 5}).then((res: any) => {
-    console.log(res)
-    let {list, total} = res;
-    list.forEach((station: any) => {
-      if (station.location) {
-        let stationLocation = JSON.parse(station.location);
-        station.distance = calcMapDistance(state.location.latitude, state.location.longitude, stationLocation.stationLat, stationLocation.stationLng);
-      }
+  if (isLogin.value) {
+    post(`/wash-station/listStation`, {pageSize: 5}).then((res: any) => {
+      console.log(res)
+      let {list, total} = res;
+      list.forEach((station: any) => {
+        if (station.location) {
+          let stationLocation = JSON.parse(station.location);
+          station.distance = calcMapDistance(state.location.latitude, state.location.longitude, stationLocation.stationLat, stationLocation.stationLng);
+        }
+      })
+      state.stationList = list;
     })
-    state.stationList = list;
-  })
+  }
 }
 
 const handleNavMap = (station: any) => {