删除模块 取消打开紫鸟
This commit is contained in:
@@ -249,6 +249,9 @@ const queuePayloadText = ref('')
|
||||
const taskDetails = ref<Record<number, DeleteBrandTaskDetailVo>>({})
|
||||
const pollTimer = ref<number | null>(null)
|
||||
const pollingInFlight = ref(false)
|
||||
const chainStarted = ref(false)
|
||||
const activeItemKey = ref('')
|
||||
const autoAdvancing = ref(false)
|
||||
const displayPaths = computed(() => selectedPaths.value.slice(0, 10))
|
||||
|
||||
const currentSectionItems = computed(() => {
|
||||
@@ -517,6 +520,7 @@ function scheduleNextPoll(immediate = false) {
|
||||
let stateChanged = false
|
||||
try {
|
||||
await refreshTaskDetails(taskIds)
|
||||
await maybeAutoAdvance()
|
||||
for (const taskId of taskIds) {
|
||||
if (isTaskTerminal(taskId)) {
|
||||
removeSessionTaskFromStorage(taskId)
|
||||
@@ -766,34 +770,38 @@ function isPythonQueueBusy() {
|
||||
return false
|
||||
}
|
||||
|
||||
async function triggerItemRun(item: DeleteBrandResultItem) {
|
||||
function getItemKey(item: DeleteBrandResultItem) {
|
||||
if (item.resultId != null) return `result:${item.resultId}`
|
||||
return `task:${item.taskId || 0}:${item.sourceFilename || ''}`
|
||||
}
|
||||
|
||||
function findNextAutoRunnableItem() {
|
||||
return currentSectionItems.value.find((item) => {
|
||||
if (!item.openStoreUrl) return false
|
||||
if (getItemKey(item) === activeItemKey.value) return false
|
||||
return getQueueStatus(item) === '未入队'
|
||||
})
|
||||
}
|
||||
|
||||
async function runItem(item: DeleteBrandResultItem, options?: { auto?: boolean }) {
|
||||
if (isPythonQueueBusy()) {
|
||||
ElMessage.warning('当前存在正在处理的任务,请等待其完成后再推送下一条!')
|
||||
return
|
||||
if (!options?.auto) {
|
||||
ElMessage.warning('当前存在正在处理的任务,请等待其完成后再推送下一条!')
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
const api = getPywebviewApi()
|
||||
if (item.openStoreUrl) {
|
||||
if (api?.open_external_url) {
|
||||
const openResult = await api.open_external_url(item.openStoreUrl)
|
||||
if (!openResult?.success) {
|
||||
ElMessage.error(openResult?.error || '打开紫鸟失败')
|
||||
return
|
||||
}
|
||||
} else {
|
||||
window.open(item.openStoreUrl, '_self')
|
||||
}
|
||||
}
|
||||
|
||||
const taskId = item.taskId
|
||||
if (!taskId) return
|
||||
if (!taskId) return false
|
||||
|
||||
const sessionTask = sessionTasks.value.find(t => t.taskId === taskId)
|
||||
if (!sessionTask) return
|
||||
if (!sessionTask) return false
|
||||
|
||||
if (!api?.enqueue_json) {
|
||||
ElMessage.error('当前环境未启用 pywebview enqueue_json(浏览器环境不会推送)')
|
||||
return
|
||||
return false
|
||||
}
|
||||
|
||||
const payload = {
|
||||
@@ -811,18 +819,60 @@ async function triggerItemRun(item: DeleteBrandResultItem) {
|
||||
if (pushResult?.success) {
|
||||
qpr = `已单独推送文件 ${item.sourceFilename},当前队列长度:${pushResult.queue_size ?? '-'}`
|
||||
|
||||
// Mark the item as pushed
|
||||
const sessionItem = sessionTask.items.find(i => i.resultId === item.resultId || i.sourceFilename === item.sourceFilename)
|
||||
if (sessionItem) {
|
||||
(sessionItem as any)._pushed = true
|
||||
}
|
||||
activeItemKey.value = getItemKey(item)
|
||||
saveSessionTask(taskId, sessionTask.items, qpr, queuePayloadText.value)
|
||||
|
||||
ensurePolling(true)
|
||||
} else {
|
||||
qpr = `推送到 Python 队列失败:${pushResult?.error || '未知错误'}`
|
||||
}
|
||||
queuePushResult.value = qpr
|
||||
return Boolean(pushResult?.success)
|
||||
}
|
||||
|
||||
async function maybeAutoAdvance() {
|
||||
if (!chainStarted.value || autoAdvancing.value) return
|
||||
if (isPythonQueueBusy()) return
|
||||
|
||||
const currentKey = activeItemKey.value
|
||||
if (currentKey) {
|
||||
const currentItem = currentSectionItems.value.find(item => getItemKey(item) === currentKey)
|
||||
if (currentItem) {
|
||||
const status = getQueueStatus(currentItem)
|
||||
if (status === '已入队' || status === '处理中') {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const nextItem = findNextAutoRunnableItem()
|
||||
if (!nextItem) {
|
||||
activeItemKey.value = ''
|
||||
chainStarted.value = false
|
||||
return
|
||||
}
|
||||
|
||||
autoAdvancing.value = true
|
||||
try {
|
||||
const started = await runItem(nextItem, { auto: true })
|
||||
if (!started) {
|
||||
chainStarted.value = false
|
||||
}
|
||||
} finally {
|
||||
autoAdvancing.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function triggerItemRun(item: DeleteBrandResultItem) {
|
||||
chainStarted.value = true
|
||||
const started = await runItem(item)
|
||||
if (!started) {
|
||||
chainStarted.value = false
|
||||
activeItemKey.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
function openShop(url: string) {
|
||||
|
||||
@@ -21,7 +21,6 @@ export interface PywebviewApi {
|
||||
save_template_xlsx?: () => Promise<{ success: boolean; path?: string; error?: string }>
|
||||
save_template_zip?: () => Promise<{ success: boolean; path?: string; error?: string }>
|
||||
enqueue_json?: (data: unknown) => Promise<{ success: boolean; queue_size?: number; error?: string }>
|
||||
open_external_url?: (url: string) => Promise<{ success: boolean; error?: string }>
|
||||
}
|
||||
|
||||
declare global {
|
||||
|
||||
Reference in New Issue
Block a user