提交代码

This commit is contained in:
ldh
2026-11-19 16:42:26 +08:00
parent c5908eff03
commit 9d06abe41c
209 changed files with 158631 additions and 1311 deletions
+841
View File
@@ -0,0 +1,841 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { useRouter } from 'vue-router'
import AppStage from '@/components/AppStage.vue'
import PageHeader from '@/components/PageHeader.vue'
import { getScanHistory, deleteScan, type ScanHistoryItem } from '@/api/scan'
import { showToast } from '@/composables/useToast'
const router = useRouter()
const items = ref<ScanHistoryItem[]>([])
const loading = ref(true)
const error = ref('')
const deleteTarget = ref<ScanHistoryItem | null>(null)
const removing = ref(false)
function goHome() {
void router.replace({ name: 'home' })
}
function openDetail(item: ScanHistoryItem) {
void router.push({ name: 'historyDetail', params: { scanId: item.scanId } })
}
function askDelete(item: ScanHistoryItem) {
if (removing.value) return
deleteTarget.value = item
}
function cancelDelete() {
if (removing.value) return
deleteTarget.value = null
}
async function confirmDelete() {
const target = deleteTarget.value
if (!target || removing.value) return
removing.value = true
try {
await deleteScan(target.scanId)
items.value = items.value.filter((item) => item.scanId !== target.scanId)
deleteTarget.value = null
showToast('检测记录已删除')
} catch (err) {
showToast(err instanceof Error ? err.message : '删除检测记录失败')
} finally {
removing.value = false
}
}
async function load() {
loading.value = true
error.value = ''
try {
items.value = await getScanHistory()
} catch (err) {
error.value = err instanceof Error ? err.message : '读取历史记录失败'
showToast(error.value)
} finally {
loading.value = false
}
}
function statusLabel(status: string) {
switch (status) {
case 'Completed':
return '已完成'
case 'Failed':
return '失败'
case 'Aborted':
return '已中止'
default:
return '进行中'
}
}
function statusTone(status: string) {
switch (status) {
case 'Completed':
return 'is-completed'
case 'Failed':
return 'is-failed'
case 'Aborted':
return 'is-aborted'
default:
return ''
}
}
function formatTime(value: string | null) {
if (!value) return '—'
const date = new Date(value)
if (Number.isNaN(date.getTime())) return '—'
return date.toLocaleString('zh-CN', { hour12: false }).replace(/\//g, '-')
}
function formatDuration(item: ScanHistoryItem) {
if (!item.finishedAt) return '—'
const start = new Date(item.startedAt).getTime()
const end = new Date(item.finishedAt).getTime()
if (!Number.isFinite(start) || !Number.isFinite(end) || end < start) return '—'
const seconds = Math.round((end - start) / 1000)
if (seconds < 60) return `${seconds} 秒`
const minutes = Math.floor(seconds / 60)
const rest = seconds % 60
return rest === 0 ? `${minutes} 分` : `${minutes} 分 ${rest} 秒`
}
onMounted(() => {
void load()
})
</script>
<template>
<AppStage>
<div class="history-bg" aria-hidden="true">
<span class="history-bg__orb history-bg__orb--blue"></span>
<span class="history-bg__orb history-bg__orb--cyan"></span>
<span class="history-bg__orb history-bg__orb--violet"></span>
</div>
<PageHeader
title="检测历史"
subtitle="查看已保存的扫描记录与检测结果"
theme="dark"
>
<template #left>
<button class="admin-back" type="button" @click="goHome">
返回
</button>
</template>
</PageHeader>
<main class="history-main">
<section class="history-card">
<header class="history-card__header">
<div class="history-card__heading">
<span class="history-card__eyebrow">Scan History</span>
<h2>检测记录</h2>
</div>
<div class="history-card__actions">
<span class="history-card__count">共 {{ items.length }} 条</span>
<button
class="history-refresh"
type="button"
:disabled="loading"
@click="load"
>
{{ loading ? '加载中...' : '刷新' }}
</button>
</div>
</header>
<div class="history-table">
<div class="history-table__head">
<span>检测时间</span>
<span>状态</span>
<span>采样点</span>
<span>耗时</span>
<span>记录编号</span>
<span>操作</span>
</div>
<div class="history-table__body">
<div
v-for="item in items"
:key="item.scanId"
class="history-row"
@click="openDetail(item)"
>
<span class="history-row__time">{{ formatTime(item.startedAt) }}</span>
<span>
<span class="history-status" :class="statusTone(item.status)">
{{ statusLabel(item.status) }}
</span>
</span>
<span class="history-row__points">
{{ item.completedPoints }} / {{ item.totalPoints }}
</span>
<span class="history-row__duration">{{ formatDuration(item) }}</span>
<span class="history-row__id" :title="item.scanId">{{ item.scanId }}</span>
<span class="history-row__actions">
<button
class="row-action row-action--view"
type="button"
@click.stop="openDetail(item)"
>
查看
</button>
<button
class="row-action row-action--danger"
type="button"
@click.stop="askDelete(item)"
>
删除
</button>
</span>
</div>
<div v-if="!items.length" class="history-empty">
<template v-if="error">
<p>{{ error }}</p>
<button class="history-empty__retry" type="button" @click="load">
重新加载
</button>
</template>
<p v-else-if="loading">正在读取历史记录...</p>
<p v-else>暂无历史检测记录</p>
</div>
</div>
</div>
<footer class="history-footer">
按开始时间倒序显示,最多 100 条记录 · 点击任意记录查看靶面图与光谱分析结果
</footer>
</section>
</main>
<Teleport to="body">
<Transition name="delete-modal">
<div v-if="deleteTarget" class="delete-backdrop" @click.self="cancelDelete">
<section
class="delete-card"
role="dialog"
aria-modal="true"
aria-label="删除检测记录"
>
<div class="delete-card__icon" aria-hidden="true">
<svg viewBox="0 0 64 64">
<path
d="M20 22h24M26 22v-4h12v4M24 22l2 28h12l2-28"
fill="none"
stroke="currentColor"
stroke-width="3"
stroke-linecap="round"
stroke-linejoin="round"
/>
<path
d="M29 30v12M35 30v12"
fill="none"
stroke="currentColor"
stroke-width="3"
stroke-linecap="round"
/>
</svg>
</div>
<h2>删除检测记录</h2>
<p>
确定删除 <strong>{{ formatTime(deleteTarget.startedAt) }}</strong> 的检测记录吗?
</p>
<p class="delete-card__hint">
靶面图、光谱数据与元素分析结果将一并删除,删除后无法恢复。
</p>
<div class="delete-card__actions">
<button
class="delete-button delete-button--ghost"
type="button"
:disabled="removing"
@click="cancelDelete"
>
取消
</button>
<button
class="delete-button delete-button--danger"
type="button"
:disabled="removing"
@click="confirmDelete"
>
{{ removing ? '删除中...' : '删除' }}
</button>
</div>
</section>
</div>
</Transition>
</Teleport>
</AppStage>
</template>
<style scoped>
.history-bg {
position: absolute;
inset: 0;
overflow: hidden;
pointer-events: none;
background:
radial-gradient(1000px 600px at 8% -16%, rgba(48, 112, 255, 0.28), transparent 62%),
radial-gradient(820px 520px at 98% 4%, rgba(0, 209, 255, 0.14), transparent 60%),
radial-gradient(900px 680px at 58% 116%, rgba(122, 84, 255, 0.18), transparent 62%),
linear-gradient(156deg, #050a16 0%, #081226 46%, #0a1730 100%);
}
.history-bg::before {
content: '';
position: absolute;
inset: 0;
background-image:
linear-gradient(rgba(130, 175, 255, 0.05) 1px, transparent 1px),
linear-gradient(90deg, rgba(130, 175, 255, 0.05) 1px, transparent 1px);
background-size: 64px 64px;
mask-image: radial-gradient(ellipse 78% 72% at 50% 32%, #000 20%, transparent 78%);
}
.history-bg__orb {
position: absolute;
border-radius: 50%;
filter: blur(100px);
animation: history-orb-drift 16s ease-in-out infinite alternate;
}
.history-bg__orb--blue {
top: -340px;
left: -160px;
width: 760px;
height: 760px;
background: rgba(48, 118, 255, 0.3);
}
.history-bg__orb--cyan {
top: -200px;
right: -220px;
width: 640px;
height: 640px;
background: rgba(0, 214, 255, 0.18);
animation-delay: -5s;
}
.history-bg__orb--violet {
bottom: -360px;
left: 36%;
width: 700px;
height: 700px;
background: rgba(124, 92, 255, 0.18);
animation-delay: -10s;
}
@keyframes history-orb-drift {
from {
transform: translate3d(0, 0, 0) scale(1);
}
to {
transform: translate3d(42px, 30px, 0) scale(1.08);
}
}
.admin-back {
width: 132px;
height: 60px;
border: 1px solid rgba(130, 190, 255, 0.35);
border-radius: 12px;
background: rgba(18, 40, 78, 0.5);
color: #bcd9ff;
font-size: 24px;
font-weight: 600;
letter-spacing: 3px;
backdrop-filter: blur(10px);
transition:
transform 0.2s ease,
border-color 0.2s ease,
background 0.2s ease;
}
.admin-back:hover {
border-color: rgba(150, 205, 255, 0.55);
background: rgba(30, 66, 128, 0.65);
transform: translateY(-1px);
}
.history-main {
position: absolute;
top: 176px;
right: 44px;
bottom: 40px;
left: 44px;
}
.history-card {
position: relative;
display: flex;
flex-direction: column;
height: 100%;
overflow: hidden;
border: 1px solid rgba(130, 175, 255, 0.18);
border-radius: 26px;
background: linear-gradient(158deg, rgba(20, 40, 78, 0.7) 0%, rgba(6, 14, 30, 0.85) 100%);
box-shadow:
0 30px 70px rgba(0, 10, 32, 0.5),
0 0 40px rgba(48, 118, 255, 0.1),
inset 0 1px 0 rgba(255, 255, 255, 0.08);
backdrop-filter: blur(16px);
}
.history-card::before {
content: '';
position: absolute;
top: 0;
right: 40px;
left: 40px;
z-index: 2;
height: 1px;
background: linear-gradient(90deg, transparent, rgba(130, 214, 255, 0.55), transparent);
pointer-events: none;
}
.history-card__header {
display: flex;
flex: none;
align-items: center;
justify-content: space-between;
height: 110px;
padding: 0 32px;
border-bottom: 1px solid rgba(130, 175, 255, 0.12);
background: linear-gradient(120deg, rgba(26, 58, 112, 0.24) 0%, transparent 70%);
}
.history-card__heading {
display: flex;
flex-direction: column;
gap: 6px;
}
.history-card__eyebrow {
color: #5aa2ff;
font-size: 12px;
font-weight: 600;
letter-spacing: 2.6px;
text-transform: uppercase;
}
.history-card__header h2 {
display: flex;
align-items: center;
gap: 12px;
color: #eaf3ff;
font-size: 30px;
font-weight: 600;
letter-spacing: 3px;
}
.history-card__header h2::before {
content: '';
width: 4px;
height: 26px;
border-radius: 4px;
background: linear-gradient(180deg, #7fe0ff, #4d8bf0);
box-shadow: 0 0 14px rgba(90, 170, 255, 0.7);
}
.history-card__actions {
display: flex;
align-items: center;
gap: 14px;
}
.history-card__count {
padding: 6px 16px;
border: 1px solid rgba(130, 195, 255, 0.28);
border-radius: 30px;
background: rgba(16, 40, 80, 0.5);
color: #9fe8ff;
font-size: 16px;
letter-spacing: 1px;
}
.history-refresh {
height: 48px;
padding: 0 24px;
border: 1px solid rgba(130, 175, 255, 0.28);
border-radius: 12px;
background: rgba(18, 40, 78, 0.5);
color: #bcd9ff;
font-size: 18px;
font-weight: 600;
letter-spacing: 2px;
transition:
transform 0.2s ease,
border-color 0.2s ease,
background 0.2s ease;
}
.history-refresh:hover:not(:disabled) {
border-color: rgba(150, 205, 255, 0.5);
background: rgba(30, 66, 128, 0.6);
transform: translateY(-1px);
}
.history-refresh:disabled {
cursor: default;
opacity: 0.55;
}
.history-table {
display: flex;
flex: 1;
flex-direction: column;
min-height: 0;
padding: 0 32px;
}
.history-table__head,
.history-row {
display: grid;
grid-template-columns: 320px 150px 150px 160px minmax(0, 1fr) 200px;
align-items: center;
gap: 20px;
padding: 0 22px;
}
.history-table__head {
flex: none;
height: 62px;
margin-top: 18px;
border: 1px solid rgba(130, 175, 255, 0.12);
border-radius: 14px;
background: rgba(255, 255, 255, 0.04);
color: rgba(158, 190, 226, 0.65);
font-size: 18px;
font-weight: 600;
letter-spacing: 1px;
}
.history-table__body {
flex: 1;
min-height: 0;
overflow-y: auto;
margin-right: -6px;
padding-right: 6px;
}
.history-table__body::-webkit-scrollbar {
width: 6px;
}
.history-table__body::-webkit-scrollbar-thumb {
border-radius: 3px;
background: rgba(130, 175, 255, 0.25);
}
.history-row {
width: 100%;
min-height: 78px;
border-bottom: 1px solid rgba(130, 175, 255, 0.08);
color: rgba(210, 228, 250, 0.82);
font-size: 19px;
text-align: left;
cursor: pointer;
transition: background 0.18s ease;
}
.history-row:hover {
background: rgba(70, 140, 255, 0.08);
}
.history-row__time {
color: rgba(226, 240, 255, 0.9);
font-variant-numeric: tabular-nums;
}
.history-row__points {
font-variant-numeric: tabular-nums;
}
.history-row__duration {
color: rgba(158, 190, 226, 0.7);
}
.history-row__id {
overflow: hidden;
color: rgba(158, 190, 226, 0.5);
font-size: 16px;
letter-spacing: 0.5px;
text-overflow: ellipsis;
white-space: nowrap;
}
.history-row__actions {
display: flex;
align-items: center;
justify-content: flex-end;
gap: 10px;
}
.row-action {
height: 40px;
padding: 0 16px;
border: 1px solid rgba(120, 190, 255, 0.28);
border-radius: 10px;
background: rgba(70, 140, 255, 0.12);
color: #8fd0ff;
font-family: inherit;
font-size: 16px;
font-weight: 600;
letter-spacing: 1px;
cursor: pointer;
transition:
background 0.18s ease,
border-color 0.18s ease,
color 0.18s ease;
}
.row-action:hover {
border-color: rgba(150, 205, 255, 0.5);
background: rgba(70, 140, 255, 0.22);
}
.row-action--danger {
border-color: rgba(255, 120, 120, 0.28);
background: rgba(255, 84, 84, 0.1);
color: #ff9d9d;
}
.row-action--danger:hover {
border-color: rgba(255, 150, 150, 0.5);
background: rgba(255, 84, 84, 0.18);
}
.history-status {
display: inline-block;
min-width: 86px;
padding: 4px 12px;
border: 1px solid rgba(130, 195, 255, 0.28);
border-radius: 20px;
background: rgba(16, 40, 80, 0.5);
color: #9fe8ff;
font-size: 16px;
text-align: center;
}
.history-status.is-completed {
border-color: rgba(116, 244, 197, 0.32);
background: rgba(14, 60, 56, 0.45);
color: #8ff5e7;
}
.history-status.is-failed {
border-color: rgba(255, 120, 120, 0.32);
background: rgba(60, 20, 26, 0.45);
color: #ff9d9d;
}
.history-status.is-aborted {
border-color: rgba(255, 216, 106, 0.3);
background: rgba(60, 46, 12, 0.45);
color: #ffd98a;
}
.history-empty {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 18px;
padding: 120px 0;
color: rgba(158, 190, 226, 0.55);
font-size: 20px;
letter-spacing: 1px;
text-align: center;
}
.history-empty__retry {
height: 46px;
padding: 0 26px;
border: 1px solid rgba(130, 175, 255, 0.28);
border-radius: 12px;
background: rgba(18, 40, 78, 0.5);
color: #bcd9ff;
font-family: inherit;
font-size: 18px;
letter-spacing: 2px;
}
.history-empty__retry:hover {
border-color: rgba(150, 205, 255, 0.5);
}
.history-footer {
display: flex;
flex: none;
align-items: center;
height: 64px;
padding: 0 54px;
border-top: 1px solid rgba(130, 175, 255, 0.12);
background: rgba(8, 18, 38, 0.55);
color: rgba(158, 190, 226, 0.6);
font-size: 16px;
letter-spacing: 1px;
}
.delete-backdrop {
position: fixed;
inset: 0;
z-index: 70;
display: grid;
place-items: center;
padding: 24px;
background: rgba(3, 8, 18, 0.68);
backdrop-filter: blur(8px);
}
.delete-card {
width: 600px;
padding: 38px 44px 34px;
border: 1px solid rgba(130, 175, 255, 0.2);
border-radius: 26px;
background: linear-gradient(158deg, rgba(22, 42, 78, 0.98) 0%, rgba(8, 16, 32, 0.99) 100%);
box-shadow:
0 40px 90px rgba(0, 6, 20, 0.6),
0 0 50px rgba(48, 118, 255, 0.12),
inset 0 1px 0 rgba(255, 255, 255, 0.08);
color-scheme: dark;
text-align: center;
}
.delete-card__icon {
display: grid;
place-items: center;
width: 86px;
height: 86px;
margin: 0 auto 22px;
border: 1px solid rgba(255, 120, 120, 0.3);
border-radius: 50%;
background: rgba(255, 84, 84, 0.12);
box-shadow:
0 0 32px rgba(255, 84, 84, 0.18),
inset 0 1px 0 rgba(255, 255, 255, 0.08);
color: #ff9d9d;
}
.delete-card__icon svg {
width: 44px;
height: 44px;
}
.delete-card h2 {
color: #eef5ff;
font-size: 30px;
font-weight: 600;
letter-spacing: 2px;
text-shadow: 0 0 24px rgba(80, 150, 255, 0.28);
}
.delete-card p {
margin-top: 14px;
color: rgba(158, 190, 226, 0.72);
font-size: 19px;
line-height: 1.6;
letter-spacing: 0.5px;
}
.delete-card p strong {
color: #ffd166;
font-weight: 600;
}
.delete-card__hint {
font-size: 16px;
color: rgba(158, 190, 226, 0.55);
}
.delete-card__actions {
display: flex;
justify-content: center;
gap: 20px;
margin-top: 28px;
}
.delete-button {
width: 180px;
height: 56px;
border-radius: 12px;
font-family: inherit;
font-size: 20px;
font-weight: 600;
letter-spacing: 3px;
transition:
transform 0.2s ease,
box-shadow 0.2s ease,
background 0.2s ease,
border-color 0.2s ease;
}
.delete-button:disabled {
cursor: default;
opacity: 0.5;
}
.delete-button--ghost {
border: 1px solid rgba(130, 175, 255, 0.28);
background: rgba(18, 40, 78, 0.5);
color: #bcd9ff;
}
.delete-button--ghost:hover:not(:disabled) {
border-color: rgba(150, 205, 255, 0.5);
background: rgba(30, 66, 128, 0.6);
}
.delete-button--danger {
background: linear-gradient(180deg, #ff8b84 0%, #e15b55 100%);
box-shadow:
0 14px 30px rgba(225, 91, 85, 0.28),
0 0 26px rgba(255, 110, 100, 0.16),
inset 0 1px 0 rgba(255, 255, 255, 0.4);
color: #2a0806;
}
.delete-button--danger:hover:not(:disabled) {
box-shadow:
0 18px 38px rgba(225, 91, 85, 0.36),
0 0 34px rgba(255, 110, 100, 0.26),
inset 0 1px 0 rgba(255, 255, 255, 0.45);
transform: translateY(-2px);
}
.delete-modal-enter-active,
.delete-modal-leave-active {
transition: opacity 0.24s ease;
}
.delete-modal-enter-active .delete-card,
.delete-modal-leave-active .delete-card {
transition: transform 0.24s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.24s ease;
}
.delete-modal-enter-from,
.delete-modal-leave-to {
opacity: 0;
}
.delete-modal-enter-from .delete-card,
.delete-modal-leave-to .delete-card {
opacity: 0;
transform: translateY(16px) scale(0.97);
}
</style>