This commit is contained in:
ldh
2026-11-17 16:28:24 +08:00
parent b30d9f92ce
commit 19b7b10e97
28 changed files with 3891 additions and 46 deletions
+312 -13
View File
@@ -1,24 +1,115 @@
<script setup lang="ts">
import { computed } from 'vue'
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 { useTimedProgress } from '@/composables/useTimedProgress'
import { analyzeSample, type SampleAnalysisResult } from '@/api/sample'
type AnalysisStatus = 'processing' | 'done' | 'error'
const router = useRouter()
const { progress } = useTimedProgress(15000, () => {
void router.replace({ name: 'spectrum' })
const status = ref<AnalysisStatus>('processing')
const result = ref<SampleAnalysisResult | null>(null)
const errorMessage = ref('')
const progress = ref(0)
let progressTimer: number | undefined
const resultImageUrl = computed(() =>
result.value
? `data:${result.value.mimeType};base64,${result.value.imageBase64}`
: '',
)
const samplingPointCount = computed(
() => result.value?.samplingPointCount ?? '—',
)
const progressLabel = computed(() => {
if (status.value === 'done') return '靶样轮廓与采样点 100%'
if (status.value === 'error') return '图像分析失败'
return `靶样轮廓识别 ${Math.round(progress.value)}%`
})
const progressLabel = computed(() => `点位扫描 ${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()
}
function goSpectrum() {
void router.replace({ name: 'spectrum' })
}
onMounted(() => {
void runAnalysis()
})
onBeforeUnmount(stopProgress)
</script>
<template>
@@ -40,7 +131,39 @@ function abortProcess() {
</PageHeader>
<main class="scan-main">
<ScanVisual class="scan-card" />
<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">
@@ -50,7 +173,7 @@ function abortProcess() {
<div class="params-card__body">
<div class="param-field">
<span class="param-field__label">采样点数</span>
<div class="param-field__value">5</div>
<div class="param-field__value">{{ samplingPointCount }}</div>
</div>
<div class="param-field">
@@ -71,14 +194,22 @@ function abortProcess() {
</aside>
</main>
<div class="scan-progress">
<ProgressStrip :progress="progress" :label="progressLabel" note="已规划 5 个采样点" />
<div v-if="status !== 'error'" class="scan-progress">
<div class="scan-progress__strip">
<ProgressStrip :progress="progress" :label="progressLabel" :note="progressNote" />
</div>
<button
v-if="status === 'done'"
class="scan-next"
type="button"
@click="goSpectrum"
>
开始采集光谱
</button>
</div>
<StatusFooter
icon="info"
:items="['轮廓提取完成', '点位校验通过', '等待采集光谱']"
/>
<StatusFooter icon="info" :items="footerItems" />
</AppStage>
</template>
@@ -101,6 +232,147 @@ function abortProcess() {
justify-self: center;
}
.result-card {
display: flex;
flex-direction: column;
width: 1120px;
max-width: 100%;
height: 100%;
overflow: hidden;
border: 1px solid #1e55a4;
border-radius: 18px;
background: #0b1220;
box-shadow: 0 18px 44px rgba(31, 77, 147, 0.28);
justify-self: center;
}
.result-card__header {
display: flex;
flex: none;
align-items: center;
justify-content: space-between;
height: 66px;
padding: 0 26px;
background: linear-gradient(180deg, #3d80e2 0%, #2f6fd0 100%);
}
.result-card__header h2 {
color: #fff;
font-size: 28px;
font-weight: 600;
letter-spacing: 3px;
text-shadow: 0 1px 3px rgba(16, 49, 101, 0.22);
}
.result-card__count {
padding: 5px 14px;
border: 1px solid rgba(255, 255, 255, 0.3);
border-radius: 30px;
background: rgba(255, 255, 255, 0.12);
color: #fff;
font-size: 17px;
letter-spacing: 1px;
}
.result-card__viewport {
display: grid;
flex: 1;
min-height: 0;
place-items: center;
padding: 10px;
}
.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 #d9e0e8;
border-radius: 18px;
background: #fff;
box-shadow: var(--shadow-card);
justify-self: center;
text-align: center;
}
.error-card__icon {
display: grid;
place-items: center;
width: 96px;
height: 96px;
margin-bottom: 24px;
border-radius: 50%;
color: var(--red);
background: #fdeeee;
}
.error-card__icon svg {
width: 54px;
height: 54px;
}
.error-card h2 {
color: #1f2937;
font-size: 32px;
font-weight: 600;
letter-spacing: 2px;
}
.error-card p {
margin-top: 16px;
max-width: 760px;
color: var(--muted);
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;
}
.error-button--ghost {
border: 2px solid var(--line-strong);
color: var(--ink-soft);
background: #fff;
}
.error-button--ghost:hover {
background: var(--surface-soft);
}
.error-button--primary {
color: #fff;
background: linear-gradient(180deg, #4b89e4 0%, #2f6fd0 100%);
box-shadow: 0 10px 22px rgba(47, 111, 208, 0.28);
}
.error-button--primary:hover {
transform: translateY(-1px);
box-shadow: 0 14px 28px rgba(47, 111, 208, 0.36);
}
.params-card {
display: flex;
flex-direction: column;
@@ -173,6 +445,33 @@ function abortProcess() {
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: 10px;
color: #fff;
font-size: 23px;
font-weight: 600;
letter-spacing: 3px;
background: linear-gradient(180deg, #4b89e4 0%, #2f6fd0 100%);
box-shadow: 0 10px 22px rgba(47, 111, 208, 0.28);
transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.scan-next:hover {
transform: translateY(-1px);
box-shadow: 0 14px 28px rgba(47, 111, 208, 0.36);
}
</style>