提交 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"
type="text" type="text"
v-model="phoneNumber" v-model="phoneNumber"
: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" </div>
@click="getVeriCode()" <alert v-show="phoneError" type="error">电话号码格式错误</alert>
>{{ disabled ? `${countDown}s ${$t('components.login.getcodeafter')}` : `${$t('components.login.getcode')}` }}</el-button <div class="code" v-show="this.show">
> <i-input
size="default"
type="text"
:value="currentValue"
@input="codeChange"
:placeholder="$t('components.login.codeplaceholder')"
></i-input>
</div>
</div> </div>
<div class="code">
<i-input
size="default"
type="text"
:value="currentValue"
@input="codeChange"
:placeholder="$t('components.login.codeplaceholder')"
></i-input>
</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}
* @type {string} * @memberof AppLoginInput
* @memberof AppPresetSmsVerification */
*/ @Prop() public model!: PanelFieldModel;
@Prop() public value!: string;
/**
/** * 值
*验证码当前值 *
* * @type {string}
* @type {string} * @memberof AppLoginInput
* @memberof AppPresetSmsVerification */
*/ @Prop() public value!: string;
get currentValue(): string {
return this.value; /**
} * 名称
*
* @type {string}
/** * @memberof AppLoginInput
* 手机号 */
* @Prop() public name!: string;
* @type {*}
* @memberof AppPresetSmsVerification /**
*/ *验证码当前值
public phoneNumber: string = ''; *
* @type {string}
/** * @memberof AppLoginNoteVerify
* 倒计时 */
* get currentValue(): string {
* @type {*} return this.value;
* @memberof AppPresetSmsVerification
*/
public countDown: number = 60;
/**
* 错误提示
* @type {*}
* @memberof AppPresetSmsVerification
*/
public phoneError = false;
/**
* 是否禁用获取验证码按钮
*
* @type {*}
* @memberof AppPresetSmsVerification
*/
public disabled: boolean = false;
/**
* 定时器
*
* @type {*}
* @memberof AppPresetSmsVerification
*/
public timer: any;
/**
* @description 设置倒计时
* @memberof AppPresetSmsVerification
*/
public setCountDown() {
if (this.countDown > 0) {
this.countDown--;
} else {
this.countDown = 60;
this.disabled = false;
clearInterval(this.timer);
} }
this.$forceUpdate();
} /**
* 手机号
/** *
* @description 验证码输入变化 * @type {*}
* @memberof AppPresetSmsVerification * @memberof AppLoginNoteVerify
*/ */
public codeChange(value: string) { public phoneNumber: string = "";
this.$emit("change", value);
} /**
* 错误提示
/** * @type {*}
* @description 校验手机号 * @memberof AppLoginNoteVerify
* @memberof AppPresetSmsVerification */
*/ public phoneError = false;
public veriPhoneNumber(): boolean {
this.phoneError = !/^1[3-9]\d{9}$/.test(this.phoneNumber); /**
if(this.phoneError) { * 是否禁用获取验证码按钮
this.$emit("error", this.$t('components.login.phonefailed')); *
} else { * @type {boolean}
this.$emit("error", ''); * @memberof AppLoginNoteVerify
*/
public disabled: boolean = false;
/**
* 显示验证码输入框
*
* @type {boolean}
* @memberof AppLoginNoteVerify
*/
public show: boolean = false;
/**
* 延迟
*
* @type {number}
* @memberof AppLoginNoteVerify
*/
public delay: number = 60;
/**
* 定时器
*
* @type {any}
* @memberof AppLoginNoteVerify
*/
public timer: any = null;
/**
* @description 验证码输入变化
* @memberof AppLoginNoteVerify
*/
public codeChange(value: string) {
this.$emit("valueChange", { name: this.name, value: value });
}
/**
* @description 校验手机号
* @memberof AppLoginNoteVerify
*/
public veriPhoneNumber(): boolean {
this.phoneError = !/^1[3-9]\d{9}$/.test(this.phoneNumber);
return this.phoneError;
}
/**
* @description 设置延迟时间
* @memberof AppLoginNoteVerify
*/
public setDelay() {
this.timer = setInterval(() => {
if (this.delay > 0) {
this.delay--;
} else {
this.delay = 60;
this.disabled = false;
clearInterval(this.timer);
}
}, 1000)
}
/**
* @description 获取验证码
* @memberof AppLoginNoteVerify
*/
public getVeriCode() {
if (this.phoneError) return;
// todo 获取验证码
this.show = true;
this.disabled = true;
this.setDelay();
} }
return this.phoneError;
}
/**
* @description 获取验证码
* @memberof AppPresetSmsVerification
*/
public getVeriCode() {
if(this.phoneError) return;
// todo 获取验证码
}
} }
</script> </script>
<style lang='less'> <style lang="less">
@import "./app-login-note-verify.less"; @import "./app-login-note-verify.less";
</style> </style>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册