浏览代码

Merge pull request #5648 from wenzhixin/fix/5644

fix #5644
文翼 4 年之前
父节点
当前提交
7334a03480
共有 1 个文件被更改,包括 11 次插入6 次删除
  1. 11 6
      src/extensions/auto-refresh/bootstrap-table-auto-refresh.js

+ 11 - 6
src/extensions/auto-refresh/bootstrap-table-auto-refresh.js

@@ -35,9 +35,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
     super.init(...args)
 
     if (this.options.autoRefresh && this.options.autoRefreshStatus) {
-      this.options.autoRefreshFunction = setInterval(() => {
-        this.refresh({ silent: this.options.autoRefreshSilent })
-      }, this.options.autoRefreshInterval * 1000)
+      this.setupRefreshInterval()
     }
   }
 
@@ -68,9 +66,7 @@ $.BootstrapTable = class extends $.BootstrapTable {
         this.$toolbar.find('>.columns .auto-refresh')
           .removeClass(this.constants.classes.buttonActive)
       } else {
-        this.options.autoRefreshFunction = setInterval(() => {
-          this.refresh({ silent: this.options.autoRefreshSilent })
-        }, this.options.autoRefreshInterval * 1000)
+        this.setupRefreshInterval()
         this.$toolbar.find('>.columns .auto-refresh')
           .addClass(this.constants.classes.buttonActive)
       }
@@ -85,4 +81,13 @@ $.BootstrapTable = class extends $.BootstrapTable {
 
     super.destroy()
   }
+
+  setupRefreshInterval () {
+    this.options.autoRefreshFunction = setInterval(() => {
+      if (!this.options.autoRefresh || !this.options.autoRefreshStatus) {
+        return
+      }
+      this.refresh({ silent: this.options.autoRefreshSilent })
+    }, this.options.autoRefreshInterval * 1000)
+  }
 }