675 lines
17 KiB
Vue
675 lines
17 KiB
Vue
<script setup lang="ts">
|
||
import { computed, onBeforeUnmount, onMounted, ref, watch } 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 ProgressStrip from '@/components/ProgressStrip.vue'
|
||
import StatusFooter from '@/components/StatusFooter.vue'
|
||
import { abortScan, getCurrentScan, type ScanProgress } from '@/api/scan'
|
||
import { useStageHub } from '@/composables/useStageHub'
|
||
import { showToast } from '@/composables/useToast'
|
||
|
||
const router = useRouter()
|
||
const route = useRoute()
|
||
|
||
const queryScanId = computed(() => {
|
||
const raw = route.query.scanId
|
||
return typeof raw === 'string' ? raw : ''
|
||
})
|
||
|
||
const activeScanId = ref(queryScanId.value)
|
||
const fallbackProgress = ref<ScanProgress | null>(null)
|
||
|
||
const {
|
||
position,
|
||
progress: hubProgress,
|
||
spectrum: liveSpectrum,
|
||
finished,
|
||
connect,
|
||
} = useStageHub()
|
||
|
||
const progress = computed(() => hubProgress.value ?? fallbackProgress.value)
|
||
|
||
const phaseText = computed(() => mapPhase(progress.value?.phase))
|
||
|
||
const percent = computed(() => progress.value?.percent ?? 0)
|
||
const progressLabel = computed(() => `光谱采集 ${percent.value}%`)
|
||
const progressNote = computed(
|
||
() => progress.value?.message ?? '等待扫描开始',
|
||
)
|
||
|
||
const chartWavelengths = computed(() => liveSpectrum.value?.wavelengths ?? [])
|
||
const chartSpectrum = computed(() => liveSpectrum.value?.spectrum ?? [])
|
||
const chartSegments = computed(() => liveSpectrum.value?.segments ?? [])
|
||
|
||
const chartStatus = computed(() => {
|
||
if (progress.value?.phase === 'Acquiring') return '正在采集光谱'
|
||
if (liveSpectrum.value) {
|
||
return `第 ${liveSpectrum.value.pointIndex + 1} 点光谱`
|
||
}
|
||
return '等待光谱数据'
|
||
})
|
||
|
||
const activeStep = computed(() => {
|
||
switch (progress.value?.phase) {
|
||
case 'Homing':
|
||
case 'Moving':
|
||
case 'Returning':
|
||
return 'move'
|
||
case 'Focusing':
|
||
return 'focus'
|
||
case 'Acquiring':
|
||
return 'acquire'
|
||
case 'Analyzing':
|
||
case 'Writing':
|
||
return 'analyze'
|
||
case 'Completed':
|
||
return 'done'
|
||
default:
|
||
return ''
|
||
}
|
||
})
|
||
|
||
const stepOrder = ['move', 'focus', 'acquire', 'analyze'] as const
|
||
|
||
function stepState(key: (typeof stepOrder)[number]) {
|
||
const active = activeStep.value
|
||
if (active === 'done') return 'done'
|
||
if (!active) return ''
|
||
|
||
const activeIndex = stepOrder.indexOf(active as (typeof stepOrder)[number])
|
||
const index = stepOrder.indexOf(key)
|
||
|
||
if (index < activeIndex) return 'done'
|
||
if (index === activeIndex) return 'active'
|
||
return ''
|
||
}
|
||
|
||
const footerItems = computed(() => [
|
||
position.value
|
||
? `X ${position.value.x} mm / Y ${position.value.y} mm`
|
||
: '位移台未连接',
|
||
phaseText.value,
|
||
progress.value
|
||
? `采样点 ${Math.min(progress.value.completedPoints, progress.value.totalPoints)} / ${progress.value.totalPoints}`
|
||
: '等待开始',
|
||
])
|
||
|
||
let pollTimer: number | undefined
|
||
let navigated = false
|
||
|
||
function mapPhase(phase?: string) {
|
||
switch (phase) {
|
||
case 'Idle':
|
||
return '准备中'
|
||
case 'Homing':
|
||
return '位移台回零'
|
||
case 'Moving':
|
||
return '位移台移动'
|
||
case 'Focusing':
|
||
return '对焦中'
|
||
case 'Acquiring':
|
||
return '收光中'
|
||
case 'Returning':
|
||
return '位移台回零'
|
||
case 'Analyzing':
|
||
return 'NIST 分析中'
|
||
case 'Writing':
|
||
return '写入数据库'
|
||
case 'Completed':
|
||
return '采集完成'
|
||
case 'Aborted':
|
||
return '已中止'
|
||
case 'Failed':
|
||
return '采集失败'
|
||
default:
|
||
return '等待开始'
|
||
}
|
||
}
|
||
|
||
function goResult(scanId: string) {
|
||
if (navigated) return
|
||
navigated = true
|
||
void router.replace({
|
||
name: 'result',
|
||
query: { scanId },
|
||
})
|
||
}
|
||
|
||
function goHomeWithToast(message?: string) {
|
||
if (navigated) return
|
||
navigated = true
|
||
if (message) showToast(message)
|
||
void router.replace({ name: 'home' })
|
||
}
|
||
|
||
async function abortProcess() {
|
||
try {
|
||
await abortScan()
|
||
} catch (error) {
|
||
showToast(error instanceof Error ? error.message : '中止扫描失败')
|
||
}
|
||
|
||
goHomeWithToast()
|
||
}
|
||
|
||
async function poll() {
|
||
try {
|
||
const current = await getCurrentScan()
|
||
fallbackProgress.value = current
|
||
|
||
if (!activeScanId.value && current.scanId) {
|
||
activeScanId.value = current.scanId
|
||
}
|
||
|
||
if (!activeScanId.value && current.phase === 'Idle') {
|
||
goHomeWithToast()
|
||
return
|
||
}
|
||
|
||
if (current.phase === 'Completed' && current.scanId) {
|
||
goResult(current.scanId)
|
||
return
|
||
}
|
||
|
||
if (current.phase === 'Aborted' || current.phase === 'Failed') {
|
||
goHomeWithToast(current.message || '扫描已结束')
|
||
}
|
||
} catch {
|
||
// 轮询失败时保留 SignalR 推送的状态
|
||
}
|
||
}
|
||
|
||
watch(finished, (value) => {
|
||
if (!value) return
|
||
|
||
if (value.status === 'Completed') {
|
||
goResult(value.scanId || activeScanId.value)
|
||
return
|
||
}
|
||
|
||
goHomeWithToast(value.error ?? '扫描已中止')
|
||
})
|
||
|
||
onMounted(() => {
|
||
void connect()
|
||
void poll()
|
||
pollTimer = window.setInterval(poll, 2000)
|
||
})
|
||
|
||
onBeforeUnmount(() => {
|
||
if (pollTimer !== undefined) {
|
||
window.clearInterval(pollTimer)
|
||
pollTimer = undefined
|
||
}
|
||
})
|
||
</script>
|
||
|
||
<template>
|
||
<AppStage>
|
||
<div class="spectrum-bg" aria-hidden="true">
|
||
<span class="spectrum-bg__orb spectrum-bg__orb--blue"></span>
|
||
<span class="spectrum-bg__orb spectrum-bg__orb--cyan"></span>
|
||
<span class="spectrum-bg__orb spectrum-bg__orb--violet"></span>
|
||
</div>
|
||
|
||
<PageHeader title="光谱数据采集与分析" variant="process" theme="dark">
|
||
<template #left>
|
||
<button class="spectrum-abort" type="button" @click="abortProcess">
|
||
中止流程
|
||
</button>
|
||
</template>
|
||
</PageHeader>
|
||
|
||
<main class="spectrum-main">
|
||
<SpectrumChart
|
||
class="spectrum-chart"
|
||
:wavelengths="chartWavelengths"
|
||
:spectrum="chartSpectrum"
|
||
:segments="chartSegments"
|
||
:status-text="chartStatus"
|
||
/>
|
||
|
||
<aside class="analysis-card">
|
||
<header class="analysis-card__header">
|
||
<div class="analysis-card__heading">
|
||
<span class="analysis-card__eyebrow">Scan Steps</span>
|
||
<h2>扫描步骤</h2>
|
||
</div>
|
||
</header>
|
||
|
||
<div class="analysis-card__body">
|
||
<div
|
||
class="analysis-step"
|
||
:class="{
|
||
'analysis-step--active': stepState('move') === 'active',
|
||
'analysis-step--done': stepState('move') === 'done',
|
||
}"
|
||
>
|
||
<span class="analysis-step__icon analysis-step__icon--blue">
|
||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||
<path d="M4 12h16M4 12l4-4M4 12l4 4M20 12l-4-4M20 12l-4 4" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" />
|
||
</svg>
|
||
</span>
|
||
<span class="analysis-step__text">位移台移动</span>
|
||
<span class="analysis-step__chevron">›</span>
|
||
</div>
|
||
|
||
<div
|
||
class="analysis-step"
|
||
:class="{
|
||
'analysis-step--active': stepState('focus') === 'active',
|
||
'analysis-step--done': stepState('focus') === 'done',
|
||
}"
|
||
>
|
||
<span class="analysis-step__icon analysis-step__icon--amber">
|
||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||
<circle cx="12" cy="12" r="7" fill="none" stroke="currentColor" stroke-width="1.6" />
|
||
<path d="M12 2v4M12 18v4M2 12h4M18 12h4" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" />
|
||
</svg>
|
||
</span>
|
||
<span class="analysis-step__text">单次对焦</span>
|
||
<span class="analysis-step__chevron">›</span>
|
||
</div>
|
||
|
||
<div
|
||
class="analysis-step"
|
||
:class="{
|
||
'analysis-step--active': stepState('acquire') === 'active',
|
||
'analysis-step--done': stepState('acquire') === 'done',
|
||
}"
|
||
>
|
||
<span class="analysis-step__icon analysis-step__icon--blue">
|
||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||
<path d="M3 14l3-6 3 10 3-14 3 12 3-8 3 6" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" stroke-linejoin="round" />
|
||
</svg>
|
||
</span>
|
||
<span class="analysis-step__text">光谱仪收光</span>
|
||
<span class="analysis-step__chevron">›</span>
|
||
</div>
|
||
|
||
<div
|
||
class="analysis-step"
|
||
:class="{
|
||
'analysis-step--active': stepState('analyze') === 'active',
|
||
'analysis-step--done': stepState('analyze') === 'done',
|
||
}"
|
||
>
|
||
<span class="analysis-step__icon analysis-step__icon--amber">
|
||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||
<rect x="6" y="4" width="12" height="16" rx="2" fill="none" stroke="currentColor" stroke-width="1.6" />
|
||
<path d="M9 8h6M9 11h6M9 14h3" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" />
|
||
</svg>
|
||
</span>
|
||
<span class="analysis-step__text">NIST 元素分析</span>
|
||
<span class="analysis-step__chevron">›</span>
|
||
</div>
|
||
|
||
<div class="analysis-position">
|
||
<span class="analysis-position__label">当前位置</span>
|
||
<span class="analysis-position__value">
|
||
X {{ position ? position.x : '—' }} / Y {{ position ? position.y : '—' }}
|
||
<small>mm</small>
|
||
</span>
|
||
</div>
|
||
|
||
<div class="analysis-hint">
|
||
<span class="analysis-hint__mark">i</span>
|
||
<p>扫描过程中请勿打开样品仓或触碰位移台,以免影响点位与光谱数据。</p>
|
||
</div>
|
||
</div>
|
||
</aside>
|
||
</main>
|
||
|
||
<div class="spectrum-progress">
|
||
<ProgressStrip
|
||
:progress="percent"
|
||
:label="progressLabel"
|
||
:note="progressNote"
|
||
theme="dark"
|
||
/>
|
||
</div>
|
||
|
||
<StatusFooter icon="laser" :items="footerItems" theme="dark" />
|
||
</AppStage>
|
||
</template>
|
||
|
||
<style scoped>
|
||
.spectrum-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%);
|
||
}
|
||
|
||
.spectrum-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%);
|
||
}
|
||
|
||
.spectrum-bg__orb {
|
||
position: absolute;
|
||
border-radius: 50%;
|
||
filter: blur(100px);
|
||
animation: spectrum-orb-drift 16s ease-in-out infinite alternate;
|
||
}
|
||
|
||
.spectrum-bg__orb--blue {
|
||
top: -340px;
|
||
left: -160px;
|
||
width: 760px;
|
||
height: 760px;
|
||
background: rgba(48, 118, 255, 0.3);
|
||
}
|
||
|
||
.spectrum-bg__orb--cyan {
|
||
top: -200px;
|
||
right: -220px;
|
||
width: 640px;
|
||
height: 640px;
|
||
background: rgba(0, 214, 255, 0.18);
|
||
animation-delay: -5s;
|
||
}
|
||
|
||
.spectrum-bg__orb--violet {
|
||
bottom: -360px;
|
||
left: 36%;
|
||
width: 700px;
|
||
height: 700px;
|
||
background: rgba(124, 92, 255, 0.18);
|
||
animation-delay: -10s;
|
||
}
|
||
|
||
@keyframes spectrum-orb-drift {
|
||
from {
|
||
transform: translate3d(0, 0, 0) scale(1);
|
||
}
|
||
|
||
to {
|
||
transform: translate3d(42px, 30px, 0) scale(1.08);
|
||
}
|
||
}
|
||
|
||
.spectrum-abort {
|
||
width: 300px;
|
||
height: 68px;
|
||
border: 1px solid rgba(255, 190, 60, 0.45);
|
||
border-radius: 14px;
|
||
background: linear-gradient(120deg, rgba(255, 186, 40, 0.18), rgba(255, 150, 20, 0.06));
|
||
color: #ffd98a;
|
||
font-size: 26px;
|
||
font-weight: 600;
|
||
letter-spacing: 3px;
|
||
backdrop-filter: blur(10px);
|
||
transition:
|
||
transform 0.2s ease,
|
||
border-color 0.2s ease,
|
||
background 0.2s ease;
|
||
}
|
||
|
||
.spectrum-abort:hover {
|
||
border-color: rgba(255, 205, 100, 0.65);
|
||
background: linear-gradient(120deg, rgba(255, 186, 40, 0.26), rgba(255, 150, 20, 0.1));
|
||
transform: translateY(-1px);
|
||
}
|
||
|
||
.spectrum-main {
|
||
position: absolute;
|
||
top: 142px;
|
||
right: 44px;
|
||
left: 44px;
|
||
display: grid;
|
||
grid-template-columns: minmax(0, 1fr) 342px;
|
||
gap: 20px;
|
||
height: 730px;
|
||
}
|
||
|
||
.spectrum-chart {
|
||
min-width: 0;
|
||
}
|
||
|
||
.analysis-card {
|
||
position: relative;
|
||
display: flex;
|
||
flex-direction: column;
|
||
height: 100%;
|
||
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);
|
||
}
|
||
|
||
.analysis-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;
|
||
}
|
||
|
||
.analysis-card__header {
|
||
display: flex;
|
||
flex: none;
|
||
align-items: center;
|
||
height: 96px;
|
||
padding: 0 26px;
|
||
border-bottom: 1px solid rgba(130, 175, 255, 0.12);
|
||
background: linear-gradient(120deg, rgba(30, 66, 128, 0.24) 0%, transparent 70%);
|
||
}
|
||
|
||
.analysis-card__heading {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 6px;
|
||
}
|
||
|
||
.analysis-card__eyebrow {
|
||
color: #5aa2ff;
|
||
font-size: 12px;
|
||
font-weight: 600;
|
||
letter-spacing: 2.6px;
|
||
text-transform: uppercase;
|
||
}
|
||
|
||
.analysis-card__header h2 {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
color: #eaf3ff;
|
||
font-size: 26px;
|
||
font-weight: 600;
|
||
letter-spacing: 2px;
|
||
}
|
||
|
||
.analysis-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);
|
||
}
|
||
|
||
.analysis-card__body {
|
||
display: flex;
|
||
flex: 1;
|
||
flex-direction: column;
|
||
padding: 18px;
|
||
}
|
||
|
||
.analysis-step {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 16px;
|
||
height: 78px;
|
||
padding: 0 14px;
|
||
border: 1px solid transparent;
|
||
border-radius: 14px;
|
||
opacity: 0.45;
|
||
transition:
|
||
opacity 0.2s ease,
|
||
background 0.2s ease,
|
||
border-color 0.2s ease,
|
||
box-shadow 0.2s ease;
|
||
}
|
||
|
||
.analysis-step + .analysis-step {
|
||
margin-top: 8px;
|
||
}
|
||
|
||
.analysis-step--active {
|
||
border-color: rgba(120, 200, 255, 0.35);
|
||
background: rgba(70, 140, 255, 0.14);
|
||
box-shadow:
|
||
0 0 24px rgba(70, 140, 255, 0.18),
|
||
inset 0 1px 0 rgba(255, 255, 255, 0.06);
|
||
opacity: 1;
|
||
}
|
||
|
||
.analysis-step--done {
|
||
opacity: 0.9;
|
||
}
|
||
|
||
.analysis-step__icon {
|
||
display: grid;
|
||
flex: none;
|
||
place-items: center;
|
||
width: 42px;
|
||
height: 42px;
|
||
border: 1px solid rgba(255, 255, 255, 0.1);
|
||
border-radius: 12px;
|
||
}
|
||
|
||
.analysis-step__icon svg {
|
||
width: 26px;
|
||
height: 26px;
|
||
}
|
||
|
||
.analysis-step__icon--blue {
|
||
border-color: rgba(120, 190, 255, 0.25);
|
||
background: rgba(70, 140, 255, 0.16);
|
||
color: #8fd0ff;
|
||
}
|
||
|
||
.analysis-step__icon--amber {
|
||
border-color: rgba(255, 205, 100, 0.22);
|
||
background: rgba(255, 180, 40, 0.14);
|
||
color: #ffd166;
|
||
}
|
||
|
||
.analysis-step__text {
|
||
flex: 1;
|
||
color: rgba(200, 220, 245, 0.72);
|
||
font-size: 21px;
|
||
letter-spacing: 0.5px;
|
||
}
|
||
|
||
.analysis-step--active .analysis-step__text {
|
||
color: #f2f8ff;
|
||
}
|
||
|
||
.analysis-step--done .analysis-step__text {
|
||
color: rgba(220, 238, 255, 0.9);
|
||
}
|
||
|
||
.analysis-step__chevron {
|
||
color: rgba(130, 175, 255, 0.35);
|
||
font-size: 30px;
|
||
line-height: 1;
|
||
}
|
||
|
||
.analysis-step--active .analysis-step__chevron {
|
||
color: #7fe0ff;
|
||
}
|
||
|
||
.analysis-position {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
margin-top: 18px;
|
||
padding: 16px 18px;
|
||
border: 1px solid rgba(130, 175, 255, 0.14);
|
||
border-radius: 14px;
|
||
background: rgba(8, 18, 38, 0.55);
|
||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
|
||
}
|
||
|
||
.analysis-position__label {
|
||
color: rgba(158, 190, 226, 0.7);
|
||
font-size: 16px;
|
||
letter-spacing: 1px;
|
||
}
|
||
|
||
.analysis-position__value {
|
||
color: #e8f2ff;
|
||
font-size: 26px;
|
||
font-weight: 600;
|
||
letter-spacing: 1px;
|
||
}
|
||
|
||
.analysis-position__value small {
|
||
margin-left: 6px;
|
||
color: rgba(158, 190, 226, 0.55);
|
||
font-size: 16px;
|
||
font-weight: 400;
|
||
}
|
||
|
||
.analysis-hint {
|
||
display: flex;
|
||
gap: 12px;
|
||
margin-top: auto;
|
||
padding: 16px 18px;
|
||
border: 1px solid rgba(130, 175, 255, 0.14);
|
||
border-radius: 14px;
|
||
background: rgba(8, 18, 38, 0.45);
|
||
color: rgba(158, 190, 226, 0.66);
|
||
font-size: 15px;
|
||
line-height: 1.6;
|
||
}
|
||
|
||
.analysis-hint__mark {
|
||
display: grid;
|
||
flex: none;
|
||
place-items: center;
|
||
width: 24px;
|
||
height: 24px;
|
||
border: 1px solid rgba(130, 195, 255, 0.35);
|
||
border-radius: 50%;
|
||
color: #8fc6ff;
|
||
font-size: 14px;
|
||
font-weight: 700;
|
||
}
|
||
|
||
.spectrum-progress {
|
||
position: absolute;
|
||
top: 900px;
|
||
right: 44px;
|
||
left: 44px;
|
||
height: 54px;
|
||
}
|
||
</style>
|