jiangping
2024-08-27 3a992a2be8c1cc815719ac76cd7242dd7a2f7c2d
h5/pages/driver/login.vue
@@ -7,7 +7,7 @@
    <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" maxlength="18" placeholder="手机号" />
      </view>
      <view class="login_list_item">
        <image src="@/static/login_ic_password@2x.png" mode="widthFix" />
@@ -25,52 +25,53 @@
      <view class="btns">
         <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: '13996529050',
            password: '1'
      },
      isShowProtocol: false,
      countDown: 0
    }
  },
  onLoad() {
      this.initCaptcha()
  },
  methods: {
      ...mapMutations(["setToken", "setDriverInfo"]),
      handleRegister() {
         uni.navigateTo({
            url: "/pages/driver/register"
         })
      },
      handleSetPsd() {
         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 => {
        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 +79,21 @@
        title: '密码不能为空',
        icon: 'none'
      })
      resetPassword({
        ...form
      driverLogin({
        ...form,
            uuid: this.captcha.uuid,
            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"
          })
        }
      })