Jelajahi Sumber

chore: 去除租户host必填限制

喵你个旺呀 1 tahun lalu
induk
melakukan
833daae5c8

+ 4 - 6
Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs

@@ -66,7 +66,7 @@ public class SysAuthService : IDynamicApiController, ITransient
         if (await _sysConfigService.GetConfigValue<bool>(ConfigConst.SysCaptcha) && !_captcha.Validate(input.CodeId.ToString(), input.Code)) throw Oops.Oh(ErrorCodeEnum.D0008);
 
         // 获取登录租户和用户
-        var (tenant, user) = await GetLoginUserAndTenant(input.TenantId, codeId: input.CodeId, code: input.Code, account: input.Account);
+        var (tenant, user) = await GetLoginUserAndTenant(input.TenantId, account: input.Account);
 
         // 账号是否被冻结
         if (user.Status == StatusEnum.Disable) throw Oops.Oh(ErrorCodeEnum.D1017);
@@ -98,16 +98,14 @@ public class SysAuthService : IDynamicApiController, ITransient
     /// 获取登录租户和用户
     /// </summary>
     /// <param name="tenantId"></param>
-    /// <param name="codeId"></param>
-    /// <param name="code"></param>
     /// <param name="account"></param>
     /// <param name="phone"></param>
     /// <returns></returns>
     [NonAction]
-    public async Task<(SysTenant tenant, SysUser user)> GetLoginUserAndTenant(long? tenantId, long codeId = 0, string code = null, string account = null, string phone = null)
+    public async Task<(SysTenant tenant, SysUser user)> GetLoginUserAndTenant(long? tenantId, string account = null, string phone = null)
     {
-        // 如果租户为空,使用默认租户
-        tenantId ??= SqlSugarConst.DefaultTenantId;
+        // 如果租户为空或为-1使用默认租户
+        if (tenantId is null or -1) tenantId = SqlSugarConst.DefaultTenantId;
 
         // 租户是否存在或已禁用
         var tenant = await _sysUserRep.ChangeRepository<SqlSugarRepository<SysTenant>>().GetFirstAsync(u => u.Id == tenantId);

+ 0 - 6
Admin.NET/Admin.NET.Core/Service/Tenant/Dto/TenantInput.cs

@@ -40,12 +40,6 @@ public class AddTenantInput : TenantOutput
     /// </summary>
     [Required(ErrorMessage = "租管账号不能为空"), MinLength(3, ErrorMessage = "租管账号不能少于3个字符")]
     public override string AdminAccount { get; set; }
-
-    /// <summary>
-    /// 租户域名
-    /// </summary>
-    [Required(ErrorMessage = "域名不能为空"), MinLength(5, ErrorMessage = "域名不能少于5个字符")]
-    public override string Host { get; set; }
     
     /// <summary>
     /// 系统主标题

+ 4 - 4
Admin.NET/Admin.NET.Core/Service/Tenant/SysTenantService.cs

@@ -102,12 +102,12 @@ public class SysTenantService : IDynamicApiController, ITransient
         return await _sysTenantRep.AsQueryable()
            .LeftJoin<SysOrg>((u, a) => u.OrgId == a.Id).ClearFilter()
            .Where(u => u.Status == StatusEnum.Enable && u.IsDelete == false)
-            .Select((u, a) => new
-            {
+           .Select((u, a) => new
+           {
                 Label = $"{u.Title}-{a.Name}",
+                Host = u.Host.ToLower(),
                 Value = u.Id,
-                Host = u.Host.ToLower()
-            }).ToListAsync();
+           }).ToListAsync();
     }
     
     /// <summary>

+ 2 - 1
Web/src/views/login/component/account.vue

@@ -28,7 +28,7 @@
 					<template #prefix>
 						<i class="iconfont icon-shuxingtu el-input__icon"></i>
 					</template>
-					<el-option :value="item.value" :label="`${item.label} (${item.host})`" v-for="(item, index) in tenantInfo.list" :key="index" />
+					<el-option :value="item.value" :label="item.label" v-for="(item, index) in tenantInfo.list" :key="index" />
 				</el-select>
 			</el-form-item>
 			<el-form-item class="login-animation3" prop="captcha" v-if="state.captchaEnabled">
@@ -230,6 +230,7 @@ const onSignIn = async () => {
 			const password = sm2.doEncrypt(state.ruleForm.password, publicKey, 1);
 
 			state.ruleForm.tenantId ??= props.tenantInfo.id ?? props.tenantInfo.list[0]?.value;
+			console.log(state.ruleForm.tenantId)
 			const [err, res] = await feature(getAPI(SysAuthApi).apiSysAuthLoginPost({ ...state.ruleForm, password: password } as any));
 			if (err) {
 				getCaptcha(); // 重新获取验证码

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

@@ -5,7 +5,7 @@
 				<template #prefix>
 					<i class="iconfont icon-shuxingtu el-input__icon"></i>
 				</template>
-				<el-option :value="item.value" :label="`${item.label} (${item.host})`" v-for="(item, index) in tenantInfo.list" :key="index" />
+				<el-option :value="item.value" :label="item.label" v-for="(item, index) in tenantInfo.list" :key="index" />
 			</el-select>
 		</el-form-item>
 		<el-form-item class="login-animation1">

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

@@ -6,7 +6,7 @@
 					<template #prefix>
 						<i class="iconfont icon-shuxingtu el-input__icon"></i>
 					</template>
-					<el-option :value="item.value" :label="`${item.label} (${item.host})`" v-for="(item, index) in tenantInfo.list" :key="index" />
+					<el-option :value="item.value" :label="item.label" v-for="(item, index) in tenantInfo.list" :key="index" />
 				</el-select>
 			</el-form-item>
 			<el-form-item class="login-animation1" prop="phone" clearable>
@@ -111,7 +111,6 @@ const { themeConfig } = storeToRefs(storesThemeConfig);
 
 const { t } = useI18n();
 const route = useRoute();
-const router = useRouter();
 
 const ruleFormRef = ref();
 const accountRef = ref<InputInstance>();
@@ -154,7 +153,7 @@ let timer: any = null;
 // 页面初始化
 onMounted(async () => {
 	// 默认尝试从地址栏获取wayid注册方案id
-	if (route.query.wayid) state.ruleForm.wayId = route.query.wayid;
+	if (route.query.wayid) state.ruleForm.wayId = route.query.wayid as any;
 	watch(
 		() => themeConfig.value.isLoaded,
 		(isLoaded) => {

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

@@ -4,7 +4,7 @@
 			<template #prefix>
 				<i class="iconfont icon-shuxingtu el-input__icon"></i>
 			</template>
-			<el-option :value="item.value" :label="`${item.label} (${item.host})`" v-for="(item, index) in tenantInfo.list" :key="index" />
+			<el-option :value="item.value" :label="item.label" v-for="(item, index) in tenantInfo.list" :key="index" />
 		</el-select>
 		<div ref="qrcodeRef"></div>
 		<div class="font12 mt20 login-msg">

+ 2 - 2
Web/src/views/login/index.vue

@@ -113,7 +113,7 @@ onMounted(async () => {
 const getTenantInfo = async () => {
 	if (themeConfig.value.hideTenantForLogin) {
 		if (!route.query.t) {
-			const query = Object.assign({}, route.query?.params, { t: '1300000000001' });
+			const query = Object.assign({}, route.query?.params, { t: '-1' });
 			router.push({
 				path: route.path,
 				query: query as any,
@@ -125,7 +125,7 @@ const getTenantInfo = async () => {
 	}
 	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);
+	const tenant = tenantInfo.value.list.find((item: any) => item.value == route.query.t || (!item.host && item.host === host)) as any;
 	if (tenant?.value) tenantInfo.value.id = parseInt(tenant?.value);
 	return tenantInfo.value;
 }

+ 1 - 23
Web/src/views/system/tenant/component/editTenant.vue

@@ -63,7 +63,7 @@
 								</el-form-item>
 							</el-col>
 							<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
-								<el-form-item label="绑定域名" :rules="[{ required: true, message: '绑定域名不能为空', trigger: 'blur' }]">
+								<el-form-item label="主机host">
 									<el-input v-model="state.ruleForm.host" placeholder="例:gitee.com" clearable />
 								</el-form-item>
 							</el-col>
@@ -147,28 +147,6 @@
 							</el-col>
 						</el-row>
 					</el-tab-pane>
-<!--					<el-tab-pane label="配置开关" style="height: 550px; overflow: auto; overflow-x: hidden;">-->
-<!--						<el-row :gutter="35">-->
-<!--							<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">-->
-<!--								<el-form-item label="启用验证码" prop="captcha">-->
-<!--									<el-switch-->
-<!--											v-model="state.ruleForm.captcha"-->
-<!--											:active-value="1"-->
-<!--											:inactive-value="2"-->
-<!--									/>-->
-<!--								</el-form-item>-->
-<!--							</el-col>-->
-<!--							<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">-->
-<!--								<el-form-item label="启用二次验证" prop="secondVer">-->
-<!--									<el-switch-->
-<!--											v-model="state.ruleForm.secondVer"-->
-<!--											:active-value="1"-->
-<!--											:inactive-value="2"-->
-<!--									/>-->
-<!--								</el-form-item>-->
-<!--							</el-col>-->
-<!--						</el-row>-->
-<!--					</el-tab-pane>-->
 				</el-tabs>
 			</el-form>
 			<template #footer>