喵你个旺呀 1 год назад
Родитель
Сommit
cb4e089316

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

@@ -119,6 +119,9 @@ public class SysAuthService : IDynamicApiController, ITransient
             .FirstAsync();
         _ = user ?? throw Oops.Oh(ErrorCodeEnum.D0009);
 
+        // 如果是超级管理员,则引用登录选择的租户进入系统
+        if (user.AccountType == AccountTypeEnum.SuperAdmin) user.TenantId = tenantId;
+
         return (tenant, user);
     }
 
@@ -209,8 +212,7 @@ public class SysAuthService : IDynamicApiController, ITransient
     /// <summary>
     /// 生成Token令牌 🔖
     /// </summary>
-    /// <param name="user"></param>
-    /// <param name="appId"></param>
+    /// <param name="user"></param>\
     /// <returns></returns>
     [NonAction]
     internal virtual async Task<LoginOutput> CreateToken(SysUser user)

+ 0 - 3
Admin.NET/Admin.NET.Core/Service/Region/SysRegionService.cs

@@ -18,9 +18,6 @@ public class SysRegionService : IDynamicApiController, ITransient
     private readonly SqlSugarRepository<SysRegion> _sysRegionRep;
     private readonly SysConfigService _sysConfigService;
 
-    // Url地址-国家统计局行政区域2023年
-    private readonly string _url = "http://www.stats.gov.cn/sj/tjbz/tjyqhdmhcxhfdm/2023/index.html";
-
     public SysRegionService(SqlSugarRepository<SysRegion> sysRegionRep, SysConfigService sysConfigService)
     {
         _sysRegionRep = sysRegionRep;

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

@@ -105,7 +105,7 @@ public class SysTenantService : IDynamicApiController, ITransient
            .Where(u => u.Status == StatusEnum.Enable && u.IsDelete == false)
             .Select((u, a) => new
             {
-                Label = a.Name,
+                Label = $"{u.Title}-{a.Name}",
                 Value = u.Id,
                 Host = u.Host.ToLower()
             }).ToListAsync();

+ 2 - 8
Web/src/layout/navBars/topBar/changeTenant.vue

@@ -30,10 +30,9 @@
 
 <script lang="ts" setup name="sysEditApp">
 import { reactive, ref } from 'vue';
-import { Local } from "/@/utils/storage";
 import { getAPI } from '/@/utils/axios-utils';
 import { SysTenantApi } from "/@/api-services";
-import { accessTokenKey, refreshAccessTokenKey } from "/@/utils/request";
+import { reLoadLoginAccessToken } from "/@/utils/request";
 
 const ruleFormRef = ref();
 const state = reactive({
@@ -58,12 +57,7 @@ const submit = () => {
 	ruleFormRef.value.validate(async (valid: boolean) => {
 		if (!valid) return;
 		state.loading = true;
-		const newToken = await getAPI(SysTenantApi).apiSysTenantChangeTenantPost(state.ruleForm).then(res => res.data.result);
-		if (newToken) {
-			Local.set(accessTokenKey, newToken.accessToken);
-			Local.set(refreshAccessTokenKey, newToken.refreshToken);
-			location.href = "/";
-		}
+		getAPI(SysTenantApi).apiSysTenantChangeTenantPost(state.ruleForm).then(res => reLoadLoginAccessToken(res.data.result));
 		state.loading = false;
 		state.isShowDialog = false;
 	});

+ 13 - 0
Web/src/utils/request.ts

@@ -261,5 +261,18 @@ export function request2(config: AxiosRequestConfig<any>): any {
 			});
 	});
 }
+
+/**
+ * 使用新的令牌登录
+ * @param accessInfo
+ */
+export function reLoadLoginAccessToken(accessInfo: any) {
+	if (accessInfo?.accessToken && accessInfo?.refreshToken) {
+		Local.set(accessTokenKey, accessInfo.accessToken);
+		Local.set(refreshAccessTokenKey, accessInfo.refreshToken);
+		setTimeout(() => location.href = "/", 300);
+	}
+}
+
 // 导出 axios 实例
 export default service;

+ 23 - 34
Web/src/views/system/tenant/index.vue

@@ -31,6 +31,18 @@
 					</template>
 				</el-table-column>
 				<el-table-column prop="name" label="名称" width="180" align="center" show-overflow-tooltip />
+				<el-table-column prop="title" label="标题" width="180" show-overflow-tooltip />
+				<el-table-column prop="viceTitle" label="副标题" width="180" show-overflow-tooltip />
+				<el-table-column prop="viceDesc" label="描述" width="300" show-overflow-tooltip />
+				<el-table-column prop="watermark" label="水印" width="130" show-overflow-tooltip />
+				<el-table-column prop="copyright" label="版权信息" width="350" show-overflow-tooltip />
+				<el-table-column prop="icp" label="备案号" width="130" show-overflow-tooltip />
+				<el-table-column prop="icpUrl" label="icp地址" width="280" show-overflow-tooltip />
+				<el-table-column prop="enableReg" label="启用注册" width="280" show-overflow-tooltip>
+					<template #default="scope">
+						<g-sys-dict v-model="scope.row.enableReg" code="YesNoEnum" />
+					</template>
+				</el-table-column>
 				<el-table-column prop="adminAccount" label="租管账号" align="center" width="120" show-overflow-tooltip />
 				<el-table-column prop="phone" label="电话" width="120" align="center" show-overflow-tooltip />
 				<el-table-column prop="host" label="域名" width="150" show-overflow-tooltip />
@@ -80,18 +92,6 @@
 					show-overflow-tooltip />
 				<el-table-column prop="slaveConnections" label="从库连接" min-width="300" header-align="center"
 					show-overflow-tooltip />
-				<el-table-column prop="title" label="标题" width="180" show-overflow-tooltip />
-				<el-table-column prop="viceTitle" label="副标题" width="180" show-overflow-tooltip />
-				<el-table-column prop="viceDesc" label="描述" width="300" show-overflow-tooltip />
-				<el-table-column prop="watermark" label="水印" width="130" show-overflow-tooltip />
-				<el-table-column prop="copyright" label="版权信息" width="350" show-overflow-tooltip />
-				<el-table-column prop="icp" label="备案号" width="130" show-overflow-tooltip />
-				<el-table-column prop="icpUrl" label="icp地址" width="280" show-overflow-tooltip />
-				<el-table-column prop="enableReg" label="启用注册" width="280" show-overflow-tooltip>
-					<template #default="scope">
-						<g-sys-dict v-model="scope.row.enableReg" code="YesNoEnum" />
-					</template>
-				</el-table-column>
 				<el-table-column prop="orderNo" label="排序" width="70" show-overflow-tooltip />
 				<el-table-column label="修改记录" width="100" align="center" show-overflow-tooltip>
 					<template #default="scope">
@@ -147,8 +147,7 @@ import ModifyRecord from '/@/components/table/modifyRecord.vue';
 import { getAPI } from '/@/utils/axios-utils';
 import { SysTenantApi } from '/@/api-services/api';
 import { TenantOutput } from '/@/api-services/models';
-import {Local} from "/@/utils/storage";
-import {accessTokenKey, refreshAccessTokenKey} from "/@/utils/request";
+import { reLoadLoginAccessToken } from "/@/utils/request";
 import GSysDict from "/@/components/sysDict/sysDict.vue";
 
 const editTenantRef = ref<InstanceType<typeof EditTenant>>();
@@ -188,16 +187,11 @@ const goTenant = (row: any) => {
 		confirmButtonText: '确定',
 		cancelButtonText: '取消',
 		type: 'warning',
-	}).then(async () => {
-		await getAPI(SysTenantApi).apiSysTenantGoTenantPost({ id: row.id }).then(res => {
-			const newToken = res.data.result;
-			if (newToken) {
-				Local.set(accessTokenKey, newToken.accessToken);
-				Local.set(refreshAccessTokenKey, newToken.refreshToken);
-				location.href = "/";
-			}
-		});
-	});
+	}).then(() =>
+			getAPI(SysTenantApi)
+			.apiSysTenantGoTenantPost({ id: row.id })
+			.then(res => reLoadLoginAccessToken(res.data.result))
+	);
 }
 
 // 切换租户
@@ -206,16 +200,11 @@ const changeTenant = (row: any) => {
 		confirmButtonText: '确定',
 		cancelButtonText: '取消',
 		type: 'warning',
-	}).then(async () => {
-		await getAPI(SysTenantApi).apiSysTenantChangeTenantPost({ id: row.id }).then(res => {
-			const newToken = res.data.result;
-			if (newToken) {
-				Local.set(accessTokenKey, newToken.accessToken);
-				Local.set(refreshAccessTokenKey, newToken.refreshToken);
-				location.href = "/";
-			}
-		});
-	});
+	}).then(() =>
+			getAPI(SysTenantApi)
+			.apiSysTenantChangeTenantPost({ id: row.id })
+			.then(res => reLoadLoginAccessToken(res.data.result))
+	);
 }
 
 const syncGrantMenu = (row: any) => {