Step1.vue 5.5 KB
Newer Older
1 2 3
<template>
  <div class="main">

4
    <a-form style="max-width: 500px; margin: 40px auto 0;" :form="form" @keyup.enter.native="nextStep">
5 6 7 8 9 10
      <a-form-item>
        <a-input
          v-decorator="['username',validatorRules.username]"
          size="large"
          type="text"
          autocomplete="false"
11
          placeholder="请输入用户账号或手机号">
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
          <a-icon slot="prefix" type="lock" :style="{ color: 'rgba(0,0,0,.25)' }"/>
        </a-input>
      </a-form-item>
      <a-row :gutter="0">
        <a-col :span="14">
          <a-form-item>
            <a-input
              v-decorator="['inputCode',validatorRules.inputCode]"
              size="large"
              type="text"
              @change="inputCodeChange"
              placeholder="请输入验证码">
              <a-icon slot="prefix" v-if=" inputCodeContent==verifiedCode " type="smile"
                      :style="{ color: 'rgba(0,0,0,.25)' }"/>
              <a-icon slot="prefix" v-else type="frown" :style="{ color: 'rgba(0,0,0,.25)' }"/>
            </a-input>
          </a-form-item>
        </a-col>
30 31 32
        <a-col :span="10" style="text-align: right">
          <img v-if="requestCodeSuccess" style="margin-top: 2px;" :src="randCodeImage" @click="handleChangeCheckCode"/>
          <img v-else style="margin-top: 2px;" src="../../assets/checkcode.png" @click="handleChangeCheckCode"/>
33 34 35
        </a-col>
      </a-row>
      <a-form-item :wrapperCol="{span: 19, offset: 5}">
36
        <router-link style="float: left;line-height: 40px;" :to="{ name: 'login' }">使用已有账户登录</router-link>
37 38 39 40 41 42 43
        <a-button type="primary" @click="nextStep">下一步</a-button>
      </a-form-item>
    </a-form>
  </div>
</template>

<script>
44 45
  import { getAction,postAction } from '@/api/manage'
  import { checkOnlyUser } from '@/api/api'
46

47 48
  export default {
    name: "Step1",
49
    data() {
50 51 52
      return {
        form: this.$form.createForm(this),
        inputCodeContent: "",
53 54
        inputCodeNull: true,
        verifiedCode: "",
55
        validatorRules: {
56
          username: {rules: [{required: false}, {validator: this.validateInputUsername}]},
57
          inputCode: {rules: [{required: true, message: '请输入验证码!'}]},
58
        },
59 60 61
        randCodeImage:'',
        requestCodeSuccess:true,
        currdatetime:''
62 63 64

      }
    },
65 66 67
    created(){
      this.handleChangeCheckCode();
    },
68
    methods: {
69 70 71 72 73 74 75 76 77 78 79 80 81 82
      handleChangeCheckCode(){
        this.currdatetime = new Date().getTime();
        getAction(`/sys/randomImage/${this.currdatetime}`).then(res=>{
          if(res.success){
            this.randCodeImage = res.result
            this.requestCodeSuccess=true
          }else{
            this.$message.error(res.message)
            this.requestCodeSuccess=false
          }
        }).catch(()=>{
          this.requestCodeSuccess=false
        })
      },
83
      nextStep() {
84 85
        let that = this
        this.form.validateFields((err, values) => {
86 87 88 89 90 91 92 93 94 95 96
          if (!err) {
            let isPhone = false;
            var params = {}
            var reg = /^[1-9]\d*$|^0$/;
            var username = values.username;
            if (reg.test(username) == true) {
              params.phone = username;
              isPhone = true
            } else {
              params.username = username;
            }
97 98 99 100 101 102 103 104 105 106 107 108 109 110
            that.validateInputCode().then(()=>{
              getAction("/sys/user/querySysUser", params).then((res) => {
                if (res.success) {
                  var userList = {
                    username: res.result.username,
                    phone: res.result.phone,
                    isPhone: isPhone
                  };
                  setTimeout(function () {
                    that.$emit('nextStep', userList)
                  })
                }
              });
            })
111
          }
112
        })
113 114

      },
115 116 117 118 119 120 121 122 123 124 125 126 127 128
      validateInputCode() {
        return new Promise((resolve,reject)=>{
          postAction("/sys/checkCaptcha",{
            captcha:this.inputCodeContent,
            checkKey:this.currdatetime
          }).then(res=>{
            if(res.success){
              resolve();
            }else{
              this.$message.error(res.message)
              reject();
            }
          });
        })
129
      },
130
      inputCodeChange(e) {
131 132
        this.inputCodeContent = e.target.value;
        console.log(this.inputCodeContent)
133 134 135
        if (!e.target.value || 0 == e.target.value) {
          this.inputCodeNull = true
        } else {
136
          this.inputCodeContent = this.inputCodeContent.toLowerCase()
137
          this.inputCodeNull = false
138 139
        }
      },
140
      generateCode(value) {
141 142 143
        this.verifiedCode = value.toLowerCase();
        console.log(this.verifiedCode);
      },
144
      validateInputUsername(rule, value, callback) {
145
        console.log(value);
146 147
        var reg = /^[0-9]+.?[0-9]*/;
        if (!value) {
148 149 150
          callback("请输入用户名和手机号!");
        }

151
        //判断用户输入账号还是手机号码
152
        if (reg.test(value)) {
153
          var params = {
154
            phone: value,
155
          };
156
          checkOnlyUser(params).then((res) => {
157
            if (res.success) {
158 159 160 161 162 163
              callback("用户名不存在!")
            } else {
              callback()
            }
          })
        } else {
164
          var params = {
165
            username: value,
166
          };
167
          checkOnlyUser(params).then((res) => {
168
            if (res.success) {
169 170 171 172 173
              callback("用户名不存在!")
            } else {
              callback()
            }
          })
174 175 176 177 178 179 180 181 182 183
        }
      },

    }
  }
</script>

<style scoped>

</style>