feat: 简化 Pipeline 对话框,支持智能检测和统一运行
This commit is contained in:
1 parent
6d147e758a
commit
71fd6ef134
1 file changed
+136
-124
@@ -298,52 +298,42 @@
|
||||
</div>
|
||||
</el-dialog>
|
||||
|
||||
<!-- 统一运行(Pipeline)对话框 -->
|
||||
<el-dialog v-model="pipelineVisible" title="运行处理流程" width="600px" @close="resetPipeline">
|
||||
<el-form label-width="140px">
|
||||
<el-form-item label="滤波类型">
|
||||
<el-select v-model="pipelineForm.filter_type" style="width: 100%">
|
||||
<el-option label="带通 0.5-40 Hz" value="bandpass_0.5_40" />
|
||||
<el-option label="带通 1-30 Hz" value="bandpass_1_30" />
|
||||
<el-option label="低通 40 Hz" value="lowpass_40" />
|
||||
<el-option label="高通 0.5 Hz" value="highpass_0.5" />
|
||||
<el-option label="陷波 50 Hz" value="notch_50" />
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="推理模型">
|
||||
<el-select v-model="pipelineForm.model_path" placeholder="选择模型(不选则仅滤波)" clearable style="width: 100%">
|
||||
<!-- 运行处理(Pipeline)对话框 -->
|
||||
<el-dialog v-model="pipelineVisible" title="运行处理" width="550px" @close="resetPipeline">
|
||||
<el-form :model="pipelineForm" label-width="100px">
|
||||
<!-- 数据状态提示 -->
|
||||
<el-alert
|
||||
v-if="pipelineStatusInfo"
|
||||
:type="pipelineStatusInfo.type"
|
||||
:closable="false"
|
||||
style="margin-bottom: 16px"
|
||||
>
|
||||
<template #title>
|
||||
{{ pipelineStatusInfo.message }}
|
||||
</template>
|
||||
</el-alert>
|
||||
|
||||
<!-- 推理配置 -->
|
||||
<el-form-item label="推理模型" required>
|
||||
<el-select v-model="pipelineForm.model_path" placeholder="选择推理模型" style="width: 100%">
|
||||
<el-option
|
||||
v-for="model in availableModels"
|
||||
:key="model.path"
|
||||
:label="model.name + ' (' + formatFileSize(model.size) + ')'"
|
||||
:label="model.name"
|
||||
:value="model.path"
|
||||
/>
|
||||
</el-select>
|
||||
<div style="font-size: 12px; color: #909399; margin-top: 4px">
|
||||
不选择模型则仅执行滤波处理
|
||||
</div>
|
||||
</el-form-item>
|
||||
<el-form-item label="信号长度" v-if="pipelineForm.model_path">
|
||||
<el-input-number v-model="pipelineForm.signal_len" :min="100" :max="5000" :step="100" />
|
||||
<el-form-item label="信号长度">
|
||||
<el-input-number v-model="pipelineForm.signal_len" :min="1000" :max="10000" :step="500" />
|
||||
</el-form-item>
|
||||
<el-form-item label="步长" v-if="pipelineForm.model_path">
|
||||
<el-input-number v-model="pipelineForm.stride" :min="100" :max="2000" :step="100" />
|
||||
</el-form-item>
|
||||
<el-form-item label="置信度阈值" v-if="pipelineForm.model_path">
|
||||
<el-slider v-model="pipelineForm.confidence_threshold" :min="0" :max="1" :step="0.05" />
|
||||
</el-form-item>
|
||||
<el-form-item label="流程说明">
|
||||
<el-alert
|
||||
title="运行流程:先执行滤波处理 → 滤波完成后自动执行推理 → 完成后可查看结果"
|
||||
type="info"
|
||||
:closable="false"
|
||||
show-icon
|
||||
/>
|
||||
<el-form-item label="步长">
|
||||
<el-input-number v-model="pipelineForm.stride" :min="500" :max="5000" :step="500" />
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
<template #footer>
|
||||
<el-button @click="pipelineVisible = false">{{ $t('common.cancel') }}</el-button>
|
||||
<el-button type="primary" :loading="submitting" @click="confirmPipeline">{{ $t('common.confirm') }}</el-button>
|
||||
<el-button @click="pipelineVisible = false">取消</el-button>
|
||||
<el-button type="primary" @click="confirmPipeline" :loading="pipelineRunning">运行</el-button>
|
||||
</template>
|
||||
</el-dialog>
|
||||
|
||||
@@ -647,15 +637,18 @@ const currentPatient = ref(null)
|
||||
const pipelineVisible = ref(false)
|
||||
const pipelineProgressVisible = ref(false)
|
||||
const submitting = ref(false)
|
||||
const pipelineRunning = ref(false)
|
||||
const pipelineForm = ref({
|
||||
folder_ids: [],
|
||||
filter_type: 'bandpass_0.5_40',
|
||||
model_path: '',
|
||||
signal_len: 1000,
|
||||
stride: 1000,
|
||||
signal_len: 3000,
|
||||
stride: 1500,
|
||||
confidence_threshold: 0.75,
|
||||
num_classes: 2
|
||||
})
|
||||
const pipelineStatusInfo = ref(null) // 数据状态提示信息
|
||||
const selectedPatientIds = ref([]) // 选中的患者 ID
|
||||
const currentPipeline = ref(null)
|
||||
const inferenceTaskProgress = ref(null)
|
||||
|
||||
@@ -1021,12 +1014,15 @@ const cancelZipTask = async (zipTask) => {
|
||||
}
|
||||
|
||||
// 运行单个原始文件夹处理
|
||||
const runRawJob = (row) => {
|
||||
selectedRawIds.value = [row.folder_name || row.id]
|
||||
pipelineForm.value.folder_ids = [...selectedRawIds.value]
|
||||
const runRawJob = async (row) => {
|
||||
selectedPatientIds.value = [row.folder_name || row.id]
|
||||
pipelineForm.value.model_path = ''
|
||||
pipelineForm.value.signal_len = 3000
|
||||
pipelineForm.value.stride = 1500
|
||||
pipelineStatusInfo.value = null
|
||||
activeTab.value = 'raw'
|
||||
openPipelineDialog()
|
||||
await loadAvailableModels()
|
||||
pipelineVisible.value = true
|
||||
}
|
||||
|
||||
// 显示文件夹摘要
|
||||
@@ -1243,15 +1239,41 @@ const openInferenceDialog = () => {
|
||||
}
|
||||
|
||||
// 单个患者推理(使用 Pipeline 方式)
|
||||
const runInferenceSingle = (row) => {
|
||||
// 如果已经有滤波数据,直接弹出推理配置
|
||||
if (row.has_filtered || row.has_pkl) {
|
||||
pipelineForm.value.folder_ids = [row.patient_id] // 不传 folder_ids,仅推理
|
||||
pipelineForm.value.model_path = availableModels.value[0]?.path || ''
|
||||
pipelineVisible.value = true
|
||||
ElMessage.info('该患者已有滤波数据,将直接执行推理')
|
||||
const runInferenceSingle = async (row) => {
|
||||
// 直接打开简化的 Pipeline 对话框
|
||||
selectedPatientIds.value = [row.patient_id || row.folder_id]
|
||||
pipelineForm.value.model_path = ''
|
||||
pipelineForm.value.signal_len = 3000
|
||||
pipelineForm.value.stride = 1500
|
||||
|
||||
// 检测数据状态并显示提示
|
||||
const needsFilter = !row.has_filtered && !row.has_pkl
|
||||
if (needsFilter) {
|
||||
pipelineStatusInfo.value = {
|
||||
type: 'info',
|
||||
message: `检测到 ${row.patient_name || row.folder_name || row.patient_id} 需要滤波处理,将先执行滤波,再自动执行推理`
|
||||
}
|
||||
} else {
|
||||
ElMessage.warning('请先运行滤波处理')
|
||||
pipelineStatusInfo.value = {
|
||||
type: 'success',
|
||||
message: `检测到 ${row.patient_name || row.folder_name || row.patient_id} 已有滤波数据,将直接执行推理`
|
||||
}
|
||||
}
|
||||
|
||||
// 加载可用模型
|
||||
await loadAvailableModels()
|
||||
|
||||
pipelineVisible.value = true
|
||||
}
|
||||
|
||||
// 加载可用模型列表
|
||||
const loadAvailableModels = async () => {
|
||||
try {
|
||||
const res = await api.get('/admin/inference-data/models')
|
||||
availableModels.value = res.models || []
|
||||
} catch (error) {
|
||||
console.error('加载模型列表失败', error)
|
||||
availableModels.value = []
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1308,7 +1330,7 @@ const confirmInference = async () => {
|
||||
// Pipeline 相关函数
|
||||
|
||||
// 打开 Pipeline 对话框
|
||||
const openPipelineDialog = () => {
|
||||
const openPipelineDialog = async () => {
|
||||
const hasRawSelection = selectedRawIds.value.length > 0
|
||||
const hasProcessedSelection = selectedIds.value.length > 0
|
||||
|
||||
@@ -1319,111 +1341,95 @@ const openPipelineDialog = () => {
|
||||
|
||||
// 优先使用原始数据选择
|
||||
if (hasRawSelection) {
|
||||
pipelineForm.value.folder_ids = [...selectedRawIds.value]
|
||||
selectedPatientIds.value = [...selectedRawIds.value]
|
||||
} else {
|
||||
pipelineForm.value.folder_ids = [...selectedIds.value]
|
||||
selectedPatientIds.value = [...selectedIds.value]
|
||||
}
|
||||
|
||||
pipelineForm.value.model_path = ''
|
||||
pipelineForm.value.signal_len = 3000
|
||||
pipelineForm.value.stride = 1500
|
||||
pipelineStatusInfo.value = null
|
||||
|
||||
await loadAvailableModels()
|
||||
pipelineVisible.value = true
|
||||
}
|
||||
|
||||
// 确认 Pipeline 运行
|
||||
const confirmPipeline = async () => {
|
||||
if (!pipelineForm.value.folder_ids.length && !pipelineForm.value.model_path) {
|
||||
ElMessage.warning('请选择文件夹或模型')
|
||||
if (!pipelineForm.value.model_path) {
|
||||
ElMessage.warning('请选择推理模型')
|
||||
return
|
||||
}
|
||||
|
||||
submitting.value = true
|
||||
pipelineRunning.value = true
|
||||
|
||||
try {
|
||||
// 如果有 folder_ids,使用 pipeline API(滤波+推理)
|
||||
if (pipelineForm.value.folder_ids.length) {
|
||||
const body = {
|
||||
folder_ids: pipelineForm.value.folder_ids,
|
||||
filter_type: pipelineForm.value.filter_type,
|
||||
}
|
||||
if (pipelineForm.value.model_path) {
|
||||
body.model_path = pipelineForm.value.model_path
|
||||
body.signal_len = pipelineForm.value.signal_len
|
||||
body.stride = pipelineForm.value.stride
|
||||
body.confidence_threshold = pipelineForm.value.confidence_threshold
|
||||
body.num_classes = pipelineForm.value.num_classes
|
||||
}
|
||||
|
||||
const res = await api.post('/admin/integration/run-pipeline', body)
|
||||
const pipelineUuid = res.data?.pipeline_uuid
|
||||
ElMessage.success(res.msg || 'Pipeline 已启动')
|
||||
pipelineVisible.value = false
|
||||
|
||||
currentPipeline.value = {
|
||||
pipeline_uuid: pipelineUuid,
|
||||
status: 'queued',
|
||||
stage: 'filter',
|
||||
folder_ids: pipelineForm.value.folder_ids,
|
||||
filter_type: pipelineForm.value.filter_type,
|
||||
model_path: pipelineForm.value.model_path,
|
||||
created_at: new Date().toISOString(),
|
||||
}
|
||||
pipelineProgressVisible.value = true
|
||||
startPipelinePolling(pipelineUuid)
|
||||
} else {
|
||||
// 仅推理(使用旧的推理 API)
|
||||
ElMessage.warning('请选择文件夹以执行滤波+推理流程')
|
||||
const payload = {
|
||||
folder_ids: selectedPatientIds.value,
|
||||
filter_type: 'bandpass_0.5_40',
|
||||
model_path: pipelineForm.value.model_path,
|
||||
signal_len: pipelineForm.value.signal_len,
|
||||
stride: pipelineForm.value.stride,
|
||||
auto_detect: true
|
||||
}
|
||||
|
||||
const res = await api.post('/admin/integration/run-pipeline', payload)
|
||||
|
||||
ElMessage.success('处理任务已启动')
|
||||
pipelineVisible.value = false
|
||||
pipelineStatusInfo.value = null
|
||||
|
||||
// 开始轮询进度
|
||||
if (res.pipeline_uuid) {
|
||||
startPipelinePolling(res.pipeline_uuid)
|
||||
}
|
||||
|
||||
// 刷新列表
|
||||
await fetchItems()
|
||||
} catch (error) {
|
||||
if (error.response?.status === 409) {
|
||||
ElMessage.warning(error.response.data.msg)
|
||||
} else {
|
||||
ElMessage.error(error.response?.data?.msg || 'Pipeline 启动失败')
|
||||
}
|
||||
console.error('Pipeline 启动失败:', error)
|
||||
ElMessage.error(error.response?.data?.msg || '启动失败')
|
||||
} finally {
|
||||
submitting.value = false
|
||||
pipelineRunning.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// Pipeline 进度轮询
|
||||
let pipelineTimer = null
|
||||
let pipelinePollingTimer = null
|
||||
|
||||
const startPipelinePolling = (pipelineUuid) => {
|
||||
stopPipelinePolling()
|
||||
if (pipelinePollingTimer) {
|
||||
clearInterval(pipelinePollingTimer)
|
||||
}
|
||||
|
||||
pipelineTimer = setInterval(async () => {
|
||||
pipelinePollingTimer = setInterval(async () => {
|
||||
try {
|
||||
const res = await api.get(`/admin/integration/pipeline-tasks/${pipelineUuid}`)
|
||||
const data = res.data || res
|
||||
currentPipeline.value = data
|
||||
|
||||
// 如果正在推理阶段,同时获取推理任务进度
|
||||
if (data.inference_task_uuid && data.stage === 'inference') {
|
||||
try {
|
||||
const infRes = await api.get(`/admin/inference-data/tasks/${data.inference_task_uuid}`)
|
||||
inferenceTaskProgress.value = infRes.data?.data || infRes.data
|
||||
} catch (e) {
|
||||
// 推理任务可能还未创建
|
||||
}
|
||||
}
|
||||
if (res.status === 'completed' || res.status === 'error') {
|
||||
clearInterval(pipelinePollingTimer)
|
||||
pipelinePollingTimer = null
|
||||
|
||||
const status = data.status
|
||||
if (['completed', 'failed', 'filter_failed', 'inference_failed', 'timeout', 'filter_only'].includes(status)) {
|
||||
stopPipelinePolling()
|
||||
if (status === 'completed' || status === 'filter_only') {
|
||||
if (res.status === 'completed') {
|
||||
ElMessage.success('处理完成')
|
||||
} else if (status === 'filter_failed') {
|
||||
ElMessage.warning('滤波阶段失败,跳过推理')
|
||||
} else {
|
||||
ElMessage.error('处理失败:' + (data.error || '未知错误'))
|
||||
ElMessage.error(`处理失败: ${res.error || '未知错误'}`)
|
||||
}
|
||||
setTimeout(fetchItems, 1000)
|
||||
|
||||
// 刷新列表
|
||||
await fetchItems()
|
||||
}
|
||||
} catch (error) {
|
||||
// 静默失败
|
||||
console.error('轮询 Pipeline 进度失败:', error)
|
||||
}
|
||||
}, 5000)
|
||||
}, 3000) // 每 3 秒轮询一次
|
||||
}
|
||||
|
||||
const stopPipelinePolling = () => {
|
||||
if (pipelineTimer) {
|
||||
clearInterval(pipelineTimer)
|
||||
pipelineTimer = null
|
||||
if (pipelinePollingTimer) {
|
||||
clearInterval(pipelinePollingTimer)
|
||||
pipelinePollingTimer = null
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1450,12 +1456,14 @@ const resetPipeline = () => {
|
||||
pipelineForm.value = {
|
||||
folder_ids: [],
|
||||
filter_type: 'bandpass_0.5_40',
|
||||
model_path: availableModels.value[0]?.path || '',
|
||||
signal_len: 1000,
|
||||
stride: 1000,
|
||||
model_path: '',
|
||||
signal_len: 3000,
|
||||
stride: 1500,
|
||||
confidence_threshold: 0.75,
|
||||
num_classes: 2
|
||||
}
|
||||
pipelineStatusInfo.value = null
|
||||
selectedPatientIds.value = []
|
||||
}
|
||||
|
||||
// Pipeline 状态文本
|
||||
@@ -1870,6 +1878,10 @@ onUnmounted(() => {
|
||||
stopSyncTimer()
|
||||
stopAutoSync() // 停止自动同步
|
||||
stopPipelinePolling() // 停止 Pipeline 轮询
|
||||
if (pipelinePollingTimer) {
|
||||
clearInterval(pipelinePollingTimer)
|
||||
pipelinePollingTimer = null
|
||||
}
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
Reference in new issue
Block a user