Browse Source

详情刷新

wangyani 11 months ago
parent
commit
d2cae197b7
1 changed files with 38 additions and 6 deletions
  1. 38 6
      src/views/mes/job/jobplay/jobPlayDetail.vue

+ 38 - 6
src/views/mes/job/jobplay/jobPlayDetail.vue

@@ -174,7 +174,8 @@ export default {
       lockUserList: [],
       colockUserList: [],
       ticketPointsList: [],
-      ticketId:null
+      ticketId: null,
+      intervalId: null,
     };
   },
   // mounted() {
@@ -186,20 +187,51 @@ export default {
     if (this.$route.query.ticketId) {
       this.ticketId = this.$route.query.ticketId;
       // 将 ticketId 存储到 localStorage
-      localStorage.setItem('ticketId', this.ticketId);
+      localStorage.setItem("ticketId", this.ticketId);
     } else {
       // 从 localStorage 获取 ticketId
-      this.ticketId = localStorage.getItem('ticketId');
+      this.ticketId = localStorage.getItem("ticketId");
     }
   },
 
   mounted() {
     this.getJobPlayInfo();
-    setInterval(() => {
-      this.getJobPlayInfo();
-    }, 5000);
+    // setInterval(() => {
+    //   this.getJobPlayInfo();
+    // }, 5000);
+    this.startRefreshing();
+    // 监听页面可见性变化
+    document.addEventListener("visibilitychange", this.handleVisibilityChange);
+  },
+  beforeDestroy() {
+    // 清理定时器和事件监听器
+    this.stopRefreshing();
+    document.removeEventListener(
+      "visibilitychange",
+      this.handleVisibilityChange
+    );
   },
   methods: {
+    startRefreshing() {
+      // 防止多次触发刷新
+      if (this.intervalId) return;
+      this.intervalId = setInterval(() => {
+        this.getList();
+      }, 5000);
+    },
+    stopRefreshing() {
+      if (this.intervalId) {
+        clearInterval(this.intervalId);
+        this.intervalId = null;
+      }
+    },
+    handleVisibilityChange() {
+      if (document.visibilityState === "visible") {
+        this.startRefreshing();
+      } else {
+        this.stopRefreshing();
+      }
+    },
     getJobPlayInfo() {
       getJobPlayTicketInfo(this.ticketId).then((res) => {
         console.log(res, "作业执行详细信息");