提交 9afe1cdd authored 作者: 王鹏飞's avatar 王鹏飞

增加验证码

上级 0e42d7d1
...@@ -22,6 +22,15 @@ textarea { ...@@ -22,6 +22,15 @@ textarea {
border-radius: 0; border-radius: 0;
font: inherit; font: inherit;
} }
::placeholder {
color: #999;
}
.line-clamp {
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.main-layout { .main-layout {
max-width: 750px; max-width: 750px;
min-height: 100vh; min-height: 100vh;
......
...@@ -10,13 +10,20 @@ ...@@ -10,13 +10,20 @@
</div> </div>
<div class="form-item"> <div class="form-item">
<select class="form-select" placeholder="请选择项目" v-model="ruleForm.project_id"> <select class="form-select" placeholder="请选择项目" v-model="ruleForm.project_id">
<option value="" disabled selected>请选择项目</option>
<option v-for="(item, index) in projectList" :value="item.value" :key="index">{{ item.label }}</option> <option v-for="(item, index) in projectList" :value="item.value" :key="index">{{ item.label }}</option>
</select> </select>
</div> </div>
<!-- <div class="form-item"> <div class="form-item">
<input type="text" class="form-input" placeholder="请输入短信验证码" maxlength="4" v-model="ruleForm.code" /> <input type="text" class="form-input" placeholder="请输入短信验证码" maxlength="4" v-model="phoneCode" />
<input type="button" value="获取验证码" class="form-button" /> <input
</div> --> type="button"
class="form-button"
:disabled="codeButtonDisabled"
:value="buttonText"
@click="onSendCode"
/>
</div>
<div class="form-item"> <div class="form-item">
<input type="button" value="立即预约" class="form-button" @click="onSbumit" /> <input type="button" value="立即预约" class="form-button" @click="onSbumit" />
</div> </div>
...@@ -38,12 +45,15 @@ export default { ...@@ -38,12 +45,15 @@ export default {
{ label: '教育学硕士', value: '1005' }, { label: '教育学硕士', value: '1005' },
{ label: '中国未来金融领袖计划', value: '1007' } { label: '中国未来金融领袖计划', value: '1007' }
], ],
timer: null phoneCode: '',
codeButtonDisabled: false,
timer: null,
disabledTime: 60
} }
}, },
computed: { computed: {
buttonText() { buttonText() {
return '' return this.codeButtonDisabled ? `${this.disabledTime}秒后重发` : '获取验证码'
} }
}, },
methods: { methods: {
...@@ -56,11 +66,11 @@ export default { ...@@ -56,11 +66,11 @@ export default {
this.$notify('请输入正确的手机号') this.$notify('请输入正确的手机号')
return return
} }
// if (!this.ruleForm.code) { if (!this.phoneCode) {
// this.$notify('请输入短信验证码') this.$notify('请输入短信验证码')
// return return
// } }
this.handleSubmit() this.checkPhoneCode().then(this.handleSubmit)
}, },
handleSubmit() { handleSubmit() {
api.submit(this.ruleForm).then(response => { api.submit(this.ruleForm).then(response => {
...@@ -71,15 +81,40 @@ export default { ...@@ -71,15 +81,40 @@ export default {
}) })
}, },
// 校验短信验证码 // 校验短信验证码
checkPhoneCode() {}, checkPhoneCode() {
return api.checkCode({ account: this.ruleForm.phone, code: this.phoneCode })
},
onSendCode() {
if (!this.ruleForm.phone || !/^1[3-9]\d{9}$/.test(this.ruleForm.phone)) {
this.$notify('请输入正确的手机号')
return
}
this.sendCode()
},
// 发送验证码 // 发送验证码
sendCode() { sendCode() {
this.setTimer() this.setTimer()
api
.sendCode({ account: this.ruleForm.phone })
.then(() => {
this.$notify({ type: 'success', message: '验证码发送成功,注意查收' })
})
.catch(() => {
this.clearTimer()
})
}, },
setTimer() { setTimer() {
this.timer = setInterval(() => {}, 1000) this.codeButtonDisabled = true
this.disabledTime = 60
this.timer = setInterval(() => {
this.disabledTime--
if (this.disabledTime <= 0) {
this.clearTimer()
}
}, 1000)
}, },
clearTimer() { clearTimer() {
this.codeButtonDisabled = false
this.timer && clearInterval(this.timer) this.timer && clearInterval(this.timer)
} }
}, },
...@@ -113,10 +148,13 @@ export default { ...@@ -113,10 +148,13 @@ export default {
border: none; border: none;
} }
.form-select { .form-select {
position: relative;
padding: 0 10px; padding: 0 10px;
width: 100%; width: 100%;
height: 38px; height: 38px;
background-color: #fff; background: #fff url('https://webapp-pub.ezijing.com/www/h5/images/icon_arrows.png') no-repeat;
background-position: right 0.7em top 50%, 0 0;
background-size: 30px 30px;
box-sizing: border-box; box-sizing: border-box;
border: none; border: none;
} }
......
...@@ -32,8 +32,6 @@ ...@@ -32,8 +32,6 @@
</template> </template>
<script> <script>
import ApplyForm from '@/components/ApplyForm' import ApplyForm from '@/components/ApplyForm'
// import { sendCode, checkCode, postNes } from '../plugins/api'
const MOBILE_REG = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/
export default { export default {
components: { ApplyForm }, components: { ApplyForm },
data() { data() {
......
import axios from 'axios' import axios from 'axios'
import qs from 'qs' import qs from 'qs'
import { Notify } from 'vant'
const httpRequest = axios.create({ const httpRequest = axios.create({
baseURL: 'https://project-api.ezijing.com', baseURL: 'https://project-api.ezijing.com',
...@@ -34,33 +35,19 @@ httpRequest.interceptors.request.use( ...@@ -34,33 +35,19 @@ httpRequest.interceptors.request.use(
httpRequest.interceptors.response.use( httpRequest.interceptors.response.use(
function(response) { function(response) {
const { data } = response const { data } = response
if (data.msg) { if (parseInt(data.code)) {
if (data.msg === '请先登录') { Notify(data.msg)
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}` return Promise.reject(data)
}
}
if (parseInt(data.code) === 1) {
return Message.error(data.msg)
}
if (data.code) {
if (data.code === 4001) {
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
}
return data.message ? Message.error(data.message) : Message.error(data.msg)
} }
return data return data
}, },
function(error) { function(error) {
if (error.response) { if (error.response) {
const { status, message } = error.response.data const { message } = error.response.data
// 未登录 Notify(message || error.response.data)
if (status === 403) {
window.location.href = `${webConf.others.loginUrl}?rd=${encodeURIComponent(window.location.href)}`
}
Message.error(message || error.response.data)
return Promise.reject(error.response) return Promise.reject(error.response)
} else { } else {
Message.error(error) Notify(error)
} }
return Promise.reject(error) return Promise.reject(error)
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论