fix: 处理login的warn,vbenselect只支持string类型

pull/87/head
xingyu4j 2025-04-26 16:30:45 +08:00
parent 4d1bff9d4a
commit 0e92472904
6 changed files with 52 additions and 49 deletions

View File

@ -30,7 +30,7 @@ const loginRef = ref();
/** 获取租户列表,并默认选中 */ /** 获取租户列表,并默认选中 */
const tenantList = ref<AuthApi.TenantResult[]>([]); // const tenantList = ref<AuthApi.TenantResult[]>([]); //
const fetchTenantList = async () => { async function fetchTenantList() {
if (!tenantEnable) { if (!tenantEnable) {
return; return;
} }
@ -56,11 +56,11 @@ const fetchTenantList = async () => {
// //
accessStore.setTenantId(tenantId); accessStore.setTenantId(tenantId);
loginRef.value.getFormApi().setFieldValue('tenantId', tenantId); loginRef.value.getFormApi().setFieldValue('tenantId', tenantId?.toString());
} catch (error) { } catch (error) {
console.error('获取租户列表失败:', error); console.error('获取租户列表失败:', error);
} }
}; }
/** 组件挂载时获取租户信息 */ /** 组件挂载时获取租户信息 */
onMounted(() => { onMounted(() => {
@ -74,19 +74,19 @@ const formSchema = computed((): VbenFormSchema[] => {
componentProps: { componentProps: {
options: tenantList.value.map((item) => ({ options: tenantList.value.map((item) => ({
label: item.name, label: item.name,
value: item.id, value: item.id.toString(),
})), })),
placeholder: $t('authentication.tenantTip'), placeholder: $t('authentication.tenantTip'),
}, },
fieldName: 'tenantId', fieldName: 'tenantId',
label: $t('authentication.tenant'), label: $t('authentication.tenant'),
rules: z.number().positive(), rules: z.string().min(1, { message: $t('authentication.tenantTip') }),
dependencies: { dependencies: {
triggerFields: ['tenantId'], triggerFields: ['tenantId'],
if: tenantEnable, if: tenantEnable,
trigger(values) { trigger(values) {
if (values.tenantId) { if (values.tenantId) {
accessStore.setTenantId(values.tenantId); accessStore.setTenantId(Number(values.tenantId));
} }
}, },
}, },

View File

@ -29,7 +29,7 @@ const forgetPasswordRef = ref();
/** 获取租户列表,并默认选中 */ /** 获取租户列表,并默认选中 */
const tenantList = ref<AuthApi.TenantResult[]>([]); // const tenantList = ref<AuthApi.TenantResult[]>([]); //
const fetchTenantList = async () => { async function fetchTenantList() {
if (!tenantEnable) { if (!tenantEnable) {
return; return;
} }
@ -55,11 +55,13 @@ const fetchTenantList = async () => {
// //
accessStore.setTenantId(tenantId); accessStore.setTenantId(tenantId);
forgetPasswordRef.value.getFormApi().setFieldValue('tenantId', tenantId); forgetPasswordRef.value
.getFormApi()
.setFieldValue('tenantId', tenantId?.toString());
} catch (error) { } catch (error) {
console.error('获取租户列表失败:', error); console.error('获取租户列表失败:', error);
} }
}; }
/** 组件挂载时获取租户信息 */ /** 组件挂载时获取租户信息 */
onMounted(() => { onMounted(() => {
@ -73,19 +75,19 @@ const formSchema = computed((): VbenFormSchema[] => {
componentProps: { componentProps: {
options: tenantList.value.map((item) => ({ options: tenantList.value.map((item) => ({
label: item.name, label: item.name,
value: item.id, value: item.id.toString(),
})), })),
placeholder: $t('authentication.tenantTip'), placeholder: $t('authentication.tenantTip'),
}, },
fieldName: 'tenantId', fieldName: 'tenantId',
label: $t('authentication.tenant'), label: $t('authentication.tenant'),
rules: z.number().positive(), rules: z.string().min(1, { message: $t('authentication.tenantTip') }),
dependencies: { dependencies: {
triggerFields: ['tenantId'], triggerFields: ['tenantId'],
if: tenantEnable, if: tenantEnable,
trigger(values) { trigger(values) {
if (values.tenantId) { if (values.tenantId) {
accessStore.setTenantId(values.tenantId); accessStore.setTenantId(Number(values.tenantId));
} }
}, },
}, },

View File

@ -35,7 +35,7 @@ const captchaType = 'blockPuzzle'; // 验证码类型:'blockPuzzle' | 'clickWo
/** 获取租户列表,并默认选中 */ /** 获取租户列表,并默认选中 */
const tenantList = ref<AuthApi.TenantResult[]>([]); // const tenantList = ref<AuthApi.TenantResult[]>([]); //
const fetchTenantList = async () => { async function fetchTenantList() {
if (!tenantEnable) { if (!tenantEnable) {
return; return;
} }
@ -61,26 +61,25 @@ const fetchTenantList = async () => {
// //
accessStore.setTenantId(tenantId); accessStore.setTenantId(tenantId);
loginRef.value.getFormApi().setFieldValue('tenantId', tenantId); loginRef.value.getFormApi().setFieldValue('tenantId', tenantId?.toString());
} catch (error) { } catch (error) {
console.error('获取租户列表失败:', error); console.error('获取租户列表失败:', error);
} }
}; }
/** 处理登录 */ /** 处理登录 */
const handleLogin = async (values: any) => { async function handleLogin(values: any) {
// //
if (captchaEnable) { if (captchaEnable) {
verifyRef.value.show(); verifyRef.value.show();
return; return;
} }
// //
await authStore.authLogin('username', values); await authStore.authLogin('username', values);
}; }
/** 验证码通过,执行登录 */ /** 验证码通过,执行登录 */
const handleVerifySuccess = async ({ captchaVerification }: any) => { async function handleVerifySuccess({ captchaVerification }: any) {
try { try {
await authStore.authLogin('username', { await authStore.authLogin('username', {
...(await loginRef.value.getFormApi().getValues()), ...(await loginRef.value.getFormApi().getValues()),
@ -89,11 +88,11 @@ const handleVerifySuccess = async ({ captchaVerification }: any) => {
} catch (error) { } catch (error) {
console.error('Error in handleLogin:', error); console.error('Error in handleLogin:', error);
} }
}; }
/** 处理第三方登录 */ /** 处理第三方登录 */
const redirect = query?.redirect; const redirect = query?.redirect;
const handleThirdLogin = async (type: number) => { async function handleThirdLogin(type: number) {
if (type <= 0) { if (type <= 0) {
return; return;
} }
@ -111,7 +110,7 @@ const handleThirdLogin = async (type: number) => {
} catch (error) { } catch (error) {
console.error('第三方登录处理失败:', error); console.error('第三方登录处理失败:', error);
} }
}; }
/** 组件挂载时获取租户信息 */ /** 组件挂载时获取租户信息 */
onMounted(() => { onMounted(() => {
@ -125,19 +124,19 @@ const formSchema = computed((): VbenFormSchema[] => {
componentProps: { componentProps: {
options: tenantList.value.map((item) => ({ options: tenantList.value.map((item) => ({
label: item.name, label: item.name,
value: item.id, value: item.id.toString(),
})), })),
placeholder: $t('authentication.tenantTip'), placeholder: $t('authentication.tenantTip'),
}, },
fieldName: 'tenantId', fieldName: 'tenantId',
label: $t('authentication.tenant'), label: $t('authentication.tenant'),
rules: z.number().positive(), rules: z.string().min(1, { message: $t('authentication.tenantTip') }),
dependencies: { dependencies: {
triggerFields: ['tenantId'], triggerFields: ['tenantId'],
if: tenantEnable, if: tenantEnable,
trigger(values) { trigger(values) {
if (values.tenantId) { if (values.tenantId) {
accessStore.setTenantId(values.tenantId); accessStore.setTenantId(Number(values.tenantId));
} }
}, },
}, },

View File

@ -34,7 +34,7 @@ const captchaType = 'blockPuzzle'; // 验证码类型:'blockPuzzle' | 'clickWo
/** 获取租户列表,并默认选中 */ /** 获取租户列表,并默认选中 */
const tenantList = ref<AuthApi.TenantResult[]>([]); // const tenantList = ref<AuthApi.TenantResult[]>([]); //
const fetchTenantList = async () => { async function fetchTenantList() {
if (!tenantEnable) { if (!tenantEnable) {
return; return;
} }
@ -60,14 +60,16 @@ const fetchTenantList = async () => {
// //
accessStore.setTenantId(tenantId); accessStore.setTenantId(tenantId);
registerRef.value.getFormApi().setFieldValue('tenantId', tenantId); registerRef.value
.getFormApi()
.setFieldValue('tenantId', tenantId?.toString());
} catch (error) { } catch (error) {
console.error('获取租户列表失败:', error); console.error('获取租户列表失败:', error);
} }
}; }
/** 执行注册 */ /** 执行注册 */
const handleRegister = async (values: any) => { async function handleRegister(values: any) {
// //
if (captchaEnable) { if (captchaEnable) {
verifyRef.value.show(); verifyRef.value.show();
@ -76,7 +78,7 @@ const handleRegister = async (values: any) => {
// //
await authStore.authLogin('register', values); await authStore.authLogin('register', values);
}; }
/** 验证码通过,执行注册 */ /** 验证码通过,执行注册 */
const handleVerifySuccess = async ({ captchaVerification }: any) => { const handleVerifySuccess = async ({ captchaVerification }: any) => {
@ -108,13 +110,13 @@ const formSchema = computed((): VbenFormSchema[] => {
}, },
fieldName: 'tenantId', fieldName: 'tenantId',
label: $t('authentication.tenant'), label: $t('authentication.tenant'),
rules: z.number().positive(), rules: z.string().min(1, { message: $t('authentication.tenantTip') }),
dependencies: { dependencies: {
triggerFields: ['tenantId'], triggerFields: ['tenantId'],
if: tenantEnable, if: tenantEnable,
trigger(values) { trigger(values) {
if (values.tenantId) { if (values.tenantId) {
accessStore.setTenantId(values.tenantId); accessStore.setTenantId(Number(values.tenantId));
} }
}, },
}, },

View File

@ -35,7 +35,7 @@ const captchaType = 'blockPuzzle'; // 验证码类型:'blockPuzzle' | 'clickWo
/** 获取租户列表,并默认选中 */ /** 获取租户列表,并默认选中 */
const tenantList = ref<AuthApi.TenantResult[]>([]); // const tenantList = ref<AuthApi.TenantResult[]>([]); //
const fetchTenantList = async () => { async function fetchTenantList() {
if (!tenantEnable) { if (!tenantEnable) {
return; return;
} }
@ -66,14 +66,14 @@ const fetchTenantList = async () => {
} catch (error) { } catch (error) {
console.error('获取租户列表失败:', error); console.error('获取租户列表失败:', error);
} }
}; }
/** 尝试登录当账号已经绑定socialLogin 会直接获得 token */ /** 尝试登录当账号已经绑定socialLogin 会直接获得 token */
const socialType = Number(getUrlValue('type')); const socialType = Number(getUrlValue('type'));
const redirect = getUrlValue('redirect'); const redirect = getUrlValue('redirect');
const socialCode = query?.code as string; const socialCode = query?.code as string;
const socialState = query?.state as string; const socialState = query?.state as string;
const tryLogin = async () => { async function tryLogin() {
// redirect // redirect
if (redirect) { if (redirect) {
await router.replace({ await router.replace({
@ -90,10 +90,10 @@ const tryLogin = async () => {
code: socialCode, code: socialCode,
state: socialState, state: socialState,
}); });
}; }
/** 处理登录 */ /** 处理登录 */
const handleLogin = async (values: any) => { async function handleLogin(values: any) {
// //
if (captchaEnable) { if (captchaEnable) {
verifyRef.value.show(); verifyRef.value.show();
@ -107,10 +107,10 @@ const handleLogin = async (values: any) => {
socialCode, socialCode,
socialState, socialState,
}); });
}; }
/** 验证码通过,执行登录 */ /** 验证码通过,执行登录 */
const handleVerifySuccess = async ({ captchaVerification }: any) => { async function handleVerifySuccess({ captchaVerification }: any) {
try { try {
await authStore.authLogin('username', { await authStore.authLogin('username', {
...(await loginRef.value.getFormApi().getValues()), ...(await loginRef.value.getFormApi().getValues()),
@ -122,7 +122,7 @@ const handleVerifySuccess = async ({ captchaVerification }: any) => {
} catch (error) { } catch (error) {
console.error('Error in handleLogin:', error); console.error('Error in handleLogin:', error);
} }
}; }
/** tricky: 配合 login.vue 中redirectUri 需要对参数进行 encode需要在回调后进行decode */ /** tricky: 配合 login.vue 中redirectUri 需要对参数进行 encode需要在回调后进行decode */
function getUrlValue(key: string): string { function getUrlValue(key: string): string {
@ -144,19 +144,19 @@ const formSchema = computed((): VbenFormSchema[] => {
componentProps: { componentProps: {
options: tenantList.value.map((item) => ({ options: tenantList.value.map((item) => ({
label: item.name, label: item.name,
value: item.id, value: item.id.toString(),
})), })),
placeholder: $t('authentication.tenantTip'), placeholder: $t('authentication.tenantTip'),
}, },
fieldName: 'tenantId', fieldName: 'tenantId',
label: $t('authentication.tenant'), label: $t('authentication.tenant'),
rules: z.number().positive(), rules: z.string().min(1, { message: $t('authentication.tenantTip') }),
dependencies: { dependencies: {
triggerFields: ['tenantId'], triggerFields: ['tenantId'],
if: tenantEnable, if: tenantEnable,
trigger(values) { trigger(values) {
if (values.tenantId) { if (values.tenantId) {
accessStore.setTenantId(values.tenantId); accessStore.setTenantId(Number(values.tenantId));
} }
}, },
}, },

View File

@ -29,7 +29,7 @@ const queryParams = reactive({
const loading = ref(false); // const loading = ref(false); //
/** 初始化授权信息 */ /** 初始化授权信息 */
const init = async () => { async function init() {
// //
if (query.client_id === undefined) { if (query.client_id === undefined) {
return; return;
@ -75,10 +75,10 @@ const init = async () => {
'scopes', 'scopes',
scopes.filter((scope) => scope.value).map((scope) => scope.key), scopes.filter((scope) => scope.value).map((scope) => scope.key),
); );
}; }
/** 处理授权的提交 */ /** 处理授权的提交 */
const handleSubmit = async (approved: boolean) => { async function handleSubmit(approved: boolean) {
// checkedScopes + uncheckedScopes // checkedScopes + uncheckedScopes
let checkedScopes: string[]; let checkedScopes: string[];
let uncheckedScopes: string[]; let uncheckedScopes: string[];
@ -107,7 +107,7 @@ const handleSubmit = async (approved: boolean) => {
} finally { } finally {
loading.value = false; loading.value = false;
} }
}; }
/** 调用授权 API 接口 */ /** 调用授权 API 接口 */
const doAuthorize = ( const doAuthorize = (
@ -127,7 +127,7 @@ const doAuthorize = (
}; };
/** 格式化 scope 文本 */ /** 格式化 scope 文本 */
const formatScope = (scope: string) => { function formatScope(scope: string) {
// scope 便 // scope 便
// demo "system_oauth2_scope" scope // demo "system_oauth2_scope" scope
switch (scope) { switch (scope) {
@ -141,7 +141,7 @@ const formatScope = (scope: string) => {
return scope; return scope;
} }
} }
}; }
const formSchema = computed((): VbenFormSchema[] => { const formSchema = computed((): VbenFormSchema[] => {
return [ return [