Просмотр исходного кода

fix(login): correct tenant host matching

YY968XX 2 месяцев назад
Родитель
Сommit
0b243f1b5a
1 измененных файлов с 13 добавлено и 4 удалено
  1. 13 4
      Web/src/views/login/index.vue

+ 13 - 4
Web/src/views/login/index.vue

@@ -86,9 +86,15 @@ const Scan = defineAsyncComponent(() => import('./component/scan.vue'));
 const route = useRoute();
 const storesThemeConfig = useThemeConfig();
 const { themeConfig } = storeToRefs(storesThemeConfig);
+type TenantOption = {
+	label: string;
+	host?: string | null;
+	value: string;
+};
+
 const tenantInfo = ref({
 	id: undefined as number | undefined,
-	list: [],
+	list: [] as TenantOption[],
 });
 
 const state = reactive({
@@ -115,9 +121,12 @@ const getTenantInfo = async () => {
 		return tenantInfo.value;
 	}
 	const host = location.host.toLowerCase();
-	tenantInfo.value.list = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? null);
-	const tenant = tenantInfo.value.list.find((item: any) => !item.host && item.host === host) as any;
-	if (tenant?.value) tenantInfo.value.id = parseInt(tenant?.value);
+	const result = await getAPI(SysTenantApi)
+		.apiSysTenantListGet()
+		.then((res) => res.data.result);
+	tenantInfo.value.list = Array.isArray(result) ? result : [];
+	const tenant = tenantInfo.value.list.find((item) => String(item?.host ?? '').trim().toLowerCase() === host);
+	if (tenant?.value) tenantInfo.value.id = parseInt(tenant.value);
 	return tenantInfo.value;
 }