feat: 在播放控制器和运动监控页面中新增日期选择功能,支持用户选择回放日期并同步更新状态

This commit is contained in:
xudan 2025-10-13 16:08:28 +08:00
parent b7db343ba7
commit a6a77a3111
2 changed files with 22 additions and 5 deletions

View File

@ -1,6 +1,7 @@
<script setup lang="ts">
import { CaretRightOutlined, PauseOutlined } from '@ant-design/icons-vue';
import { computed, ref, watch, onUnmounted } from 'vue';
import type { Dayjs } from 'dayjs';
import { computed, onUnmounted, ref, watch } from 'vue';
import { useTimelineTicks } from '../hooks/useTimelineTicks';
@ -8,12 +9,14 @@ const props = defineProps<{
isPlaying: boolean;
currentTime: number; // in milliseconds
totalDuration: number; // in milliseconds
selectedDate?: Dayjs;
}>();
const emit = defineEmits<{
(e: 'play'): void;
(e: 'pause'): void;
(e: 'seek', time: number): void;
(e: 'dateChange', date: Dayjs): void;
}>();
// --- Constants ---
@ -75,8 +78,6 @@ watch(
return;
}
// / currentTime
if (Number.isFinite(newValue) && newValue >= 0 && props.totalDuration > 0) {
const maxHour = Math.max(Math.ceil(props.totalDuration / HOUR_IN_MS) - 1, 0);
@ -127,6 +128,12 @@ const hourOptions = computed(() => {
const timelineContainerRef = ref<HTMLElement | null>(null);
let interactionTimer: number | undefined;
const handleDateChange = (date: Dayjs | null) => {
if (date) {
emit('dateChange', date);
}
};
//
const setUserInteraction = () => {
isUserInteracting.value = true;
@ -200,6 +207,12 @@ const handleTimelineClick = (event: MouseEvent) => {
<!-- Hour Selector -->
<a-col>
<a-date-picker
:value="selectedDate"
placeholder="请选择回放日期"
@change="handleDateChange"
style="margin-right: 8px"
/>
<a-select :value="selectedHour" style="width: 150px" :options="hourOptions" @change="handleHourChange" />
</a-col>

View File

@ -121,6 +121,10 @@ const handleSeek = (relativeTime: number) => {
}
};
const handleDateChange = (date: Dayjs) => {
selectedDate.value = date;
};
// UI
watch(playback.currentTime, (newTimestamp) => {
if (newTimestamp > 0 && selectedDate.value) {
@ -647,8 +651,6 @@ const handleGlobalKeydown = (event: KeyboardEvent) => {
楼层 {{ index + 1 }}
</a-select-option>
</a-select>
<a-date-picker v-if="isPlaybackMode" v-model:value="selectedDate" placeholder="请选择回放日期" />
</a-space>
</a-flex>
</a-layout-header>
@ -739,9 +741,11 @@ const handleGlobalKeydown = (event: KeyboardEvent) => {
:is-playing="playback.isPlaying.value"
:current-time="playback.currentTime.value - (selectedDate?.startOf('day').valueOf() ?? 0)"
:total-duration="playback.totalDuration.value"
:selected-date="selectedDate"
@play="playback.play"
@pause="playback.pause"
@seek="handleSeek"
@date-change="handleDateChange"
/>
</template>
</template>