Browse Source

驾驶舱-添加实时更新(定时3秒)

wanglt 4 tháng trước cách đây
mục cha
commit
73d27d0f72
2 tập tin đã thay đổi với 32 bổ sung4 xóa
  1. 16 2
      ygtx-ui/src/views/index4.vue
  2. 16 2
      ygtx-ui/src/views/index5.vue

+ 16 - 2
ygtx-ui/src/views/index4.vue

@@ -682,16 +682,30 @@ export default {
       },
       equipmentKeyword: '',
       originalEquipmentOptions: null,
-      filteredEquipmentOptions: null
+      filteredEquipmentOptions: null,
+      // 定时器
+      timer: null
     }
   },
   created() {
     this.selectPeriod('本月');
-    this.loadHomePageData(); // 加载首页统计数据
+    this.loadHomePageData(); // 首次加载首页统计数据
     this.loadEquipmentData(); // 加载设备数据
     this.applyFilter();
+    
+    // 设置定时器,每3秒执行一次loadHomePageData函数
+    this.timer = setInterval(() => {
+      this.loadHomePageData();
+    }, 3000);
   },
   methods: {
+    // 在组件销毁前清除定时器
+    beforeDestroy() {
+      if (this.timer) {
+        clearInterval(this.timer);
+        this.timer = null;
+      }
+    },
     handleCascaderChange(val) {
       console.log('选中的节点值:', val);
       

+ 16 - 2
ygtx-ui/src/views/index5.vue

@@ -306,14 +306,28 @@ export default {
       // 新增的数据属性
       showRankingTable: false, // 控制排名列表卡片显示
       currentRankingType: '', // 当前显示的排名类型
-      currentRankingData: [] // 当前显示的排名数据
+      currentRankingData: [], // 当前显示的排名数据
+      // 定时器
+      timer: null
     }
   },
   created() {
-    this.loadHomePageData(); // 加载首页统计数据
+    this.loadHomePageData(); // 首次加载首页统计数据
     this.applyFilter();
+    
+    // 设置定时器,每3秒执行一次loadHomePageData函数
+    this.timer = setInterval(() => {
+      this.loadHomePageData();
+    }, 3000);
   },
   methods: {
+    // 在组件销毁前清除定时器
+    beforeDestroy() {
+      if (this.timer) {
+        clearInterval(this.timer);
+        this.timer = null;
+      }
+    },
     // 新增的方法:显示排名列表
     showRankingList(type) {
       // 如果点击的是同一个排名类型,则隐藏列表卡片