重构:优化代码结构

This commit is contained in:
yueliuli 2026-05-08 14:52:00 +08:00
parent b477db4bd2
commit 709d9fe796
2 changed files with 17 additions and 31 deletions

View File

@ -18,8 +18,8 @@ const props = defineProps({
const emit = defineEmits(['click']) const emit = defineEmits(['click'])
// //
function handleItemClick(item: string, index: number) { function handleItemClick(index: number) {
emit('click', item, index) emit('click', index)
} }
</script> </script>
@ -38,7 +38,7 @@ function handleItemClick(item: string, index: number) {
<el-row v-for="(item, index) in props.data" :key="index"> <el-row v-for="(item, index) in props.data" :key="index">
<!-- 无物体类型标签 隐患等级体颜色显示在编号标签上 --> <!-- 无物体类型标签 隐患等级体颜色显示在编号标签上 -->
<!-- 0为隐患等级 1为隐患描述 --> <!-- 0为隐患等级 1为隐患描述 -->
<el-button class="item-btn" text @click="handleItemClick(item as string, index)"> <el-button class="item-btn" text @click="handleItemClick(index)">
<el-tag v-if="(item as number[])[0] === 0" type="primary" size="small"> <el-tag v-if="(item as number[])[0] === 0" type="primary" size="small">
{{ index + 1 }} {{ index + 1 }}
</el-tag> </el-tag>

View File

@ -131,9 +131,9 @@ const totalFrames = computed(() => {
return maxEndFrame + 100 return maxEndFrame + 100
}) })
function handleTimelineHazardClick(hazardId: string) { function handleTimelineHazardClick(hazardId: number) {
selectedHazard.value = Number(hazardId) selectedHazard.value = hazardId
handleJumpToHazard(Number(hazardId)) handleJumpToHazard(hazardId)
} }
function handleFrameChange(frame: number) { function handleFrameChange(frame: number) {
@ -209,7 +209,7 @@ function getData() {
} }
// //
function handleHazardClick(item: string, index: number) { function handleHazardClick(index: number) {
selectedHazard.value = index selectedHazard.value = index
handleJumpToHazard(selectedHazard.value) handleJumpToHazard(selectedHazard.value)
@ -221,10 +221,10 @@ function handleJumpToHazard(index: number) {
// //
// console.log(`: ${seconds}`) // console.log(`: ${seconds}`)
handleJumpToTimePoint(seconds) handleJumpToTimePoint(seconds, 'pause')
} }
function handleJumpToTimePoint(seconds: number) { function handleJumpToTimePoint(seconds: number, action: string = 'play') {
// 0 // 0
if (Number.isNaN(seconds) || seconds < 0) if (Number.isNaN(seconds) || seconds < 0)
return return
@ -236,23 +236,10 @@ function handleJumpToTimePoint(seconds: number) {
// currentTime // currentTime
videoEl.currentTime = seconds videoEl.currentTime = seconds
currentFrame.value = Math.floor(seconds * 30) currentFrame.value = Math.floor(seconds * 30)
if (action === 'play')
// videoEl.play()
videoEl.pause() else if (action === 'pause')
} videoEl.pause()
function handlePlayAndSeek(item: any[]) {
const seconds = item[0]
if (Number.isNaN(seconds) || seconds < 0)
return
const videoEl = videoRef.value
if (!videoEl)
return
videoEl.currentTime = seconds
currentFrame.value = Math.floor(seconds * 30)
videoEl.play()
} }
function getAudioRecData(res: any) { function getAudioRecData(res: any) {
@ -373,8 +360,7 @@ onMounted(async () => {
getData() getData()
if (data.value.隐患列表.length > 0) { if (data.value.隐患列表.length > 0) {
selectedHazard.value = 0 handleHazardClick(0)
handleJumpToHazard(0)
} }
}) })
@ -432,7 +418,7 @@ onMounted(async () => {
:current-frame="currentFrame" :current-frame="currentFrame"
:total-frames="totalFrames" :total-frames="totalFrames"
:hazard-ranges="data.隐患范围字典 as Record<string, { ranges: number[]; level: number; tip: string }>" :hazard-ranges="data.隐患范围字典 as Record<string, { ranges: number[]; level: number; tip: string }>"
@hazard-click="(id: number) => handleTimelineHazardClick(String(id))" @hazard-click="(id: number) => handleTimelineHazardClick(id)"
@frame-change="handleFrameChange" @frame-change="handleFrameChange"
/> />
</el-footer> </el-footer>
@ -483,8 +469,8 @@ onMounted(async () => {
:data="data.对话列表" :data="data.对话列表"
:current-time="videoCurrentTime" :current-time="videoCurrentTime"
:keywords="keywords" :keywords="keywords"
@click="(item: any[]) => handleJumpToTimePoint(Number(item[0]))" @click="(item: any[]) => handleJumpToTimePoint(Number(item[0]), 'pause')"
@play="(item: any[]) => handlePlayAndSeek(item)" @play="(item: any[]) => handleJumpToTimePoint(Number(item[0]), 'play')"
/> />
</el-row> </el-row>
<!-- <el-row class="px-1 py-1"> <!-- <el-row class="px-1 py-1">