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

815 lines
19 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 { useRouter } from 'vue-router'
import AppStage from '@/components/AppStage.vue'
import PageHeader from '@/components/PageHeader.vue'
import ScanVisual from '@/components/ScanVisual.vue'
import ProgressStrip from '@/components/ProgressStrip.vue'
import StatusFooter from '@/components/StatusFooter.vue'
import { analyzeSample, type SampleAnalysisResult } from '@/api/sample'
import { startScan } from '@/api/scan'
import { useStageHub } from '@/composables/useStageHub'
import { showToast } from '@/composables/useToast'
type AnalysisStatus = 'processing' | 'done' | 'error'
const router = useRouter()
const status = ref<AnalysisStatus>('processing')
const result = ref<SampleAnalysisResult | null>(null)
const errorMessage = ref('')
const progress = ref(0)
const scanStarting = ref(false)
const { position: stagePosition, connect: connectStageHub } = useStageHub()
let progressTimer: number | undefined
const resultImageUrl = computed(() =>
result.value
? `data:${result.value.mimeType};base64,${result.value.imageBase64}`
: '',
)
const samplingPointCount = computed(
() => result.value?.samplingPointCount ?? '—',
)
const stageStatusText = computed(() => {
if (!stagePosition.value) return '未连接'
return stagePosition.value.moving ? '运动中' : '就绪'
})
const stageStatusTone = computed(() => {
if (!stagePosition.value) return 'is-off'
return stagePosition.value.moving ? 'is-moving' : 'is-ready'
})
const progressLabel = computed(() => {
if (status.value === 'done') return '靶样轮廓与采样点 100%'
if (status.value === 'error') return '图像分析失败'
return `靶样轮廓识别 ${Math.round(progress.value)}%`
})
const progressNote = computed(() => {
if (status.value === 'done') {
return `已规划 ${result.value?.samplingPointCount ?? 0} 个采样点`
}
if (status.value === 'error') return '请返回或重试'
return '背景差分分析中'
})
const footerItems = computed(() => {
if (status.value === 'done') {
return [
'轮廓提取完成',
`已规划 ${result.value?.samplingPointCount ?? 0} 个采样点`,
'等待采集光谱',
]
}
if (status.value === 'error') {
return ['轮廓提取失败', '请检查靶样放置', '等待重试']
}
return ['相机画面分析中', '背景差分识别轮廓', '采样点规划中']
})
function stopProgress() {
if (progressTimer !== undefined) {
window.clearInterval(progressTimer)
progressTimer = undefined
}
}
function startProgress() {
stopProgress()
progress.value = 0
progressTimer = window.setInterval(() => {
if (progress.value >= 90) return
progress.value = Math.min(90, progress.value + (progress.value < 60 ? 4 : 1.5))
}, 120)
}
async function runAnalysis() {
status.value = 'processing'
result.value = null
errorMessage.value = ''
startProgress()
try {
result.value = await analyzeSample()
progress.value = 100
status.value = 'done'
} catch (error) {
status.value = 'error'
errorMessage.value =
error instanceof Error ? error.message : '靶样轮廓分析失败'
} finally {
stopProgress()
}
}
function abortProcess() {
void router.replace({ name: 'home' })
}
function retry() {
void runAnalysis()
}
async function startScanning() {
if (scanStarting.value) return
if (!result.value) {
showToast('请等待靶样分析完成')
return
}
scanStarting.value = true
try {
const started = await startScan()
await router.push({
name: 'spectrum',
query: { scanId: started.scanId },
})
} catch (error) {
showToast(error instanceof Error ? error.message : '启动扫描失败')
} finally {
scanStarting.value = false
}
}
onMounted(() => {
void runAnalysis()
void connectStageHub()
})
onBeforeUnmount(stopProgress)
</script>
<template>
<AppStage>
<div class="scan-bg" aria-hidden="true">
<span class="scan-bg__orb scan-bg__orb--blue"></span>
<span class="scan-bg__orb scan-bg__orb--cyan"></span>
<span class="scan-bg__orb scan-bg__orb--violet"></span>
</div>
<PageHeader title="样品轮廓识别与激光点位规划" variant="process" theme="dark">
<template #left>
<button class="scan-abort" type="button" @click="abortProcess">
中止流程
</button>
</template>
<template #right>
<button class="scan-close" type="button" aria-label="关闭并返回首页" @click="abortProcess">
<svg viewBox="0 0 24 24" aria-hidden="true">
<path d="m6 6 12 12M18 6 6 18" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" />
</svg>
</button>
</template>
</PageHeader>
<main class="scan-main">
<ScanVisual v-if="status === 'processing'" class="scan-card" />
<section v-else-if="status === 'done'" class="result-card">
<header class="result-card__header">
<h2>靶样轮廓与采样点</h2>
<span class="result-card__count">
采样点 {{ result?.samplingPointCount ?? 0 }} 个
</span>
</header>
<div class="result-card__viewport">
<img class="result-card__image" :src="resultImageUrl" alt="靶样轮廓与采样点分析结果" />
</div>
</section>
<section v-else class="error-card">
<div class="error-card__icon" aria-hidden="true">
<svg viewBox="0 0 64 64">
<circle cx="32" cy="32" r="24" fill="none" stroke="currentColor" stroke-width="3" />
<path d="M32 20v18M32 44v2" fill="none" stroke="currentColor" stroke-width="3" stroke-linecap="round" />
</svg>
</div>
<h2>靶样轮廓识别失败</h2>
<p>{{ errorMessage }}</p>
<div class="error-card__actions">
<button class="error-button error-button--ghost" type="button" @click="abortProcess">
返回首页
</button>
<button class="error-button error-button--primary" type="button" @click="retry">
重新分析
</button>
</div>
</section>
<aside class="params-card">
<header class="params-card__header">
<div class="params-card__heading">
<span class="params-card__eyebrow">Sampling Plan</span>
<h2>采样点</h2>
</div>
</header>
<div class="params-card__body">
<div class="param-field">
<span class="param-field__label">采样点数</span>
<div class="param-field__value">{{ samplingPointCount }}</div>
</div>
<div class="param-field">
<span class="param-field__label">当前位置</span>
<div class="param-field__value param-field__value--position">
<span>X {{ stagePosition ? stagePosition.x : '—' }}</span>
<span>Y {{ stagePosition ? stagePosition.y : '—' }}</span>
</div>
</div>
<div class="param-field">
<span class="param-field__label">位移台状态</span>
<div
class="param-field__value param-field__value--status"
:class="stageStatusTone"
>
<i class="param-field__dot"></i>
{{ stageStatusText }}
</div>
</div>
</div>
<div class="params-card__hint">
<span class="params-card__hint-mark">i</span>
<p>确认靶样轮廓与采样点分布符合要求后,点击“开始采集”进入光谱采集流程。</p>
</div>
</aside>
</main>
<div v-if="status !== 'error'" class="scan-progress">
<div class="scan-progress__strip">
<ProgressStrip
:progress="progress"
:label="progressLabel"
:note="progressNote"
theme="dark"
/>
</div>
<button
v-if="status === 'done'"
class="scan-next"
type="button"
:disabled="scanStarting"
@click="startScanning"
>
{{ scanStarting ? '启动中...' : '开始采集' }}
</button>
</div>
<StatusFooter icon="info" :items="footerItems" theme="dark" />
</AppStage>
</template>
<style scoped>
.scan-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%);
}
.scan-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%);
}
.scan-bg__orb {
position: absolute;
border-radius: 50%;
filter: blur(100px);
animation: scan-orb-drift 16s ease-in-out infinite alternate;
}
.scan-bg__orb--blue {
top: -340px;
left: -160px;
width: 760px;
height: 760px;
background: rgba(48, 118, 255, 0.3);
}
.scan-bg__orb--cyan {
top: -200px;
right: -220px;
width: 640px;
height: 640px;
background: rgba(0, 214, 255, 0.18);
animation-delay: -5s;
}
.scan-bg__orb--violet {
bottom: -360px;
left: 36%;
width: 700px;
height: 700px;
background: rgba(124, 92, 255, 0.18);
animation-delay: -10s;
}
@keyframes scan-orb-drift {
from {
transform: translate3d(0, 0, 0) scale(1);
}
to {
transform: translate3d(42px, 30px, 0) scale(1.08);
}
}
.scan-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;
}
.scan-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);
}
.scan-close {
display: grid;
place-items: center;
width: 52px;
height: 52px;
border-radius: 50%;
color: rgba(170, 200, 235, 0.8);
transition: color 0.2s ease, background 0.2s ease;
}
.scan-close:hover {
background: rgba(255, 255, 255, 0.08);
color: #eaf3ff;
}
.scan-close svg {
width: 26px;
height: 26px;
}
.scan-main {
position: absolute;
top: 142px;
right: 44px;
left: 44px;
display: grid;
grid-template-columns: minmax(0, 1fr) 342px;
gap: 20px;
height: 730px;
}
.scan-card {
width: 1120px;
max-width: 100%;
height: 100%;
justify-self: center;
}
.result-card {
position: relative;
display: flex;
flex-direction: column;
width: 1120px;
max-width: 100%;
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);
justify-self: center;
}
.result-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%);
}
.result-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);
}
.result-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);
}
.result-card__count {
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;
}
.result-card__viewport {
display: grid;
flex: 1;
min-height: 0;
place-items: center;
padding: 10px;
background: #040810;
}
.result-card__image {
width: 100%;
height: 100%;
object-fit: contain;
}
.error-card {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
width: 1120px;
max-width: 100%;
height: 100%;
padding: 40px;
border: 1px solid rgba(255, 107, 107, 0.24);
border-radius: 26px;
background: linear-gradient(158deg, rgba(64, 22, 34, 0.4) 0%, rgba(8, 14, 28, 0.88) 70%);
box-shadow:
0 30px 70px rgba(0, 10, 32, 0.5),
0 0 40px rgba(255, 84, 84, 0.08),
inset 0 1px 0 rgba(255, 255, 255, 0.06);
backdrop-filter: blur(16px);
justify-self: center;
text-align: center;
}
.error-card__icon {
display: grid;
place-items: center;
width: 96px;
height: 96px;
margin-bottom: 24px;
border: 1px solid rgba(255, 120, 120, 0.3);
border-radius: 50%;
background: rgba(255, 84, 84, 0.12);
box-shadow: 0 0 30px rgba(255, 84, 84, 0.18);
color: #ff9d9d;
}
.error-card__icon svg {
width: 54px;
height: 54px;
}
.error-card h2 {
color: #f3f8ff;
font-size: 32px;
font-weight: 600;
letter-spacing: 2px;
text-shadow: 0 0 24px rgba(255, 100, 100, 0.2);
}
.error-card p {
margin-top: 16px;
max-width: 760px;
color: rgba(178, 202, 232, 0.72);
font-size: 20px;
line-height: 1.6;
}
.error-card__actions {
display: flex;
gap: 20px;
margin-top: 32px;
}
.error-button {
width: 200px;
height: 58px;
border-radius: 12px;
font-size: 21px;
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;
}
.error-button--ghost {
border: 1px solid rgba(130, 175, 255, 0.3);
background: rgba(18, 40, 78, 0.5);
color: #bcd9ff;
}
.error-button--ghost:hover {
border-color: rgba(150, 205, 255, 0.5);
background: rgba(30, 66, 128, 0.6);
}
.error-button--primary {
background: linear-gradient(180deg, #6fc6ff 0%, #3f86f0 55%, #2c63c9 100%);
box-shadow:
0 12px 26px rgba(47, 111, 208, 0.35),
inset 0 1px 0 rgba(255, 255, 255, 0.4);
color: #04101f;
}
.error-button--primary:hover {
box-shadow:
0 16px 32px rgba(47, 111, 208, 0.45),
inset 0 1px 0 rgba(255, 255, 255, 0.45);
transform: translateY(-1px);
}
.params-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);
}
.params-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;
}
.params-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%);
}
.params-card__heading {
display: flex;
flex-direction: column;
gap: 6px;
}
.params-card__eyebrow {
color: #5aa2ff;
font-size: 12px;
font-weight: 600;
letter-spacing: 2.6px;
text-transform: uppercase;
}
.params-card__header h2 {
display: flex;
align-items: center;
gap: 12px;
color: #eaf3ff;
font-size: 26px;
font-weight: 600;
letter-spacing: 2px;
}
.params-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);
}
.params-card__body {
padding: 28px 24px;
}
.param-field {
margin-bottom: 26px;
}
.param-field:last-child {
margin-bottom: 0;
}
.param-field__label {
display: block;
margin-bottom: 10px;
color: rgba(158, 190, 226, 0.7);
font-size: 20px;
letter-spacing: 1px;
}
.param-field__value {
display: flex;
align-items: center;
height: 62px;
padding: 0 18px;
border: 1px solid rgba(130, 175, 255, 0.16);
border-radius: 12px;
background: rgba(8, 18, 38, 0.6);
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
color: #e8f2ff;
font-size: 24px;
}
.param-field__value small {
margin-left: 8px;
color: rgba(158, 190, 226, 0.55);
font-size: 18px;
}
.param-field__value--position {
justify-content: space-between;
gap: 12px;
}
.param-field__value--status {
gap: 10px;
}
.param-field__dot {
flex: none;
width: 9px;
height: 9px;
border-radius: 50%;
background: #c9d4e4;
}
.param-field__value--status.is-ready {
color: #8ff5e7;
}
.param-field__value--status.is-ready .param-field__dot {
background: #74f4c5;
box-shadow: 0 0 10px rgba(116, 244, 197, 0.9);
}
.param-field__value--status.is-moving {
color: #ffd98a;
}
.param-field__value--status.is-moving .param-field__dot {
background: #ffd86a;
box-shadow: 0 0 10px rgba(255, 216, 106, 0.8);
}
.param-field__value--status.is-off {
color: rgba(255, 154, 145, 0.9);
}
.param-field__value--status.is-off .param-field__dot {
background: #ff9a91;
box-shadow: 0 0 10px rgba(255, 154, 145, 0.7);
}
.params-card__hint {
display: flex;
gap: 12px;
margin: auto 24px 26px;
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: 16px;
line-height: 1.6;
}
.params-card__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;
}
.scan-progress {
position: absolute;
top: 900px;
right: 44px;
left: 44px;
display: flex;
align-items: center;
gap: 20px;
height: 54px;
}
.scan-progress__strip {
flex: 1;
min-width: 0;
}
.scan-next {
flex: none;
width: 280px;
height: 54px;
border-radius: 12px;
background: linear-gradient(180deg, #ffd166 0%, #f0ac0b 100%);
box-shadow:
0 14px 30px rgba(240, 172, 11, 0.28),
0 0 26px rgba(255, 190, 60, 0.16),
inset 0 1px 0 rgba(255, 255, 255, 0.6);
color: #241500;
font-size: 23px;
font-weight: 600;
letter-spacing: 3px;
text-shadow: 0 1px 1px rgba(255, 255, 255, 0.25);
transition:
transform 0.2s ease,
box-shadow 0.2s ease,
filter 0.2s ease;
}
.scan-next:not(:disabled):hover {
box-shadow:
0 18px 38px rgba(240, 172, 11, 0.36),
0 0 34px rgba(255, 190, 60, 0.26),
inset 0 1px 0 rgba(255, 255, 255, 0.6);
transform: translateY(-2px);
}
.scan-next:disabled {
cursor: default;
filter: saturate(0.35);
opacity: 0.45;
box-shadow: none;
transform: none;
}
</style>