😎增加验证码过期提示

This commit is contained in:
zuohuaijun 2024-08-04 01:49:41 +08:00
parent a6eeb08086
commit ff09ffb01c
3 changed files with 37 additions and 4 deletions

View File

@ -335,7 +335,8 @@ public class SysAuthService : IDynamicApiController, ITransient
{
var codeId = YitIdHelper.NextId().ToString();
var captcha = _captcha.Generate(codeId);
return new { Id = codeId, Img = captcha.Base64 };
var expirySeconds = App.GetOptions<CaptchaOptions>()?.ExpirySeconds ?? 60;
return new { Id = codeId, Img = captcha.Base64, ExpirySeconds = expirySeconds };
}
/// <summary>

View File

@ -23,7 +23,7 @@ const props = defineProps({
size: { type: [Number, String], default: 14 }, // px
height: { type: Number, default: 40 }, // px
delay: { type: Number, default: 1 }, // (s)
speed: { type: Number, default: 200 }, // (px/s)
speed: { type: Number, default: 100 }, // (px/s)
scrollable: { type: Boolean, default: false }, //
leftIcon: { type: String, default: 'iconfont icon-tongzhi2' }, //
rightIcon: { type: String, default: '' }, //

View File

@ -44,8 +44,8 @@
</el-col>
<el-col :span="1"></el-col>
<el-col :span="8">
<div class="login-content-code">
<img class="login-content-code-img" @click="getCaptcha" width="130px" height="38px" :src="state.captchaImage" style="cursor: pointer" />
<div :class="[state.expirySeconds > 0 ? 'login-content-code' : 'login-content-code-expired']" @click="getCaptcha">
<img class="login-content-code-img" width="130px" height="38px" :src="state.captchaImage" style="cursor: pointer" />
</div>
</el-col>
</el-form-item>
@ -131,8 +131,12 @@ const state = reactive({
captchaEnabled: false,
isPassRotate: false,
capsLockVisible: false,
expirySeconds: 60, //
});
//
let timer: any = null;
//
onMounted(async () => {
// URLToken
@ -148,12 +152,23 @@ onMounted(async () => {
//
getCaptcha();
//
if (state.captchaEnabled) {
timer = setInterval(() => {
if (state.expirySeconds > 0) state.expirySeconds -= 1;
}, 1000);
}
// /CapsLK
document.addEventListener('keyup', handleKeyPress);
});
//
onUnmounted(() => {
//
clearInterval(timer);
timer = null;
document.removeEventListener('keyup', handleKeyPress);
});
@ -171,6 +186,7 @@ const getCaptcha = async () => {
var res = await getAPI(SysAuthApi).apiSysAuthCaptchaGet();
state.captchaImage = 'data:text/html;base64,' + res.data.result?.img;
state.ruleForm.codeId = res.data.result?.id;
state.expirySeconds = res.data.result?.expirySeconds;
};
//
@ -347,6 +363,22 @@ defineExpose({ saveTokenAndInitRoutes });
}
}
.login-content-code-expired {
@extend .login-content-code;
&::before {
content: '验证码已过期';
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
border-radius: 4px;
background-color: rgba(0, 0, 0, 0.5);
color: #ffffff;
text-align: center;
}
}
.login-content-submit {
width: 100%;
letter-spacing: 2px;