ll
liukangdong
2025-01-23 904436a616ca08fc95e1cbbbd13059835ef37e72
h5/pages/driver/login.vue
@@ -1,220 +1,360 @@
<template>
  <view class="login">
    <image class="login_bg" src="@/static/login_bg@2x.png" />
    <image class="login_logo" src="@/static/logo@2x.png" mode="widthFix" />
    <view class="login_title">安泰物流智慧园区</view>
    <view class="login_title">物流车司机登录</view>
    <view class="login_list">
      <view class="login_list_item">
        <image src="@/static/login_ic_phone@2x.png" mode="widthFix" />
        <input v-model="form.phone" maxlength="18" placeholder="手机号" />
      </view>
      <view class="login_list_item">
        <image src="@/static/login_ic_password@2x.png" mode="widthFix" />
        <input
          v-model="form.password"
          type="password"
          placeholder="密码"
        />
      </view>
    </view>
    <view class="login_btn">
      <view class="login_btn_n" @click="onLogin">立即登录</view>
    </view>
    <!--  -->
      <view class="btns">
         <view class="btn" @click="handleRegister">立即注册</view>
         <view class="btn separate"> | </view>
         <view class="btn">忘记密码</view>
      </view>
  </view>
</template>
<script>
import { resetPassword, sendSms } from '@/api'
export default {
  data() {
    return {
      form: {
      },
      isShowProtocol: false,
      countDown: 0
    }
  },
  onLoad() {
  },
  methods: {
      handleRegister() {
         uni.navigateTo({
            url: "/pages/driver/register"
         })
      },
    dealChange(e) {
      console.log(e)
    },
    initCaptcha() {
      if (!this.form.phone) return uni.showToast({
        title: '手机号不能为空',
        icon: 'none'
      })
      sendSms({ phone: this.form.phone }).then(res => {
        this.countDown = 60
        setInterval(() => {
          if (this.countDown == 0) return
          this.countDown--
        }, 1000)
      })
    },
    onLogin() {
      const { form } = this
      if (!form.phone) return uni.showToast({
        title: '手机号不能为空',
        icon: 'none'
      })
      if (!form.password) return uni.showToast({
        title: '密码不能为空',
        icon: 'none'
      })
      resetPassword({
        ...form
      }).then(res => {
        if (res && res.code == 200) {
          setTimeout(() => {
            uni.showToast({
              title: '密码修改成功,请重新登录',
              icon: 'success',
              duration: 2000
            })
          })
          uni.redirectTo({
            url: "/pages/staffLogin/login"
          })
        }
      })
    }
  }
}
</script>
<style lang="scss" scoped>
.login {
  width: 100%;
  display: flex;
  padding-top: 100rpx;
  box-sizing: border-box;
  align-items: center;
  flex-direction: column;
  background: linear-gradient(
    180deg,
    rgba(39, 155, 170, 0.2) 0%,
    rgba(39, 155, 170, 0) 100%
  );
  .login_logo {
    width: 180rpx;
    height: 180rpx;
      margin-bottom: 40rpx;
  }
  .login_bg {
    position: absolute;
    top: 0;
    width: 750rpx;
  }
  .login_title {
    font-size: 44rpx;
    font-weight: 600;
    color: #333333;
  }
  .login_list {
      margin-top: 60rpx;
    width: 100%;
    padding: 0 60rpx;
    box-sizing: border-box;
    .login_list_item {
      width: 100%;
      border-radius: 50rpx;
      height: 98rpx;
      padding: 0 40rpx;
      box-sizing: border-box;
      background: #ffffff;
      margin-bottom: 40rpx;
      display: flex;
      align-items: center;
      justify-content: space-between;
      &:last-child {
        margin-bottom: 0 !important;
      }
      image {
        flex-shrink: 0;
        width: 40rpx;
        height: 40rpx;
      }
      .captcha {
        color: $uni-color-primary;
      }
      input {
        flex: 1;
        height: 100%;
        color: #666666;
        margin-left: 24rpx;
        border: none;
      }
    }
  }
  .login_btn {
    width: 100%;
    padding: 0 60rpx;
    box-sizing: border-box;
    margin-top: 80rpx;
    .for_psd {
      color: $uni-color-primary;
      margin-top: 40rpx;
      width: 140rpx;
      text-align: center;
      margin: 40rpx auto;
    }
    .login_btn_n {
      width: 100%;
      height: 98rpx;
      background: $uni-color-primary;
      box-shadow: 0rpx 12rpx 24rpx 0rpx rgba(39, 155, 170, 0.2);
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: 600;
      font-size: 32rpx;
      color: #ffffff;
      border-radius: 50rpx;
    }
  }
  .deal_wrap {
    position: absolute;
    width: 100%;
    left: 0;
    text-align: center;
    bottom: 108rpx;
    .deal {
      color: $uni-color-primary;
    }
  }
   .btns{
      display: flex;
      align-items: center;
      justify-content: center;
      position: fixed;
      bottom: 60rpx;
      left: 0;
      width: 100%;
      .btn{
         font-size: 30rpx;
         color: $uni-color-primary;
      }
      .separate{ margin: 0 8rpx; }
   }
}
.modal {
  padding: 32rpx;
}
</style>
<template>
   <view class="login">
      <image class="login_bg" src="@/static/login_bg@2x.png" mode="widthFix" />
      <image class="login_logo" src="@/static/logo@2x.png" mode="widthFix" />
      <view class="login_title">安泰物流智慧园区</view>
      <view class="login_title">物流车司机登录</view>
      <view class="tabs">
         <view class="tab" @click="tabsClick(0)" :class="{active: activeTab == 0  }">
            <view>账号登录</view>
            <view class="bor"></view>
         </view>
         <view class="tab" @click="tabsClick(1)" :class="{active: activeTab == 1  }">
            <view>验证码登录</view>
            <view class="bor"></view>
         </view>
      </view>
      <view class="login_list">
         <template v-if="activeTab == 0">
            <view class="login_list_item">
               <image src="@/static/login_ic_phone@2x.png" mode="widthFix" />
               <input v-model="form.username" type="tel" @focus="showKeyboard = true" @blur="showKeyboard = false"
                  maxlength="18" placeholder="账号" />
            </view>
            <view class="login_list_item">
               <image src="@/static/login_ic_password@2x.png" mode="widthFix" />
               <input v-model="form.password" @focus="showKeyboard = true" @blur="showKeyboard = false" type="password"
                  placeholder="密码" />
            </view>
         </template>
         <template v-else>
            <view class="login_list_item">
               <image src="@/static/login_ic_phone@2x.png" mode="widthFix" />
               <input v-model="form.phone" type="tel" @focus="showKeyboard = true" @blur="showKeyboard = false"
                  :maxlength="18" placeholder="手机号" />
            </view>
            <view class="login_list_item">
               <image src="@/static/ic_captcha.png" mode="widthFix"></image>
               <input v-model="form.code" placeholder="请输入验证码" :maxlength="6" type="number" />
               <text class="captcha" v-if="countDown == 0" @click="initCaptcha">获取验证码</text>
               <text class="placeholder9" v-else>{{ countDown }}</text>
            </view>
         </template>
      </view>
      <view class="login_btn">
         <view class="login_btn_n" @click="onLogin">立即登录</view>
      </view>
      <!--  -->
      <view class="btns" v-if="!showKeyboard">
         <view class="btn" @click="handleRegister">立即注册</view>
         <view class="btn separate"> | </view>
         <view class="btn" @click="handleSetPsd">忘记密码</view>
      </view>
   </view>
</template>
<script>
   import {
      driverLogin,
      loginCaptcha,
      getUserInfo,
      sendSms,
      loginDriverByPhone
   } from '@/api'
   import {
      mapState,
      mapMutations
   } from 'vuex'
   export default {
      data() {
         return {
            form: {
               username: null,
               phone: null,
               password: null
            },
            isShowProtocol: false,
            showKeyboard: false,
            countDown: 0,
            activeTab: 0,
            ywinfo: {}
         }
      },
      onLoad() {
         const ywinfo = uni.getStorageSync('ywinfo') || {}
         if (ywinfo.ywid && ywinfo.type == 0) {
            this.ywinfo = ywinfo
            uni.setStorageSync('ywinfo', {})
         }
      },
      methods: {
         onLogin() {
            const {
               form,
               activeTab
            } = this
            if (activeTab == 0) {
               if (!form.username) return uni.showToast({
                  title: '账号不能为空',
                  icon: 'none'
               })
               if (!form.password) return uni.showToast({
                  title: '密码不能为空',
                  icon: 'none'
               })
            } else {
               if (!form.phone) return uni.showToast({
                  title: '手机号不能为空',
                  icon: 'none'
               })
               if (!form.code) return uni.showToast({
                  title: '验证码不能为空',
                  icon: 'none'
               })
            }
            let fn = activeTab == 0 ? driverLogin : loginDriverByPhone
            fn({
               ...form,
               openid: this.$store.state.openId,
            }).then(res => {
               if (res.code === 200) {
                  this.setToken(res.data)
                  getUserInfo().then(ress => {
                     setTimeout(() => {
                        this.showToast('登录成功')
                     })
                     uni.setStorageSync('ywinfo', this.ywinfo)
                     this.setDriverInfo(ress.data)
                     uni.redirectTo({
                        url: "/pages/driver/index"
                     })
                  })
               }
            })
         },
         ...mapMutations(["setToken", "setDriverInfo"]),
         handleRegister() {
            uni.navigateTo({
               url: "/pages/driver/register"
            })
         },
         tabsClick(val) {
            this.activeTab = val
            if (val == 0) {
               this.form.username = this.form.username || this.form.phone
               this.form.phone = null
               this.form.code = null
            } else {
               this.form.phone = this.form.username || this.form.phone
               this.form.password = null
               this.form.username = null
            }
         },
         handleSetPsd() {
            if (this.form.username || this.form.phone) {
               uni.navigateTo({
                  url: "/pages/driver/forgetPsd?phone=" + this.form.username || this.form.phone || ''
               })
            } else {
               uni.navigateTo({
                  url: "/pages/driver/forgetPsd"
               })
            }
         },
         dealChange(e) {
            console.log(e)
         },
         initCaptcha() {
            if (!this.form.phone) return uni.showToast({
               title: '手机号不能为空',
               icon: 'none'
            })
            sendSms({
               phone: this.form.phone
            }).then(res => {
               if (res.code === 200) {
                  this.countDown = 60
                  setInterval(() => {
                     if (this.countDown == 0) return
                     this.countDown--
                  }, 1000)
               }
            })
         },
      }
   }
</script>
<style lang="scss" scoped>
   .login {
      width: 100%;
      display: flex;
      padding-top: 100rpx;
      box-sizing: border-box;
      align-items: center;
      flex-direction: column;
      background: linear-gradient(180deg,
            rgba(39, 155, 170, 0.2) 0%,
            rgba(39, 155, 170, 0) 100%);
      .login_logo {
         width: 180rpx;
         height: 180rpx;
         margin-bottom: 40rpx;
      }
      .login_bg {
         position: absolute;
         top: 0;
         left: 0;
         width: 100%;
         z-index: -1;
      }
      .login_title {
         font-size: 44rpx;
         font-weight: 600;
         color: #333333;
      }
      .tabs {
         display: flex;
         align-items: center;
         justify-content: space-evenly;
         width: 530rpx;
         margin: 48rpx auto 0rpx;
         .tab {
            font-size: 30rpx;
            color: #666666;
            display: flex;
            flex-direction: column;
            align-items: center;
            height: 52rpx;
            line-height: 36rpx;
         }
         .active {
            font-weight: bold;
            font-size: 34rpx;
            color: #222222;
            .bor {
               width: 80rpx;
               height: 8rpx;
               background: linear-gradient(to bottom, #4d99a8, #a3c8d4);
            }
         }
      }
      .login_list {
         margin-top: 36rpx;
         width: 100%;
         padding: 0 60rpx;
         box-sizing: border-box;
         .login_list_item {
            width: 100%;
            border-radius: 50rpx;
            height: 98rpx;
            padding: 0 40rpx;
            box-sizing: border-box;
            background: #ffffff;
            margin-bottom: 40rpx;
            display: flex;
            align-items: center;
            justify-content: space-between;
            &:last-child {
               margin-bottom: 0 !important;
            }
            image {
               flex-shrink: 0;
               width: 40rpx;
               height: 40rpx;
            }
            .captcha {
               color: $uni-color-primary;
               font-size: 30rpx;
            }
            input {
               flex: 1;
               height: 100%;
               color: #666666;
               margin-left: 24rpx;
               border: none;
            }
         }
      }
      .login_btn {
         width: 100%;
         padding: 0 60rpx;
         box-sizing: border-box;
         margin-top: 80rpx;
         .for_psd {
            color: $uni-color-primary;
            margin-top: 40rpx;
            width: 140rpx;
            text-align: center;
            margin: 40rpx auto;
         }
         .login_btn_n {
            width: 100%;
            height: 98rpx;
            background: $uni-color-primary;
            box-shadow: 0rpx 12rpx 24rpx 0rpx rgba(39, 155, 170, 0.2);
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 600;
            font-size: 32rpx;
            color: #ffffff;
            border-radius: 50rpx;
         }
      }
      .deal_wrap {
         position: absolute;
         width: 100%;
         left: 0;
         text-align: center;
         bottom: 108rpx;
         .deal {
            color: $uni-color-primary;
         }
      }
      .btns {
         display: flex;
         align-items: center;
         justify-content: center;
         position: fixed;
         bottom: 60rpx;
         left: 0;
         width: 100%;
         .btn {
            font-size: 30rpx;
            color: $uni-color-primary;
         }
         .separate {
            margin: 0 8rpx;
         }
      }
   }
   .modal {
      padding: 32rpx;
   }
</style>