Browse Source

add phonenumber valdiate

old
wangqing 4 years ago
parent
commit
4ee18058f1
  1. 43
      src/components/form/PhoneVerification/index.vue
  2. 19
      src/components/generator/config.js
  3. 4
      src/components/render/render.js
  4. 4
      src/views/test.vue

43
src/components/form/PhoneVerification/index.vue

@ -1,25 +1,26 @@
<template> <template>
<div> <div class="phone-number-container">
<el-input <el-input
v-model="inputValue" v-model="inputValue"
class="input-with-select"
maxlength="11" maxlength="11"
readonly placeholder="点击验证手机号" readonly @click.native="openDialogHandle"
placeholder="点击验证手机号" class="input-with-select" @click="open=true"
> >
<i slot="prefix" class="el-input__icon el-icon-mobile" /> <i slot="prefix" class="el-input__icon el-icon-mobile" />
<el-button slot="append" icon="el-icon-message" @click="open=true" /> <el-button slot="append" icon="el-icon-message" @click="openDialogHandle" />
</el-input> </el-input>
<el-dialog title="手机号验证" :visible.sync="open"> <el-dialog :visible.sync="open" title="手机号验证">
<el-form ref="form" :model="phoneValidateForm" label-width="80px" :rules="rules"> <el-form ref="form" :model="phoneValidateForm" :rules="rules" label-width="80px">
<el-form-item label="手机号" prop="phoneNumber"> <el-form-item label="手机号" prop="phoneNumber">
<el-input v-model="phoneValidateForm.phoneNumber" maxlength="11" show-word-limit <el-input v-model="phoneValidateForm.phoneNumber" maxlength="11" prefix-icon=" el-icon-mobile "
prefix-icon=" el-icon-mobile " show-word-limit
/> />
</el-form-item> </el-form-item>
<el-form-item label="验证码" prop="code"> <el-form-item label="验证码" prop="code">
<el-input v-model="validateCode" prefix-icon="el-icon-message" class="width80" /> <el-input v-model="phoneValidateForm.code" style="width: 85%;" prefix-icon="el-icon-message" />
<el-button type="primary" <el-button :disabled="phoneValidateCodeBtn"
:disabled="phoneValidateCodeBtn" style="width: 10%;"
type="primary"
@click="sendValidateMsgHandle" @click="sendValidateMsgHandle"
> >
{{ phoneValidateCodeBtnText }} {{ phoneValidateCodeBtnText }}
@ -44,7 +45,6 @@ export default {
return { return {
phoneValidateCodeBtnText: '发送验证码', phoneValidateCodeBtnText: '发送验证码',
phoneValidateCodeBtn: false, phoneValidateCodeBtn: false,
validateCode: '',
open: false, open: false,
inputValue: null, inputValue: null,
phoneValidateForm: { phoneValidateForm: {
@ -64,10 +64,22 @@ export default {
} }
}, },
methods: { methods: {
openDialogHandle() {
this.open = true
this.phoneValidateForm = {
phoneNumber: '',
code: ''
}
},
validateCodeHandle() { validateCodeHandle() {
this.$refs['form'].validate(valid => { this.$refs['form'].validate(valid => {
if (valid) { if (valid) {
// //
this.$api.post('/project/phone/code/check', this.phoneValidateForm).then(res => {
this.inputValue = res.data
this.open = false
this.$emit('input', res.data)
})
} else { } else {
return false return false
} }
@ -77,7 +89,7 @@ export default {
this.$refs['form'].validateField('phoneNumber', err => { this.$refs['form'].validateField('phoneNumber', err => {
if (!err) { if (!err) {
this.phoneValidateCodeBtn = true this.phoneValidateCodeBtn = true
this.$api.get(`/register/phone/code?phoneNumber=${this.inputPhoneNumber}`).then(() => { this.$api.get(`/project/phone/code?phoneNumber=${this.phoneValidateForm.phoneNumber}`).then(() => {
this.msgSuccess('验证码发送成功,5分钟内有效') this.msgSuccess('验证码发送成功,5分钟内有效')
this.phoneValidateCodeBtn = true this.phoneValidateCodeBtn = true
let count = 60 let count = 60
@ -98,3 +110,8 @@ export default {
} }
</script> </script>
<style lang="scss" scoped>
.phone-number-container {
display: flex;
}
</style>

19
src/components/generator/config.js

@ -818,5 +818,24 @@ export const personalInfoComponents = [
}, },
placeholder: '请选择位置', placeholder: '请选择位置',
style: {width: '100%'} style: {width: '100%'}
},
{
typeId: 'PHONE_VERIFICATION',
__config__: {
label: '手机号验证',
labelWidth: null,
showLabel: true,
changeTag: false,
tag: 'phone-verification',
tagIcon: 'input',
defaultValue: undefined,
required: true,
layout: 'colFormItem',
span: 24,
showRegList: false,
document: 'https://element.eleme.cn/#/zh-CN/component/input'
},
placeholder: '请验证手机号',
style: {width: '100%'}
} }
] ]

4
src/components/render/render.js

@ -1,5 +1,6 @@
import {deepClone} from '@/utils/index' import {deepClone} from '@/utils/index'
import SignPad from '@/components/form/SignPad/index' import SignPad from '@/components/form/SignPad/index'
import PhoneVerification from '@/components/form/PhoneVerification/index'
const componentChild = {} const componentChild = {}
/** /**
@ -127,7 +128,8 @@ function makeDataObject() {
export default { export default {
components: { components: {
SignPad SignPad,
PhoneVerification
}, },
props: { props: {
conf: { conf: {

4
src/views/test.vue

@ -4,6 +4,7 @@
<pagination /> <pagination />
<province-city /> <province-city />
<input-map /> <input-map />
<phone-verification />
</div> </div>
</template> </template>
@ -13,10 +14,13 @@ import pagination from '../components/form/pagination'
import ProvinceCity from '@/components/form/ProvinceCity' import ProvinceCity from '@/components/form/ProvinceCity'
import InputMap from '@/components/form/InputMap/index' import InputMap from '@/components/form/InputMap/index'
import PhoneVerification from '@/components/form/PhoneVerification/index'
export default { export default {
name: 'App', name: 'App',
components: { components: {
ProvinceCity, ProvinceCity,
PhoneVerification,
SignPad, SignPad,
pagination, pagination,
InputMap InputMap

Loading…
Cancel
Save