Ver Fonte

fix 问题

luogang há 2 meses atrás
pai
commit
da5e6c6918
1 ficheiros alterados com 7 adições e 5 exclusões
  1. 7 5
      plus-ui-ts/src/views/index.vue

+ 7 - 5
plus-ui-ts/src/views/index.vue

@@ -688,14 +688,14 @@ const getList = async (type) => {
 };
 // 响应式变量定义
 const timer = ref(null);
-const lastEventId = ref(null);
+const lastEventTime = ref(null);
 // 定时监测新事件的方法
 const startMonitoring = (interval = 5000) => {
   // 首次获取时设置监测起点
   const initMonitoring = () => {
-    listEvent({}).then(({ code, rows }) => {
+    listEvent({ pageNum: 1, pageSize: 15 }).then(({ code, rows }) => {
       if (rows.length) {
-        lastEventId.value = rows[0].id;
+        lastEventTime.value = rows[0].createTime;
       }
     });
   };
@@ -704,9 +704,11 @@ const startMonitoring = (interval = 5000) => {
   initMonitoring();
   // 设置定时器
   timer.value = setInterval(async () => {
-    const { rows } = await listEvent({});
+    const { rows } = await listEvent({ pageNum: 1, pageSize: 15 });
     if (rows.length > 0) {
-      if (rows[0].id !== lastEventId.value) {
+      const index = rows.findIndex((item) => new Date(item.createTime).getTime() > new Date(lastEventTime.value).getTime());
+      if (index > -1) {
+        lastEventTime.value = rows[index].createTime;
         ElNotification({
           title: '提示',
           message: '有新事件产生',