feat(useSchedulerLogic):修复新建队列循环调用导致卡死问题

This commit is contained in:
MoeSnowyFox
2025-09-19 23:58:59 +08:00
parent 969e223fb4
commit 199907eb26

View File

@@ -1,4 +1,4 @@
import { computed, nextTick, ref } from 'vue' import { computed, nextTick, ref, watch } from 'vue'
import { message, Modal, notification } from 'ant-design-vue' import { message, Modal, notification } from 'ant-design-vue'
import { Service } from '@/api/services/Service' import { Service } from '@/api/services/Service'
import { TaskCreateIn } from '@/api/models/TaskCreateIn' import { TaskCreateIn } from '@/api/models/TaskCreateIn'
@@ -106,10 +106,14 @@ export function useSchedulerLogic() {
const activeSchedulerTab = ref(schedulerTabs.value[0]?.key || 'main') const activeSchedulerTab = ref(schedulerTabs.value[0]?.key || 'main')
const logRefs = ref(new Map<string, HTMLElement>()) const logRefs = ref(new Map<string, HTMLElement>())
let tabCounter = schedulerTabs.value.length > 1 ? let tabCounter =
Math.max(...schedulerTabs.value schedulerTabs.value.length > 1
.filter(tab => tab.key.startsWith('tab-')) ? Math.max(
.map(tab => parseInt(tab.key.replace('tab-', '')) || 0)) + 1 : 1 ...schedulerTabs.value
.filter(tab => tab.key.startsWith('tab-'))
.map(tab => parseInt(tab.key.replace('tab-', '')) || 0)
) + 1
: 1
// 任务选项 // 任务选项
const taskOptionsLoading = ref(false) const taskOptionsLoading = ref(false)
@@ -140,24 +144,14 @@ export function useSchedulerLogic() {
// 监听调度台变化并保存到本地存储 // 监听调度台变化并保存到本地存储
const watchTabsChanges = () => { const watchTabsChanges = () => {
const saveState = () => { // 使用Vue的watch API来监听数组变化而不是重写原生方法
saveTabsToStorage(schedulerTabs.value) watch(
} schedulerTabs,
newTabs => {
// 监听各种可能导致状态变化的操作 saveTabsToStorage(newTabs)
const originalPush = schedulerTabs.value.push },
schedulerTabs.value.push = function(...items: SchedulerTab[]) { { deep: true }
const result = originalPush.apply(this, items) )
saveState()
return result
}
const originalSplice = schedulerTabs.value.splice
schedulerTabs.value.splice = function(start: number, deleteCount?: number, ...items: SchedulerTab[]) {
const result = originalSplice.apply(this, [start, deleteCount, ...items] as any)
saveState()
return result
}
} }
// 初始化监听 // 初始化监听
@@ -182,7 +176,6 @@ export function useSchedulerLogic() {
} }
schedulerTabs.value.push(tab) schedulerTabs.value.push(tab)
activeSchedulerTab.value = tab.key activeSchedulerTab.value = tab.key
saveTabsToStorage(schedulerTabs.value)
} }
const removeSchedulerTab = (key: string) => { const removeSchedulerTab = (key: string) => {
@@ -222,7 +215,6 @@ export function useSchedulerLogic() {
logRefs.value.delete(key) logRefs.value.delete(key)
schedulerTabs.value.splice(idx, 1) schedulerTabs.value.splice(idx, 1)
saveTabsToStorage(schedulerTabs.value)
if (activeSchedulerTab.value === key) { if (activeSchedulerTab.value === key) {
const newActiveIndex = Math.max(0, idx - 1) const newActiveIndex = Math.max(0, idx - 1)
@@ -613,4 +605,4 @@ export function useSchedulerLogic() {
loadTaskOptions, loadTaskOptions,
cleanup, cleanup,
} }
} }