fix: 处理login的warn,vbenselect只支持string类型
parent
4d1bff9d4a
commit
0e92472904
|
@ -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));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -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));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -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 [
|
||||||
|
|
Loading…
Reference in New Issue