新增:隐患检查主页添加运行日志

This commit is contained in:
yueliuli 2026-05-09 14:12:34 +08:00
parent ed64a9c5a3
commit 45e3a8b754
1 changed files with 59 additions and 8 deletions

View File

@ -11,6 +11,8 @@ const runCheckBtnRef = ref()
const isRunningCheck = ref(false) const isRunningCheck = ref(false)
const vidPaths = ref<string[]>([]) const vidPaths = ref<string[]>([])
const processLog = ref<string[]>([])
interface RuleForm { interface RuleForm {
vidPath: string vidPath: string
function: 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() { async function runProcess() {
isRunningCheck.value = true isRunningCheck.value = true
startTimer() startTimer()
const tasks: Promise<any>[] = [] const tasks: Promise<any>[] = []
processLog.value = []
processLog.value.push(`[${formatTime(new Date())}] 💬开始运行...`)
if (ruleForm.function.includes('runAudioRecognition')) { if (ruleForm.function.includes('runAudioRecognition')) {
tasks.push(runApiAudio('recognize', 'GET', { tasks.push(runApiAudio('recognize', 'GET', {
path: vidPaths.value[vidPaths.value.indexOf(ruleForm.vidPath)], 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')) { if (ruleForm.function.includes('convertToMp4')) {
tasks.push(runApiAudio('convert', 'GET', { tasks.push(runApiAudio('convert', 'GET', {
path: vidPaths.value[vidPaths.value.indexOf(ruleForm.vidPath)], 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_sam3: ruleForm.function.includes('runSam3'),
run_inspection: ruleForm.function.includes('runHazardCheck'), run_inspection: ruleForm.function.includes('runHazardCheck'),
gen_report: ruleForm.function.includes('runGenerateReport'), 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) => { await Promise.all(tasks).then((results) => {
isRunningCheck.value = false isRunningCheck.value = false
stopTimer()
processLog.value.push(`[${formatTime(new Date())}] 💬运行结束,耗时${timerDisplay.value}`)
// //
const lastRes = results[results.length - 1] for (const res of results) {
if (lastRes !== 'error') { // console.log('', String(res))
router.push({ if (res === 'error') {
path: '/nav/hazardCheckResult', return
query: { vid_file: vidPaths.value[vidPaths.value.indexOf(ruleForm.vidPath)] }, }
})
} }
})
stopTimer() router.push({
path: '/nav/hazardCheckResult',
query: { vid_file: vidPaths.value[vidPaths.value.indexOf(ruleForm.vidPath)] },
})
})
} }
async function reloadFiles() { async function reloadFiles() {
@ -213,6 +243,18 @@ onMounted(() => {
> >
<el-text>{{ timerDisplay }}</el-text> <el-text>{{ timerDisplay }}</el-text>
</el-progress> </el-progress>
<div v-if="processLog.length > 0" class="log-container">
<div class="log-header">
<el-text size="large">
运行日志
</el-text>
</div>
<div v-for="(item, index) in processLog" :key="index" class="log-item">
<el-text :key="item" type="info">
{{ item }}
</el-text>
</div>
</div>
</div> </div>
</el-main> </el-main>
</el-container> </el-container>
@ -231,4 +273,13 @@ onMounted(() => {
gap: 16px; gap: 16px;
justify-content: flex-start; justify-content: flex-start;
} }
.log-container {
// text-align: left;
margin-top: 20px;
width: 100%;
display: flex;
flex-direction: column;
align-items: flex-start;
}
</style> </style>