ll
liukangdong
2024-12-06 86baa8ff948d2e79588e0dd7efa16f6b8ac3b157
h5/pages/driver/login.vue
@@ -1,18 +1,19 @@
<template>
  <view class="login">
    <image class="login_bg" src="@/static/login_bg@2x.png" />
    <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="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="手机号" />
        <input v-model="form.username"  @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="密码"
        />
@@ -22,55 +23,57 @@
      <view class="login_btn_n" @click="onLogin">立即登录</view>
    </view>
    <!--  -->
      <view class="btns">
      <view class="btns" v-if="!showKeyboard">
         <view class="btn" @click="handleRegister">立即注册</view>
         <view class="btn separate"> | </view>
         <view class="btn">忘记密码</view>
         <view class="btn" @click="handleSetPsd">忘记密码</view>
      </view>
  </view>
</template>
<script>
import { resetPassword, sendSms } from '@/api'
import { driverLogin, loginCaptcha, getUserInfo } from '@/api'
import { mapState, mapMutations } from 'vuex'
export default {
  data() {
    return {
      form: {
            username: '',
            password: ''
      },
      isShowProtocol: false,
         showKeyboard: false,
      countDown: 0
    }
  },
  onLoad() {
      this.initCaptcha()
  },
  methods: {
      ...mapMutations(["setToken", "setDriverInfo"]),
      handleRegister() {
         uni.navigateTo({
            url: "/pages/driver/register"
         })
      },
      handleSetPsd() {
         uni.navigateTo({
            url: "/pages/driver/forgetPsd?phone=" + this.form.username
         })
      },
    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)
      loginCaptcha().then(res => {
        this.captcha = res.data
      })
    },
    onLogin() {
      const { form } = this
      if (!form.phone) return uni.showToast({
      if (!form.username) return uni.showToast({
        title: '手机号不能为空',
        icon: 'none'
      })
@@ -78,19 +81,22 @@
        title: '密码不能为空',
        icon: 'none'
      })
      resetPassword({
        ...form
      driverLogin({
        ...form,
            uuid: this.captcha.uuid,
            openid: this.$store.state.openId,
            code: '1'
      }).then(res => {
        if (res && res.code == 200) {
          setTimeout(() => {
            uni.showToast({
              title: '密码修改成功,请重新登录',
              icon: 'success',
              duration: 2000
        if (res.code === 200) {
          this.setToken(res.data)
          getUserInfo().then(ress => {
                  setTimeout(() => {
                     this.showToast('登录成功')
                  })
            this.setDriverInfo(ress.data)
            uni.redirectTo({
              url: "/pages/driver/index"
            })
          })
          uni.redirectTo({
            url: "/pages/staffLogin/login"
          })
        }
      })
@@ -118,9 +124,11 @@
      margin-bottom: 40rpx;
  }
  .login_bg {
    position: absolute;
    top: 0;
    width: 750rpx;
     position: absolute;
     top: 0;
     left: 0;
     width: 100%;
     z-index: -1;
  }
  .login_title {
    font-size: 44rpx;