提交 cc011ece 编写于 作者: RedPig97's avatar RedPig97

update:短信验证

上级 5d82654e
...@@ -6,16 +6,19 @@ ...@@ -6,16 +6,19 @@
border: 1px solid #dcdee2; border: 1px solid #dcdee2;
margin-left: 10px; margin-left: 10px;
color: #606266; color: #606266;
background-color: #fff;
&:hover { &:hover {
border: 1px solid #dcdee2; border: 1px solid #dcdee2;
} }
&.is-disabled {
background-color: #f5f5f5;
color: #00000040;
}
} }
} }
.code{ .code{
padding-top: 8px; padding-top: 8px;
} }
.error { .ivu-alert-error {
color: red; background-color: rgb(255, 225, 225);
} }
} }
\ No newline at end of file
<template> <template>
<div class="app-login-note-verify"> <div :class="[model.sysCss, 'app-login-note-verify']" :style="containerStyle">
<div class="content"> <div class="content">
<i-input <i-input
size="default" size="default"
...@@ -8,15 +8,12 @@ ...@@ -8,15 +8,12 @@
:placeholder="$t('components.login.phoneplaceholder')" :placeholder="$t('components.login.phoneplaceholder')"
@on-blur="veriPhoneNumber" @on-blur="veriPhoneNumber"
></i-input> ></i-input>
<el-button <el-button :disabled="disabled" size="mini" @click="getVeriCode()">{{
:disabled="disabled" disabled ? `${delay}s ${$t("components.login.getcodeafter")}` : `${$t("components.login.getcode")}`
size="mini" }}</el-button>
type="primary"
@click="getVeriCode()"
>{{ disabled ? `${countDown}s ${$t('components.login.getcodeafter')}` : `${$t('components.login.getcode')}` }}</el-button
>
</div> </div>
<div class="code"> <alert v-show="phoneError" type="error">电话号码格式错误</alert>
<div class="code" v-show="this.show">
<i-input <i-input
size="default" size="default"
type="text" type="text"
...@@ -28,118 +25,140 @@ ...@@ -28,118 +25,140 @@
</div> </div>
</template> </template>
<script lang='ts'> <script lang="ts">
import { PanelFieldModel } from "@/model/panel-detail";
import { Vue, Component, Prop } from "vue-property-decorator"; import { Vue, Component, Prop } from "vue-property-decorator";
@Component({}) @Component({})
export default class AppPresetSmsVerification extends Vue { export default class AppLoginNoteVerify extends Vue {
/**
* 模型
*
* @type {string}
* @memberof AppLoginInput
*/
@Prop() public model!: PanelFieldModel;
/** /**
*验证码 *
* *
* @type {string} * @type {string}
* @memberof AppPresetSmsVerification * @memberof AppLoginInput
*/ */
@Prop() public value!: string; @Prop() public value!: string;
/**
* 名称
*
* @type {string}
* @memberof AppLoginInput
*/
@Prop() public name!: string;
/** /**
*验证码当前值 *验证码当前值
* *
* @type {string} * @type {string}
* @memberof AppPresetSmsVerification * @memberof AppLoginNoteVerify
*/ */
get currentValue(): string { get currentValue(): string {
return this.value; return this.value;
} }
/** /**
* 手机号 * 手机号
* *
* @type {*} * @type {*}
* @memberof AppPresetSmsVerification * @memberof AppLoginNoteVerify
*/ */
public phoneNumber: string = ''; public phoneNumber: string = "";
/**
* 倒计时
*
* @type {*}
* @memberof AppPresetSmsVerification
*/
public countDown: number = 60;
/** /**
* 错误提示 * 错误提示
* @type {*} * @type {*}
* @memberof AppPresetSmsVerification * @memberof AppLoginNoteVerify
*/ */
public phoneError = false; public phoneError = false;
/** /**
* 是否禁用获取验证码按钮 * 是否禁用获取验证码按钮
* *
* @type {*} * @type {boolean}
* @memberof AppPresetSmsVerification * @memberof AppLoginNoteVerify
*/ */
public disabled: boolean = false; public disabled: boolean = false;
/** /**
* 定时器 * 显示验证码输入框
* *
* @type {*} * @type {boolean}
* @memberof AppPresetSmsVerification * @memberof AppLoginNoteVerify
*/ */
public timer: any; public show: boolean = false;
/** /**
* @description 设置倒计时 * 延迟
* @memberof AppPresetSmsVerification *
* @type {number}
* @memberof AppLoginNoteVerify
*/ */
public setCountDown() { public delay: number = 60;
if (this.countDown > 0) {
this.countDown--; /**
} else { * 定时器
this.countDown = 60; *
this.disabled = false; * @type {any}
clearInterval(this.timer); * @memberof AppLoginNoteVerify
} */
this.$forceUpdate(); public timer: any = null;
}
/** /**
* @description 验证码输入变化 * @description 验证码输入变化
* @memberof AppPresetSmsVerification * @memberof AppLoginNoteVerify
*/ */
public codeChange(value: string) { public codeChange(value: string) {
this.$emit("change", value); this.$emit("valueChange", { name: this.name, value: value });
} }
/** /**
* @description 校验手机号 * @description 校验手机号
* @memberof AppPresetSmsVerification * @memberof AppLoginNoteVerify
*/ */
public veriPhoneNumber(): boolean { public veriPhoneNumber(): boolean {
this.phoneError = !/^1[3-9]\d{9}$/.test(this.phoneNumber); this.phoneError = !/^1[3-9]\d{9}$/.test(this.phoneNumber);
if(this.phoneError) { return this.phoneError;
this.$emit("error", this.$t('components.login.phonefailed')); }
/**
* @description 设置延迟时间
* @memberof AppLoginNoteVerify
*/
public setDelay() {
this.timer = setInterval(() => {
if (this.delay > 0) {
this.delay--;
} else { } else {
this.$emit("error", ''); this.delay = 60;
this.disabled = false;
clearInterval(this.timer);
} }
return this.phoneError; }, 1000)
} }
/** /**
* @description 获取验证码 * @description 获取验证码
* @memberof AppPresetSmsVerification * @memberof AppLoginNoteVerify
*/ */
public getVeriCode() { public getVeriCode() {
if(this.phoneError) return; if (this.phoneError) return;
// todo 获取验证码 // todo 获取验证码
this.show = true;
this.disabled = true;
this.setDelay();
} }
} }
</script> </script>
<style lang='less'> <style lang="less">
@import "./app-login-note-verify.less"; @import "./app-login-note-verify.less";
</style> </style>
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册