From daae3c89e763d62f3ed0ffe1fbd91c3855919e58 Mon Sep 17 00:00:00 2001
From: lvjunzhao <967725@dms.yudean.com>
Date: Thu, 10 Apr 2025 17:12:15 +0800
Subject: [PATCH] =?UTF-8?q?feat:=E7=99=BB=E5=BD=95-=E6=96=B0=E5=A2=9E?=
=?UTF-8?q?=E7=94=A8=E6=88=B7=E8=B4=A6=E5=8F=B7=E7=99=BB=E5=BD=95=20?=
=?UTF-8?q?=E9=AA=8C=E8=AF=81=E7=A0=81=20ipBlock=201.=20=E6=96=B0=E5=A2=9E?=
=?UTF-8?q?=20=E7=99=BB=E5=BD=95=E7=9A=84=20=E5=9B=BE=E5=BD=A2=E6=A0=A1?=
=?UTF-8?q?=E9=AA=8C=E7=A0=81=202.=20=E9=81=97=E8=90=BD=E9=97=AE=E9=A2=98?=
=?UTF-8?q?=EF=BC=8C=E7=99=BB=E5=BD=95=E9=A1=B5=E7=9A=84=E6=8F=90=E4=BA=A4?=
=?UTF-8?q?=EF=BC=8C=E8=A1=A8=E5=8D=95=E5=85=A8=E9=83=A8=E7=BB=9F=E4=B8=80?=
=?UTF-8?q?=E4=BA=86=E3=80=82=E6=B2=A1=E6=9C=89=E5=8C=BA=E5=88=86=E7=B1=BB?=
=?UTF-8?q?=E5=9E=8B=EF=BC=8C=E8=80=8C=E4=B8=94=E7=B1=BB=E5=9E=8B=E7=9A=84?=
=?UTF-8?q?=E6=9E=9A=E4=B8=BE=E5=92=8C=E6=A0=A1=E9=AA=8C=E6=B2=A1=E7=9C=9F?=
=?UTF-8?q?=E6=AD=A3=E4=BD=BF=E7=94=A8=E3=80=82=E8=BF=98=E6=9C=89=E5=85=B6?=
=?UTF-8?q?=E4=BB=96=E5=8A=9F=E8=83=BD=E5=A6=82=E6=B3=A8=E5=86=8C=EF=BC=8C?=
=?UTF-8?q?=E6=94=B9=E5=AF=86=E7=A0=81=E9=83=BD=E6=B2=A1=E5=BC=80=E5=87=BA?=
=?UTF-8?q?=E6=9D=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/api/system/login/index.ts | 12 ++
src/api/system/login/model/index.ts | 1 +
src/views/secondDev/Login.vue | 5 +
src/views/secondDev/LoginForm.vue | 89 +++++++++++++--
src/views/sys/login/useLogin.ts | 11 ++
src/views/system/loginSetting/loginInfo.vue | 120 ++++++++++++++++++++
6 files changed, 231 insertions(+), 7 deletions(-)
diff --git a/src/api/system/login/index.ts b/src/api/system/login/index.ts
index 87320dc..506fda1 100644
--- a/src/api/system/login/index.ts
+++ b/src/api/system/login/index.ts
@@ -34,6 +34,7 @@ enum Api {
loginConfig = '/system/loginConfig',
mobileLoginCode = '/system/captcha',
mobileLoginImg = '/system/captchaImg',
+ checkAccountCaptcha = '/system/checkAccountCaptcha',
}
/**
@@ -262,3 +263,14 @@ export function sendMobileLoginCode(params, mode: ErrorMessageMode = 'modal') {
},
);
}
+export function checkAccountCaptchaApi(params, mode: ErrorMessageMode = 'modal') {
+ return defHttp.get(
+ {
+ url: Api.checkAccountCaptcha,
+ params: params,
+ },
+ {
+ errorMessageMode: mode,
+ },
+ );
+}
diff --git a/src/api/system/login/model/index.ts b/src/api/system/login/model/index.ts
index b95ba73..9eecbce 100644
--- a/src/api/system/login/model/index.ts
+++ b/src/api/system/login/model/index.ts
@@ -8,6 +8,7 @@ export interface LoginParams {
password: string;
tenantCode: string;
deviceType?: number;
+ captchaCode: string;
}
export interface RoleInfo {
diff --git a/src/views/secondDev/Login.vue b/src/views/secondDev/Login.vue
index ecef95d..7a9bf68 100644
--- a/src/views/secondDev/Login.vue
+++ b/src/views/secondDev/Login.vue
@@ -279,3 +279,8 @@
}
}
+
diff --git a/src/views/secondDev/LoginForm.vue b/src/views/secondDev/LoginForm.vue
index d712a2a..a1e3165 100644
--- a/src/views/secondDev/LoginForm.vue
+++ b/src/views/secondDev/LoginForm.vue
@@ -3,7 +3,7 @@
-
+
@@ -17,6 +17,22 @@
+
+
+
+
+
+
+
+
+
+
+
+
@@ -43,8 +59,10 @@
+
+
+
-
@@ -64,7 +82,7 @@
@@ -118,7 +136,7 @@
import { useUserStore } from '/@/store/modules/user';
import { LoginStateEnum, useLoginState, useFormRules, useFormValid } from '/@/views/sys/login/useLogin';
- import { getMobileLoginCode, getMobileLoginImg, sendMobileLoginCode } from '/@/api/system/login';
+ import { getMobileLoginCode, getMobileLoginImg, sendMobileLoginCode, checkAccountCaptchaApi, } from '/@/api/system/login';
import { useDesign } from '/@/hooks/web/useDesign';
import { Base64 } from 'js-base64';
@@ -126,6 +144,8 @@
import { useRouter } from 'vue-router';
import { getAppEnvConfig } from '/@/utils/env';
import Icon from '/@/components/Icon/index';
+
+ import { PhoneOutlined, PictureOutlined, ReloadOutlined } from '@ant-design/icons-vue';
const ACol = Col;
const ARow = Row;
@@ -138,7 +158,7 @@
const { currentRoute } = useRouter();
- const { getLoginState } = useLoginState();
+ const { getLoginState, setLoginState } = useLoginState();
const { getFormRules } = useFormRules();
const formRef = ref();
@@ -146,6 +166,7 @@
const loading = ref(false);
const rememberMe = ref(false);
const loginType = ref('mobile')
+ const loginUseType = ref();
const countdown = ref(60)
const visible = ref(false);
@@ -153,6 +174,9 @@
const imgObj = ref({
imgBase64: ''
})
+ const captchaImage = ref({
+ imgBase64: ''
+ })
const imgCode = ref('')
const formData = reactive({
@@ -160,7 +184,8 @@
password: '',
mobile: '',
code: '',
- tenantCode: 'system'
+ tenantCode: 'system',
+ captchaCode: ''
});
const getCodeButtonName = ref('获取验证码')
const codeButtonDisabled = ref(false)
@@ -228,6 +253,24 @@
}
}
+ /**
+ * 账号失焦 请求后台获取业务状态
+ */
+ async function handleBlur() {
+ if (!formData.account) {
+ return;
+ }
+ let checkAccountCaptcha = await checkAccountCaptchaApi({username: formData.account})
+ if(checkAccountCaptcha == true) {
+ loginUseType.value = 'captcha';
+ // setLoginState(LoginStateEnum.LOGIN_WITH_CAPTCHA)
+ refreshCaptcha();
+ } else {
+ loginUseType.value = '';
+ // setLoginState(LoginStateEnum.LOGIN)
+ }
+ }
+
function refreshTodo() {
refreshLoading.value = true
onMobileLoginImg()
@@ -236,7 +279,12 @@
// 图形验证
async function onMobileLoginImg() {
- imgObj.value = await getMobileLoginImg({mobile: formData.mobile})
+ imgObj.value = await getMobileLoginImg({account: formData.mobile})
+ }
+
+ // 图形账号验证
+ async function refreshCaptcha() {
+ captchaImage.value = await getMobileLoginImg({account: formData.account})
}
async function handleOk() {
@@ -283,11 +331,22 @@
if (!data) return;
if (loginType.value == 'pw') {
try {
+ // 校验有没带图形验证码提交
+ if (loginUseType.value == 'captcha' && !data.captchaCode) {
+ createErrorModal({
+ title: t('错误提示'),
+ content: '请输入图形验证码',
+ getContainer: () => document.body.querySelector(`.${prefixCls}`) || document.body
+ });
+ return;
+ }
+
loading.value = true;
const userInfo = await userStore.login({
password: data.password,
userName: data.account,
tenantCode: data.tenantCode,
+ captchaCode: data.captchaCode,
deviceType: 0, //pc-0,app-1
mode: 'none' //不要默认的错误提示
});
@@ -309,6 +368,11 @@
}
}
} catch (error) {
+ if ((error as unknown as Error).message.includes('验证码')) {
+ loginUseType.value = 'captcha';
+ // setLoginState(LoginStateEnum.LOGIN_WITH_CAPTCHA);
+ refreshCaptcha();
+ }
createErrorModal({
title: t('错误提示'),
content: (error as unknown as Error).message || t('网络异常,请检查您的网络连接是否正常!'),
@@ -316,6 +380,7 @@
});
} finally {
loading.value = false;
+ handleBlur();
}
} else {
try {
@@ -400,4 +465,14 @@
cursor: pointer;
}
}
+ :deep(.captcha-image) {
+ cursor: pointer;
+ border: 1px solid #ddd;
+ border-radius: 4px;
+ height: 48px;
+ }
+ // :deep(.phone-outlined-class) {
+ // height: 25.99px;
+ // width: 25.99px;
+ // }
diff --git a/src/views/sys/login/useLogin.ts b/src/views/sys/login/useLogin.ts
index 4ab1179..36c8a06 100644
--- a/src/views/sys/login/useLogin.ts
+++ b/src/views/sys/login/useLogin.ts
@@ -9,6 +9,7 @@ export enum LoginStateEnum {
RESET_PASSWORD,
MOBILE,
QR_CODE,
+ LOGIN_WITH_CAPTCHA,
}
const currentState = ref(LoginStateEnum.LOGIN);
@@ -43,6 +44,7 @@ export function useFormRules(formData?: Recordable) {
const getAccountFormRule = computed(() => createRule(t('请输入账号')));
const getPasswordFormRule = computed(() => createRule(t('请输入密码')));
+ const getCaptchaCodeFormRule = computed(() => createRule(t('请输入图形验证码')));
const getSmsFormRule = computed(() => createRule(t('请输入验证码')));
const getMobileFormRule = computed(() => createRule(t('请输入手机号码')));
@@ -65,6 +67,7 @@ export function useFormRules(formData?: Recordable) {
const getFormRules = computed((): { [k: string]: ValidationRule | ValidationRule[] } => {
const accountFormRule = unref(getAccountFormRule);
const passwordFormRule = unref(getPasswordFormRule);
+ const captchaCodeFormRule = unref(getCaptchaCodeFormRule);
const smsFormRule = unref(getSmsFormRule);
const mobileFormRule = unref(getMobileFormRule);
@@ -96,6 +99,14 @@ export function useFormRules(formData?: Recordable) {
case LoginStateEnum.MOBILE:
return mobileRule;
+ // 枚举没实现,暂不适用
+ case LoginStateEnum.LOGIN_WITH_CAPTCHA:
+ return {
+ account: accountFormRule,
+ password: passwordFormRule,
+ captchaCode: captchaCodeFormRule,
+ };
+
// login form rules
default:
return {
diff --git a/src/views/system/loginSetting/loginInfo.vue b/src/views/system/loginSetting/loginInfo.vue
index 3126cc2..f1bf9f8 100644
--- a/src/views/system/loginSetting/loginInfo.vue
+++ b/src/views/system/loginSetting/loginInfo.vue
@@ -117,6 +117,100 @@
/>
+·
+
+
{{ t('密码错误超过最大次数需要填写验证码') }}
+
+
+
+
+ 验证码策略
+
+
+
+
1.登录验证码策略是指在登录过程中出现密码错误情况时的系统处理方式。
+
2.默认“密码错误超过最大次需要验证码登录”的策略状态为启用。
+
3.如果设置验证码最大次数为0 ,即每次登录都需要验证码
+
+
+
+
+
+
+
+
+
+
+
+
+
{{ t('密码错误超过最大次数锁定') }}
+
+
+
+
+
+
+
+
1.锁定ip策略是指在登录过程中出现密码错误情况时的系统处理方式。
+
2.默认“密码错误超过最大次数锁定ip”的策略状态为启用。
+
3.当用户的ip被锁定后,需要等待配置时间恢复后才能重新登录!或者,请联系管理员。
+
+
+
+
+
+
+
+
+
+
+
+
{{ t('提交') }}
@@ -145,6 +239,11 @@
withoutLogin?: number;
strategyMaxNumber?: number | null;
passwordStrategy?: number;
+ checkErrorLoginCaptcha?: boolean;
+ checkErrorLoginCaptchaCount?: number | null;
+ checkErrorLoginBlockIp?: boolean;
+ checkErrorLoginBlockIpCount?: number | null;
+ checkErrorLoginBlockIpRestoreTime?: number | null;
}
let formState = ref({});
@@ -162,6 +261,11 @@
withoutLogin: res.withoutLogin,
strategyMaxNumber: res.strategyMaxNumber,
passwordStrategy: res.passwordStrategy,
+ checkErrorLoginCaptcha: res.checkErrorLoginCaptcha,
+ checkErrorLoginCaptchaCount: res.checkErrorLoginCaptchaCount,
+ checkErrorLoginBlockIp: res.checkErrorLoginBlockIp,
+ checkErrorLoginBlockIpCount: res.checkErrorLoginBlockIpCount,
+ checkErrorLoginBlockIpRestoreTime: res.checkErrorLoginBlockIpRestoreTime,
};
id.value = res.id;
});
@@ -198,6 +302,22 @@
}
}
+ function handleCaptchaClick() {
+ if (formState.value.checkErrorLoginCaptcha) {
+ formState.value.checkErrorLoginCaptcha = false;
+ } else {
+ formState.value.checkErrorLoginCaptcha = true;
+ }
+ }
+
+ function handleBlockIpClick() {
+ if (formState.value.checkErrorLoginBlockIp) {
+ formState.value.checkErrorLoginBlockIp = false;
+ } else {
+ formState.value.checkErrorLoginBlockIp = true;
+ }
+ }
+
function handleClick(val) {
if (proDisabled.value) return;
if (formState.value.mulLogin?.includes(val)) {