Selaa lähdekoodia

机构更新时页面数据刷新

zuohuaijun 3 vuotta sitten
vanhempi
commit
55b54fcaed

+ 2 - 2
Admin.NET/Admin.NET.Core/Admin.NET.Core.xml

@@ -7193,9 +7193,9 @@
             附加数据
             </summary>
         </member>
-        <member name="P:Admin.NET.Core.AdminResult`1.Timestamp">
+        <member name="P:Admin.NET.Core.AdminResult`1.Time">
             <summary>
-            时间
+            时间
             </summary>
         </member>
         <member name="T:Admin.NET.Core.BaseIdInput">

+ 3 - 3
Admin.NET/Admin.NET.Core/Util/AdminResultProvider.cs

@@ -85,7 +85,7 @@ public class AdminResultProvider : IUnifyResultProvider
             Result = data,
             Type = succeeded ? "success" : "error",
             Extras = UnifyContext.Take(),
-            Timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
+            Time = DateTime.Now  
         };
     }
 }
@@ -122,7 +122,7 @@ public class AdminResult<T>
     public object Extras { get; set; }
 
     /// <summary>
-    /// 时间
+    /// 时间
     /// </summary>
-    public long Timestamp { get; set; }
+    public DateTime Time { get; set; }
 }

+ 37 - 25
Web/src/views/system/onlineUser/index.vue

@@ -21,10 +21,10 @@
 					<el-table-column type="index" label="序号" width="55" align="center" />
 					<el-table-column prop="userName" label="账号" show-overflow-tooltip></el-table-column>
 					<el-table-column prop="realName" label="姓名" show-overflow-tooltip></el-table-column>
-					<el-table-column prop="time" label="登录时间" show-overflow-tooltip></el-table-column>
 					<el-table-column prop="ip" label="IP地址" show-overflow-tooltip> </el-table-column>
 					<el-table-column prop="browser" label="浏览器" show-overflow-tooltip></el-table-column>
-					<el-table-column prop="connectionId" label="连接Id" show-overflow-tooltip></el-table-column>
+					<!-- <el-table-column prop="connectionId" label="连接Id" show-overflow-tooltip></el-table-column> -->
+					<el-table-column prop="time" label="登录时间" show-overflow-tooltip></el-table-column>
 					<el-table-column label="操作" width="70" fixed="right" align="center" show-overflow-tooltip>
 						<template #default="scope">
 							<el-button icon="ele-CircleClose" size="small" text type="danger" v-auth="'sysUser:forceOffline'" @click="forceOffline(scope.row.connectionId)"> 下线 </el-button>
@@ -55,10 +55,6 @@ import * as SignalR from '@microsoft/signalr';
 import { getAPI, getToken, clearAccessTokens } from '/@/utils/axios-utils';
 import { SysOnlineUserApi, SysAuthApi } from '/@/api-services/api';
 
-const reciveMessage = (msg: any) => {
-	console.log('接收消息:', msg);
-};
-
 const state = reactive({
 	loading: false,
 	isVisible: false,
@@ -74,23 +70,51 @@ const state = reactive({
 	onlineUserList: [] as any, // 在线用户列表
 });
 
-const signalrUrl = `${import.meta.env.VITE_API_URL}/hubs/onlineUser`;
 // 初始化SignalR对象
 const connection = new SignalR.HubConnectionBuilder()
 	.configureLogging(SignalR.LogLevel.Information)
-	.withUrl(`${signalrUrl}?access_token=${getToken()}`)
+	.withUrl(`${import.meta.env.VITE_API_URL}/hubs/onlineUser?access_token=${getToken()}`)
 	.withAutomaticReconnect({
-		nextRetryDelayInMilliseconds: () => {
+		nextRetryDelayInMilliseconds: (a) => {
+			console.log(a)
 			return 5000; // 每5秒重连一次
 		},
 	})
 	.build();
 
-connection.keepAliveIntervalInMilliseconds = 15000; // 心跳检测15s
+connection.keepAliveIntervalInMilliseconds = 15 * 1000; // 心跳检测15s
+connection.serverTimeoutInMilliseconds = 30 * 60 * 1000; // 超时时间30m
+
+// 启动连接
+connection.start().then(() => {
+	console.log('启动连接');
+});
+// 断开连接
+connection.onclose(async () => {
+	console.log('断开连接');
+	state.onlineUserList = [];
+});
+// 重连中
+connection.onreconnecting(() => {
+	ElNotification({
+		title: '提示',
+		message: '与服务器重连中...',
+		type: 'error',
+		position: 'bottom-right',
+	});
+});
+// 重连成功
+connection.onreconnected(() => {
+	console.log('重连成功');
+});
+
+const reciveMessage = (msg: any) => {
+	console.log('接收消息:', msg);
+};
 
-// 注册web端方法供后端调用
+// 接收消息
 connection.on('ReceiveMessage', reciveMessage);
-// 强制用户下线
+// 强制下线
 connection.on('ForceOffline', async (data: any) => {
 	console.log('强制下线', data);
 	await connection.stop();
@@ -104,23 +128,11 @@ connection.on('OnlineUserChange', (data: any) => {
 	ElNotification({
 		title: '提示',
 		message: `${data.online ? `【${data.realName}】上线了` : `【${data.realName}】离开了`}`,
-		type: 'info',
+		type: `${data.online ? 'info' : 'error'}`,
 		position: 'bottom-right',
 	});
 });
 
-// 第一次连接成功
-connection.start().then(() => {});
-
-// 连接断开
-connection.onclose(async () => {});
-
-// 掉线重连中
-connection.onreconnecting(() => {});
-
-// 重新连接成功
-connection.onreconnected(() => {});
-
 // 打开页面
 const openDrawer = () => {
 	state.isVisible = true;

+ 6 - 1
Web/src/views/system/org/component/orgTree.vue

@@ -77,6 +77,11 @@ const initTreeData = async () => {
 	state.loading = false;
 };
 
+// 更新树节点数据
+const updateTreeData = (treeData: any) => {
+	state.orgData = treeData;
+};
+
 // 设置默认选择
 const setCheckedKeys = (orgData: any) => {
 	state.isShowCheckbox = true;
@@ -118,7 +123,7 @@ const nodeClick = (node: any) => {
 
 const orgTreeData = state.orgData; // 异步数据导出不了?
 // 导出
-defineExpose({ orgTreeData, setCheckedKeys, getCheckedKeys });
+defineExpose({ orgTreeData, setCheckedKeys, getCheckedKeys, updateTreeData });
 </script>
 
 <style scoped>

+ 16 - 5
Web/src/views/system/org/index.vue

@@ -2,7 +2,7 @@
 	<div class="sys-org-container">
 		<el-row :gutter="8" style="width: 100%">
 			<el-col :span="4" :xs="24">
-				<OrgTree @node-click="nodeClick" />
+				<OrgTree ref="orgTreeRef" @node-click="nodeClick" />
 			</el-col>
 
 			<el-col :span="20" :xs="24">
@@ -64,10 +64,11 @@ export default defineComponent({
 	setup() {
 		const { proxy } = getCurrentInstance() as any;
 		const editOrgRef = ref();
+		const orgTreeRef = ref();
 		const state = reactive({
 			loading: true,
-			orgData: [] as any,
-			orgTreeData: [] as any, // 编辑页面上级机构树
+			orgData: [] as any, // 机构列表数据
+			orgTreeData: [] as any, // 机构树所有数据
 			queryParams: {
 				id: -1,
 				name: undefined,
@@ -78,8 +79,15 @@ export default defineComponent({
 		onMounted(() => {
 			handleQuery();
 
-			proxy.mittBus.on('submitRefresh', () => {
+			proxy.mittBus.on('submitRefresh', async () => {
 				handleQuery();
+
+				// 编辑删除后更新机构数据
+				state.loading = true;
+				var res = await getAPI(SysOrgApi).sysOrgListGet(-1, '', '');
+				state.orgTreeData = res.data.result;
+				state.loading = false;
+				orgTreeRef.value.updateTreeData(state.orgTreeData);
 			});
 		});
 		onUnmounted(() => {
@@ -92,7 +100,8 @@ export default defineComponent({
 			state.orgData = res.data.result;
 			state.loading = false;
 
-			if (state.queryParams.id == -1) state.orgTreeData = state.orgData;
+			// 若无选择节点并且查询条件为空时
+			if (state.queryParams.id == -1 && state.queryParams.name == undefined && state.queryParams.code == undefined) state.orgTreeData = state.orgData;
 		};
 		// 重置操作
 		const resetQuery = () => {
@@ -122,6 +131,7 @@ export default defineComponent({
 					await getAPI(SysOrgApi).sysOrgDeletePost({ id: row.id });
 					handleQuery();
 					ElMessage.success('删除成功');
+					proxy.mittBus.emit('submitRefresh');
 				})
 				.catch(() => {});
 		};
@@ -136,6 +146,7 @@ export default defineComponent({
 			handleQuery,
 			resetQuery,
 			editOrgRef,
+			orgTreeRef,
 			openAddOrg,
 			openEditOrg,
 			delOrg,