From 0548ec93f085cc07ba9aaf62b6a6c5bc42b4da6c Mon Sep 17 00:00:00 2001 From: zjf <1799650030@qq.com> Date: Wed, 4 Nov 2026 14:20:47 +0800 Subject: [PATCH] =?UTF-8?q?=E9=85=92=E5=BA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/mall/product/hotelZax.ts | 4 +-- src/views/mall/product/hotelZax/index.vue | 43 ++++++++++++++++++----- 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/src/api/mall/product/hotelZax.ts b/src/api/mall/product/hotelZax.ts index 3d986b3f..db4837b1 100644 --- a/src/api/mall/product/hotelZax.ts +++ b/src/api/mall/product/hotelZax.ts @@ -156,9 +156,9 @@ export const getHotelZaxSyncCursor = () => { return request.get({ url: '/product/hotel-zax/sync-cursor' }) } -/** full=true:按当前资安心授权范围全量拉(改授权后必须全量,否则增量水位会显示 0) */ +/** full=true:按当前资安心授权范围异步全量拉(立刻返回;改授权后必须全量;进度看 sync-cursor) */ export const syncHotelZax = (full = true) => { - return request.post({ url: '/product/hotel-zax/sync', params: { full } }) + return request.post({ url: '/product/hotel-zax/sync', params: { full }, timeout: 30000 }) } export const resetHotelZaxCursor = () => { diff --git a/src/views/mall/product/hotelZax/index.vue b/src/views/mall/product/hotelZax/index.vue index 5062ed8d..5d474ae7 100644 --- a/src/views/mall/product/hotelZax/index.vue +++ b/src/views/mall/product/hotelZax/index.vue @@ -225,10 +225,25 @@ const onChanged = async () => { await getList() } +const isSyncRunningMsg = (msg?: string) => String(msg || '').startsWith('running,') + +/** 提交后轮询水位,直到 running 结束或超时 */ +const pollSyncCursorUntilDone = async (maxMs = 30 * 60 * 1000) => { + const started = Date.now() + while (Date.now() - started < maxMs) { + await loadCursor() + if (!isSyncRunningMsg(cursor.value?.lastMsg)) { + return true + } + await new Promise((r) => setTimeout(r, 2000)) + } + return false +} + const handleSync = async () => { try { await message.confirm( - '将按资安心当前授权范围全量同步到本地(改授权后也请用此按钮)。供应方已上架的会恢复为上架;不在授权内的本地酒店会标为未授权。确认继续?' + '将按资安心当前授权范围后台全量同步(改授权后也请用此按钮)。界面立刻返回,进度看「上次结果」;数据量大时可能较久。确认继续?' ) } catch { return @@ -236,14 +251,24 @@ const handleSync = async () => { syncing.value = true try { const res = await HotelZaxApi.syncHotelZax(true) - const offline = res?.offlineOutOfScope ?? 0 - const dailyFail = res?.dailyFail ?? 0 - message.success( - `同步完成:写入 ${res?.upsert ?? 0},详情 ${res?.detailOk ?? 0},日历 ${res?.dailyRows ?? 0} 条` + - (dailyFail > 0 ? `,日历失败 ${dailyFail} 家` : '') + - (offline > 0 ? `,下架授权外 ${offline}` : '') - ) - await onChanged() + if (res?.accepted === false || res?.running) { + message.warning(res?.message || '已有同步任务在执行,请稍后刷新水位') + await loadCursor() + return + } + message.success(res?.message || '已提交后台同步,正在拉取…') + const done = await pollSyncCursorUntilDone() + await getList() + if (!done) { + message.warning('同步仍在进行,可稍后刷新页面查看「上次结果」') + return + } + const msg = cursor.value?.lastMsg || '' + if (String(msg).startsWith('fail,')) { + message.error(`同步失败:${msg}`) + } else { + message.success(`同步完成:${msg || '请查看水位'}`) + } } catch (e: any) { message.error(e?.msg || e?.message || '同步失败') } finally {