From 0e92472904de660e9e73473a9ae1023a6eb67d4b Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Sat, 26 Apr 2025 16:30:45 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86login=E7=9A=84warn?= =?UTF-8?q?=EF=BC=8Cvbenselect=E5=8F=AA=E6=94=AF=E6=8C=81string=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/_core/authentication/code-login.vue | 12 ++++----- .../_core/authentication/forget-password.vue | 14 ++++++----- .../src/views/_core/authentication/login.vue | 25 +++++++++---------- .../views/_core/authentication/register.vue | 16 ++++++------ .../_core/authentication/social-login.vue | 22 ++++++++-------- .../views/_core/authentication/sso-login.vue | 12 ++++----- 6 files changed, 52 insertions(+), 49 deletions(-) diff --git a/apps/web-antd/src/views/_core/authentication/code-login.vue b/apps/web-antd/src/views/_core/authentication/code-login.vue index 3df82e0e7..1862abf8c 100644 --- a/apps/web-antd/src/views/_core/authentication/code-login.vue +++ b/apps/web-antd/src/views/_core/authentication/code-login.vue @@ -30,7 +30,7 @@ const loginRef = ref(); /** 获取租户列表,并默认选中 */ const tenantList = ref([]); // 租户列表 -const fetchTenantList = async () => { +async function fetchTenantList() { if (!tenantEnable) { return; } @@ -56,11 +56,11 @@ const fetchTenantList = async () => { // 设置选中的租户编号 accessStore.setTenantId(tenantId); - loginRef.value.getFormApi().setFieldValue('tenantId', tenantId); + loginRef.value.getFormApi().setFieldValue('tenantId', tenantId?.toString()); } catch (error) { console.error('获取租户列表失败:', error); } -}; +} /** 组件挂载时获取租户信息 */ onMounted(() => { @@ -74,19 +74,19 @@ const formSchema = computed((): VbenFormSchema[] => { componentProps: { options: tenantList.value.map((item) => ({ label: item.name, - value: item.id, + value: item.id.toString(), })), placeholder: $t('authentication.tenantTip'), }, fieldName: 'tenantId', label: $t('authentication.tenant'), - rules: z.number().positive(), + rules: z.string().min(1, { message: $t('authentication.tenantTip') }), dependencies: { triggerFields: ['tenantId'], if: tenantEnable, trigger(values) { if (values.tenantId) { - accessStore.setTenantId(values.tenantId); + accessStore.setTenantId(Number(values.tenantId)); } }, }, diff --git a/apps/web-antd/src/views/_core/authentication/forget-password.vue b/apps/web-antd/src/views/_core/authentication/forget-password.vue index 52f65b15b..2ef4b0ff1 100644 --- a/apps/web-antd/src/views/_core/authentication/forget-password.vue +++ b/apps/web-antd/src/views/_core/authentication/forget-password.vue @@ -29,7 +29,7 @@ const forgetPasswordRef = ref(); /** 获取租户列表,并默认选中 */ const tenantList = ref([]); // 租户列表 -const fetchTenantList = async () => { +async function fetchTenantList() { if (!tenantEnable) { return; } @@ -55,11 +55,13 @@ const fetchTenantList = async () => { // 设置选中的租户编号 accessStore.setTenantId(tenantId); - forgetPasswordRef.value.getFormApi().setFieldValue('tenantId', tenantId); + forgetPasswordRef.value + .getFormApi() + .setFieldValue('tenantId', tenantId?.toString()); } catch (error) { console.error('获取租户列表失败:', error); } -}; +} /** 组件挂载时获取租户信息 */ onMounted(() => { @@ -73,19 +75,19 @@ const formSchema = computed((): VbenFormSchema[] => { componentProps: { options: tenantList.value.map((item) => ({ label: item.name, - value: item.id, + value: item.id.toString(), })), placeholder: $t('authentication.tenantTip'), }, fieldName: 'tenantId', label: $t('authentication.tenant'), - rules: z.number().positive(), + rules: z.string().min(1, { message: $t('authentication.tenantTip') }), dependencies: { triggerFields: ['tenantId'], if: tenantEnable, trigger(values) { if (values.tenantId) { - accessStore.setTenantId(values.tenantId); + accessStore.setTenantId(Number(values.tenantId)); } }, }, diff --git a/apps/web-antd/src/views/_core/authentication/login.vue b/apps/web-antd/src/views/_core/authentication/login.vue index 926926f90..aa1db4c53 100644 --- a/apps/web-antd/src/views/_core/authentication/login.vue +++ b/apps/web-antd/src/views/_core/authentication/login.vue @@ -35,7 +35,7 @@ const captchaType = 'blockPuzzle'; // 验证码类型:'blockPuzzle' | 'clickWo /** 获取租户列表,并默认选中 */ const tenantList = ref([]); // 租户列表 -const fetchTenantList = async () => { +async function fetchTenantList() { if (!tenantEnable) { return; } @@ -61,26 +61,25 @@ const fetchTenantList = async () => { // 设置选中的租户编号 accessStore.setTenantId(tenantId); - loginRef.value.getFormApi().setFieldValue('tenantId', tenantId); + loginRef.value.getFormApi().setFieldValue('tenantId', tenantId?.toString()); } catch (error) { console.error('获取租户列表失败:', error); } -}; +} /** 处理登录 */ -const handleLogin = async (values: any) => { +async function handleLogin(values: any) { // 如果开启验证码,则先验证验证码 if (captchaEnable) { verifyRef.value.show(); return; } - // 无验证码,直接登录 await authStore.authLogin('username', values); -}; +} /** 验证码通过,执行登录 */ -const handleVerifySuccess = async ({ captchaVerification }: any) => { +async function handleVerifySuccess({ captchaVerification }: any) { try { await authStore.authLogin('username', { ...(await loginRef.value.getFormApi().getValues()), @@ -89,11 +88,11 @@ const handleVerifySuccess = async ({ captchaVerification }: any) => { } catch (error) { console.error('Error in handleLogin:', error); } -}; +} /** 处理第三方登录 */ const redirect = query?.redirect; -const handleThirdLogin = async (type: number) => { +async function handleThirdLogin(type: number) { if (type <= 0) { return; } @@ -111,7 +110,7 @@ const handleThirdLogin = async (type: number) => { } catch (error) { console.error('第三方登录处理失败:', error); } -}; +} /** 组件挂载时获取租户信息 */ onMounted(() => { @@ -125,19 +124,19 @@ const formSchema = computed((): VbenFormSchema[] => { componentProps: { options: tenantList.value.map((item) => ({ label: item.name, - value: item.id, + value: item.id.toString(), })), placeholder: $t('authentication.tenantTip'), }, fieldName: 'tenantId', label: $t('authentication.tenant'), - rules: z.number().positive(), + rules: z.string().min(1, { message: $t('authentication.tenantTip') }), dependencies: { triggerFields: ['tenantId'], if: tenantEnable, trigger(values) { if (values.tenantId) { - accessStore.setTenantId(values.tenantId); + accessStore.setTenantId(Number(values.tenantId)); } }, }, diff --git a/apps/web-antd/src/views/_core/authentication/register.vue b/apps/web-antd/src/views/_core/authentication/register.vue index 567bb04c8..734f4c27d 100644 --- a/apps/web-antd/src/views/_core/authentication/register.vue +++ b/apps/web-antd/src/views/_core/authentication/register.vue @@ -34,7 +34,7 @@ const captchaType = 'blockPuzzle'; // 验证码类型:'blockPuzzle' | 'clickWo /** 获取租户列表,并默认选中 */ const tenantList = ref([]); // 租户列表 -const fetchTenantList = async () => { +async function fetchTenantList() { if (!tenantEnable) { return; } @@ -60,14 +60,16 @@ const fetchTenantList = async () => { // 设置选中的租户编号 accessStore.setTenantId(tenantId); - registerRef.value.getFormApi().setFieldValue('tenantId', tenantId); + registerRef.value + .getFormApi() + .setFieldValue('tenantId', tenantId?.toString()); } catch (error) { console.error('获取租户列表失败:', error); } -}; +} /** 执行注册 */ -const handleRegister = async (values: any) => { +async function handleRegister(values: any) { // 如果开启验证码,则先验证验证码 if (captchaEnable) { verifyRef.value.show(); @@ -76,7 +78,7 @@ const handleRegister = async (values: any) => { // 无验证码,直接登录 await authStore.authLogin('register', values); -}; +} /** 验证码通过,执行注册 */ const handleVerifySuccess = async ({ captchaVerification }: any) => { @@ -108,13 +110,13 @@ const formSchema = computed((): VbenFormSchema[] => { }, fieldName: 'tenantId', label: $t('authentication.tenant'), - rules: z.number().positive(), + rules: z.string().min(1, { message: $t('authentication.tenantTip') }), dependencies: { triggerFields: ['tenantId'], if: tenantEnable, trigger(values) { if (values.tenantId) { - accessStore.setTenantId(values.tenantId); + accessStore.setTenantId(Number(values.tenantId)); } }, }, diff --git a/apps/web-antd/src/views/_core/authentication/social-login.vue b/apps/web-antd/src/views/_core/authentication/social-login.vue index c4826a535..e75a9c0d4 100644 --- a/apps/web-antd/src/views/_core/authentication/social-login.vue +++ b/apps/web-antd/src/views/_core/authentication/social-login.vue @@ -35,7 +35,7 @@ const captchaType = 'blockPuzzle'; // 验证码类型:'blockPuzzle' | 'clickWo /** 获取租户列表,并默认选中 */ const tenantList = ref([]); // 租户列表 -const fetchTenantList = async () => { +async function fetchTenantList() { if (!tenantEnable) { return; } @@ -66,14 +66,14 @@ const fetchTenantList = async () => { } catch (error) { console.error('获取租户列表失败:', error); } -}; +} /** 尝试登录:当账号已经绑定,socialLogin 会直接获得 token */ const socialType = Number(getUrlValue('type')); const redirect = getUrlValue('redirect'); const socialCode = query?.code as string; const socialState = query?.state as string; -const tryLogin = async () => { +async function tryLogin() { // 用于登录后,基于 redirect 的重定向 if (redirect) { await router.replace({ @@ -90,10 +90,10 @@ const tryLogin = async () => { code: socialCode, state: socialState, }); -}; +} /** 处理登录 */ -const handleLogin = async (values: any) => { +async function handleLogin(values: any) { // 如果开启验证码,则先验证验证码 if (captchaEnable) { verifyRef.value.show(); @@ -107,10 +107,10 @@ const handleLogin = async (values: any) => { socialCode, socialState, }); -}; +} /** 验证码通过,执行登录 */ -const handleVerifySuccess = async ({ captchaVerification }: any) => { +async function handleVerifySuccess({ captchaVerification }: any) { try { await authStore.authLogin('username', { ...(await loginRef.value.getFormApi().getValues()), @@ -122,7 +122,7 @@ const handleVerifySuccess = async ({ captchaVerification }: any) => { } catch (error) { console.error('Error in handleLogin:', error); } -}; +} /** tricky: 配合 login.vue 中,redirectUri 需要对参数进行 encode,需要在回调后进行decode */ function getUrlValue(key: string): string { @@ -144,19 +144,19 @@ const formSchema = computed((): VbenFormSchema[] => { componentProps: { options: tenantList.value.map((item) => ({ label: item.name, - value: item.id, + value: item.id.toString(), })), placeholder: $t('authentication.tenantTip'), }, fieldName: 'tenantId', label: $t('authentication.tenant'), - rules: z.number().positive(), + rules: z.string().min(1, { message: $t('authentication.tenantTip') }), dependencies: { triggerFields: ['tenantId'], if: tenantEnable, trigger(values) { if (values.tenantId) { - accessStore.setTenantId(values.tenantId); + accessStore.setTenantId(Number(values.tenantId)); } }, }, diff --git a/apps/web-antd/src/views/_core/authentication/sso-login.vue b/apps/web-antd/src/views/_core/authentication/sso-login.vue index ae5ac89c5..1bc7ad9b1 100644 --- a/apps/web-antd/src/views/_core/authentication/sso-login.vue +++ b/apps/web-antd/src/views/_core/authentication/sso-login.vue @@ -29,7 +29,7 @@ const queryParams = reactive({ const loading = ref(false); // 表单是否提交中 /** 初始化授权信息 */ -const init = async () => { +async function init() { // 防止在没有登录的情况下循环弹窗 if (query.client_id === undefined) { return; @@ -75,10 +75,10 @@ const init = async () => { 'scopes', scopes.filter((scope) => scope.value).map((scope) => scope.key), ); -}; +} /** 处理授权的提交 */ -const handleSubmit = async (approved: boolean) => { +async function handleSubmit(approved: boolean) { // 计算 checkedScopes + uncheckedScopes let checkedScopes: string[]; let uncheckedScopes: string[]; @@ -107,7 +107,7 @@ const handleSubmit = async (approved: boolean) => { } finally { loading.value = false; } -}; +} /** 调用授权 API 接口 */ const doAuthorize = ( @@ -127,7 +127,7 @@ const doAuthorize = ( }; /** 格式化 scope 文本 */ -const formatScope = (scope: string) => { +function formatScope(scope: string) { // 格式化 scope 授权范围,方便用户理解。 // 这里仅仅是一个 demo,可以考虑录入到字典数据中,例如说字典类型 "system_oauth2_scope",它的每个 scope 都是一条字典数据。 switch (scope) { @@ -141,7 +141,7 @@ const formatScope = (scope: string) => { return scope; } } -}; +} const formSchema = computed((): VbenFormSchema[] => { return [