| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- <template>
- <Teleport to="body">
- <div v-if="state.open" class="video-monitor-backdrop">
- <section class="video-monitor" role="dialog" aria-modal="true" aria-labelledby="video-monitor-title"
- data-video-monitor data-video-design="dahua-cockpit-b">
- <header class="video-monitor__header">
- <div><span class="video-monitor__eyebrow">VIDEO / 现场监控</span><h2 id="video-monitor-title">{{ state.device?.deviceName || '视频监控设备' }}</h2></div>
- <button type="button" class="video-monitor__close" aria-label="关闭监控" @click="video.close">关闭 <span aria-hidden="true">×</span></button>
- </header>
- <dl class="video-monitor__meta" data-video-meta>
- <div><dt>设备名称</dt><dd data-video-meta-field="deviceName">{{ state.device?.deviceName || '—' }}</dd></div>
- <div><dt>业务设备编码</dt><dd data-video-meta-field="businessCode">{{ state.device?.businessCode || state.device?.deviceCode || '—' }}</dd></div>
- <div><dt>接入方式</dt><dd data-video-meta-field="accessType">{{ accessTypeText }}</dd></div>
- <div><dt>国标设备 / 通道</dt><dd data-video-meta-field="gb">{{ gbText }}</dd></div>
- <div><dt>安装位置</dt><dd data-video-meta-field="location">{{ state.device?.location || '—' }}</dd></div>
- <div><dt>厂商</dt><dd data-video-meta-field="manufacturer">{{ state.device?.manufacturer || '—' }}</dd></div>
- </dl>
- <div class="video-monitor__body">
- <aside class="video-monitor__ptz-panel" data-ptz-panel aria-label="云台界面预留">
- <div class="video-monitor__section-head"><h3>云台控制</h3><span class="video-monitor__badge">界面预留</span></div>
- <div class="video-monitor__ptz-pad" data-ptz-pad role="group" aria-label="八向云台方向盘">
- <button v-for="key in PTZ_DIRECTIONS" :key="key" type="button" :data-ptz-direction="key"
- :class="'video-monitor__direction--' + key" disabled :title="ptzReason" :aria-label="'云台' + PTZ_LABELS[key]">
- <span aria-hidden="true">{{ PTZ_ARROWS[key] }}</span>
- </button>
- <button type="button" class="video-monitor__ptz-stop" data-ptz-stop disabled :title="ptzReason" aria-label="云台停止"><span aria-hidden="true">■</span><small>停止</small></button>
- </div>
- <label class="video-monitor__speed">速度 <span>STEP {{ ptzSpeed }}</span><input v-model="ptzSpeed" type="range" min="1" max="8" step="1" disabled :title="ptzReason" aria-label="云台速度" data-ptz-speed /></label>
- <div class="video-monitor__lens" role="group" aria-label="云台镜头控制">
- <span>变倍</span><button type="button" data-ptz-zoom="out" disabled :title="ptzReason" aria-label="云台缩小">−</button><button type="button" data-ptz-zoom="in" disabled :title="ptzReason" aria-label="云台放大">+</button>
- <span>聚焦</span><button type="button" data-ptz-focus="far" disabled :title="ptzReason" aria-label="云台远焦">−</button><button type="button" data-ptz-focus="near" disabled :title="ptzReason" aria-label="云台近焦">+</button>
- </div>
- <p class="video-monitor__ptz-hint" data-ptz-hint>{{ ptzReason }}</p>
- <p class="video-monitor__note">本期仅呈现控制布局,不发送物理控制命令。</p>
- </aside>
- <div class="video-monitor__viewer">
- <div ref="surface" class="video-monitor__surface" data-video-surface>
- <div class="video-monitor__screen">
- <VideoPlayer v-if="mode === 'live' && state.media" key="live" :media="state.media" :controls="false"
- :muted="playbackMuted" :volume="volume / 100" @ready="video.ready" @error="video.fail" @presentation-error="presentationError = $event" />
- <VideoPlayer v-else-if="mode === 'history' && state.playbackMedia" key="history" :media="state.playbackMedia" :controls="false"
- label="历史录像画面" :muted="playbackMuted" :volume="volume / 100" @ready="video.readyPlayback" @error="video.failPlayback" @presentation-error="presentationError = $event" />
- <div v-else class="video-monitor__placeholder"><span aria-hidden="true">▷</span><p>{{ mode === 'history' ? (state.historyError || '请选择已有录像开始回放') : (state.error || '等待视频连接') }}</p></div>
- </div>
- <div class="video-monitor__toolbar" data-video-toolbar :data-playback-surface="mode === 'history' ? '' : undefined">
- <div class="video-monitor__tabs" role="group" aria-label="视频模式">
- <button type="button" :aria-pressed="mode === 'live'" :disabled="switching" @click="switchMode('live')">实时视频</button>
- <button type="button" :aria-pressed="mode === 'history'" :disabled="switching || !state.device?.capabilities?.records"
- :title="state.device?.capabilities?.records ? '' : '此设备未提供录像查询能力'" @click="switchMode('history')">历史录像</button>
- </div>
- <span class="video-monitor__status" role="status" :data-video-phase="mode === 'live' ? state.phase : state.historyPhase">{{ statusText }}</span>
- <div class="video-monitor__presentation">
- <button type="button" data-video-mute :data-playback-mute="mode === 'history' ? '' : undefined" :disabled="!activeMedia" :aria-pressed="playbackMuted"
- :aria-label="playbackMuted ? '取消静音' : '静音'" @click="togglePlaybackMute">{{ playbackMuted ? '取消静音' : '静音' }}</button>
- <label>音量<input v-model="volume" type="range" min="0" max="100" step="1" :disabled="!activeMedia" aria-label="视频音量" data-video-volume /></label>
- <button type="button" data-video-fullscreen :data-playback-fullscreen="mode === 'history' ? '' : undefined" :disabled="!activeMedia" aria-label="视频画面全屏" @click="enterPlaybackFullscreen">全屏</button>
- </div>
- </div>
- <template v-if="mode === 'history' && state.playbackMedia">
- <div class="video-monitor__playback-controls" role="group" aria-label="录像回放控制">
- <button v-for="control in playbackControls" :key="control.key" type="button" :data-playback-control="control.key" :disabled="!control.enabled"
- :title="control.enabled ? '' : control.reason" :aria-label="control.label" @click="runControl(control)">{{ control.label }}</button>
- </div>
- <label v-if="state.playbackControls?.seek" class="video-monitor__seek">跳转位置
- <input v-model="playbackPosition" type="number" min="0" :max="playbackDuration" step="1" aria-label="录像跳转秒数" data-playback-position />
- <span>/ {{ playbackDuration }} 秒</span>
- <input v-model="playbackPosition" type="range" min="0" :max="playbackDuration" step="1" aria-label="选择录像跳转位置" data-playback-seek-slider />
- </label>
- </template>
- <p v-if="presentationError" class="video-monitor__warning" role="alert" data-video-presentation-error>{{ presentationError }}</p>
- </div>
- <div v-if="mode === 'history'" class="video-monitor__history" data-video-history>
- <div class="video-monitor__range">
- <label>开始(UTC+8)<input v-model="range.startTime" type="text" placeholder="yyyy-MM-dd HH:mm:ss" aria-label="录像查询开始时间" /></label>
- <label>结束(UTC+8)<input v-model="range.endTime" type="text" placeholder="yyyy-MM-dd HH:mm:ss" aria-label="录像查询结束时间" /></label>
- <button type="button" :disabled="state.historyPhase === 'querying'" @click="video.queryHistory(range.startTime, range.endTime)">查询录像</button>
- </div>
- <div class="video-monitor__records-scroll" tabindex="0" aria-label="录像查询结果" data-video-records-region>
- <p v-if="state.historyPhase === 'querying'">正在查询录像…</p>
- <p v-else-if="state.historyError" role="alert">{{ state.historyError }}</p>
- <p v-else-if="state.empty">该时间段没有录像(查询范围不代表留存期限)</p>
- <ul v-else-if="state.records?.length" class="video-monitor__records">
- <li v-for="(record, index) in state.records" :key="index" :class="{ 'is-selected': selectedRecord === record }">
- <span><b>{{ record.name || '录像' }}</b><small>{{ record.type || '录像片段' }} · {{ record.startTime }} ~ {{ record.endTime }}</small></span>
- <button type="button" :disabled="switching || state.historyPhase === 'starting'" :aria-label="'播放录像 ' + record.startTime" @click="playRecord(record)">播放</button>
- </li>
- </ul>
- </div>
- </div>
- </div>
- </div>
- <p v-if="retryNote && mode === 'live'" class="video-monitor__status" role="status">{{ retryNote }}</p>
- <p v-if="state.error && mode === 'live' && state.media" role="alert">{{ state.error }}</p>
- <p v-if="state.cleanupError" class="video-monitor__warning" role="alert">{{ state.cleanupError }}</p>
- <footer class="video-monitor__footer">
- <button v-if="mode === 'live' && !state.media && !['starting','connecting','retrying'].includes(state.phase)" type="button" :disabled="Boolean(state.cleanupError)" @click="video.retry">重新播放</button>
- <button v-if="state.cleanupError" type="button" @click="video.retryCleanup">重试清理</button>
- <span>默认静音 · 不提供截图、下载或录制</span><span>Jessibuca / FLV</span>
- </footer>
- </section>
- </div>
- </Teleport>
- </template>
- <script setup>
- import { watch, onMounted, onBeforeUnmount, nextTick, computed, ref, reactive } from 'vue'
- import { storeToRefs } from 'pinia'
- import { useVideoStore } from '../stores/videoStore.js'
- import { useUiStore } from '../stores/uiStore.js'
- import { useDetailStore } from '../stores/detailStore.js'
- import { useEnhancementDevicesStore } from '../stores/enhancementDevicesStore.js'
- import VideoPlayer from './VideoPlayer.vue'
- const video = useVideoStore(), ui = useUiStore(), detail = useDetailStore(), enhancement = useEnhancementDevicesStore()
- const { state } = storeToRefs(video)
- const labels = { idle: '未播放', starting: '正在建立视频会话', connecting: '等待视频画面', playing: '正在播放', retrying: '连接中断,正在自动重连', failed: '播放失败', querying: '正在查询录像', listed: '已返回录像列表' }
- // Switching tabs ends the current stream but must keep the monitor open.
- const mode = ref('live')
- const range = reactive(video.historyWindow())
- const switching = ref(false)
- // This release presents PTZ only; a capability flag alone must never enable physical commands.
- const PTZ_DIRECTIONS = ['up-left', 'up', 'up-right', 'left', 'right', 'down-left', 'down', 'down-right']
- const PTZ_LABELS = { up: '上', down: '下', left: '左', right: '右', 'up-left': '左上', 'up-right': '右上', 'down-left': '左下', 'down-right': '右下' }
- const PTZ_ARROWS = { up: '↑', down: '↓', left: '←', right: '→', 'up-left': '↖', 'up-right': '↗', 'down-left': '↙', 'down-right': '↘' }
- const ptzSpeed = ref(4)
- const ptzReason = computed(() => state.value.cleanupError ? '会话释放未确认,暂停控制'
- : state.value.device?.capabilities?.ptz ? '云台操作尚未接入,本期仅界面预留' : '设备暂不支持云台控制')
- // Access mode and GB identifiers come straight from the binding; blanks show as a dash.
- const ACCESS_TEXT = { GB28181: '国标接入', MANUAL: '手工接入' }
- const accessTypeText = computed(() => {
- const type = state.value.device?.sourceType || state.value.device?.accessType
- return ACCESS_TEXT[type] || type || '—'
- })
- const gbText = computed(() => {
- const device = state.value.device
- return device?.gbDeviceId || device?.gbChannelId
- ? `${device.gbDeviceId || '—'} / ${device.gbChannelId || '—'}`
- : '—'
- })
- let modeVersion = 0
- const switchMode = async (next) => {
- if (next === mode.value || switching.value) return
- const version = ++modeVersion
- switching.value = true
- try {
- if (next === 'history') await video.stopLive()
- else await video.stopPlayback()
- // Close, selection changes and unconfirmed cleanup must not resume an old switch.
- if (version !== modeVersion || !state.value.open || state.value.cleanupError) return
- mode.value = next
- if (next === 'history') await video.queryHistory(range.startTime, range.endTime)
- else await video.startLive()
- } finally { if (version === modeVersion) switching.value = false }
- }
- const selectedRecord = ref(null)
- const playRecord = async (record) => {
- playbackPosition.value = ''
- selectedRecord.value = record
- await video.play(record.startTime, record.endTime)
- }
- // Controls describe the server operation set, not a claim of physical device support.
- const CONTROL_REASON = '服务端未开放此控制能力'
- const playbackControls = computed(() => {
- const granted = state.value.playbackControls || {}
- // Speed keys are per-rate in the UI but share one confirmed capability on the server.
- const control = (key, label, capability = key) => ({ key, label, enabled: granted[capability] === true, reason: CONTROL_REASON })
- return [control('pause', '暂停'), control('resume', '继续'), control('speed-0.25', '0.25×', 'speed'),
- control('speed-0.5', '0.5×', 'speed'), control('speed-1', '1×', 'speed'), control('speed-2', '2×', 'speed'),
- control('speed-4', '4×', 'speed'), control('seek', '跳转')]
- })
- // A seek needs a position inside the chosen recording; the panel asks for one instead of guessing.
- const playbackPosition = ref('')
- // The chosen recording's own length, so the seek input cannot promise a position it does not have.
- const playbackDuration = computed(() => Math.floor(Number(state.value.durationSeconds) || 0))
- // A disabled control must not reach the server even when activated programmatically.
- const runControl = (control) => {
- if (!control.enabled) return
- if (control.key === 'seek') {
- // An empty box must not silently mean "seek to 0".
- if (String(playbackPosition.value).trim() === '') return
- const seconds = Number(playbackPosition.value)
- if (!Number.isFinite(seconds)) return
- void video.controlPlayback('seek', seconds)
- return
- }
- void video.controlPlayback(control.key)
- }
- // Local presentation never creates a new business session or sends a device command.
- const surface = ref(null)
- const playbackMuted = ref(true), volume = ref(50), presentationError = ref('')
- const activeMedia = computed(() => mode.value === 'live' ? state.value.media : state.value.playbackMedia)
- const statusText = computed(() => labels[mode.value === 'live' ? state.value.phase : state.value.historyPhase] || '未播放')
- const togglePlaybackMute = () => { playbackMuted.value = !playbackMuted.value; presentationError.value = '' }
- const enterPlaybackFullscreen = async () => {
- const target = surface.value
- presentationError.value = ''
- try {
- if (!target?.requestFullscreen) throw new Error('此浏览器不支持画面全屏')
- await target.requestFullscreen()
- } catch (error) { presentationError.value = error?.message || '无法进入全屏,请检查浏览器权限' }
- }
- watch(activeMedia, () => { playbackMuted.value = true; presentationError.value = '' })
- const retryNote = computed(() => state.value.phase !== 'retrying' || !state.value.retryAttempt
- ? ''
- : `第 ${state.value.retryAttempt} 次自动重试,等待 ${Math.round((state.value.retryDelayMs || 0) / 1000)} 秒(剩余 ${state.value.retriesLeft ?? 0} 次)`)
- watch(() => ui.mode, () => { void video.close() }, { flush: 'sync' })
- watch(() => [state.value.ownerSource, detail.selection.deviceCode, enhancement.selected?.code], ([ownerSource, detailCode, enhancementCode]) => {
- const currentCode = ownerSource === 'enhancement' ? enhancementCode : detailCode
- if (state.value.open && currentCode !== state.value.device?.deviceCode) void video.close()
- }, { flush: 'sync' })
- let trigger
- watch(() => state.value.open, async (open) => {
- modeVersion++; switching.value = false
- if (!open) { if (trigger?.isConnected) trigger.focus?.(); return }
- mode.value = 'live'; selectedRecord.value = null; playbackPosition.value = ''; playbackMuted.value = true; volume.value = 50
- Object.assign(range, video.historyWindow())
- trigger = document.activeElement
- await nextTick()
- if (state.value.open) document.querySelector('[data-video-monitor] [aria-label="关闭监控"]')?.focus()
- })
- const keyboard = (event) => {
- if (!state.value.open) return
- if (event.key === 'Escape') { event.preventDefault(); void video.close(); return }
- if (event.key !== 'Tab') return
- // Fullscreen hides the rest of the dialog; never wrap focus onto an invisible close button.
- const root = document.fullscreenElement === surface.value ? surface.value : document.querySelector('[data-video-monitor]')
- const items = Array.from(root?.querySelectorAll('button:not(:disabled), input:not(:disabled), select:not(:disabled), [tabindex="0"]') || [])
- .filter(element => !element.hidden && element.getAttribute('aria-hidden') !== 'true')
- if (!items.length) return
- const index = items.indexOf(document.activeElement)
- if (index < 0 || (event.shiftKey && index === 0) || (!event.shiftKey && index === items.length - 1)) {
- event.preventDefault(); items[event.shiftKey ? items.length - 1 : 0].focus?.()
- }
- }
- const hidden = () => { if (document.hidden) void video.close() }
- const leave = () => { void video.close() }
- onMounted(() => { document.addEventListener('visibilitychange', hidden); document.addEventListener('keydown', keyboard); window.addEventListener('pagehide', leave) })
- onBeforeUnmount(() => { document.removeEventListener('visibilitychange', hidden); document.removeEventListener('keydown', keyboard); window.removeEventListener('pagehide', leave); void video.close() })
- </script>
- <style scoped src="./videoMonitorPanel.css"></style>
|