提交代码
This commit is contained in:
@@ -1,17 +1,9 @@
|
||||
/**
|
||||
* 靶样轮廓识别与采样点规划接口封装。
|
||||
* 后端实现见 HardwareWeb/Controllers/SampleAnalysisController.cs:
|
||||
* POST /api/sample/baseline -> { width, height, capturedAt }
|
||||
* POST /api/sample/target -> { width, height, capturedAt }
|
||||
* POST /api/sample/analyze -> { imageBase64, mimeType, width, height, samplingPointCount, samplingPoints }
|
||||
*/
|
||||
|
||||
export interface SampleFrameResult {
|
||||
width: number
|
||||
height: number
|
||||
capturedAt: string
|
||||
}
|
||||
|
||||
export interface SamplePoint {
|
||||
x: number
|
||||
y: number
|
||||
@@ -28,7 +20,9 @@ export interface SampleAnalysisResult {
|
||||
|
||||
const API_BASE = (import.meta.env.VITE_API_BASE ?? '').replace(/\/$/, '')
|
||||
const DEFAULT_TIMEOUT = 15000
|
||||
const ANALYZE_TIMEOUT = 30000
|
||||
// 轮廓识别的等待时间优先取系统参数 camera_Identification_outtime,
|
||||
// 读取失败时使用该默认值。
|
||||
const DEFAULT_ANALYZE_TIMEOUT = 60000
|
||||
|
||||
export class SampleApiError extends Error {
|
||||
readonly status: number
|
||||
@@ -74,7 +68,9 @@ async function request<T>(
|
||||
} catch (error) {
|
||||
if (error instanceof SampleApiError) throw error
|
||||
if (error instanceof DOMException && error.name === 'AbortError') {
|
||||
throw new SampleApiError('图像分析服务响应超时')
|
||||
throw new SampleApiError(
|
||||
`图像分析服务响应超时(等待上限 ${Math.round(timeout / 1000)} 秒)`,
|
||||
)
|
||||
}
|
||||
throw new SampleApiError(
|
||||
error instanceof Error ? error.message : '无法连接图像分析服务',
|
||||
@@ -84,21 +80,27 @@ async function request<T>(
|
||||
}
|
||||
}
|
||||
|
||||
/** 相机画面稳定后采集基准画面。 */
|
||||
export function captureSampleBaseline(): Promise<SampleFrameResult> {
|
||||
return request<SampleFrameResult>('/api/sample/baseline', { method: 'POST' })
|
||||
}
|
||||
|
||||
/** 放置靶样并点击开始检测时采集第二张画面。 */
|
||||
export function captureSampleTarget(): Promise<SampleFrameResult> {
|
||||
return request<SampleFrameResult>('/api/sample/target', { method: 'POST' })
|
||||
/** 读取系统参数 camera_Identification_outtime 换算的等待超时(毫秒)。 */
|
||||
export async function getAnalyzeTimeoutMs(): Promise<number> {
|
||||
try {
|
||||
const result = await request<{ timeoutSeconds: number }>(
|
||||
'/api/sample/analyze-timeout',
|
||||
)
|
||||
return result.timeoutSeconds > 0
|
||||
? result.timeoutSeconds * 1000
|
||||
: DEFAULT_ANALYZE_TIMEOUT
|
||||
} catch {
|
||||
return DEFAULT_ANALYZE_TIMEOUT
|
||||
}
|
||||
}
|
||||
|
||||
/** 提取靶样轮廓、绘制采样点并返回处理后的图像。 */
|
||||
export function analyzeSample(): Promise<SampleAnalysisResult> {
|
||||
export function analyzeSample(
|
||||
timeout = DEFAULT_ANALYZE_TIMEOUT,
|
||||
): Promise<SampleAnalysisResult> {
|
||||
return request<SampleAnalysisResult>(
|
||||
'/api/sample/analyze',
|
||||
{ method: 'POST' },
|
||||
ANALYZE_TIMEOUT,
|
||||
timeout,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,21 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onBeforeUnmount, onMounted, ref, watch } from 'vue'
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { connectCamera } from '@/api/camera'
|
||||
import { useCameraStatus } from '@/composables/useCameraStatus'
|
||||
import { useCameraStream } from '@/composables/useCameraStream'
|
||||
import cameraPlaceholder from '@/assets/camera-placeholder.webp'
|
||||
|
||||
const emit = defineEmits<{
|
||||
/** 相机画面稳定显示后触发一次,用于采集基准画面。 */
|
||||
ready: []
|
||||
}>()
|
||||
|
||||
const { state: cameraState, refresh, startPolling } = useCameraStatus(5000, false)
|
||||
const { state: streamState, frameUrl, isLive, connect } = useCameraStream()
|
||||
|
||||
const connectingCamera = ref(false)
|
||||
const readyEmitted = ref(false)
|
||||
let readyTimer: number | undefined
|
||||
|
||||
const statusText = computed(() => {
|
||||
if (isLive.value) return '实时画面'
|
||||
@@ -39,34 +32,6 @@ const statusTone = computed<'on' | 'wait' | 'off'>(() => {
|
||||
return 'off'
|
||||
})
|
||||
|
||||
watch(isLive, (live) => {
|
||||
if (readyTimer !== undefined) {
|
||||
window.clearTimeout(readyTimer)
|
||||
readyTimer = undefined
|
||||
}
|
||||
|
||||
if (!live) {
|
||||
readyEmitted.value = false
|
||||
return
|
||||
}
|
||||
|
||||
if (readyEmitted.value) return
|
||||
|
||||
// 画面连续显示 800ms 视为稳定,再通知外部采集基准画面
|
||||
readyTimer = window.setTimeout(() => {
|
||||
readyTimer = undefined
|
||||
if (!isLive.value || readyEmitted.value) return
|
||||
readyEmitted.value = true
|
||||
emit('ready')
|
||||
}, 800)
|
||||
})
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
if (readyTimer !== undefined) {
|
||||
window.clearTimeout(readyTimer)
|
||||
}
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
await refresh()
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,396 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue'
|
||||
import ReportDocument from '@/components/ReportDocument.vue'
|
||||
import type { ScanRun } from '@/api/scan'
|
||||
import { showToast } from '@/composables/useToast'
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
open: boolean
|
||||
run: ScanRun | null
|
||||
imageUrl?: string
|
||||
pointIndex?: number
|
||||
}>(),
|
||||
{ imageUrl: '', pointIndex: 0 },
|
||||
)
|
||||
|
||||
const emit = defineEmits<{
|
||||
close: []
|
||||
}>()
|
||||
|
||||
const closeButton = ref<HTMLButtonElement | null>(null)
|
||||
|
||||
function pad2(value: number) {
|
||||
return String(value).padStart(2, '0')
|
||||
}
|
||||
|
||||
const reportNo = computed(() => {
|
||||
const run = props.run
|
||||
if (!run) return 'LIBS-00000000-000000'
|
||||
|
||||
const date = new Date(run.startedAt)
|
||||
const stamp = Number.isNaN(date.getTime())
|
||||
? '00000000'
|
||||
: `${date.getFullYear()}${pad2(date.getMonth() + 1)}${pad2(date.getDate())}`
|
||||
const tail =
|
||||
run.scanId.replace(/[^a-zA-Z0-9]/g, '').slice(-6).toUpperCase() || '000000'
|
||||
return `LIBS-${stamp}-${tail}`
|
||||
})
|
||||
|
||||
function close() {
|
||||
emit('close')
|
||||
}
|
||||
|
||||
function exportPdf() {
|
||||
if (!props.run) return
|
||||
|
||||
showToast('正在打开打印窗口,请选择“另存为 PDF”导出 A4 报告')
|
||||
const previousTitle = document.title
|
||||
document.title = `${reportNo.value} 检测报告`
|
||||
|
||||
const restoreTitle = () => {
|
||||
document.title = previousTitle
|
||||
window.removeEventListener('afterprint', restoreTitle)
|
||||
}
|
||||
window.addEventListener('afterprint', restoreTitle)
|
||||
|
||||
window.setTimeout(() => {
|
||||
window.print()
|
||||
window.setTimeout(restoreTitle, 4000)
|
||||
}, 180)
|
||||
}
|
||||
|
||||
function onKeydown(event: KeyboardEvent) {
|
||||
if (event.key === 'Escape') close()
|
||||
}
|
||||
|
||||
watch(
|
||||
() => props.open,
|
||||
async (open) => {
|
||||
if (open) {
|
||||
window.addEventListener('keydown', onKeydown)
|
||||
await nextTick()
|
||||
closeButton.value?.focus()
|
||||
} else {
|
||||
window.removeEventListener('keydown', onKeydown)
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
window.removeEventListener('keydown', onKeydown)
|
||||
})
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Transition name="report-modal">
|
||||
<div v-if="open" class="report-modal" role="dialog" aria-modal="true" aria-label="检测报告预览">
|
||||
<div class="report-modal__backdrop" @click.self="close"></div>
|
||||
|
||||
<section class="report-modal__shell">
|
||||
<header class="report-modal__bar">
|
||||
<div class="report-modal__identity">
|
||||
<span class="report-modal__badge" aria-hidden="true">
|
||||
<svg viewBox="0 0 32 32">
|
||||
<path
|
||||
d="M8 4h11l6 6v18H8z"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.8"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
<path d="M19 4v6h6" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linejoin="round" />
|
||||
<path d="M12 16h9M12 20h9M12 24h6" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" />
|
||||
</svg>
|
||||
</span>
|
||||
<div>
|
||||
<h2>检测报告预览</h2>
|
||||
<p>{{ reportNo }} · A4 210 × 297 mm · 共 3 页</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="report-modal__actions">
|
||||
<button
|
||||
ref="closeButton"
|
||||
class="report-modal__button report-modal__button--ghost"
|
||||
type="button"
|
||||
@click="close"
|
||||
>
|
||||
关闭
|
||||
</button>
|
||||
<button
|
||||
class="report-modal__button report-modal__button--primary"
|
||||
type="button"
|
||||
:disabled="!run"
|
||||
@click="exportPdf"
|
||||
>
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path
|
||||
d="M12 4v10m0 0 3.5-3.5M12 14 8.5 10.5M5 16v2.5A1.5 1.5 0 0 0 6.5 20h11a1.5 1.5 0 0 0 1.5-1.5V16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="1.8"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
导出 PDF
|
||||
</button>
|
||||
</div>
|
||||
</header>
|
||||
|
||||
<div class="report-modal__scroll">
|
||||
<ReportDocument
|
||||
v-if="run"
|
||||
:run="run"
|
||||
:image-url="imageUrl"
|
||||
:point-index="pointIndex"
|
||||
preview
|
||||
/>
|
||||
<p v-else class="report-modal__empty">暂无可导出的检测结果</p>
|
||||
</div>
|
||||
|
||||
<footer class="report-modal__foot">
|
||||
<span class="report-modal__dot"></span>
|
||||
点击“导出 PDF”后将打开系统打印窗口,请在“目标打印机”中选择“另存为 PDF”,纸张保持 A4。
|
||||
</footer>
|
||||
</section>
|
||||
</div>
|
||||
</Transition>
|
||||
|
||||
<Teleport to="body">
|
||||
<div v-if="open && run" class="report-print-root">
|
||||
<ReportDocument :run="run" :image-url="imageUrl" :point-index="pointIndex" />
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.report-modal {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 70;
|
||||
display: grid;
|
||||
place-items: center;
|
||||
}
|
||||
|
||||
.report-modal__backdrop {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(3, 9, 20, 0.74);
|
||||
backdrop-filter: blur(10px);
|
||||
}
|
||||
|
||||
.report-modal__shell {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 1300px;
|
||||
height: 976px;
|
||||
overflow: hidden;
|
||||
border: 1px solid rgba(130, 175, 255, 0.26);
|
||||
border-radius: 24px;
|
||||
background: linear-gradient(158deg, #0e1e3a 0%, #081226 62%, #070f1f 100%);
|
||||
box-shadow:
|
||||
0 44px 120px rgba(0, 6, 20, 0.72),
|
||||
0 0 70px rgba(48, 118, 255, 0.14),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.08);
|
||||
}
|
||||
|
||||
.report-modal__bar {
|
||||
display: flex;
|
||||
flex: none;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
height: 88px;
|
||||
padding: 0 28px 0 30px;
|
||||
border-bottom: 1px solid rgba(130, 175, 255, 0.14);
|
||||
background: linear-gradient(120deg, rgba(30, 66, 128, 0.4) 0%, rgba(8, 18, 38, 0.2) 70%);
|
||||
}
|
||||
|
||||
.report-modal__identity {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.report-modal__badge {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 52px;
|
||||
height: 52px;
|
||||
border: 1px solid rgba(130, 195, 255, 0.3);
|
||||
border-radius: 14px;
|
||||
background: rgba(30, 66, 128, 0.4);
|
||||
color: #9fe8ff;
|
||||
box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
|
||||
}
|
||||
|
||||
.report-modal__badge svg {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
}
|
||||
|
||||
.report-modal__identity h2 {
|
||||
color: #f0f7ff;
|
||||
font-size: 26px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 2px;
|
||||
}
|
||||
|
||||
.report-modal__identity p {
|
||||
margin-top: 4px;
|
||||
color: rgba(158, 190, 226, 0.72);
|
||||
font-size: 15px;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
|
||||
.report-modal__actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.report-modal__button {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
gap: 10px;
|
||||
height: 56px;
|
||||
border-radius: 12px;
|
||||
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;
|
||||
}
|
||||
|
||||
.report-modal__button:hover {
|
||||
transform: translateY(-1px);
|
||||
}
|
||||
|
||||
.report-modal__button svg {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
}
|
||||
|
||||
.report-modal__button--ghost {
|
||||
width: 132px;
|
||||
border: 1px solid rgba(150, 200, 255, 0.32);
|
||||
background: rgba(18, 40, 78, 0.4);
|
||||
color: #cfe4ff;
|
||||
letter-spacing: 4px;
|
||||
}
|
||||
|
||||
.report-modal__button--ghost:hover {
|
||||
border-color: rgba(160, 210, 255, 0.55);
|
||||
background: rgba(30, 66, 128, 0.55);
|
||||
}
|
||||
|
||||
.report-modal__button--primary {
|
||||
width: 194px;
|
||||
background: linear-gradient(180deg, #ffd166 0%, #f0ac0b 100%);
|
||||
color: #241500;
|
||||
box-shadow:
|
||||
0 14px 30px rgba(240, 172, 11, 0.3),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
||||
.report-modal__button--primary:hover {
|
||||
box-shadow:
|
||||
0 18px 38px rgba(240, 172, 11, 0.4),
|
||||
inset 0 1px 0 rgba(255, 255, 255, 0.6);
|
||||
}
|
||||
|
||||
.report-modal__button--primary:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.5;
|
||||
transform: none;
|
||||
}
|
||||
|
||||
.report-modal__scroll {
|
||||
position: relative;
|
||||
display: flex;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
min-height: 0;
|
||||
padding: 30px 0 40px;
|
||||
overflow-y: auto;
|
||||
background:
|
||||
radial-gradient(760px 420px at 50% -8%, rgba(48, 118, 255, 0.16), transparent 70%),
|
||||
radial-gradient(600px 400px at 88% 100%, rgba(42, 183, 172, 0.08), transparent 70%),
|
||||
#091325;
|
||||
scrollbar-width: thin;
|
||||
scrollbar-color: rgba(130, 175, 255, 0.32) transparent;
|
||||
}
|
||||
|
||||
.report-modal__scroll::-webkit-scrollbar {
|
||||
width: 10px;
|
||||
}
|
||||
|
||||
.report-modal__scroll::-webkit-scrollbar-thumb {
|
||||
border: 3px solid #091325;
|
||||
border-radius: 6px;
|
||||
background: rgba(130, 175, 255, 0.36);
|
||||
}
|
||||
|
||||
.report-modal__scroll::-webkit-scrollbar-track {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.report-modal__empty {
|
||||
margin-top: 200px;
|
||||
color: rgba(158, 190, 226, 0.7);
|
||||
font-size: 20px;
|
||||
letter-spacing: 2px;
|
||||
}
|
||||
|
||||
.report-modal__foot {
|
||||
display: flex;
|
||||
flex: none;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
height: 46px;
|
||||
padding: 0 30px;
|
||||
border-top: 1px solid rgba(130, 175, 255, 0.12);
|
||||
background: rgba(8, 18, 38, 0.75);
|
||||
color: rgba(158, 190, 226, 0.66);
|
||||
font-size: 15px;
|
||||
letter-spacing: 0.6px;
|
||||
}
|
||||
|
||||
.report-modal__dot {
|
||||
width: 7px;
|
||||
height: 7px;
|
||||
border-radius: 50%;
|
||||
background: #8df6ff;
|
||||
box-shadow: 0 0 10px rgba(141, 246, 255, 0.8);
|
||||
}
|
||||
|
||||
.report-modal-enter-active,
|
||||
.report-modal-leave-active {
|
||||
transition: opacity 0.26s ease;
|
||||
}
|
||||
|
||||
.report-modal-enter-active .report-modal__shell,
|
||||
.report-modal-leave-active .report-modal__shell {
|
||||
transition:
|
||||
transform 0.28s cubic-bezier(0.22, 1, 0.36, 1),
|
||||
opacity 0.26s ease;
|
||||
}
|
||||
|
||||
.report-modal-enter-from,
|
||||
.report-modal-leave-to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
.report-modal-enter-from .report-modal__shell,
|
||||
.report-modal-leave-to .report-modal__shell {
|
||||
opacity: 0;
|
||||
transform: translateY(18px) scale(0.975);
|
||||
}
|
||||
</style>
|
||||
@@ -170,7 +170,7 @@ const markers = [
|
||||
text-anchor="middle"
|
||||
opacity="0.95"
|
||||
>
|
||||
样品图片识别动画
|
||||
样品图片识别中...
|
||||
</text>
|
||||
<text
|
||||
x="500"
|
||||
|
||||
@@ -5,6 +5,7 @@ export function useCountdown(
|
||||
seconds: number,
|
||||
onComplete: () => void,
|
||||
enabled = true,
|
||||
isPaused: () => boolean = () => false,
|
||||
) {
|
||||
const remaining = ref(seconds)
|
||||
|
||||
@@ -15,6 +16,8 @@ export function useCountdown(
|
||||
if (!enabled) return
|
||||
|
||||
timer = window.setInterval(() => {
|
||||
if (isPaused()) return
|
||||
|
||||
remaining.value = Math.max(0, remaining.value - 1)
|
||||
|
||||
if (remaining.value === 0 && !finished) {
|
||||
|
||||
@@ -179,6 +179,38 @@ ol {
|
||||
transform: translateY(-6px);
|
||||
}
|
||||
|
||||
/* 报告导出:屏幕预览使用 #app 内的弹窗,打印时仅保留 A4 报告 DOM。 */
|
||||
.report-print-root {
|
||||
display: none;
|
||||
}
|
||||
|
||||
@media print {
|
||||
@page {
|
||||
size: A4;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
html,
|
||||
body {
|
||||
width: 210mm;
|
||||
height: auto;
|
||||
overflow: visible;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
#app {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.toast {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.report-print-root {
|
||||
display: block !important;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
*,
|
||||
*::before,
|
||||
|
||||
@@ -3,6 +3,7 @@ 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 ReportModal from '@/components/ReportModal.vue'
|
||||
import SpectrumChart from '@/components/SpectrumChart.vue'
|
||||
import { getLatestScan, getScan, type ScanRun } from '@/api/scan'
|
||||
import { useCountdown } from '@/composables/useCountdown'
|
||||
@@ -18,6 +19,7 @@ const run = ref<ScanRun | null>(null)
|
||||
const loading = ref(true)
|
||||
const loadError = ref('')
|
||||
const selectedIndex = ref(0)
|
||||
const reportOpen = ref(false)
|
||||
|
||||
const viewport = ref<HTMLElement | null>(null)
|
||||
const imageWidth = ref(0)
|
||||
@@ -34,7 +36,12 @@ function goHistory() {
|
||||
void router.replace({ name: 'history' })
|
||||
}
|
||||
|
||||
const { remaining } = useCountdown(60, goHome, !isHistoryMode)
|
||||
const { remaining } = useCountdown(
|
||||
60,
|
||||
goHome,
|
||||
!isHistoryMode,
|
||||
() => reportOpen.value,
|
||||
)
|
||||
|
||||
const targetScanId = computed(() => {
|
||||
const raw = isHistoryMode ? route.params.scanId : route.query.scanId
|
||||
@@ -159,7 +166,12 @@ async function loadResult() {
|
||||
}
|
||||
|
||||
function exportReport() {
|
||||
showToast('报告导出功能正在研发中')
|
||||
if (!run.value) {
|
||||
showToast('暂无可导出的检测结果')
|
||||
return
|
||||
}
|
||||
|
||||
reportOpen.value = true
|
||||
}
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -377,6 +389,14 @@ onBeforeUnmount(() => {
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<ReportModal
|
||||
:open="reportOpen"
|
||||
:run="run"
|
||||
:image-url="imageUrl"
|
||||
:point-index="selectedIndex"
|
||||
@close="reportOpen = false"
|
||||
/>
|
||||
</AppStage>
|
||||
</template>
|
||||
|
||||
|
||||
@@ -1,19 +1,15 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue'
|
||||
import { ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
import AppStage from '@/components/AppStage.vue'
|
||||
import PageHeader from '@/components/PageHeader.vue'
|
||||
import CameraPreview from '@/components/CameraPreview.vue'
|
||||
import GuideIcon from '@/components/GuideIcon.vue'
|
||||
import StatusFooter from '@/components/StatusFooter.vue'
|
||||
import { captureSampleBaseline, captureSampleTarget } from '@/api/sample'
|
||||
import { showToast } from '@/composables/useToast'
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const baselineReady = ref(false)
|
||||
const capturingBaseline = ref(false)
|
||||
const starting = ref(false)
|
||||
const requirementsConfirmed = ref(false)
|
||||
|
||||
const steps = [
|
||||
@@ -28,66 +24,19 @@ const placementRequirements = [
|
||||
'样品高度不能超过 2 厘米',
|
||||
]
|
||||
|
||||
const footerItems = computed(() => [
|
||||
baselineReady.value
|
||||
? '基准画面已采集'
|
||||
: capturingBaseline.value
|
||||
? '正在采集基准画面'
|
||||
: '等待相机画面稳定',
|
||||
'激光安全等级 Class 1',
|
||||
'环境温度 22℃',
|
||||
])
|
||||
|
||||
const captureStatusText = computed(() => {
|
||||
if (baselineReady.value) return '基准画面就绪'
|
||||
if (capturingBaseline.value) return '正在采集基准画面'
|
||||
return '等待相机画面'
|
||||
})
|
||||
const footerItems = ['等待开始检测', '激光安全等级 Class 1', '环境温度 22℃']
|
||||
|
||||
function goHome() {
|
||||
void router.push({ name: 'home' })
|
||||
}
|
||||
|
||||
async function onCameraReady() {
|
||||
if (baselineReady.value || capturingBaseline.value) return
|
||||
|
||||
capturingBaseline.value = true
|
||||
try {
|
||||
await captureSampleBaseline()
|
||||
baselineReady.value = true
|
||||
} catch (error) {
|
||||
showToast(
|
||||
error instanceof Error
|
||||
? `基准画面采集失败:${error.message}`
|
||||
: '基准画面采集失败',
|
||||
)
|
||||
} finally {
|
||||
capturingBaseline.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function startDetection() {
|
||||
if (starting.value) return
|
||||
|
||||
function startDetection() {
|
||||
if (!requirementsConfirmed.value) {
|
||||
showToast('请先确认样品放置符合要求')
|
||||
return
|
||||
}
|
||||
|
||||
if (!baselineReady.value) {
|
||||
showToast('基准画面尚未采集完成,请稍候再试')
|
||||
return
|
||||
}
|
||||
|
||||
starting.value = true
|
||||
try {
|
||||
await captureSampleTarget()
|
||||
void router.push({ name: 'scan' })
|
||||
} catch (error) {
|
||||
showToast(error instanceof Error ? error.message : '靶样画面采集失败')
|
||||
} finally {
|
||||
starting.value = false
|
||||
}
|
||||
void router.push({ name: 'scan' })
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -108,7 +57,7 @@ async function startDetection() {
|
||||
</PageHeader>
|
||||
|
||||
<main class="sample-main">
|
||||
<CameraPreview class="sample-camera" @ready="onCameraReady" />
|
||||
<CameraPreview class="sample-camera" />
|
||||
|
||||
<aside class="guide-column">
|
||||
<section class="guide-card">
|
||||
@@ -158,19 +107,14 @@ async function startDetection() {
|
||||
</section>
|
||||
|
||||
<div class="guide-actions">
|
||||
<span class="capture-status" :class="{ 'is-ready': baselineReady }">
|
||||
<i class="capture-status__dot"></i>
|
||||
{{ captureStatusText }}
|
||||
</span>
|
||||
|
||||
<button
|
||||
class="action-button action-button--start"
|
||||
type="button"
|
||||
:disabled="starting || !requirementsConfirmed"
|
||||
:disabled="!requirementsConfirmed"
|
||||
:title="requirementsConfirmed ? undefined : '请先确认样品放置符合要求'"
|
||||
@click="startDetection"
|
||||
>
|
||||
{{ starting ? '准备中...' : '开始检测' }}
|
||||
开始检测
|
||||
</button>
|
||||
</div>
|
||||
</aside>
|
||||
@@ -524,52 +468,17 @@ async function startDetection() {
|
||||
}
|
||||
|
||||
.guide-actions {
|
||||
display: grid;
|
||||
flex: none;
|
||||
grid-template-columns: minmax(0, 1fr) 320px;
|
||||
align-items: center;
|
||||
gap: 18px;
|
||||
height: 78px;
|
||||
}
|
||||
|
||||
.capture-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
height: 78px;
|
||||
padding: 0 24px;
|
||||
border: 1px solid rgba(130, 175, 255, 0.16);
|
||||
border-radius: 14px;
|
||||
background: rgba(10, 24, 48, 0.55);
|
||||
color: rgba(178, 202, 232, 0.7);
|
||||
font-size: 17px;
|
||||
letter-spacing: 1px;
|
||||
backdrop-filter: blur(12px);
|
||||
}
|
||||
|
||||
.capture-status__dot {
|
||||
flex: none;
|
||||
width: 9px;
|
||||
height: 9px;
|
||||
border-radius: 50%;
|
||||
background: #ffd86a;
|
||||
box-shadow: 0 0 10px rgba(255, 216, 106, 0.8);
|
||||
}
|
||||
|
||||
.capture-status.is-ready {
|
||||
border-color: rgba(92, 227, 214, 0.3);
|
||||
background: rgba(14, 46, 56, 0.5);
|
||||
color: #8ff5e7;
|
||||
}
|
||||
|
||||
.capture-status.is-ready .capture-status__dot {
|
||||
background: #74f4c5;
|
||||
box-shadow: 0 0 10px rgba(116, 244, 197, 0.9);
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
height: 78px;
|
||||
}
|
||||
|
||||
.action-button {
|
||||
display: grid;
|
||||
place-items: center;
|
||||
width: 320px;
|
||||
height: 78px;
|
||||
border-radius: 14px;
|
||||
font-size: 30px;
|
||||
|
||||
@@ -6,7 +6,7 @@ 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 { analyzeSample, getAnalyzeTimeoutMs, type SampleAnalysisResult } from '@/api/sample'
|
||||
import { startScan } from '@/api/scan'
|
||||
import { useStageHub } from '@/composables/useStageHub'
|
||||
import { showToast } from '@/composables/useToast'
|
||||
@@ -23,7 +23,11 @@ const scanStarting = ref(false)
|
||||
|
||||
const { position: stagePosition, connect: connectStageHub } = useStageHub()
|
||||
|
||||
let progressTimer: number | undefined
|
||||
// 首次分析没有历史耗时可参考,按经验值预估;后续使用上一次的真实耗时。
|
||||
const FALLBACK_ANALYSIS_DURATION_MS = 20000
|
||||
|
||||
let progressFrame: number | undefined
|
||||
let lastAnalysisDurationMs = 0
|
||||
|
||||
const resultImageUrl = computed(() =>
|
||||
result.value
|
||||
@@ -74,38 +78,61 @@ const footerItems = computed(() => {
|
||||
})
|
||||
|
||||
function stopProgress() {
|
||||
if (progressTimer !== undefined) {
|
||||
window.clearInterval(progressTimer)
|
||||
progressTimer = undefined
|
||||
if (progressFrame !== undefined) {
|
||||
window.cancelAnimationFrame(progressFrame)
|
||||
progressFrame = undefined
|
||||
}
|
||||
}
|
||||
|
||||
function startProgress() {
|
||||
/**
|
||||
* 按真实耗时推进进度:在预估的分析时长内匀速走到 99%,
|
||||
* 超过预估时长后继续缓慢爬升,分析结束后再置为 100%,
|
||||
* 避免像以往那样提前卡在固定百分比上空等。
|
||||
*/
|
||||
function startProgress(durationMs: number) {
|
||||
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)
|
||||
const total = Math.max(1000, durationMs)
|
||||
const startedAt = performance.now()
|
||||
|
||||
const tick = (now: number) => {
|
||||
const ratio = (now - startedAt) / total
|
||||
progress.value = ratio <= 1
|
||||
? ratio * 99
|
||||
: 99 + 0.9 * (1 - Math.exp(-(ratio - 1) * 2))
|
||||
progressFrame = window.requestAnimationFrame(tick)
|
||||
}
|
||||
|
||||
progressFrame = window.requestAnimationFrame(tick)
|
||||
}
|
||||
|
||||
async function runAnalysis() {
|
||||
status.value = 'processing'
|
||||
result.value = null
|
||||
errorMessage.value = ''
|
||||
startProgress()
|
||||
progress.value = 0
|
||||
|
||||
try {
|
||||
result.value = await analyzeSample()
|
||||
const timeout = await getAnalyzeTimeoutMs()
|
||||
const expectedDuration = Math.min(
|
||||
timeout,
|
||||
lastAnalysisDurationMs || FALLBACK_ANALYSIS_DURATION_MS,
|
||||
)
|
||||
startProgress(expectedDuration)
|
||||
|
||||
const startedAt = performance.now()
|
||||
result.value = await analyzeSample(timeout)
|
||||
lastAnalysisDurationMs = performance.now() - startedAt
|
||||
|
||||
stopProgress()
|
||||
progress.value = 100
|
||||
status.value = 'done'
|
||||
} catch (error) {
|
||||
stopProgress()
|
||||
status.value = 'error'
|
||||
errorMessage.value =
|
||||
error instanceof Error ? error.message : '靶样轮廓分析失败'
|
||||
} finally {
|
||||
stopProgress()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user