Files
SpectraElement/Hardware-Vue/src/views/ResultView.vue
T
2026-11-19 16:42:26 +08:00

960 lines
23 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.
<script setup lang="ts">
import { computed, onBeforeUnmount, onMounted, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import AppStage from '@/components/AppStage.vue'
import PageHeader from '@/components/PageHeader.vue'
import SpectrumChart from '@/components/SpectrumChart.vue'
import { getLatestScan, getScan, type ScanRun } from '@/api/scan'
import { useCountdown } from '@/composables/useCountdown'
import { showToast } from '@/composables/useToast'
const router = useRouter()
const route = useRoute()
/** 从管理员“查看历史”进入时复用本页,作为只读详情展示。 */
const isHistoryMode = route.name === 'historyDetail'
const run = ref<ScanRun | null>(null)
const loading = ref(true)
const loadError = ref('')
const selectedIndex = ref(0)
const viewport = ref<HTMLElement | null>(null)
const imageWidth = ref(0)
const imageHeight = ref(0)
const overlayRect = ref({ left: 0, top: 0, width: 0, height: 0 })
let resizeObserver: ResizeObserver | null = null
function goHome() {
void router.replace({ name: 'home' })
}
function goHistory() {
void router.replace({ name: 'history' })
}
const { remaining } = useCountdown(60, goHome, !isHistoryMode)
const targetScanId = computed(() => {
const raw = isHistoryMode ? route.params.scanId : route.query.scanId
return typeof raw === 'string' ? raw : ''
})
const imageUrl = computed(() =>
run.value?.imageBase64
? `data:${run.value.imageMimeType ?? 'image/jpeg'};base64,${run.value.imageBase64}`
: '',
)
const selectedPoint = computed(
() => run.value?.points[selectedIndex.value] ?? null,
)
const statusText = computed(() => {
switch (run.value?.status) {
case 'Completed':
return '检测完成'
case 'Failed':
return '检测失败'
case 'Aborted':
return '流程已中止'
default:
return '检测结果'
}
})
const statusTone = computed(() => {
switch (run.value?.status) {
case 'Completed':
return 'is-completed'
case 'Failed':
return 'is-failed'
case 'Aborted':
return 'is-aborted'
default:
return ''
}
})
const chartLabels = computed(() =>
(selectedPoint.value?.elements ?? [])
.filter((element) => element.matchedWavelength > 0)
.slice()
.sort((left, right) => right.maxIntensity - left.maxIntensity)
.slice(0, 3)
.map((element) => ({
element: element.symbol,
wavelength: element.matchedWavelength,
})),
)
const overlayStyle = computed(() => ({
left: `${overlayRect.value.left}px`,
top: `${overlayRect.value.top}px`,
width: `${overlayRect.value.width}px`,
height: `${overlayRect.value.height}px`,
}))
const markerRadius = computed(() => Math.max(8, imageWidth.value * 0.008))
function updateOverlayRect() {
const element = viewport.value
if (!element || !imageWidth.value || !imageHeight.value) return
const viewWidth = element.clientWidth
const viewHeight = element.clientHeight
if (!viewWidth || !viewHeight) return
const aspect = imageWidth.value / imageHeight.value
let width = viewWidth
let height = viewHeight
if (viewWidth / viewHeight > aspect) {
width = viewHeight * aspect
} else {
height = viewWidth / aspect
}
overlayRect.value = {
left: (viewWidth - width) / 2,
top: (viewHeight - height) / 2,
width,
height,
}
}
function onImageLoad(event: Event) {
const image = event.target as HTMLImageElement
if (run.value?.imageWidth && run.value?.imageHeight) {
imageWidth.value = run.value.imageWidth
imageHeight.value = run.value.imageHeight
} else {
imageWidth.value = image.naturalWidth
imageHeight.value = image.naturalHeight
}
updateOverlayRect()
}
function selectPoint(index: number) {
selectedIndex.value = index
}
async function loadResult() {
loading.value = true
loadError.value = ''
try {
run.value = targetScanId.value
? await getScan(targetScanId.value)
: await getLatestScan()
selectedIndex.value = 0
} catch (error) {
loadError.value =
error instanceof Error ? error.message : '读取检测结果失败'
} finally {
loading.value = false
}
}
function exportReport() {
showToast('报告导出功能正在研发中')
}
onMounted(async () => {
await loadResult()
resizeObserver = new ResizeObserver(() => updateOverlayRect())
if (viewport.value) {
resizeObserver.observe(viewport.value)
}
})
onBeforeUnmount(() => {
resizeObserver?.disconnect()
resizeObserver = null
})
</script>
<template>
<AppStage>
<div class="result-bg" aria-hidden="true">
<span class="result-bg__orb result-bg__orb--blue"></span>
<span class="result-bg__orb result-bg__orb--cyan"></span>
<span class="result-bg__orb result-bg__orb--violet"></span>
</div>
<PageHeader
:title="isHistoryMode ? '历史检测详情' : '检测完成'"
:subtitle="isHistoryMode ? '查看已保存的扫描记录' : undefined"
variant="result"
theme="dark"
>
<template #left>
<button
v-if="isHistoryMode"
class="detail-back"
type="button"
@click="goHistory"
>
返回列表
</button>
</template>
</PageHeader>
<main class="result-main">
<section class="image-card">
<header class="image-card__header">
<h2>靶面图与采样点</h2>
<span class="image-card__status" :class="statusTone">{{ statusText }}</span>
</header>
<div ref="viewport" class="image-viewport">
<img
v-if="imageUrl"
class="image-viewport__image"
:src="imageUrl"
alt="靶面图与采样点"
@load="onImageLoad"
/>
<svg
v-if="imageUrl && imageWidth && imageHeight"
class="image-overlay"
:style="overlayStyle"
:viewBox="`0 0 ${imageWidth} ${imageHeight}`"
preserveAspectRatio="none"
>
<g
v-for="point in run?.points ?? []"
:key="point.index"
class="point-marker"
:class="{ 'point-marker--active': point.index === selectedIndex }"
@click="selectPoint(point.index)"
>
<circle
:cx="point.pixelX"
:cy="point.pixelY"
:r="markerRadius"
class="point-marker__dot"
/>
<circle
v-if="point.index === selectedIndex"
:cx="point.pixelX"
:cy="point.pixelY"
:r="markerRadius * 1.9"
class="point-marker__ring"
/>
<text
:x="point.pixelX + markerRadius * 1.2"
:y="point.pixelY - markerRadius * 1.2"
class="point-marker__label"
:font-size="markerRadius * 1.4"
>
{{ point.index + 1 }}
</text>
</g>
</svg>
<p v-if="loading" class="image-viewport__tip">正在读取检测结果...</p>
<p v-else-if="loadError" class="image-viewport__tip">{{ loadError }}</p>
<p v-else-if="!imageUrl" class="image-viewport__tip">本次扫描没有保存靶面图</p>
</div>
<footer class="point-tabs">
<button
v-for="point in run?.points ?? []"
:key="point.index"
class="point-tab"
:class="{
'point-tab--active': point.index === selectedIndex,
'point-tab--error': Boolean(point.error),
}"
type="button"
@click="selectPoint(point.index)"
>
<span class="point-tab__index">{{ point.index + 1 }}</span>
<span class="point-tab__coord">{{ point.stageX }}, {{ point.stageY }} mm</span>
</button>
<span v-if="!(run?.points?.length)" class="point-tabs__empty">
没有采样点数据
</span>
</footer>
</section>
<aside class="detail-card">
<header class="detail-card__header">
<h2>采样点 {{ selectedPoint ? selectedPoint.index + 1 : '—' }} 元素分析</h2>
<span class="detail-card__count">
{{ selectedPoint?.elements.length ?? 0 }} 种元素
</span>
</header>
<div class="detail-card__body">
<p v-if="loading" class="detail-tip">加载中...</p>
<p v-else-if="loadError" class="detail-tip detail-tip--error">{{ loadError }}</p>
<p v-else-if="!selectedPoint" class="detail-tip">没有可显示的采样点</p>
<template v-else>
<p v-if="selectedPoint.error" class="point-error">
{{ selectedPoint.error }}
</p>
<div v-if="selectedPoint.elements.length" class="element-table-wrap">
<table class="element-table">
<thead>
<tr>
<th>元素</th>
<th>强度</th>
<th>含量</th>
<th>判定</th>
</tr>
</thead>
<tbody>
<tr v-for="element in selectedPoint.elements" :key="element.symbol">
<td class="element-table__element">
{{ element.symbol }}
<small>{{ element.name }}</small>
</td>
<td>{{ element.intensityLevel }}</td>
<td>{{ element.abundance.toFixed(3) }}%</td>
<td>
<span
class="verdict"
:class="element.verdict === '检出' ? 'verdict--detected' : 'verdict--trace'"
>
{{ element.verdict }}
</span>
</td>
</tr>
</tbody>
</table>
</div>
<p v-else class="detail-tip">该采样点未检出元素</p>
<div
v-if="selectedPoint.temperature > 0"
class="plasma-stats"
>
<span>等离子体温度 {{ selectedPoint.temperature.toExponential(2) }} K</span>
<span>电子密度 {{ selectedPoint.electronDensity.toExponential(2) }} cm⁻³</span>
</div>
<SpectrumChart
class="detail-spectrum"
:wavelengths="selectedPoint.wavelengths"
:spectrum="selectedPoint.spectrum"
:segments="selectedPoint.segments"
:labels="chartLabels"
compact
/>
</template>
</div>
</aside>
</main>
<div class="result-actions">
<p v-if="!isHistoryMode" class="result-actions__countdown">
当前界面还有 <strong>{{ remaining }}</strong>s 后自动关闭...
</p>
<p v-else class="result-actions__hint">
历史记录仅供查看,不会影响当前检测流程
</p>
<div class="result-actions__buttons">
<button
class="result-button result-button--close"
type="button"
@click="isHistoryMode ? goHistory() : goHome()"
>
{{ isHistoryMode ? '返回列表' : '关闭' }}
</button>
<button class="result-button result-button--export" type="button" @click="exportReport">
导出报告
</button>
</div>
</div>
</AppStage>
</template>
<style scoped>
.result-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%);
}
.result-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%);
}
.result-bg__orb {
position: absolute;
border-radius: 50%;
filter: blur(100px);
animation: result-orb-drift 16s ease-in-out infinite alternate;
}
.result-bg__orb--blue {
top: -340px;
left: -160px;
width: 760px;
height: 760px;
background: rgba(48, 118, 255, 0.3);
}
.result-bg__orb--cyan {
top: -200px;
right: -220px;
width: 640px;
height: 640px;
background: rgba(0, 214, 255, 0.18);
animation-delay: -5s;
}
.result-bg__orb--violet {
bottom: -360px;
left: 36%;
width: 700px;
height: 700px;
background: rgba(124, 92, 255, 0.18);
animation-delay: -10s;
}
@keyframes result-orb-drift {
from {
transform: translate3d(0, 0, 0) scale(1);
}
to {
transform: translate3d(42px, 30px, 0) scale(1.08);
}
}
.detail-back {
width: 180px;
height: 56px;
border: 1px solid rgba(130, 190, 255, 0.35);
border-radius: 12px;
background: rgba(18, 40, 78, 0.5);
color: #bcd9ff;
font-size: 20px;
font-weight: 600;
letter-spacing: 2px;
backdrop-filter: blur(10px);
transition:
transform 0.2s ease,
border-color 0.2s ease,
background 0.2s ease;
}
.detail-back:hover {
border-color: rgba(150, 205, 255, 0.55);
background: rgba(30, 66, 128, 0.65);
transform: translateY(-1px);
}
.result-main {
position: absolute;
top: 146px;
right: 44px;
left: 44px;
display: grid;
grid-template-columns: 860px minmax(0, 1fr);
gap: 24px;
height: 792px;
}
.image-card {
position: relative;
display: flex;
flex-direction: column;
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);
}
.image-card__header {
display: flex;
flex: none;
align-items: center;
justify-content: space-between;
height: 72px;
padding: 0 28px;
border-bottom: 1px solid rgba(130, 175, 255, 0.12);
background: linear-gradient(120deg, rgba(26, 58, 112, 0.85) 0%, rgba(10, 24, 52, 0.8) 100%);
}
.image-card__header h2 {
display: flex;
align-items: center;
gap: 12px;
color: #eef5ff;
font-size: 28px;
font-weight: 600;
letter-spacing: 3px;
text-shadow: 0 0 22px rgba(80, 150, 255, 0.3);
}
.image-card__header h2::before {
content: '';
width: 4px;
height: 24px;
border-radius: 4px;
background: linear-gradient(180deg, #7fe0ff, #4d8bf0);
box-shadow: 0 0 14px rgba(90, 170, 255, 0.7);
}
.image-card__status {
padding: 6px 16px;
border: 1px solid rgba(130, 195, 255, 0.3);
border-radius: 30px;
background: rgba(16, 40, 80, 0.5);
color: #9fe8ff;
font-size: 17px;
letter-spacing: 1px;
}
.image-card__status.is-completed {
border-color: rgba(116, 244, 197, 0.35);
background: rgba(14, 60, 56, 0.45);
color: #8ff5e7;
}
.image-card__status.is-failed {
border-color: rgba(255, 120, 120, 0.35);
background: rgba(60, 20, 26, 0.45);
color: #ff9d9d;
}
.image-card__status.is-aborted {
border-color: rgba(255, 216, 106, 0.35);
background: rgba(60, 46, 12, 0.45);
color: #ffd98a;
}
.image-viewport {
position: relative;
flex: 1;
min-height: 0;
overflow: hidden;
background: #040810;
}
.image-viewport__image {
width: 100%;
height: 100%;
object-fit: contain;
}
.image-overlay {
position: absolute;
touch-action: none;
}
.point-marker {
cursor: pointer;
}
.point-marker__dot {
fill: rgba(116, 241, 223, 0.9);
stroke: rgba(8, 13, 20, 0.7);
stroke-width: 2;
}
.point-marker--active .point-marker__dot {
fill: #ffd166;
}
.point-marker__ring {
fill: none;
stroke: #ffffff;
stroke-width: 2.5;
stroke-dasharray: 6 5;
}
.point-marker__label {
fill: #ffffff;
font-weight: 600;
paint-order: stroke;
stroke: rgba(8, 13, 20, 0.75);
stroke-width: 2;
}
.image-viewport__tip {
position: absolute;
top: 50%;
left: 50%;
max-width: 80%;
color: rgba(216, 228, 243, 0.75);
font-size: 20px;
letter-spacing: 2px;
text-align: center;
transform: translate(-50%, -50%);
}
.point-tabs {
display: flex;
flex: none;
flex-wrap: wrap;
gap: 10px;
align-items: center;
min-height: 82px;
padding: 12px 20px;
border-top: 1px solid rgba(130, 175, 255, 0.12);
background: rgba(8, 18, 38, 0.6);
}
.point-tab {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 2px;
min-width: 118px;
padding: 8px 14px;
border: 1px solid rgba(130, 175, 255, 0.16);
border-radius: 12px;
background: rgba(12, 26, 50, 0.6);
color: rgba(210, 228, 250, 0.85);
cursor: pointer;
transition:
border-color 0.2s ease,
background 0.2s ease,
transform 0.2s ease,
box-shadow 0.2s ease;
}
.point-tab:hover {
border-color: rgba(150, 205, 255, 0.4);
transform: translateY(-1px);
}
.point-tab--active {
border-color: rgba(120, 200, 255, 0.55);
background: rgba(70, 140, 255, 0.2);
box-shadow: 0 0 20px rgba(70, 140, 255, 0.18);
color: #f2f8ff;
}
.point-tab--error {
border-color: rgba(255, 120, 120, 0.35);
background: rgba(60, 20, 26, 0.4);
color: #ffb4b4;
}
.point-tab__index {
font-size: 20px;
font-weight: 600;
}
.point-tab__coord {
color: rgba(158, 190, 226, 0.6);
font-size: 14px;
}
.point-tabs__empty {
color: rgba(158, 190, 226, 0.55);
font-size: 17px;
}
.detail-card {
position: relative;
display: flex;
flex-direction: column;
overflow: hidden;
border: 1px solid rgba(130, 175, 255, 0.16);
border-radius: 26px;
background: linear-gradient(
158deg,
rgba(255, 255, 255, 0.07) 0%,
rgba(255, 255, 255, 0.025) 58%,
rgba(255, 255, 255, 0.04) 100%
);
box-shadow:
0 30px 70px rgba(0, 10, 32, 0.45),
inset 0 1px 0 rgba(255, 255, 255, 0.08);
backdrop-filter: blur(16px);
}
.detail-card::before {
content: '';
position: absolute;
top: 0;
right: 32px;
left: 32px;
height: 1px;
background: linear-gradient(90deg, transparent, rgba(120, 180, 255, 0.55), transparent);
pointer-events: none;
}
.detail-card__header {
display: flex;
flex: none;
align-items: center;
justify-content: space-between;
height: 72px;
padding: 0 24px;
border-bottom: 1px solid rgba(130, 175, 255, 0.12);
background: linear-gradient(120deg, rgba(30, 66, 128, 0.24) 0%, transparent 70%);
}
.detail-card__header h2 {
display: flex;
align-items: center;
gap: 12px;
color: #eaf3ff;
font-size: 25px;
font-weight: 600;
letter-spacing: 2px;
}
.detail-card__header h2::before {
content: '';
width: 4px;
height: 22px;
border-radius: 4px;
background: linear-gradient(180deg, #7fe0ff, #4d8bf0);
box-shadow: 0 0 14px rgba(90, 170, 255, 0.7);
}
.detail-card__count {
padding: 5px 14px;
border: 1px solid rgba(130, 195, 255, 0.28);
border-radius: 30px;
background: rgba(16, 40, 80, 0.5);
color: #9fe8ff;
font-size: 17px;
}
.detail-card__body {
display: flex;
flex: 1;
min-height: 0;
flex-direction: column;
padding: 16px 20px 20px;
}
.detail-tip {
margin: 20px 0;
color: rgba(158, 190, 226, 0.6);
font-size: 18px;
text-align: center;
}
.detail-tip--error {
color: #ff9d9d;
}
.point-error {
margin-bottom: 12px;
padding: 10px 14px;
border: 1px solid rgba(255, 120, 120, 0.3);
border-radius: 10px;
background: rgba(60, 20, 26, 0.4);
color: #ffb4b4;
font-size: 16px;
line-height: 1.5;
}
.element-table-wrap {
flex: 1;
min-height: 0;
margin-right: -6px;
padding-right: 6px;
overflow-y: auto;
}
.element-table-wrap::-webkit-scrollbar {
width: 6px;
}
.element-table-wrap::-webkit-scrollbar-thumb {
border-radius: 3px;
background: rgba(130, 175, 255, 0.25);
}
.element-table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
}
.element-table th {
height: 44px;
border-bottom: 1px solid rgba(130, 175, 255, 0.14);
color: rgba(158, 190, 226, 0.66);
font-size: 18px;
font-weight: 500;
text-align: center;
}
.element-table td {
height: 52px;
border-bottom: 1px solid rgba(130, 175, 255, 0.08);
color: rgba(226, 240, 255, 0.9);
font-size: 19px;
text-align: center;
}
.element-table__element {
color: #f2f8ff;
font-weight: 600;
}
.element-table__element small {
margin-left: 4px;
color: rgba(158, 190, 226, 0.55);
font-size: 14px;
font-weight: 400;
}
.verdict {
display: inline-block;
min-width: 58px;
padding: 3px 10px;
border: 1px solid transparent;
border-radius: 20px;
font-size: 16px;
}
.verdict--detected {
border-color: rgba(116, 244, 197, 0.28);
background: rgba(30, 120, 90, 0.22);
color: #8ff5d2;
}
.verdict--trace {
border-color: rgba(255, 216, 106, 0.26);
background: rgba(120, 86, 20, 0.24);
color: #ffd98a;
}
.plasma-stats {
display: flex;
flex-wrap: wrap;
gap: 8px 22px;
margin-top: 12px;
color: rgba(158, 190, 226, 0.6);
font-size: 14px;
}
.element-table thead {
position: sticky;
top: 0;
z-index: 1;
background: #0b1830;
}
.detail-spectrum {
flex: none;
height: 380px;
margin-top: 12px;
border-radius: 16px;
}
.result-actions {
position: absolute;
right: 44px;
bottom: 48px;
left: 44px;
display: flex;
align-items: center;
justify-content: space-between;
}
.result-actions__countdown {
color: rgba(190, 212, 238, 0.78);
font-size: 27px;
letter-spacing: 1px;
}
.result-actions__hint {
color: rgba(158, 190, 226, 0.6);
font-size: 20px;
letter-spacing: 1px;
}
.result-actions__countdown strong {
color: #ffd166;
font-size: 32px;
font-weight: 700;
text-shadow: 0 0 18px rgba(255, 190, 60, 0.35);
}
.result-actions__buttons {
display: flex;
gap: 22px;
}
.result-button {
display: grid;
place-items: center;
width: 208px;
height: 70px;
border-radius: 14px;
font-size: 29px;
font-weight: 600;
letter-spacing: 5px;
transition:
transform 0.2s ease,
box-shadow 0.2s ease,
background 0.2s ease,
border-color 0.2s ease;
}
.result-button:hover {
transform: translateY(-2px);
}
.result-button--close {
background: linear-gradient(180deg, #ffd166 0%, #f0ac0b 100%);
box-shadow:
0 16px 34px rgba(240, 172, 11, 0.28),
0 0 28px rgba(255, 190, 60, 0.18),
inset 0 1px 0 rgba(255, 255, 255, 0.6);
color: #241500;
text-shadow: 0 1px 1px rgba(255, 255, 255, 0.25);
}
.result-button--close:hover {
box-shadow:
0 20px 42px rgba(240, 172, 11, 0.36),
0 0 36px rgba(255, 190, 60, 0.28),
inset 0 1px 0 rgba(255, 255, 255, 0.6);
}
.result-button--export {
border: 1px solid rgba(255, 205, 100, 0.35);
background: linear-gradient(120deg, rgba(255, 186, 40, 0.14), rgba(255, 150, 20, 0.05));
color: #ffd98a;
backdrop-filter: blur(10px);
}
.result-button--export:hover {
border-color: rgba(255, 205, 100, 0.55);
background: linear-gradient(120deg, rgba(255, 186, 40, 0.22), rgba(255, 150, 20, 0.08));
}
</style>