Răsfoiți Sursa

登录校验,导航样式调整

zuypeng 1 an în urmă
părinte
comite
1014d12712

+ 1 - 15
src/App.vue

@@ -5,22 +5,8 @@ import {groupByKey} from "@/utils/common";
 
 export default <any>{
   globalData: {
-    token: "bafdaa62-49a8-42a7-b4c9-d323703f65b0",
+    token: "",
     user: {
-      balance: 0,
-      defaultPlateNo: "",
-      discountAmount: 0,
-      gender: "",
-      id: "1306350524487958528",
-      lastLoginTime: "2024-11-17 20:47:13",
-      mobilePhone: "15071072750",
-      nickname: "",
-      openid: "oWsHs6-sE-JqrVmJgTPGO7boZGMY",
-      refundableAmount: 0,
-      status: 1,
-      userCouponList: [],
-      userRechargeRightsList: [],
-      username: "15071072750"
     },
     isLogin: false,
     last:{},

+ 6 - 5
src/components/login-bar/index.vue

@@ -2,23 +2,24 @@
   <view class="login-bar flex flex-inline" v-if="!state.isLogin">
     <text class="login-bar_title" >   请先登录以享受更多洗车功能</text>
     <uv-button class="login-bar_btn" size="mini" shape="circle" type="primary" open-type="getPhoneNumber"
+               color="#19A497"
                @getphonenumber="handleGetPhone">去登录
     </uv-button>
   </view>
 </template>
 <script setup lang="ts" name="loginBar">
 import {login} from "@/utils/auth";
-import {onLoad} from "@dcloudio/uni-app";
+import {onLoad, onShow} from "@dcloudio/uni-app";
 import {reactive} from "vue";
 
 const state= reactive({
   isLogin:false
 });
 
-onLoad(()=>{
-  let globalData = getApp<any>().globalData;
-  state.isLogin = globalData.isLogin;
-  console.log("login bar onLoad>>>>", globalData, state.isLogin)
+onShow(()=>{
+  let userData = getApp<any>().globalData.user;
+  state.isLogin =userData&&userData.id;
+  console.log("login bar onLoad>>>>", userData, state.isLogin)
 })
 
 

+ 6 - 58
src/components/tab-bar/index.vue

@@ -85,60 +85,8 @@
     })
   }
 
- /* export default {
-  props: {
-    index: {
-      type: Number,
-      default: 0
-    }
-  },
-  data() {
-    return {
-      currentItem: 0,
-      tabbarList: [
-        {
-          id: 0,
-          path: '/pages/index/index',
-          icon: '/static/tabbar/1.png',
-          selectIcon: '/static/tabbar/1-1.png',
-          text: '网点',
-          centerItem: false
-        },
-        {
-          id: 1,
-          path: '/pages/map/index',
-          icon: '/static/tabbar/2.png',
-          selectIcon: '/static/tabbar/2-1.png',
-          text: '扫码',
-          centerItem: true
-        },
-        {
-          id: 2,
-          path: '/pages/user/index',
-          icon: '/static/tabbar/4.png',
-          selectIcon: '/static/tabbar/4-1.png',
-          text: '我的',
-          centerItem: false
-        }
-      ]
-    };
-  },
-  mounted() {
-    this.currentItem = this.currentPage;
-    // uni.hideTabBar();
-  },
-  methods: {
-    changeItem(item) {
-      let _this = this;
-      //_this.currentItem = item.id;
-      uni.switchTab({
-        url: item.path
-      });
-    }
-  }
-};*/
 </script>
-<style>
+<style lang="scss" scoped>
 view {
   padding: 0;
   margin: 0;
@@ -146,14 +94,14 @@ view {
 }
 .tabbar-container {
   position: fixed;
-  bottom: 20rpx;
+  bottom: 0;
   left: 0;
   width: 100%;
   height: 110rpx;
   box-shadow: 0 0 3px #999;
   display: flex;
   align-items: center;
-  padding: 5rpx 0;
+  padding: 25rpx 0;
   color: #999999;
 }
 .tabbar-container .tabbar-item {
@@ -166,7 +114,7 @@ view {
   text-align: center;
 }
 .tabbar-container .item-active {
-  color: #398ade;
+  color: $uni-color-primary;
 }
 .tabbar-container .center-item {
   display: block;
@@ -193,11 +141,11 @@ view {
   height: 100%;
 }
 .tabbar-container .tabbar-item .item-bottom {
-  font-size: 28rpx;
+  font-size: 22rpx;
   width: 100%;
 }
 .tabbar-container .center-item .item-bottom {
   position: absolute;
-  bottom: 5rpx;
+  bottom: 30rpx;
 }
 </style>

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

@@ -41,8 +41,13 @@
     </view>
     <!--    站点清单  end-->
 
-<!--    <login-bar class="w100 text-center loginbar"></login-bar>-->
-    <tab-bar :index="0" style="height: 110rpx;"></tab-bar>
+<!--    <cover-view class="login_bar">
+      <login-bar class="w100 text-center"></login-bar>
+    </cover-view>-->
+    <cover-view class="login_bar" v-if="!isLogin">
+      <login-bar class="w100 text-center"></login-bar>
+    </cover-view>
+    <tab-bar :index="0" ></tab-bar>
   </view>
 </template>
 
@@ -54,9 +59,10 @@ import LoginBar from "@/components/login-bar/index.vue";
 import WashStation from "@/components/station/index.vue"
 import {get, post} from "@/utils/https";
 import {calcMapDistance} from "@/utils/common"
+import {checkLogin} from "@/utils/auth";
 
 const title = ref('Hello')
-const qrcode_ref = ref()
+const isLogin = ref(false)
 
 const change = () => {
   console.log("change")
@@ -110,12 +116,15 @@ onLoad((e: any) => {
 })
 
 onShow(() => {
-  let gd = getApp<any>().globalData;
-  if (!gd.token) {
-    console.log(gd)
+  const userData = getApp<any>().globalData.user;
+  if (userData&&userData.id) {
+    isLogin.value = true;
   }
+  console.log("show index>>>>",isLogin.value)
   loadCurrentLocation();
-
+  uni.$on('loginEvent', function (data) {
+    isLogin.value = data.isLogin;
+  })
 
 });
 
@@ -123,16 +132,18 @@ onHide(() => {
   Object.assign(state, initState());
 })
 
-const handleMenuClick = (menu:any) => {
-  if(menu.title==='洗车'){
-    uni.navigateTo({
-      url:'/pages-wash/scan/index'
-    })
-  }else  if(menu.title==='充值'){
-    uni.navigateTo({
-      url:'/pages-user/wallet/recharge'
-    })
-  }
+const handleMenuClick =  (menu:any) => {
+   checkLogin().then((res)=>{
+     if(menu.title==='洗车'){
+       uni.navigateTo({
+         url:'/pages-wash/scan/index'
+       })
+     }else  if(menu.title==='充值'){
+       uni.navigateTo({
+         url:'/pages-user/wallet/recharge'
+       })
+     }
+   })
 }
 
 /**

+ 24 - 29
src/pages/user/index.vue

@@ -44,7 +44,7 @@
     </view>
   </block>
 
-  <cover-view class="login_bar">
+  <cover-view class="login_bar" v-if="!isLogin">
     <login-bar class="w100 text-center"></login-bar>
   </cover-view>
 
@@ -107,29 +107,30 @@ const menu = ref([
 ]);
 
 
-const toPage = async (item: any) => {
-  // let checkUser = await checkLogin();
-  let {title, path} = item;
-  if (path.includes('contact')) {
-    uni.makePhoneCall({
-      phoneNumber: service.value,
-      fail: (error) => {
-        console.log(error)
-      }
+const toPage =  (item: any) => {
+  checkLogin().then(()=>{
+    let {title, path} = item;
+    if (path.includes('contact')) {
+      uni.makePhoneCall({
+        phoneNumber: service.value,
+        fail: (error) => {
+          console.log(error)
+        }
+      });
+      return;
+    } else if (path.includes("order") || path.includes("coupon")) {
+      uni.switchTab({
+        url: path
+      })
+    }
+    uni.navigateTo({
+      url: item.path,
     });
-    return;
-  } else if (path.includes("order") || path.includes("coupon")) {
-    uni.switchTab({
-      url: path
-    })
-  }
-  uni.navigateTo({
-    url: item.path,
-  });
+  })
+
 };
 
 const loginListen = () => {
-
   uni.$on('loginEvent', function (data) {
     isLogin.value = data.isLogin;
     console.log("event>>>",data)
@@ -146,20 +147,14 @@ onLoad(() => {
   containerStyle.value = {
     top: `${bound.bottom + 10}px`,
   };
-  // fetchContact().then((res) => {
-  //   if (res && res.mobile) {
-  //     service.value = res.mobile;
-  //   }
-  // });
-  // loginListen();
 });
 
 
 onShow(() => {
-  const user = getApp<any>().globalData.user;
-  if (user) {
+  const userData = getApp<any>().globalData.user;
+  if (userData&&userData.id) {
     isLogin.value = true;
-    user.value = user;
+    user.value = userData;
   }
   loginListen();
 });

+ 1 - 1
src/utils/auth.ts

@@ -102,7 +102,7 @@ export function login(e: any): Promise<string> {
 export function checkLogin() {
     return new Promise((resolve, reject) => {
         let user = getApp<any>().globalData.user;
-        if (!user) {
+        if (!user||!user.id) {
             uni.showToast({
                 icon: "none",
                 title: "请先登录",