diff --git a/src/pages/index.vue b/src/pages/index.vue index 3d8ab7e..7257209 100644 --- a/src/pages/index.vue +++ b/src/pages/index.vue @@ -11,6 +11,8 @@ const runCheckBtnRef = ref() const isRunningCheck = ref(false) const vidPaths = ref([]) +const processLog = ref([]) + interface RuleForm { vidPath: string function: string[] @@ -76,20 +78,38 @@ async function runCheck(formEl: FormInstance | undefined) { } } +function formatTime(date: Date) { + return `${date.getFullYear()}-${(date.getMonth() + 1).toString().padStart(2, '0')}-${date.getDate().toString().padStart(2, '0')} ${date.getHours().toString().padStart(2, '0')}:${date.getMinutes().toString().padStart(2, '0')}:${date.getSeconds().toString().padStart(2, '0')}` +} + async function runProcess() { isRunningCheck.value = true startTimer() const tasks: Promise[] = [] + processLog.value = [] + processLog.value.push(`[${formatTime(new Date())}] 💬开始运行...`) if (ruleForm.function.includes('runAudioRecognition')) { tasks.push(runApiAudio('recognize', 'GET', { path: vidPaths.value[vidPaths.value.indexOf(ruleForm.vidPath)], + }).then((res) => { + if (res === 'error') + processLog.value.push(`[${formatTime(new Date())}] ❌️音频识别失败`) + else + processLog.value.push(`[${formatTime(new Date())}] ✅️音频识别完成`) + return res })) } if (ruleForm.function.includes('convertToMp4')) { tasks.push(runApiAudio('convert', 'GET', { path: vidPaths.value[vidPaths.value.indexOf(ruleForm.vidPath)], + }).then((res) => { + if (res === 'error') + processLog.value.push(`[${formatTime(new Date())}] ❌️转码失败`) + else + processLog.value.push(`[${formatTime(new Date())}] ✅️转码完成`) + return res })) } @@ -98,21 +118,31 @@ async function runProcess() { run_sam3: ruleForm.function.includes('runSam3'), run_inspection: ruleForm.function.includes('runHazardCheck'), gen_report: ruleForm.function.includes('runGenerateReport'), + }).then((res) => { + if (res === 'error') + processLog.value.push(`[${formatTime(new Date())}] ❌️隐患检测结果不存在或运行失败`) + else + processLog.value.push(`[${formatTime(new Date())}] ✅️隐患检测完成`) + return res })) await Promise.all(tasks).then((results) => { isRunningCheck.value = false + stopTimer() + processLog.value.push(`[${formatTime(new Date())}] 💬运行结束,耗时${timerDisplay.value}`) // 判定是否成功运行 - const lastRes = results[results.length - 1] - if (lastRes !== 'error') { - router.push({ - path: '/nav/hazardCheckResult', - query: { vid_file: vidPaths.value[vidPaths.value.indexOf(ruleForm.vidPath)] }, - }) + for (const res of results) { + // console.log('判定', String(res)) + if (res === 'error') { + return + } } - }) - stopTimer() + router.push({ + path: '/nav/hazardCheckResult', + query: { vid_file: vidPaths.value[vidPaths.value.indexOf(ruleForm.vidPath)] }, + }) + }) } async function reloadFiles() { @@ -213,6 +243,18 @@ onMounted(() => { > {{ timerDisplay }} +
+
+ + 运行日志 + +
+
+ + {{ item }} + +
+
@@ -231,4 +273,13 @@ onMounted(() => { gap: 16px; justify-content: flex-start; } + +.log-container { + // text-align: left; + margin-top: 20px; + width: 100%; + display: flex; + flex-direction: column; + align-items: flex-start; +}