diff --git a/simple-mind-map/src/utils/BatchExecution.js b/simple-mind-map/src/utils/BatchExecution.js index fcdfb735..f30c3740 100644 --- a/simple-mind-map/src/utils/BatchExecution.js +++ b/simple-mind-map/src/utils/BatchExecution.js @@ -12,6 +12,7 @@ class BatchExecution { // 添加任务 push(name, fn) { if (this.has[name]) { + this.replaceTask(name, fn) return } this.has[name] = true @@ -22,6 +23,19 @@ class BatchExecution { this.nextTick() } + // 替换任务 + replaceTask(name, fn) { + const index = this.queue.findIndex(item => { + return item.name === name + }) + if (index !== -1) { + this.queue[index] = { + name, + fn + } + } + } + // 执行队列 flush() { let fns = this.queue.slice(0)