step1.vue 3.18 KB
<template>
  <el-card style="min-height: 50vh">
    <div class="pt30">
      <el-form class="d-form" size="large" label-width="120" style="max-width: 500px;margin: auto">
      <el-form-item label="手机/邮箱" required>
        <el-input type="text" v-model="form.account" @change="resetCode" @blur="verifyCode"/>
      </el-form-item>
      <el-form-item label="验证码" required>
        <el-input v-model="form.code">
          <template #append>
            <el-button type="primary" plain style="width: 110px" @click="sendsmsMsg">
              <count-down v-if="counting" v-slot="{ totalSeconds }" :time="60000" @end="counting=false">
                {{ totalSeconds }}
              </count-down>
              <span v-else>
                  发送验证码
                </span>
            </el-button>
          </template>
        </el-input>
        <div class="vcodeBox" :style="isShow?'height:240px':'height:0'">
          <Vcode :show="isShow" type="inside" @success="codeSuccess" @close="codeClose" @fail='codeFail'></Vcode>
        </div>
      </el-form-item>
    </el-form>
    </div>
    <div class="text-center">
<!--      <el-button class="primary-kx" round @click="goBack">取消</el-button>-->
      <el-button type="primary" class="btn-lineG w200px" round @click="next">下一步</el-button>
    </div>
  </el-card>
</template>

<script setup>
import {reactive} from "@vue/runtime-core";
import {toRefs} from "@vueuse/shared/index";
import Vcode from "vue3-puzzle-vcode"
import { ElMessage } from 'element-plus'
import CountDown from '@chenfengyuan/vue-countdown'
import {getCaptchaSms,checkRegisterCode} from "@/apiPc/match";
const data = reactive({
  isShow:false,
  isCodeTrue:false,
  counting:false,
  form:{},
  activeStep: 0
})
const {isShow,isCodeTrue,counting,form,activeStep} = toRefs(data)
const emit = defineEmits(['submit','userName'])
function sendsmsMsg() {
  if(!form.value.account){
    ElMessage.error('请填写手机/邮箱')
    return
  }
  if(counting.value){
    return
  } else {
    isShow.value = true
  }
}
function verifyCode() {
  if(!form.value.account){
    return
  }
  if(form.value.account.indexOf('@')>-1){
    //邮箱
  }
}
function codeSuccess(msg) {
  console.log('验证通过' + msg);
  isShow.value = false
  isCodeTrue.value = true
  counting.value = true
  // getCaptchaSms({account:form.value.account}).then(res=>{
  //
  // })
}
function resetCode() {
  isCodeTrue.value = false
}
function codeFail() {

}
function codeClose() {

}
const goBack = () => {
  router.go(-1)
}
const next = () => {
  if(!form.value.account){
    ElMessage.error('请填写手机/邮箱')
    return
  }
  if(!form.value.code){
    ElMessage.error('请填写验证码')
    return
  }
  if(!isCodeTrue.value){
    return
  }
  checkRegisterCode(form.value).then(res=>{
    emit('submit')
    emit('userName',form.value.account)
  })
}

</script>

<style scoped lang="scss">
.el-input-group__append button.el-button, .el-input-group__append button.el-button:hover{
  color: var(--el-color-primary);
  background: #efefff;
  border: var(--el-color-primary) solid 1px;
  border-radius: 0;
}
.vcodeBox{ position: relative;margin: 20px 0 0;
  width: 320px;overflow: hidden;
  height: auto;}
</style>