This commit is contained in:
lz_db
2026-10-25 16:14:26 +08:00
parent 7fae7387f5
commit 1d9cd1f9c7
10 changed files with 288 additions and 13 deletions
+39 -4
View File
@@ -47,6 +47,28 @@
<el-table-column prop="last_sync_at" label="上次同步" width="160">
<template #default="{ row }">{{ row.last_sync_at || '从未' }}</template>
</el-table-column>
<el-table-column label="同步状态" width="220">
<template #default="{ row }">
<template v-if="row.syncing">
<el-tag type="primary" size="small" effect="dark">
<el-icon class="is-loading" style="margin-right: 4px"><Loading /></el-icon>同步中
</el-tag>
<div style="font-size: 12px; color: #606266; margin-top: 4px">
<span v-if="row.sync_progress">第 {{ row.sync_progress.pages }} 页</span>
<template v-if="row.sync_progress && row.kind === 'aidrama91_vlog'">
· 新增 {{ row.sync_progress.videos_new ?? 0 }} / 跳过 {{ row.sync_progress.videos_exist ?? 0 }}
</template>
<template v-else-if="row.sync_progress && row.kind === 'aidrama91'">
· 新剧 {{ row.sync_progress.dramas_new ?? 0 }} / 集数 +{{ row.sync_progress.episodes_created ?? 0 }}
</template>
<div v-if="row.sync_progress && row.sync_progress.started_at" style="color: #909399">
开始于 {{ row.sync_progress.started_at }}
</div>
</div>
</template>
<span v-else style="color: #c0c4cc">-</span>
</template>
</el-table-column>
<el-table-column label="操作" width="290" fixed="right">
<template #default="{ row }">
<el-button link type="warning" :loading="syncingId === row.id" @click="syncOne(row)">同步</el-button>
@@ -144,8 +166,9 @@
</template>
<script setup>
import { reactive, ref, onMounted } from 'vue'
import { reactive, ref, onMounted, onBeforeUnmount } from 'vue'
import { ElMessage, ElMessageBox } from 'element-plus'
import { Loading } from '@element-plus/icons-vue'
import request from '@/api/request'
const list = ref([])
@@ -203,11 +226,23 @@ async function load() {
try {
const r = await request({ url: '/admin/collection/sources', method: 'get' })
list.value = r.list
schedulePoll()
} catch (e) {} finally {
loading.value = false
}
}
// 有源正在同步时每 5 秒自动刷新进度;无任务时停止轮询
let pollTimer = null
function schedulePoll() {
if (pollTimer) { clearTimeout(pollTimer); pollTimer = null }
if (list.value.some(s => s.syncing)) {
pollTimer = setTimeout(load, 5000)
}
}
onBeforeUnmount(() => { if (pollTimer) clearTimeout(pollTimer) })
function showCreate() {
editing.value = null
Object.assign(form, {
@@ -299,8 +334,8 @@ async function syncOne(row) {
syncingId.value = row.id
try {
await request({ url: `/admin/collection/sources/${row.id}/sync`, method: 'post', data: { max_pages: 0 } })
ElMessage.success(`「${row.name}」已触发后台同步,稍后刷新查看`)
setTimeout(load, 20000)
ElMessage.success(`「${row.name}」已触发后台同步`)
setTimeout(load, 1500)
} catch (e) {} finally {
syncingId.value = 0
}
@@ -328,7 +363,7 @@ async function syncAll() {
try {
const r = await request({ url: '/admin/collection/sources/sync-all', method: 'post' })
ElMessage.success(`已触发 ${r.started.length} 个源的后台同步`)
setTimeout(load, 20000)
setTimeout(load, 1500)
} catch (e) {} finally {
syncAllLoading.value = false
}