feat: request && login && router【e6939e22】(增加 login.vue 的租户选择、开启开关)
parent
c2358e2132
commit
c2914d2002
|
@ -13,6 +13,7 @@ import { useAuthStore } from '#/store';
|
||||||
import { useAccessStore } from '@vben/stores';
|
import { useAccessStore } from '@vben/stores';
|
||||||
|
|
||||||
import { getTenantSimpleList, getTenantByWebsite } from '#/api/core/auth';
|
import { getTenantSimpleList, getTenantByWebsite } from '#/api/core/auth';
|
||||||
|
const { tenantEnable } = useAppConfig(import.meta.env, import.meta.env.PROD);
|
||||||
|
|
||||||
defineOptions({ name: 'Login' });
|
defineOptions({ name: 'Login' });
|
||||||
|
|
||||||
|
@ -21,10 +22,11 @@ const accessStore = useAccessStore();
|
||||||
|
|
||||||
// 租户列表
|
// 租户列表
|
||||||
const tenantList = ref<AuthApi.TenantResult[]>([]);
|
const tenantList = ref<AuthApi.TenantResult[]>([]);
|
||||||
// 当前选中的租户编号
|
|
||||||
const currentTenantId = ref<null | number>();
|
|
||||||
|
|
||||||
// 获取租户列表,并默认选中
|
// 获取 AuthenticationLogin 组件的引用
|
||||||
|
const loginRef = ref();
|
||||||
|
|
||||||
|
/** 获取租户列表,并默认选中 */
|
||||||
const fetchTenantList = async () => {
|
const fetchTenantList = async () => {
|
||||||
try {
|
try {
|
||||||
// 获取租户列表、域名对应租户
|
// 获取租户列表、域名对应租户
|
||||||
|
@ -38,7 +40,6 @@ const fetchTenantList = async () => {
|
||||||
tenantId = websiteTenant.id;
|
tenantId = websiteTenant.id;
|
||||||
}
|
}
|
||||||
// 如果没有从域名获取到租户,尝试从 store 中获取
|
// 如果没有从域名获取到租户,尝试从 store 中获取
|
||||||
debugger;
|
|
||||||
if (!tenantId && accessStore.tenantId) {
|
if (!tenantId && accessStore.tenantId) {
|
||||||
tenantId = accessStore.tenantId;
|
tenantId = accessStore.tenantId;
|
||||||
}
|
}
|
||||||
|
@ -48,8 +49,8 @@ const fetchTenantList = async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置选中的租户编号
|
// 设置选中的租户编号
|
||||||
currentTenantId.value = tenantId;
|
|
||||||
accessStore.setTenantId(tenantId);
|
accessStore.setTenantId(tenantId);
|
||||||
|
loginRef.value.getFormApi().setFieldValue('tenantId', tenantId);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('获取租户列表失败:', error);
|
console.error('获取租户列表失败:', error);
|
||||||
}
|
}
|
||||||
|
@ -69,17 +70,24 @@ const formSchema = computed((): VbenFormSchema[] => {
|
||||||
label: item.name,
|
label: item.name,
|
||||||
value: item.id,
|
value: item.id,
|
||||||
})),
|
})),
|
||||||
placeholder: $t('authentication.selectTenant'),
|
placeholder: $t('authentication.tenantTip'),
|
||||||
// value: currentTenantId.value ?? null, // TODO @芋艿:change 的设置
|
|
||||||
onChange: (value: number) => {
|
|
||||||
// currentTenantId.value = value ?? null;
|
|
||||||
accessStore.setTenantId(value);
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
fieldName: 'tenantId',
|
fieldName: 'tenantId',
|
||||||
label: $t('authentication.selectTenant'),
|
label: $t('authentication.tenant'),
|
||||||
// TODO @芋艿:开关租户的逻辑
|
rules: z
|
||||||
rules: z.number().default(currentTenantId.value), // TODO @芋艿:默认值的设置
|
.number()
|
||||||
|
.nullable()
|
||||||
|
.refine((val) => val != null && val > 0, $t('authentication.tenantTip'))
|
||||||
|
.default(null),
|
||||||
|
dependencies: {
|
||||||
|
triggerFields: ['tenantId'],
|
||||||
|
if: tenantEnable,
|
||||||
|
trigger(values) {
|
||||||
|
if (values.tenantId) {
|
||||||
|
accessStore.setTenantId(values.tenantId);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
component: 'VbenInput',
|
component: 'VbenInput',
|
||||||
|
@ -96,7 +104,7 @@ const formSchema = computed((): VbenFormSchema[] => {
|
||||||
{
|
{
|
||||||
component: 'VbenInputPassword',
|
component: 'VbenInputPassword',
|
||||||
componentProps: {
|
componentProps: {
|
||||||
placeholder: $t('authentication.password'),
|
placeholder: $t('authentication.passwordTip'),
|
||||||
},
|
},
|
||||||
fieldName: 'password',
|
fieldName: 'password',
|
||||||
label: $t('authentication.password'),
|
label: $t('authentication.password'),
|
||||||
|
@ -111,6 +119,7 @@ const formSchema = computed((): VbenFormSchema[] => {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<AuthenticationLogin
|
<AuthenticationLogin
|
||||||
|
ref="loginRef"
|
||||||
:form-schema="formSchema"
|
:form-schema="formSchema"
|
||||||
:loading="authStore.loginLoading"
|
:loading="authStore.loginLoading"
|
||||||
@submit="authStore.authLogin"
|
@submit="authStore.authLogin"
|
||||||
|
|
|
@ -11,12 +11,15 @@ interface Props {
|
||||||
class?: any;
|
class?: any;
|
||||||
options?: Array<{ label: string; value: string }>;
|
options?: Array<{ label: string; value: string }>;
|
||||||
placeholder?: string;
|
placeholder?: string;
|
||||||
|
enable?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const props = defineProps<Props>();
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
|
enable: true,
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<Select>
|
<Select v-if="enable">
|
||||||
<SelectTrigger :class="props.class">
|
<SelectTrigger :class="props.class">
|
||||||
<SelectValue :placeholder="placeholder" />
|
<SelectValue :placeholder="placeholder" />
|
||||||
</SelectTrigger>
|
</SelectTrigger>
|
||||||
|
|
|
@ -6,12 +6,13 @@
|
||||||
"loginSuccessDesc": "Welcome Back",
|
"loginSuccessDesc": "Welcome Back",
|
||||||
"loginSubtitle": "Enter your account details to manage your projects",
|
"loginSubtitle": "Enter your account details to manage your projects",
|
||||||
"selectAccount": "Quick Select Account",
|
"selectAccount": "Quick Select Account",
|
||||||
"selectTenant": "Please Select Tenant",
|
|
||||||
"username": "Username",
|
"username": "Username",
|
||||||
"password": "Password",
|
"password": "Password",
|
||||||
|
"tenant": "Tenant",
|
||||||
"usernameTip": "Please enter username",
|
"usernameTip": "Please enter username",
|
||||||
"passwordErrorTip": "Password is incorrect",
|
"passwordErrorTip": "Password is incorrect",
|
||||||
"passwordTip": "Please enter password",
|
"passwordTip": "Please enter password",
|
||||||
|
"tenantTip": "Please select tenant",
|
||||||
"verifyRequiredTip": "Please complete the verification first",
|
"verifyRequiredTip": "Please complete the verification first",
|
||||||
"rememberMe": "Remember Me",
|
"rememberMe": "Remember Me",
|
||||||
"createAnAccount": "Create an Account",
|
"createAnAccount": "Create an Account",
|
||||||
|
|
|
@ -6,11 +6,12 @@
|
||||||
"loginSuccessDesc": "欢迎回来",
|
"loginSuccessDesc": "欢迎回来",
|
||||||
"loginSubtitle": "请输入您的帐户信息以开始管理您的项目",
|
"loginSubtitle": "请输入您的帐户信息以开始管理您的项目",
|
||||||
"selectAccount": "快速选择账号",
|
"selectAccount": "快速选择账号",
|
||||||
"selectTenant": "请选择租户",
|
|
||||||
"username": "账号",
|
"username": "账号",
|
||||||
"password": "密码",
|
"password": "密码",
|
||||||
|
"tenant": "租户",
|
||||||
"usernameTip": "请输入用户名",
|
"usernameTip": "请输入用户名",
|
||||||
"passwordTip": "请输入密码",
|
"passwordTip": "请输入密码",
|
||||||
|
"tenantTip": "请选择租户",
|
||||||
"verifyRequiredTip": "请先完成验证",
|
"verifyRequiredTip": "请先完成验证",
|
||||||
"passwordErrorTip": "密码错误",
|
"passwordErrorTip": "密码错误",
|
||||||
"rememberMe": "记住账号",
|
"rememberMe": "记住账号",
|
||||||
|
|
Loading…
Reference in New Issue