Преглед изворни кода

获取当前登录用户信息时,附加一个字段 CurrentTenantId 以体现当前用户所切换到的租户。
并且修改相关前端页面(使用了租户控件的界面,默认选中当前所切换到的租户)

hwj пре 10 месеци
родитељ
комит
34a266887a

+ 5 - 0
Admin.NET/Admin.NET.Core/Service/Auth/Dto/LoginUserOutput.cs

@@ -105,4 +105,9 @@ public class LoginUserOutput
     /// 租户Id
     /// </summary>
     public long? TenantId { get; set; }
+
+    /// <summary>
+    /// 当前切换到的租户Id
+    /// </summary>
+    public long? CurrentTenantId { get; set; }
 }

+ 8 - 1
Admin.NET/Admin.NET.Core/Service/Auth/SysAuthService.cs

@@ -304,7 +304,7 @@ public class SysAuthService : IDynamicApiController, ITransient
         // 获取水印文字(若系统水印为空则全局为空)
         var watermarkText = (await _sysUserRep.Context.Queryable<SysTenant>().FirstAsync(u => u.Id == user.TenantId))?.Watermark;
         if (!string.IsNullOrWhiteSpace(watermarkText)) watermarkText += $"-{user.RealName}";
-        return new LoginUserOutput
+        var loginUser = new LoginUserOutput
         {
             Id = user.Id,
             Account = user.Account,
@@ -325,6 +325,13 @@ public class SysAuthService : IDynamicApiController, ITransient
             TenantId = user.TenantId,
             WatermarkText = watermarkText
         };
+
+        //将登录信息中的当前租户id,更新为当前所切换到的租户
+        long? currentTenantId = App.User.FindFirst(ClaimConst.TenantId)?.Value?.ToLong(0);
+        loginUser.CurrentTenantId = currentTenantId > 0 ? currentTenantId : user.TenantId;
+
+        return loginUser;
+
     }
 
     /// <summary>

+ 3 - 1
Web/src/layout/navBars/topBar/changeTenant.vue

@@ -33,7 +33,9 @@ import { reactive, ref } from 'vue';
 import { getAPI } from '/@/utils/axios-utils';
 import { SysTenantApi } from "/@/api-services";
 import { reLoadLoginAccessToken } from "/@/utils/request";
+import {useUserInfo} from "/@/stores/userInfo";
 
+const userStore = useUserInfo();
 const ruleFormRef = ref();
 const state = reactive({
 	loading: false,
@@ -46,7 +48,7 @@ const state = reactive({
 // 打开弹窗
 const openDialog = async () => {
 	state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-	state.ruleForm.id = state.tenantList[0].value;
+	state.ruleForm.id = userStore.userInfos.currentTenantId as any;
 	ruleFormRef.value?.resetFields();
 	state.isShowDialog = true;
 	state.loading = false;

+ 1 - 0
Web/src/stores/userInfo.ts

@@ -81,6 +81,7 @@ export const useUserInfo = defineStore('userInfo', {
 							roles: d.roleIds,
 							authBtnList: d.buttons,
 							tenantId: d.tenantId,
+							currentTenantId: d.currentTenantId,
 							time: new Date().getTime(),
 						};
 

+ 17 - 0
Web/src/types/pinia.d.ts

@@ -9,7 +9,24 @@ declare interface UserInfos<T = any> {
 	roles: string[];
 	time: number;
 	userName: string;
+	
+	id:string;
+	account:string;
+	realName:string;
+	phone:string;
+	idCardNum:string;
+	email:string;
+	accountType:number;
+	avatar:string;
+	address:string;
+	signature:string;
+	orgId:string;
+	orgName:string;
+	tenantId:string;
+	currentTenantId:string;
+
 	[key: string]: T;
+
 }
 declare interface UserInfosState {
 	userInfos: UserInfos;

+ 1 - 1
Web/src/views/system/file/index.vue

@@ -201,7 +201,7 @@ const state = reactive({
 onMounted(async () => {
 	if (userStore.userInfos.accountType == 999) {
 		state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-		state.queryParams.tenantId = state.tenantList[0].value;
+		state.queryParams.tenantId = userStore.userInfos.currentTenantId as any;
 	}
 	handleQuery();
 });

+ 1 - 1
Web/src/views/system/ldap/index.vue

@@ -103,7 +103,7 @@ const state = reactive({
 onMounted(async () => {
 	if (userStore.userInfos.accountType == 999) {
 		state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-		state.queryParams.tenantId = state.tenantList[0].value;
+		state.queryParams.tenantId = userStore.userInfos.currentTenantId as any;
 	}
 	handleQuery();
 });

+ 1 - 1
Web/src/views/system/log/difflog/index.vue

@@ -112,7 +112,7 @@ const state = reactive({
 onMounted(async () => {
 	if (userStore.userInfos.accountType == 999) {
 		state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-		state.queryParams.tenantId = state.tenantList[0].value;
+		state.queryParams.tenantId = userStore.userInfos.currentTenantId as any;
 	}
 	handleQuery();
 });

+ 1 - 1
Web/src/views/system/log/exlog/index.vue

@@ -159,7 +159,7 @@ const state = reactive({
 onMounted(async () => {
 	if (userStore.userInfos.accountType == 999) {
 		state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-		state.queryParams.tenantId = state.tenantList[0].value;
+		state.queryParams.tenantId = userStore.userInfos.currentTenantId as any;
 	}
 	handleQuery();
 });

+ 1 - 1
Web/src/views/system/log/oplog/index.vue

@@ -152,7 +152,7 @@ const state = reactive({
 onMounted(async () => {
 	if (userStore.userInfos.accountType == 999) {
 		state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-		state.queryParams.tenantId = state.tenantList[0].value;
+		state.queryParams.tenantId = userStore.userInfos.currentTenantId as any;
 	}
 	handleQuery();
 });

+ 1 - 1
Web/src/views/system/log/vislog/index.vue

@@ -113,7 +113,7 @@ const state = reactive({
 onMounted(async () => {
 	if (userStore.userInfos.accountType == 999) {
 		state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-		state.queryParams.tenantId = state.tenantList[0].value;
+		state.queryParams.tenantId = userStore.userInfos.currentTenantId as any;
 	}
 	handleQuery();
 });

+ 1 - 1
Web/src/views/system/menu/index.vue

@@ -95,7 +95,7 @@ const state = reactive({
 onMounted(async () => {
 	if (userStore.userInfos.accountType == 999) {
 		state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-		state.queryParams.tenantId = state.tenantList[0].value;
+		state.queryParams.tenantId = userStore.userInfos.currentTenantId as any;
 	}
 	handleQuery();
 });

+ 1 - 1
Web/src/views/system/onlineUser/index.vue

@@ -90,7 +90,7 @@ const state = reactive({
 onMounted(async () => {
 	if (userStore.userInfos.accountType == 999) {
 		state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-		state.queryParams.tenantId = state.tenantList[0].value;
+		state.queryParams.tenantId = userStore.userInfos.currentTenantId as any;
 	}
 	// 在线用户列表
 	signalR.off('OnlineUserList');

+ 1 - 1
Web/src/views/system/plugin/index.vue

@@ -93,7 +93,7 @@ const state = reactive({
 onMounted(async () => {
 	if (userStore.userInfos.accountType == 999) {
 		state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-		state.queryParams.tenantId = state.tenantList[0].value;
+		state.queryParams.tenantId = userStore.userInfos.currentTenantId as any;
 	}
 	handleQuery();
 });

+ 1 - 1
Web/src/views/system/pos/index.vue

@@ -102,7 +102,7 @@ const state = reactive({
 onMounted(async () => {
 	if (userStore.userInfos.accountType == 999) {
 		state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-		state.queryParams.tenantId = state.tenantList[0].value;
+		state.queryParams.tenantId = userStore.userInfos.currentTenantId as any;
 	}
 	handleQuery();
 });

+ 1 - 1
Web/src/views/system/print/index.vue

@@ -93,7 +93,7 @@ const state = reactive({
 onMounted(async () => {
 	if (userStore.userInfos.accountType == 999) {
 		state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-		state.queryParams.tenantId = state.tenantList[0].value;
+		state.queryParams.tenantId = userStore.userInfos.currentTenantId as any;
 	}
 	handleQuery();
 });

+ 1 - 1
Web/src/views/system/role/index.vue

@@ -106,7 +106,7 @@ const state = reactive({
 onMounted(async () => {
 	if (userStore.userInfos.accountType == 999) {
 		state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-		state.queryParams.tenantId = state.tenantList[0].value;
+		state.queryParams.tenantId = userStore.userInfos.currentTenantId as any;
 	}
 	await handleQuery();
 });

+ 1 - 1
Web/src/views/system/userRegWay/index.vue

@@ -80,7 +80,7 @@ const state = reactive({
 onMounted(async () => {
 	if (userStore.userInfos.accountType == 999) {
 		state.tenantList = await getAPI(SysTenantApi).apiSysTenantListGet().then(res => res.data.result ?? []);
-		state.queryParams.tenantId = state.tenantList[0].value;
+		state.queryParams.tenantId = userStore.userInfos.currentTenantId as any;
 	}
 	handleQuery();
 });