WEB/src/views/test/index.vue
2026-10-20 18:00:51 +08:00

1623 lines
45 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div ref="pageRef" class="test-page">
<header class="page-head">
<div class="page-head__eyebrow">UI Refresh · Task Progress Dialog</div>
<h1>进度弹窗 · 优化预览</h1>
<p>猎豹 GIF + 表单/信息布局重构:参数区轻量化、进度区信息分层、操作区固定底部。</p>
</header>
<div class="toolbar">
<div class="toolbar__state">
<span class="pulse"></span>
循环演示中
</div>
<div class="toolbar__actions">
<div class="segmented">
<button
type="button"
:class="{ 'is-active': previewState === 'config' }"
@click="previewState = 'config'"
>
配置态
</button>
<button
type="button"
:class="{ 'is-active': previewState === 'progress' }"
@click="previewState = 'progress'"
>
进度态
</button>
</div>
<button class="tool-btn tool-btn--primary" type="button" @click="resetAll">重新播放</button>
</div>
</div>
<div class="stage">
<div class="stage__scrim"></div>
<section v-if="dialogVisible" class="dlg" role="dialog" aria-modal="true">
<TaskProgressPanel
v-if="previewState === 'progress'"
title="波次策略快速扫描"
subtitle="正在匹配波次策略 · 深圳保税仓"
task-id="W202610180931"
:state="progress >= 100 ? 'success' : 'running'"
:progress="progress"
:status-text="statusText"
:detail="`已处理 ${processed.toLocaleString()} / ${total.toLocaleString()}`"
:elapsed-ms="elapsedMs"
:summary="summaryItems"
:metrics="metricItems"
@close="dialogVisible = false"
>
<template #footer>
<span class="dlg__hint">
<svg viewBox="0 0 14 14" fill="none">
<rect x="2.2" y="6" width="9.6" height="6" rx="1.6" stroke="currentColor" stroke-width="1.2" />
<path d="M4.6 6V4.4a2.4 2.4 0 014.8 0V6" stroke="currentColor" stroke-width="1.2" />
</svg>
任务在后台执行,关闭窗口不会中断
</span>
<div class="dlg__actions">
<el-button size="small" @click="dialogVisible = false">
{{ percent >= 100 ? '完成' : '后台运行' }}
</el-button>
</div>
</template>
</TaskProgressPanel>
<template v-else>
<header class="dlg__head">
<div class="dlg__titles">
<h2>波次策略快速扫描</h2>
<p>选择扫描条件后开始</p>
</div>
<span class="dlg__task">任务ID:W202610180931</span>
<button class="dlg__close" type="button" aria-label="关闭" @click="dialogVisible = false">
<svg viewBox="0 0 12 12" fill="none">
<path d="M1 1L11 11M11 1L1 11" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" />
</svg>
</button>
</header>
<div class="dlg__body">
<!-- 配置态 -->
<template v-if="previewState === 'config'">
<div class="form">
<div class="field">
<span class="field__label">仓库</span>
<button class="field__control" type="button">
深圳保税仓
<svg class="field__caret" viewBox="0 0 10 6" fill="none">
<path d="M1 1L5 5L9 1" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" />
</svg>
</button>
</div>
<div class="field">
<span class="field__label">波次策略</span>
<button class="field__control" type="button">
三单波次 · 自动
<svg class="field__caret" viewBox="0 0 10 6" fill="none">
<path d="M1 1L5 5L9 1" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" />
</svg>
</button>
</div>
</div>
<div class="field field--block">
<span class="field__label">订单范围</span>
<div class="chips">
<button class="chip" type="button" :class="{ 'is-active': orderScope === 'all' }" @click="orderScope = 'all'">
全部待处理
</button>
<button class="chip" type="button" :class="{ 'is-active': orderScope === 'exception' }" @click="orderScope = 'exception'">
仅异常单
</button>
<button class="chip" type="button" :class="{ 'is-active': orderScope === 'noExpress' }" @click="orderScope = 'noExpress'">
未分配快递
</button>
</div>
</div>
<p class="form__hint">
将扫描当前仓库 {{ total.toLocaleString() }} 条待处理订单,符合波次策略的订单会进入对应波次。
</p>
</template>
</div>
<footer class="dlg__foot">
<span class="dlg__hint">
<svg viewBox="0 0 14 14" fill="none">
<rect x="2.2" y="6" width="9.6" height="6" rx="1.6" stroke="currentColor" stroke-width="1.2" />
<path d="M4.6 6V4.4a2.4 2.4 0 014.8 0V6" stroke="currentColor" stroke-width="1.2" />
</svg>
扫描开始后可在后台运行
</span>
<div class="dlg__actions">
<el-button size="small" @click="dialogVisible = false">取消</el-button>
<el-button size="small" type="primary" @click="startScan">开始扫描</el-button>
</div>
</footer>
</template>
</section>
<button v-else class="reopen" type="button" @click="dialogVisible = true">重新打开弹窗</button>
</div>
<section ref="inventoryRef" class="inventory">
<header class="inventory__head">
<h2>项目现有进度弹窗</h2>
<p>点击卡片打开项目里真实使用的组件(演示数据),共 9 个组件、约 55 处使用。</p>
</header>
<div class="inventory__group">
<h3>新统一弹窗(一个组件覆盖 9 个场景) <em>通用 / 波次 / 表单</em></h3>
<div class="inventory__grid">
<button
v-for="item in scenarioEntries"
:key="item.key"
class="entry"
type="button"
@click="openScenario(item.key)"
>
<strong>{{ item.name }}</strong>
<code>{{ item.file }}</code>
<span>{{ item.meta }}</span>
</button>
</div>
</div>
<div class="inventory__group">
<h3>通用组件 <em>35 处</em></h3>
<div class="inventory__grid">
<button
v-for="item in commonEntries"
:key="item.key"
class="entry"
type="button"
@click="openDialog(item.key)"
>
<strong>{{ item.name }}</strong>
<code>{{ item.file }}</code>
<span>{{ item.meta }}</span>
</button>
</div>
</div>
<div class="inventory__group">
<h3>波次模块 <em>12 处</em></h3>
<div class="inventory__grid">
<button
v-for="item in waveEntries"
:key="item.key"
class="entry"
type="button"
@click="openDialog(item.key)"
>
<strong>{{ item.name }}</strong>
<code>{{ item.file }}</code>
<span>{{ item.meta }}</span>
</button>
</div>
</div>
<div class="inventory__group">
<h3>弹窗表单内嵌进度 <em>8 处</em></h3>
<div class="inventory__grid">
<button
v-for="item in formEntries"
:key="item.key"
class="entry"
type="button"
@click="openDialog(item.key)"
>
<strong>{{ item.name }}</strong>
<code>{{ item.file }}</code>
<span>{{ item.meta }}</span>
</button>
</div>
</div>
</section>
<p class="footnote">
进度数值为演示模拟;猎豹使用 public/animation/animation.gif,已裁掉 GIF 空白并对齐轨道。
</p>
<!-- 真实组件预览:通用 -->
<AsyncExportProgressDialog
v-if="activeDialog === 'asyncExport'"
:visible="true"
title="导出订单数据"
:loading="true"
:progress-percent="percent"
progress-status=""
status-label="导出中"
task-id="A202610190001"
message="正在生成导出文件,请稍候…"
error=""
:update-time="clock"
@update:visible="closeDialog"
/>
<TaskProgressDialog
v-if="activeDialog === 'task'"
:visible="true"
title="分配快递号"
:polling="true"
task-id="T202610190002"
:progress-percent="percent"
status-label="处理中"
error-text=""
result-text=""
:update-time="clock"
@close="closeDialog"
@update:visible="closeDialog"
/>
<OrderExportProgressDialog
v-if="activeDialog === 'orderExport'"
:visible="true"
:loading="true"
:progress-percent="percent"
progress-status=""
status-label="导出中"
task-id="O202610190003"
message="正在导出订单数据…"
error=""
@update:visible="closeDialog"
/>
<!-- 真实组件预览:波次 -->
<WaveStrategyQuickScanProgressDialog
v-if="activeDialog === 'quickScan'"
:model-value="true"
:progress="quickScanProgress"
@update:model-value="closeDialog"
/>
<WaveFetchTaskProgressDialog
v-if="activeDialog === 'fetch'"
:model-value="true"
:progress="fetchProgress"
@update:model-value="closeDialog"
/>
<WaveBatchTaskProgressDialog
v-if="activeDialog === 'batch'"
:model-value="true"
title="快递号分配任务"
:progress="batchProgress"
success-count-label="已完成订单"
failed-count-label="失败订单"
@update:model-value="closeDialog"
/>
<!-- 真实组件预览:弹窗表单 -->
<SyncOrderIdsForm
v-if="activeDialog === 'syncOrderIds'"
:model-value="true"
:order-count="128"
:loading="true"
request-id="S202610190004"
task-status="running"
:progress-percent="percent"
:total-count="syncTotal"
:processed-count="syncProcessed"
:success-count="syncSuccess"
:failed-count="syncFailed"
message="正在同步订单 ID…"
@submit="noop"
@closed="closeDialog"
@update:model-value="closeDialog"
/>
<StorageAllocateForm
v-if="activeDialog === 'storageAllocate'"
:model-value="true"
:allow-storage-location="false"
mode="allocate"
:order-count="96"
:loading="true"
request-id="R202610190005"
task-status="running"
:progress-percent="percent"
:total-count="96"
:success-count="allocateSuccess"
:failed-count="allocateFailed"
message="正在分配储位…"
@submit="noop"
@closed="closeDialog"
@update:model-value="closeDialog"
/>
<BatchAsyncTaskForm
v-if="activeDialog === 'batchAsync'"
:model-value="true"
title="批量拦截订单"
description="将对选中订单执行拦截操作,任务在后台执行。"
submit-button-text="提交拦截"
result-count-label="已拦截"
result-ids-label="订单ID"
:order-count="batchAsyncTotal"
:loading="true"
phase="progress"
task-id="B202610190006"
task-state="running"
:progress-percent="percent"
:total-order-count="batchAsyncTotal"
:processed-order-count="batchAsyncProcessed"
:result-order-count="batchAsyncResult"
:result-order-ids="[]"
accept-message="任务已受理,正在处理…"
error-message=""
@submit="noop"
@closed="closeDialog"
@update:model-value="closeDialog"
/>
<!-- 统一弹窗:同一组件,按场景切换数据 -->
<UnifiedTaskProgressDialog
v-if="activeScenario"
v-bind="unifiedScenarioProps"
:visible="true"
@update:visible="closeAll"
@submit="handleScenarioSubmit"
/>
<button v-if="activeDialog || activeScenario" class="escape-close" type="button" @click="closeAll">
关闭预览弹窗
</button>
<button v-if="!activeDialog && !activeScenario" class="scroll-fab" type="button" @click="toggleScroll">
<span class="scroll-fab__arrow">{{ scrolled ? '↑' : '↓' }}</span>
{{ scrolled ? '回到顶部' : '查看弹窗清单' }}
</button>
</div>
</template>
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import TaskProgressPanel from '@/components/task-progress/TaskProgressPanel.vue'
import UnifiedTaskProgressDialog from '@/components/task-progress/UnifiedTaskProgressDialog.vue'
import AsyncExportProgressDialog from '@/components/AsyncExportProgressDialog.vue'
import TaskProgressDialog from '@/components/TaskProgressDialog.vue'
import OrderExportProgressDialog from '@/views/order/orderManagement/component/OrderExportProgressDialog.vue'
import WaveStrategyQuickScanProgressDialog from '@/views/order/waveOrder/component/WaveStrategyQuickScanProgressDialog.vue'
import WaveFetchTaskProgressDialog from '@/views/order/waveOrder/component/WaveFetchTaskProgressDialog.vue'
import WaveBatchTaskProgressDialog from '@/views/order/waveOrder/component/WaveBatchTaskProgressDialog.vue'
import SyncOrderIdsForm from '@/views/order/orderManagement/form/SyncOrderIdsForm.vue'
import StorageAllocateForm from '@/views/order/orderManagement/form/StorageAllocateForm.vue'
import BatchAsyncTaskForm from '@/views/order/orderManagement/form/BatchAsyncTaskForm.vue'
type PreviewState = 'config' | 'progress'
type OrderScope = 'all' | 'exception' | 'noExpress'
const previewState = ref<PreviewState>('progress')
const orderScope = ref<OrderScope>('all')
const dialogVisible = ref(true)
type ScrollableElement = {
scrollTop: number
getBoundingClientRect: () => { top: number }
}
const pageRef = ref<ScrollableElement | null>(null)
const inventoryRef = ref<ScrollableElement | null>(null)
const scrolled = ref(false)
function scrollToPosition(el: ScrollableElement, top: number) {
el.scrollTop = Math.max(0, top)
scrolled.value = el.scrollTop > 8
}
function toggleScroll() {
const el = pageRef.value
if (!el) return
// 以实际滚动位置为准,避免观察器在后台/节流时状态滞后
if (el.scrollTop > 8) {
scrollToPosition(el, 0)
return
}
const target = inventoryRef.value
if (!target) return
const top = target.getBoundingClientRect().top - el.getBoundingClientRect().top + el.scrollTop - 18
scrollToPosition(el, top)
}
type DialogKey =
| 'asyncExport'
| 'task'
| 'orderExport'
| 'quickScan'
| 'fetch'
| 'batch'
| 'syncOrderIds'
| 'storageAllocate'
| 'batchAsync'
type UnifiedScenarioKey =
| 'uAsyncExport'
| 'uTask'
| 'uOrderExport'
| 'uQuickScan'
| 'uFetch'
| 'uBatch'
| 'uSyncForm'
| 'uSyncProgress'
| 'uStorageForm'
| 'uStorageProgress'
| 'uBatchAsyncForm'
| 'uBatchAsyncProgress'
type InventoryEntry = { key: DialogKey; name: string; file: string; meta: string }
type ScenarioEntry = { key: UnifiedScenarioKey; name: string; file: string; meta: string }
const activeDialog = ref<DialogKey | null>(null)
const activeScenario = ref<UnifiedScenarioKey | null>(null)
const scenarioEntries: ScenarioEntry[] = [
{
key: 'uAsyncExport',
name: '通用 · 异步导出',
file: 'components/task-progress/UnifiedTaskProgressDialog.vue',
meta: '参数摘要 + 统计 + 后台提示'
},
{
key: 'uTask',
name: '通用 · 任务进度',
file: 'components/task-progress/UnifiedTaskProgressDialog.vue',
meta: '成功 / 失败计数'
},
{
key: 'uOrderExport',
name: '通用 · 订单导出',
file: 'components/task-progress/UnifiedTaskProgressDialog.vue',
meta: '无参数区,仅进度 + 指标'
},
{
key: 'uQuickScan',
name: '波次 · 策略快速扫描',
file: 'components/task-progress/UnifiedTaskProgressDialog.vue',
meta: '仓库/策略/范围 + 匹配/未匹配'
},
{
key: 'uFetch',
name: '波次 · 抓取任务',
file: 'components/task-progress/UnifiedTaskProgressDialog.vue',
meta: '模式/上限/件数 + 结构完成'
},
{
key: 'uBatch',
name: '波次 · 批量任务',
file: 'components/task-progress/UnifiedTaskProgressDialog.vue',
meta: '总数/失败/跳过锁定'
},
{
key: 'uSyncForm',
name: '表单 · 同步订单 ID',
file: 'components/task-progress/UnifiedTaskProgressDialog.vue',
meta: '表单态 → 提交后切进度'
},
{
key: 'uStorageForm',
name: '表单 · 批量分配储位',
file: 'components/task-progress/UnifiedTaskProgressDialog.vue',
meta: '含开关字段'
},
{
key: 'uBatchAsyncForm',
name: '表单 · 批量拦截',
file: 'components/task-progress/UnifiedTaskProgressDialog.vue',
meta: '提交后展示结果 ID'
}
]
const commonEntries: InventoryEntry[] = [
{
key: 'asyncExport',
name: '异步导出进度弹窗',
file: 'components/AsyncExportProgressDialog.vue',
meta: '导出 / 异步任务 · 23 文件 / 25 处'
},
{
key: 'task',
name: '通用异步任务进度',
file: 'components/TaskProgressDialog.vue',
meta: '分配快递号等 · 2 处'
},
{
key: 'orderExport',
name: '订单导出进度',
file: 'order/orderManagement/component/OrderExportProgressDialog.vue',
meta: '8 个订单页面'
}
]
const waveEntries: InventoryEntry[] = [
{
key: 'quickScan',
name: '波次策略快速扫描',
file: 'waveOrder/component/WaveStrategyQuickScanProgressDialog.vue',
meta: '不符合波次策略订单列表 / 团购波次 · 2 处'
},
{
key: 'fetch',
name: '抓取任务进度',
file: 'waveOrder/component/WaveFetchTaskProgressDialog.vue',
meta: '散单波次 / 团购波次 · 2 处'
},
{
key: 'batch',
name: '波次批量任务进度',
file: 'waveOrder/component/WaveBatchTaskProgressDialog.vue',
meta: '快递号 / 储位 / 移除异常 / 批量取消 · 8 处'
}
]
const formEntries: InventoryEntry[] = [
{
key: 'syncOrderIds',
name: '同步订单 ID',
file: 'orderManagement/form/SyncOrderIdsForm.vue',
meta: '待处理 / 异常订单、波次待处理 · 3 处'
},
{
key: 'storageAllocate',
name: '批量分配 / 取消储位',
file: 'orderManagement/form/StorageAllocateForm.vue',
meta: '待处理 / 异常订单、波次待处理 · 3 处'
},
{
key: 'batchAsync',
name: '批量异步任务(拦截 / 锁定)',
file: 'orderManagement/form/BatchAsyncTaskForm.vue',
meta: '待处理 / 异常订单 · 2 处'
}
]
const clock = ref(formatNow())
function formatNow() {
const date = new Date()
const pad = (value: number) => String(value).padStart(2, '0')
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())} ${pad(date.getHours())}:${pad(date.getMinutes())}:${pad(date.getSeconds())}`
}
const total = 2040
const progress = ref(0)
let timer: ReturnType<typeof globalThis.setInterval> | null = null
let completedAt = 0
/** 本轮进度开始时间(毫秒),等价于接口的 submitted_at */
let startedAt = Date.now()
/** 达到 100% 的时刻,用于冻结耗时 */
let finishedAt = 0
/** 每 tick 刷新的当前时间,保证已用时长 / 预估剩余能随时间变化 */
const nowMs = ref(Date.now())
const percent = computed(() => Math.round(progress.value))
const processed = computed(() => Math.round((progress.value / 100) * total))
const matched = computed(() => Math.round(processed.value * 0.86))
const unmatched = computed(() => processed.value - matched.value)
/** 真实已用时长(毫秒),与接口 duration_ms 同口径 */
const elapsedMs = computed(() => {
if (!startedAt) return 0
const end = progress.value >= 100 && finishedAt ? finishedAt : nowMs.value
return Math.max(0, end - startedAt)
})
const elapsed = computed(() => (elapsedMs.value / 1000).toFixed(1))
const syncTotal = 128
const syncProcessed = computed(() => Math.round((progress.value / 100) * syncTotal))
const syncSuccess = computed(() => Math.round(syncProcessed.value * 0.92))
const syncFailed = computed(() => syncProcessed.value - syncSuccess.value)
const allocateSuccess = computed(() => Math.round((progress.value / 100) * 90))
const allocateFailed = computed(() => Math.round((progress.value / 100) * 6))
const batchAsyncTotal = 56
const batchAsyncProcessed = computed(() => Math.round((progress.value / 100) * batchAsyncTotal))
const batchAsyncResult = computed(() => Math.round(batchAsyncProcessed.value * 0.9))
const quickScanProgress = computed(() => ({
status: progress.value >= 100 ? 'success' : 'running',
taskId: 'W202610190931',
warehouseId: 1,
state: progress.value >= 100 ? 'success' : 'running',
message: progress.value >= 100 ? '扫描完成' : '正在匹配波次策略…',
acceptedAt: String(Math.floor(startedAt / 1000)),
totalOrderCount: total,
processedOrderCount: processed.value,
matchedOrderCount: matched.value,
unmatchedOrderCount: unmatched.value,
progressPercent: percent.value,
durationMs: elapsedMs.value
}))
const fetchProgress = computed(() => ({
taskId: 'F202610190932',
status: progress.value >= 100 ? 'success' : 'running',
warehouseId: 1,
structureCount: 120,
finishedStructureCount: Math.round((progress.value / 100) * 120),
progressPercent: percent.value,
totalFetchedQuantity: Math.round((progress.value / 100) * 3680),
durationMs: elapsedMs.value,
error: '',
updateTime: clock.value,
message: progress.value >= 100 ? '抓取完成' : '正在抓取结构订单…',
fetchMode: '全量',
maxFetchQuantity: 5000,
limitReached: false,
stopReason: ''
}))
const batchProgress = computed(() => ({
taskId: 'B202610190933',
status: progress.value >= 100 ? 'success' : 'running',
totalCount: 860,
successCount: Math.round((progress.value / 100) * 860 * 0.95),
failedCount: Math.round((progress.value / 100) * 860 * 0.05),
skippedLockedCount: 0,
progressPercent: percent.value,
durationMs: elapsedMs.value,
updateTime: clock.value,
error: '',
message: progress.value >= 100 ? '任务完成' : '正在分配快递号…'
}))
const scopeLabel = computed(() => {
const map: Record<OrderScope, string> = {
all: '全部待处理',
exception: '仅异常单',
noExpress: '未分配快递'
}
return map[orderScope.value]
})
const summaryItems = computed(() => [
{ label: '仓库', value: '深圳保税仓' },
{ label: '波次策略', value: '三单波次 · 自动' },
{ label: '订单范围', value: scopeLabel.value }
])
const metricItems = computed(() => [
{ label: '匹配订单', value: matched.value.toLocaleString() },
{ label: '未匹配', value: unmatched.value.toLocaleString() },
{ label: '扫描耗时', value: elapsed.value, unit: 's' }
])
const statusText = computed(() => {
if (progress.value >= 100) return '扫描完成'
const stages = ['正在拉取待扫描订单', '正在匹配波次策略', '正在校验波次约束', '正在汇总扫描结果']
return stages[Math.min(stages.length - 1, Math.floor(progress.value / 25))]
})
type ScenarioProps = {
title: string
subtitle?: string
taskId?: string
mode?: 'form' | 'progress'
state?: 'running' | 'success' | 'failed'
progress?: number
statusText?: string
detail?: string
/** 已用时长(毫秒):组件据此估算「预计剩余」 */
elapsedMs?: number
summary?: Array<{ label: string; value: string }>
metrics?: Array<{ label: string; value: string | number; unit?: string }>
fields?: Array<{ label: string; value?: string | number; type?: 'text' | 'switch'; active?: boolean }>
formTip?: string
resultIds?: Array<string | number>
resultIdsLabel?: string
tip?: string
footerHint?: string
submitText?: string
}
/** 同一个统一弹窗,按场景返回不同数据 */
function buildScenario(key: UnifiedScenarioKey): ScenarioProps {
const p = progress.value
const isDone = p >= 100
switch (key) {
case 'uAsyncExport':
return {
title: '导出订单数据',
subtitle: '正在生成导出文件',
taskId: 'A202610190001',
state: isDone ? 'success' : 'running',
progress: percent.value,
statusText: isDone ? '导出完成' : '导出中',
detail: `已处理 ${processed.value.toLocaleString()} / ${total.toLocaleString()}`,
summary: [
{ label: '导出范围', value: '全部待处理订单' },
{ label: '文件格式', value: 'Excel (.xlsx)' },
{ label: '数据量', value: `${total.toLocaleString()} 条` }
],
metrics: [
{ label: '已导出', value: processed.value.toLocaleString() },
{ label: '文件大小', value: '3.2', unit: 'MB' },
{ label: '耗时', value: elapsed.value, unit: 's' }
],
tip: '导出任务在后台执行中,关闭窗口会停止自动刷新。',
footerHint: '任务在后台执行,关闭窗口不会中断'
}
case 'uTask':
return {
title: '分配快递号',
subtitle: '正在为订单分配快递号',
taskId: 'T202610190002',
state: isDone ? 'success' : 'running',
progress: percent.value,
statusText: isDone ? '处理完成' : '处理中',
detail: `已处理 ${processed.value.toLocaleString()} / ${total.toLocaleString()}`,
summary: [
{ label: '操作类型', value: '分配快递号' },
{ label: '订单数量', value: `${total.toLocaleString()} 条` },
{ label: '执行节点', value: '深圳保税仓' }
],
metrics: [
{ label: '成功', value: matched.value.toLocaleString() },
{ label: '失败', value: unmatched.value.toLocaleString() },
{ label: '耗时', value: elapsed.value, unit: 's' }
],
tip: '任务在后台执行,可关闭窗口稍后查看结果。',
footerHint: '任务在后台执行,关闭窗口不会中断'
}
case 'uOrderExport':
return {
title: '订单导出',
subtitle: '正在导出订单数据',
taskId: 'O202610190003',
state: isDone ? 'success' : 'running',
progress: percent.value,
statusText: isDone ? '导出完成' : '导出中',
detail: `已处理 ${processed.value.toLocaleString()} / ${total.toLocaleString()}`,
metrics: [
{ label: '已导出', value: processed.value.toLocaleString() },
{ label: '失败', value: unmatched.value.toLocaleString() },
{ label: '耗时', value: elapsed.value, unit: 's' }
],
tip: '导出完成后可在下载中心查看文件。'
}
case 'uQuickScan':
return {
title: '波次策略快速扫描',
subtitle: '正在匹配波次策略 · 深圳保税仓',
taskId: 'W202610190931',
state: isDone ? 'success' : 'running',
progress: percent.value,
statusText: statusText.value,
detail: `已处理 ${processed.value.toLocaleString()} / ${total.toLocaleString()}`,
summary: summaryItems.value,
metrics: metricItems.value,
tip: '扫描期间请勿关闭窗口,可最小化到后台。',
footerHint: '扫描任务在后台执行'
}
case 'uFetch':
return {
title: '抓取任务',
subtitle: '按结构抓取订单',
taskId: 'F202610190932',
state: isDone ? 'success' : 'running',
progress: percent.value,
statusText: isDone ? '抓取完成' : '抓取中',
detail: `已完成结构 ${Math.round((p / 100) * 120)} / 120`,
summary: [
{ label: '抓取模式', value: '全量' },
{ label: '抓取上限', value: '5,000 件' },
{ label: '已抓取件数', value: `${Math.round((p / 100) * 3680).toLocaleString()} 件` }
],
metrics: [
{ label: '结构完成', value: `${Math.round((p / 100) * 120)} / 120` },
{ label: '抓取件数', value: Math.round((p / 100) * 3680).toLocaleString() },
{ label: '耗时', value: ((p / 100) * 14).toFixed(1), unit: 's' }
],
tip: '达到抓取上限后任务会自动停止。'
}
case 'uBatch':
return {
title: '快递号分配任务',
subtitle: '批量处理已选波次订单',
taskId: 'B202610190933',
state: isDone ? 'success' : 'running',
progress: percent.value,
statusText: isDone ? '处理完成' : '处理中',
detail: `已完成 ${Math.round((p / 100) * 860 * 0.95).toLocaleString()} / 860`,
summary: [
{ label: '订单总数', value: '860' },
{ label: '失败', value: Math.round((p / 100) * 860 * 0.05).toLocaleString() },
{ label: '跳过锁定', value: '0' }
],
metrics: [
{ label: '已完成', value: Math.round((p / 100) * 860 * 0.95).toLocaleString() },
{ label: '失败', value: Math.round((p / 100) * 860 * 0.05).toLocaleString() },
{ label: '耗时', value: ((p / 100) * 12).toFixed(1), unit: 's' }
],
tip: '任务在后台执行,关闭窗口不会中断。'
}
case 'uSyncForm':
return {
title: '同步订单 ID',
subtitle: '提交后任务在后台执行',
mode: 'form',
fields: [
{ label: '当前勾选订单', value: '128 条' },
{ label: '数据范围', value: '已勾选的待处理订单' }
],
formTip: '将逐条同步订单 ID,任务完成后可在列表中查看最新数据。',
footerHint: '任务提交后可在后台运行',
submitText: '确认同步'
}
case 'uSyncProgress':
return {
title: '同步订单 ID',
subtitle: '任务执行中',
taskId: 'S202610190004',
state: isDone ? 'success' : 'running',
progress: percent.value,
statusText: isDone ? '同步完成' : '同步中',
detail: `已处理 ${syncProcessed.value} / ${syncTotal}`,
metrics: [
{ label: '成功', value: String(syncSuccess.value) },
{ label: '失败', value: String(syncFailed.value) },
{ label: '耗时', value: ((p / 100) * 8).toFixed(1), unit: 's' }
],
tip: '任务在后台执行,可关闭窗口稍后查看。',
footerHint: '任务在后台执行,关闭窗口不会中断'
}
case 'uStorageForm':
return {
title: '按订单批量分配储位',
subtitle: '提交后任务在后台执行',
mode: 'form',
fields: [
{ label: '已选订单数', value: '96 条' },
{ label: '允许存储储位', type: 'switch', active: true }
],
formTip: '系统会按商品与储位规则自动分配,冲突订单会记录失败原因。',
footerHint: '提交前请确认已选订单',
submitText: '确认分配'
}
case 'uStorageProgress':
return {
title: '按订单批量分配储位',
subtitle: '任务执行中',
taskId: 'R202610190005',
state: isDone ? 'success' : 'running',
progress: percent.value,
statusText: isDone ? '分配完成' : '分配中',
detail: `已处理 ${Math.round((p / 100) * 96)} / 96`,
metrics: [
{ label: '成功', value: String(allocateSuccess.value) },
{ label: '失败', value: String(allocateFailed.value) },
{ label: '耗时', value: ((p / 100) * 9).toFixed(1), unit: 's' }
],
tip: '任务在后台执行,关闭窗口不会中断。'
}
case 'uBatchAsyncForm':
return {
title: '批量拦截订单',
subtitle: '提交后任务在后台执行',
mode: 'form',
fields: [{ label: '已选订单数', value: '56 条' }],
formTip: '将对选中订单执行拦截操作,已发货订单会自动跳过。',
footerHint: '操作不可撤销,请确认后提交',
submitText: '提交拦截'
}
case 'uBatchAsyncProgress':
return {
title: '批量拦截订单',
subtitle: '任务执行中',
taskId: 'B202610190006',
state: isDone ? 'success' : 'running',
progress: percent.value,
statusText: isDone ? '处理完成' : '处理中',
detail: `已处理 ${batchAsyncProcessed.value} / ${batchAsyncTotal}`,
metrics: [
{ label: '已拦截', value: String(batchAsyncResult.value) },
{ label: '失败', value: String(batchAsyncProcessed.value - batchAsyncResult.value) },
{ label: '耗时', value: ((p / 100) * 6).toFixed(1), unit: 's' }
],
resultIds: ['SO20261019001', 'SO20261019002', 'SO20261019003'],
resultIdsLabel: '已拦截订单',
tip: '任务在后台执行,关闭窗口不会中断。'
}
default:
return { title: '' }
}
}
const unifiedScenarioProps = computed(() => ({
...buildScenario(activeScenario.value ?? 'uAsyncExport'),
// 真实已用时长(接口 duration_ms 口径),组件据此外推「预计剩余」
elapsedMs: elapsedMs.value
}))
function tick() {
clock.value = formatNow()
nowMs.value = Date.now()
// 随演示 tick 同步滚动状态,避免滚动事件被节流导致按钮文案不更新
scrolled.value = (pageRef.value?.scrollTop ?? 0) > 8
if (progress.value >= 100) {
if (!finishedAt) finishedAt = Date.now()
if (!completedAt) completedAt = Date.now()
if (Date.now() - completedAt >= 1600) {
resetProgressClock()
}
return
}
progress.value = Math.min(100, progress.value + 1.1 * (0.65 + Math.random() * 0.7))
}
/** 重置计时(新一轮演示) */
function resetProgressClock() {
progress.value = 0
completedAt = 0
startedAt = Date.now()
finishedAt = 0
nowMs.value = startedAt
}
function startScan() {
resetProgressClock()
previewState.value = 'progress'
dialogVisible.value = true
}
function resetAll() {
resetProgressClock()
previewState.value = 'progress'
dialogVisible.value = true
}
function openDialog(key: DialogKey) {
resetProgressClock()
activeScenario.value = null
activeDialog.value = key
}
function closeDialog() {
activeDialog.value = null
}
function openScenario(key: UnifiedScenarioKey) {
resetProgressClock()
activeDialog.value = null
activeScenario.value = key
}
function closeAll() {
activeDialog.value = null
activeScenario.value = null
}
/** 表单场景提交后切到对应进度场景,演示同一弹窗两态 */
function handleScenarioSubmit() {
const nextMap: Partial<Record<UnifiedScenarioKey, UnifiedScenarioKey>> = {
uSyncForm: 'uSyncProgress',
uStorageForm: 'uStorageProgress',
uBatchAsyncForm: 'uBatchAsyncProgress'
}
const current = activeScenario.value
const next = current ? nextMap[current] : undefined
if (next) activeScenario.value = next
}
function noop() {
// 预览用:不执行真实提交
}
onMounted(() => {
timer = globalThis.setInterval(tick, 120)
})
onBeforeUnmount(() => {
if (timer) globalThis.clearInterval(timer)
})
</script>
<style scoped lang="scss">
.test-page {
box-sizing: border-box;
position: relative;
height: 100vh;
height: 100dvh;
overflow-y: auto;
overflow-x: hidden;
padding: 40px clamp(20px, 4vw, 56px) 56px;
background:
radial-gradient(900px 420px at 12% -8%, #e8f1ff 0%, rgba(232, 241, 255, 0) 60%),
radial-gradient(760px 380px at 92% 0%, #eef4ff 0%, rgba(238, 244, 255, 0) 55%),
#f6f9fe;
color: #0f172a;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
scrollbar-width: thin;
scrollbar-color: #c3d6ee transparent;
&::-webkit-scrollbar {
width: 8px;
}
&::-webkit-scrollbar-track {
background: transparent;
}
&::-webkit-scrollbar-thumb {
border: 2px solid transparent;
border-radius: 999px;
background: #c9dbf2;
background-clip: padding-box;
}
&::-webkit-scrollbar-thumb:hover {
background: #a9c8ee;
background-clip: padding-box;
}
}
.page-head {
max-width: 920px;
&__eyebrow {
font-size: 11px;
font-weight: 600;
letter-spacing: 0.22em;
text-transform: uppercase;
color: #3b82f6;
}
h1 {
margin: 12px 0 0;
font-size: clamp(24px, 2.6vw, 32px);
font-weight: 650;
letter-spacing: -0.02em;
}
p {
margin: 12px 0 0;
font-size: 13px;
line-height: 1.8;
color: #64748b;
}
}
.toolbar {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: space-between;
gap: 12px;
max-width: 920px;
margin-top: 22px;
padding: 10px 14px;
border: 1px solid #e5edf8;
border-radius: 14px;
background: rgba(255, 255, 255, 0.72);
backdrop-filter: blur(8px);
&__state {
display: inline-flex;
align-items: center;
gap: 8px;
font-size: 12px;
color: #475569;
}
&__actions {
display: flex;
align-items: center;
gap: 8px;
}
}
.pulse {
width: 7px;
height: 7px;
border-radius: 50%;
background: #2563eb;
animation: page-pulse 1.6s ease-out infinite;
}
.segmented {
display: inline-flex;
padding: 2px;
border-radius: 999px;
background: #eef3fb;
button {
height: 26px;
padding: 0 12px;
border: none;
border-radius: 999px;
background: transparent;
color: #64748b;
font-size: 11.5px;
cursor: pointer;
transition: all 0.16s ease;
&.is-active {
background: #fff;
color: #1d4ed8;
font-weight: 600;
box-shadow: 0 2px 6px -2px rgba(15, 23, 42, 0.18);
}
}
}
.tool-btn {
height: 30px;
padding: 0 14px;
border-radius: 999px;
border: 1px solid #dbe4f0;
background: #fff;
color: #475569;
font-size: 11.5px;
cursor: pointer;
transition: all 0.16s ease;
&:hover {
border-color: #bfd4ef;
color: #1e293b;
}
&--primary {
border-color: transparent;
background: linear-gradient(135deg, #3b82f6, #2563eb);
color: #fff;
box-shadow: 0 8px 16px -10px rgba(37, 99, 235, 0.85);
&:hover {
color: #fff;
filter: brightness(1.05);
}
}
}
/* ---------- 预览舞台 ---------- */
.stage {
position: relative;
display: grid;
place-items: center;
max-width: 920px;
min-height: 620px;
margin-top: 20px;
padding: 28px;
border: 1px solid #e3ebf8;
border-radius: 20px;
background:
radial-gradient(680px 300px at 20% 10%, #eaf2ff 0%, rgba(234, 242, 255, 0) 70%),
linear-gradient(160deg, #f2f7ff, #eaf1fb);
overflow: hidden;
&__scrim {
position: absolute;
inset: 0;
background: rgba(15, 23, 42, 0.16);
}
}
.reopen {
position: relative;
height: 38px;
padding: 0 18px;
border: 1px solid #bfd4ef;
border-radius: 999px;
background: #fff;
color: #2563eb;
font-size: 13px;
cursor: pointer;
box-shadow: 0 12px 24px -18px rgba(15, 23, 42, 0.5);
}
/* ---------- 弹窗(对齐 Element Plus) ---------- */
.dlg {
position: relative;
width: min(560px, 100%);
border-radius: 4px;
background: #fff;
box-shadow:
0 12px 32px 4px rgba(0, 0, 0, 0.04),
0 8px 20px rgba(0, 0, 0, 0.08);
overflow: hidden;
&__head {
display: flex;
align-items: flex-start;
gap: 12px;
padding: 16px 16px 16px;
}
&__titles {
flex: 1;
min-width: 0;
h2 {
margin: 0;
font-size: 18px;
line-height: 24px;
font-weight: 400;
color: #303133;
}
p {
margin: 4px 0 0;
font-size: 12px;
line-height: 18px;
color: #909399;
}
}
&__task {
flex: none;
font-size: 12px;
line-height: 24px;
color: #909399;
white-space: nowrap;
}
&__close {
width: 24px;
height: 24px;
flex: none;
display: inline-flex;
align-items: center;
justify-content: center;
border: none;
border-radius: 4px;
background: transparent;
color: #909399;
cursor: pointer;
transition: color 0.2s;
svg {
width: 12px;
height: 12px;
}
&:hover {
color: #409eff;
}
}
&__body {
padding: 12px 16px 0;
}
&__foot {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 16px 16px 16px;
}
&__hint {
display: inline-flex;
align-items: center;
gap: 6px;
font-size: 12px;
color: #909399;
svg {
width: 13px;
height: 13px;
}
}
&__actions {
display: flex;
gap: 8px;
}
}
/* ---------- 配置态 ---------- */
.form {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 14px;
}
.field {
display: flex;
flex-direction: column;
gap: 7px;
&--block {
margin-top: 14px;
}
&__label {
font-size: 12px;
line-height: 18px;
color: #606266;
}
&__control {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
height: 32px;
padding: 0 12px;
border: 1px solid #dcdfe6;
border-radius: 4px;
background: #fff;
font-size: 13px;
color: #303133;
text-align: left;
cursor: pointer;
transition: border-color 0.2s;
&:hover {
border-color: #409eff;
}
}
&__caret {
width: 10px;
height: 6px;
color: #c0c4cc;
flex: none;
}
}
.chips {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.chip {
height: 28px;
padding: 0 12px;
border: 1px solid #dcdfe6;
border-radius: 4px;
background: #fff;
font-size: 12px;
color: #606266;
cursor: pointer;
transition: all 0.2s;
&:hover {
border-color: #409eff;
color: #409eff;
}
&.is-active {
border-color: #409eff;
background: #ecf5ff;
color: #409eff;
}
}
.form__hint {
margin: 12px 0 0;
padding: 8px 12px;
border-radius: 4px;
background: #f4f4f5;
font-size: 12px;
line-height: 18px;
color: #909399;
}
.footnote {
max-width: 920px;
margin: 20px auto 0;
font-size: 12px;
line-height: 1.8;
color: #94a3b8;
text-align: center;
}
/* ---------- 现有弹窗清单 ---------- */
.inventory {
max-width: 920px;
margin-top: 30px;
&__head {
h2 {
margin: 0;
font-size: 18px;
font-weight: 650;
letter-spacing: -0.01em;
}
p {
margin: 8px 0 0;
font-size: 12.5px;
color: #64748b;
}
}
&__group {
margin-top: 22px;
h3 {
display: flex;
align-items: center;
gap: 8px;
margin: 0;
font-size: 13px;
font-weight: 600;
color: #334155;
em {
font-style: normal;
font-size: 10.5px;
font-weight: 500;
color: #3b82f6;
background: #eff6ff;
border-radius: 999px;
padding: 2px 8px;
}
}
}
&__grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 12px;
margin-top: 10px;
}
}
.entry {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 6px;
padding: 14px;
border: 1px solid #e6edf8;
border-radius: 12px;
background: #fff;
text-align: left;
cursor: pointer;
transition: all 0.16s ease;
&:hover {
border-color: #bfd4ef;
background: #fbfdff;
transform: translateY(-1px);
box-shadow: 0 14px 26px -24px rgba(15, 23, 42, 0.65);
}
strong {
font-size: 13px;
font-weight: 600;
color: #0f172a;
}
code {
font-family: ui-monospace, 'SFMono-Regular', Menlo, Consolas, monospace;
font-size: 10.5px;
line-height: 1.5;
color: #7b8aa0;
word-break: break-all;
}
span {
font-size: 11px;
color: #3b82f6;
}
}
.escape-close {
position: fixed;
top: 18px;
right: 18px;
z-index: 9999;
height: 32px;
padding: 0 15px;
border: 1px solid #cfe0f5;
border-radius: 999px;
background: #fff;
color: #2563eb;
font-size: 12px;
cursor: pointer;
box-shadow: 0 12px 24px -16px rgba(15, 23, 42, 0.45);
transition: all 0.16s ease;
&:hover {
border-color: #a9c8ee;
background: #f4f9ff;
}
}
.scroll-fab {
position: fixed;
right: 22px;
bottom: 24px;
z-index: 1500;
display: inline-flex;
align-items: center;
gap: 7px;
height: 38px;
padding: 0 17px;
border: 1px solid #cfe0f5;
border-radius: 999px;
background: rgba(255, 255, 255, 0.92);
backdrop-filter: blur(8px);
color: #2563eb;
font-size: 12px;
cursor: pointer;
box-shadow: 0 16px 30px -18px rgba(15, 23, 42, 0.5);
transition: all 0.16s ease;
&:hover {
border-color: #a9c8ee;
background: #f4f9ff;
transform: translateY(-1px);
}
&__arrow {
display: inline-flex;
width: 18px;
height: 18px;
align-items: center;
justify-content: center;
border-radius: 50%;
background: #eff6ff;
font-size: 11px;
line-height: 1;
}
}
@media (max-width: 900px) {
.inventory__grid {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@keyframes page-pulse {
0% {
box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.45);
}
70% {
box-shadow: 0 0 0 7px rgba(37, 99, 235, 0);
}
100% {
box-shadow: 0 0 0 0 rgba(37, 99, 235, 0);
}
}
@media (max-width: 520px) {
.dlg__task {
display: none;
}
.form {
grid-template-columns: 1fr;
}
.summary {
grid-template-columns: 1fr;
}
.inventory__grid {
grid-template-columns: 1fr;
}
.stage {
padding: 16px;
min-height: 520px;
}
}
</style>