mirror of
https://github.com/xinnan-tech/xiaozhi-esp32-server.git
synced 2026-07-23 07:33:53 +08:00
Merge branch 'main' into mqtt-call
This commit is contained in:
@@ -252,9 +252,9 @@ export default {
|
||||
},
|
||||
|
||||
// 封装输入验证逻辑
|
||||
validateInput(input, message) {
|
||||
validateInput(input, messageKey) {
|
||||
if (!input.trim()) {
|
||||
showDanger(message);
|
||||
showDanger(this.$t(messageKey));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -264,24 +264,24 @@ export default {
|
||||
if (this.isMobileLogin) {
|
||||
// 手机号登录验证
|
||||
if (!validateMobile(this.form.mobile, this.form.areaCode)) {
|
||||
showDanger("请输入正确的手机号码");
|
||||
showDanger(this.$t('login.requiredMobile'));
|
||||
return;
|
||||
}
|
||||
// 拼接手机号作为用户名
|
||||
this.form.username = this.form.areaCode + this.form.mobile;
|
||||
} else {
|
||||
// 用户名登录验证
|
||||
if (!this.validateInput(this.form.username, "用户名不能为空")) {
|
||||
if (!this.validateInput(this.form.username, 'login.requiredUsername')) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 验证密码
|
||||
if (!this.validateInput(this.form.password, "密码不能为空")) {
|
||||
if (!this.validateInput(this.form.password, 'login.requiredPassword')) {
|
||||
return;
|
||||
}
|
||||
// 验证验证码
|
||||
if (!this.validateInput(this.form.captcha, "验证码不能为空")) {
|
||||
if (!this.validateInput(this.form.captcha, 'login.requiredCaptcha')) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -289,16 +289,19 @@ export default {
|
||||
Api.user.login(
|
||||
this.form,
|
||||
({ data }) => {
|
||||
showSuccess("登录成功!");
|
||||
showSuccess(this.$t('login.loginSuccess'));
|
||||
this.$store.commit("setToken", JSON.stringify(data.data));
|
||||
goToPage("/home");
|
||||
},
|
||||
(err) => {
|
||||
showDanger(err.data.msg || "登录失败");
|
||||
// 直接使用后端返回的国际化消息
|
||||
let errorMessage = err.data.msg || "登录失败";
|
||||
|
||||
showDanger(errorMessage);
|
||||
if (
|
||||
err.data != null &&
|
||||
err.data.msg != null &&
|
||||
err.data.msg.indexOf("图形验证码") > -1
|
||||
err.data.msg.indexOf("图形验证码") > -1 || err.data.msg.indexOf("Captcha") > -1
|
||||
) {
|
||||
this.fetchCaptcha();
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
<img loading="lazy" alt="" class="input-icon" src="@/assets/login/shield.png" />
|
||||
<el-input v-model="form.captcha" :placeholder="$t('register.captchaPlaceholder')" style="flex: 1;" />
|
||||
</div>
|
||||
<img loading="lazy" v-if="captchaUrl" :src="captchaUrl" alt="验证码"
|
||||
<img loading="lazy" v-if="captchaUrl" :src="captchaUrl" alt="验证码"
|
||||
style="width: 150px; height: 40px; cursor: pointer;" @click="fetchCaptcha" />
|
||||
</div>
|
||||
|
||||
@@ -61,7 +61,7 @@
|
||||
<el-button type="primary" class="send-captcha-btn" :disabled="!canSendMobileCaptcha"
|
||||
@click="sendMobileCaptcha">
|
||||
<span>
|
||||
{{ countdown > 0 ? `${countdown}秒后重试` : $t('register.sendCaptcha') }}
|
||||
{{ countdown > 0 ? `${countdown}${$t('register.secondsLater')}` : $t('register.sendCaptcha') }}
|
||||
</span>
|
||||
</el-button>
|
||||
</div>
|
||||
@@ -248,18 +248,18 @@ export default {
|
||||
return;
|
||||
}
|
||||
if (!this.form.mobileCaptcha) {
|
||||
showDanger('请输入手机验证码');
|
||||
showDanger(this.$t('register.requiredMobileCaptcha'));
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
// 用户名注册验证
|
||||
if (!this.validateInput(this.form.username, '用户名不能为空')) {
|
||||
if (!this.validateInput(this.form.username, this.$t('register.requiredUsername'))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// 验证密码
|
||||
if (!this.validateInput(this.form.password, '密码不能为空')) {
|
||||
if (!this.validateInput(this.form.password, this.$t('register.requiredPassword'))) {
|
||||
return;
|
||||
}
|
||||
if (this.form.password !== this.form.confirmPassword) {
|
||||
@@ -267,7 +267,7 @@ export default {
|
||||
return
|
||||
}
|
||||
// 验证验证码
|
||||
if (!this.validateInput(this.form.captcha, '验证码不能为空')) {
|
||||
if (!this.validateInput(this.form.captcha, this.$t('register.requiredCaptcha'))) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user