Jelajahi Sumber

fix: 登录界面通过host与t参数匹配租户成功后隐藏租户选择器

喵你个旺呀 1 tahun lalu
induk
melakukan
6a94eb50a5

+ 3 - 8
Web/src/views/login/component/account.vue

@@ -23,7 +23,7 @@
 					</template>
 				</el-input>
 			</el-form-item>
-			<el-form-item class="login-animation2" prop="tenantId" clearable v-if="!tenantInfo.list.some((e: any) => e.host === tenantInfo.host)">
+			<el-form-item class="login-animation2" prop="tenantId" clearable v-if="!props.tenantInfo.id">
 				<el-select v-model="state.ruleForm.tenantId" :placeholder="$t('message.account.accountPlaceholder3')" style="width: 100%">
 					<template #prefix>
 						<i class="iconfont icon-shuxingtu el-input__icon"></i>
@@ -97,7 +97,6 @@ import { storeToRefs } from 'pinia';
 
 import { accessTokenKey, clearTokens, feature, getAPI } from '/@/utils/axios-utils';
 import { SysAuthApi } from '/@/api-services/api';
-import {useUserInfo} from "/@/stores/userInfo";
 
 const props = defineProps({
 	tenantInfo: {
@@ -225,9 +224,10 @@ const onSignIn = async () => {
 
 			// SM2加密密码
 			// const keys = SM2.generateKeyPair();
-			state.ruleForm.tenantId ??= props.tenantInfo.id;
 			const publicKey = window.__env__.VITE_SM_PUBLIC_KEY;
 			const password = sm2.doEncrypt(state.ruleForm.password, publicKey, 1);
+
+			state.ruleForm.tenantId ??= props.tenantInfo.id ?? props.tenantInfo.list[0]?.value;
 			const [err, res] = await feature(getAPI(SysAuthApi).apiSysAuthLoginPost({ ...state.ruleForm, password: password } as any));
 			if (err) {
 				getCaptcha(); // 重新获取验证码
@@ -310,11 +310,6 @@ const handleSignIn = () => {
 	}
 };
 
-// // 微信登录
-// const weixinSignIn = () => {
-// 	window.open('http://localhost:5005/api/sysoauth/signin?provider=Gitee&redirectUrl=http://localhost:8888');
-// };
-
 // 导出对象
 defineExpose({ saveTokenAndInitRoutes });
 </script>

+ 2 - 2
Web/src/views/login/component/mobile.vue

@@ -1,6 +1,6 @@
 <template>
 	<el-form size="large" class="login-content-form">
-		<el-form-item class="login-animation1" v-if="!tenantInfo.list.some((e: any) => e.host === tenantInfo.host)">
+		<el-form-item class="login-animation1" v-if="!props.tenantInfo.id">
 			<el-select v-model="state.ruleForm.tenantId" :placeholder="$t('message.mobile.placeholder1')" clearable style="width: 100%">
 				<template #prefix>
 					<i class="iconfont icon-shuxingtu el-input__icon"></i>
@@ -98,7 +98,7 @@ const getSmsCode = async () => {
 
 // 登录
 const onSignIn = async () => {
-	state.ruleForm.tenantId ??= props.tenantInfo.id;
+	state.ruleForm.tenantId ??= props.tenantInfo.id ?? props.tenantInfo.list[0]?.value;
 	const res = await getAPI(SysAuthApi).apiSysAuthLoginPhonePost({...state.ruleForm, host: host});
 	if (res.data.result?.accessToken == undefined) {
 		ElMessage.error('登录失败,请检查账号!');

+ 4 - 3
Web/src/views/login/component/register.vue

@@ -1,7 +1,7 @@
 <template>
 	<el-tooltip :visible="state.capsLockVisible" effect="light" content="大写锁定已打开" placement="top">
 		<el-form ref="ruleFormRef" :model="state.ruleForm" size="large" :rules="state.rules" class="login-content-form">
-			<el-form-item class="login-animation2" prop="tenantId" clearable v-if="!tenantInfo.list.some((e: any) => e.host === tenantInfo.host)">
+			<el-form-item class="login-animation2" prop="tenantId" clearable v-if="!props.tenantInfo.id">
 				<el-select v-model="state.ruleForm.tenantId" :placeholder="$t('message.register.placeholder1')" style="width: 100%">
 					<template #prefix>
 						<i class="iconfont icon-shuxingtu el-input__icon"></i>
@@ -85,7 +85,7 @@
 </template>
 
 <script lang="ts" setup name="loginAccount">
-import {reactive, ref, onMounted, defineAsyncComponent, onUnmounted, watch } from 'vue';
+import {reactive, ref, onMounted, defineAsyncComponent, onUnmounted, watch, nextTick} from 'vue';
 import { useRoute, useRouter } from 'vue-router';
 import { ElMessage, InputInstance } from 'element-plus';
 import { useI18n } from 'vue-i18n';
@@ -209,9 +209,10 @@ const onRegister = async () => {
 		try {
 			state.loading.register = true;
 
-			state.ruleForm.tenantId ??= props.tenantInfo.id;
 			const publicKey = window.__env__.VITE_SM_PUBLIC_KEY;
 			const password = state.ruleForm.password ? sm2.doEncrypt(state.ruleForm.password, publicKey, 1) : undefined;
+
+			state.ruleForm.tenantId ??= props.tenantInfo.id ?? props.tenantInfo.list[0]?.value;
 			const [err, res] = await feature(getAPI(SysAuthApi).apiSysAuthUserRegistrationPost({...state.ruleForm, password: password } as any));
 
 			if (res?.data?.code === 200) {

+ 1 - 1
Web/src/views/login/component/scan.vue

@@ -1,6 +1,6 @@
 <template>
 	<div class="login-scan-container">
-		<el-select v-model="state.tenantId" v-if="!tenantInfo.list.some((e: any) => e.host === tenantInfo.host)" :placeholder="$t('message.scan.placeholder1')" clearable class="mb30" style="width: 260px; align-self: center;">
+		<el-select v-model="state.tenantId" v-if="!props.tenantInfo.id" :placeholder="$t('message.scan.placeholder1')" clearable class="mb30" style="width: 260px; align-self: center;">
 			<template #prefix>
 				<i class="iconfont icon-shuxingtu el-input__icon"></i>
 			</template>

+ 17 - 15
Web/src/views/login/index.vue

@@ -30,17 +30,17 @@
 						<div v-if="!state.isScan">
 							<el-tabs v-model="state.tabsActiveName">
 								<el-tab-pane :label="$t('message.label.one1')" name="account" v-if="state.tabsActiveName != 'register'">
-									<Account :tenant-info="state.tenantInfo" />
+									<Account :tenant-info="tenantInfo" />
 								</el-tab-pane>
 								<el-tab-pane :label="$t('message.label.two2')" name="mobile" v-if="state.tabsActiveName != 'register'">
-									<Mobile :tenant-info="state.tenantInfo" />
+									<Mobile :tenant-info="tenantInfo" />
 								</el-tab-pane>
 								<el-tab-pane :label="$t('message.label.two3')" name="register" v-if="state.tabsActiveName == 'register'">
-									<Register :tenant-info="state.tenantInfo" @goLogin="() => state.tabsActiveName = 'account'" />
+									<Register :tenant-info="tenantInfo" @goLogin="() => state.tabsActiveName = 'account'" />
 								</el-tab-pane>
 							</el-tabs>
 						</div>
-						<Scan v-if="state.isScan" :tenant-info="state.tenantInfo" />
+						<Scan v-if="state.isScan" :tenant-info="tenantInfo" />
 						<div class="login-content-main-scan" @click="state.isScan = !state.isScan">
 							<i class="iconfont" :class="state.isScan ? 'icon-diannao1' : 'icon-barcode-qr'"></i>
 							<div class="login-content-main-scan-delta"></div>
@@ -65,7 +65,7 @@
 </template>
 
 <script setup lang="ts" name="loginIndex">
-import {defineAsyncComponent, onMounted, reactive, computed} from 'vue';
+import {defineAsyncComponent, onMounted, reactive, computed, ref} from 'vue';
 import { storeToRefs } from 'pinia';
 import { useThemeConfig } from '/@/stores/themeConfig';
 import { NextLoading } from '/@/utils/loading';
@@ -85,19 +85,21 @@ const Scan = defineAsyncComponent(() => import('/@/views/login/component/scan.vu
 const route = useRoute();
 const storesThemeConfig = useThemeConfig();
 const { themeConfig } = storeToRefs(storesThemeConfig);
+const tenantInfo = ref({
+	id: undefined as number | undefined,
+	list: [],
+});
+
 const state = reactive({
 	tabsActiveName: 'account',
-	tenantInfo: {
-		host: location.host.toLowerCase(),
-		id: undefined as number | undefined,
-		list: [],
-	},
 	isScan: false,
 });
+
 // 获取布局配置信息
 const getThemeConfig = computed(() => {
 	return themeConfig.value;
 });
+
 // 页面加载时
 onMounted(async () => {
 	// 地址栏存在wayid参数时,默认切换到注册界面
@@ -108,11 +110,11 @@ onMounted(async () => {
 
 // 获取租户信息
 const getTenantInfo = async () => {
-	const list = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-	const tenant = list.find((item: any) => item.host === state.tenantInfo.host);
-	state.tenantInfo.id = parseInt(route.query.t ?? (tenant ?? list[0])?.value);
-	state.tenantInfo.list = list;
-	return state.tenantInfo;
+	const host = location.host.toLowerCase();
+	tenantInfo.value.list = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
+	const tenant = tenantInfo.value.list.find((item: any) => item.value == route.query.t || item.host === host);
+	if (tenant?.value) tenantInfo.value.id = parseInt(tenant?.value);
+	return tenantInfo.value;
 }
 </script>