VideoMonitorPanel.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. <template>
  2. <Teleport to="body">
  3. <div v-if="state.open" class="video-monitor-backdrop">
  4. <section class="video-monitor" role="dialog" aria-modal="true" aria-labelledby="video-monitor-title" data-video-monitor>
  5. <header>
  6. <div>
  7. <h2 id="video-monitor-title">{{ state.device?.deviceName || '视频监控设备' }}</h2>
  8. <!-- The six fields the operator checks on a monitor device (维护者 2026-11-18). -->
  9. <dl class="video-monitor__meta" data-video-meta>
  10. <div><dt>设备名称</dt><dd data-video-meta-field="deviceName">{{ state.device?.deviceName || '—' }}</dd></div>
  11. <div><dt>业务设备编码</dt><dd data-video-meta-field="businessCode">{{ state.device?.businessCode || state.device?.deviceCode || '—' }}</dd></div>
  12. <div><dt>接入方式</dt><dd data-video-meta-field="accessType">{{ accessTypeText }}</dd></div>
  13. <div><dt>国标设备 / 通道</dt><dd data-video-meta-field="gb">{{ gbText }}</dd></div>
  14. <div><dt>安装位置</dt><dd data-video-meta-field="location">{{ state.device?.location || '—' }}</dd></div>
  15. <div><dt>厂商</dt><dd data-video-meta-field="manufacturer">{{ state.device?.manufacturer || '—' }}</dd></div>
  16. </dl>
  17. </div>
  18. <button type="button" aria-label="关闭监控" @click="video.close">关闭</button>
  19. </header>
  20. <div class="video-monitor__tabs">
  21. <button type="button" :aria-pressed="mode === 'live'" @click="switchMode('live')">实时视频</button>
  22. <button type="button" :aria-pressed="mode === 'history'" :disabled="!state.device?.capabilities?.records"
  23. :title="state.device?.capabilities?.records ? '' : '此设备未确认录像能力'" @click="switchMode('history')">历史录像</button>
  24. </div>
  25. <template v-if="mode === 'history'">
  26. <div class="video-monitor__range">
  27. <label>开始 <input v-model="range.startTime" type="text" placeholder="yyyy-MM-dd HH:mm:ss" /></label>
  28. <label>结束 <input v-model="range.endTime" type="text" placeholder="yyyy-MM-dd HH:mm:ss" /></label>
  29. <button type="button" :disabled="state.historyPhase === 'querying'" @click="video.queryHistory(range.startTime, range.endTime)">查询录像</button>
  30. </div>
  31. <p v-if="state.historyPhase === 'querying'">正在查询录像…</p>
  32. <p v-else-if="state.historyError" role="alert">{{ state.historyError }}</p>
  33. <p v-else-if="state.historyPhase === 'listed' && state.empty">该时间段没有录像(查询范围不代表留存期限)</p>
  34. <ul v-else-if="state.records?.length" class="video-monitor__records">
  35. <li v-for="(record, index) in state.records" :key="index">
  36. <span>{{ record.name || '录像' }}{{ record.type ? ` · ${record.type}` : '' }} {{ record.startTime }} ~ {{ record.endTime }}</span>
  37. <button type="button" @click="playRecord(record)">播放</button>
  38. </li>
  39. </ul>
  40. <!-- Volume and fullscreen are not device capabilities, so they stay usable here;
  41. the native bar was removed only to stop pause/seek bypassing the grey gate. -->
  42. <div v-if="state.playbackMedia" class="video-monitor__playback-controls" data-playback-surface>
  43. <button type="button" data-playback-mute :aria-pressed="playbackMuted"
  44. @click="togglePlaybackMute">{{ playbackMuted ? '取消静音' : '静音' }}</button>
  45. <button type="button" data-playback-fullscreen @click="enterPlaybackFullscreen">全屏</button>
  46. <label v-if="state.playbackControls?.seek" class="video-monitor__seek">
  47. 跳到 <input v-model="playbackPosition" type="number" min="0" step="1" data-playback-position /> 秒
  48. </label>
  49. </div>
  50. <!-- Unconfirmed playback controls stay visible but grey, each stating why. -->
  51. <div v-if="state.playbackMedia" class="video-monitor__playback-controls">
  52. <button v-for="control in playbackControls" :key="control.key" type="button" data-playback-control
  53. :data-playback-control="control.key" :disabled="!control.enabled"
  54. :title="control.enabled ? '' : control.reason" @click="runControl(control)">{{ control.label }}</button>
  55. </div>
  56. </template>
  57. <p class="video-monitor__status" role="status">{{ labels[state.phase] || '未播放' }}</p>
  58. <p v-if="retryNote" class="video-monitor__status" role="status">{{ retryNote }}</p>
  59. <div class="video-monitor__body">
  60. <aside data-ptz-panel>
  61. <h3>云台控制</h3>
  62. <!-- Buttons always exist; an absent capability or permission only greys them (维护者 2026-11-18). -->
  63. <div class="video-monitor__ptz" role="group" aria-label="云台控制">
  64. <button v-for="key in PTZ_DIRECTIONS" :key="key" type="button" :data-ptz-direction="key"
  65. :disabled="!ptzEnabled" :title="ptzEnabled ? '' : ptzReason">{{ ptzLabel(key) }}</button>
  66. </div>
  67. <div class="video-monitor__ptz" role="group" aria-label="云台变倍">
  68. <button type="button" data-ptz-zoom="in" :disabled="!ptzEnabled" :title="ptzEnabled ? '' : ptzReason">放大</button>
  69. <button type="button" data-ptz-zoom="out" :disabled="!ptzEnabled" :title="ptzEnabled ? '' : ptzReason">缩小</button>
  70. </div>
  71. <button type="button" data-ptz-stop :disabled="!ptzEnabled" :title="ptzEnabled ? '' : ptzReason">停止</button>
  72. <p v-if="!ptzEnabled" data-ptz-hint>{{ ptzReason }}</p>
  73. </aside>
  74. <div class="video-monitor__screen">
  75. <VideoPlayer v-if="state.media" :media="state.media" @ready="video.ready" @error="video.fail" />
  76. <!-- Live and playback share one Jessibuca FLV player; native controls would
  77. also bypass the grey gate, so playback turns them off. -->
  78. <VideoPlayer v-else-if="state.playbackMedia" :media="state.playbackMedia"
  79. label="历史录像画面" :controls="false"
  80. @ready="video.readyPlayback" @error="video.failPlayback" />
  81. <p v-else-if="state.phase === 'retrying'">等待自动重连…</p>
  82. <p v-else>{{ state.error || '等待视频连接' }}</p>
  83. </div>
  84. </div>
  85. <p v-if="state.error && state.media" role="alert">{{ state.error }}</p>
  86. <p v-if="state.cleanupError" class="video-monitor__warning" role="alert">{{ state.cleanupError }}</p>
  87. <footer>
  88. <button v-if="!state.media && !['starting','connecting','retrying'].includes(state.phase)" type="button" :disabled="Boolean(state.cleanupError)" @click="video.retry">重新播放</button>
  89. <button v-if="state.cleanupError" type="button" @click="video.retryCleanup">重试清理</button>
  90. <span>默认静音 · 不提供截图、下载或录制</span>
  91. </footer>
  92. </section>
  93. </div>
  94. </Teleport>
  95. </template>
  96. <script setup>
  97. import { watch, onMounted, onBeforeUnmount, nextTick, computed, ref, reactive } from 'vue'
  98. import { storeToRefs } from 'pinia'
  99. import { useVideoStore } from '../stores/videoStore.js'
  100. import { useUiStore } from '../stores/uiStore.js'
  101. import { useDetailStore } from '../stores/detailStore.js'
  102. import { useEnhancementDevicesStore } from '../stores/enhancementDevicesStore.js'
  103. import VideoPlayer from './VideoPlayer.vue'
  104. const video = useVideoStore(), ui = useUiStore(), detail = useDetailStore(), enhancement = useEnhancementDevicesStore()
  105. const { state } = storeToRefs(video)
  106. const labels = { idle: '未播放', starting: '正在建立视频会话', connecting: '等待视频画面', playing: '正在播放', retrying: '连接中断,正在自动重连', failed: '播放失败', querying: '正在查询录像', listed: '已返回录像列表' }
  107. // Switching tabs ends the current stream but must keep the monitor open.
  108. const mode = ref('live')
  109. const range = reactive(video.historyWindow())
  110. // PTZ panel: the buttons are always present; only capability/permission greys them out.
  111. const PTZ_DIRECTIONS = ['up', 'down', 'left', 'right', 'up-left', 'up-right', 'down-left', 'down-right']
  112. const PTZ_LABELS = { up: '上', down: '下', left: '左', right: '右', 'up-left': '左上', 'up-right': '右上', 'down-left': '左下', 'down-right': '右下' }
  113. const ptzLabel = (key) => PTZ_LABELS[key]
  114. // Real device PTZ control is ticket 06; until the device confirms it, the buttons stay grey with a reason.
  115. const PTZ_UNCONFIRMED = '设备未确认云台能力或当前无控制权限'
  116. const ptzEnabled = computed(() => {
  117. const device = state.value.device
  118. return Boolean(device?.capabilities?.ptz) && !state.value.cleanupError
  119. })
  120. const ptzReason = computed(() => state.value.cleanupError ? '会话释放未确认,暂停控制' : PTZ_UNCONFIRMED)
  121. // Access mode and GB identifiers come straight from the binding; blanks show as a dash.
  122. const ACCESS_TEXT = { GB28181: '国标接入', MANUAL: '手工接入' }
  123. const accessTypeText = computed(() => {
  124. const type = state.value.device?.sourceType || state.value.device?.accessType
  125. return ACCESS_TEXT[type] || type || '—'
  126. })
  127. const gbText = computed(() => {
  128. const device = state.value.device
  129. return device?.gbDeviceId || device?.gbChannelId
  130. ? `${device.gbDeviceId || '—'} / ${device.gbChannelId || '—'}`
  131. : '—'
  132. })
  133. const switchMode = async (next) => {
  134. if (next === mode.value) return
  135. if (next === 'history') {
  136. await video.stopLive()
  137. mode.value = 'history'
  138. await video.queryHistory(range.startTime, range.endTime)
  139. } else {
  140. await video.stopPlayback()
  141. mode.value = 'live'
  142. await video.startLive()
  143. }
  144. }
  145. const playRecord = (record) => video.play(record.startTime, record.endTime)
  146. // Every playback control is advertised with its real availability. Until a device is confirmed,
  147. // each stays grey with a stated reason instead of silently disappearing.
  148. const CONTROL_REASON = '真实设备未确认此控制能力,暂不开放'
  149. const playbackControls = computed(() => {
  150. const granted = state.value.playbackControls || {}
  151. // Speed keys are per-rate in the UI but share one confirmed capability on the server.
  152. const control = (key, label, capability = key) => ({ key, label, enabled: granted[capability] === true, reason: CONTROL_REASON })
  153. return [control('pause', '暂停'), control('resume', '继续'), control('speed-0.25', '0.25×', 'speed'),
  154. control('speed-0.5', '0.5×', 'speed'), control('speed-1', '1×', 'speed'), control('speed-2', '2×', 'speed'),
  155. control('speed-4', '4×', 'speed'), control('seek', '跳转')]
  156. })
  157. // A seek needs a position inside the chosen recording; the panel asks for one instead of guessing.
  158. const playbackPosition = ref('')
  159. // A disabled control must not reach the server even when activated programmatically.
  160. const runControl = (control) => {
  161. if (!control.enabled) return
  162. if (control.key === 'seek') {
  163. const seconds = Number(playbackPosition.value)
  164. if (!Number.isFinite(seconds)) return
  165. void video.controlPlayback('seek', seconds)
  166. return
  167. }
  168. void video.controlPlayback(control.key)
  169. }
  170. // Local presentation only: the player starts muted, and neither action is a device capability.
  171. const playbackMuted = ref(true)
  172. const playbackVideo = () => document.querySelector('[data-video-monitor] video[aria-label="历史录像画面"]')
  173. const togglePlaybackMute = () => {
  174. const element = playbackVideo()
  175. if (!element) return
  176. playbackMuted.value = !playbackMuted.value
  177. element.muted = playbackMuted.value
  178. }
  179. const enterPlaybackFullscreen = () => { void playbackVideo()?.requestFullscreen?.() }
  180. const retryNote = computed(() => state.value.phase !== 'retrying' || !state.value.retryAttempt
  181. ? ''
  182. : `第 ${state.value.retryAttempt} 次自动重试,等待 ${Math.round((state.value.retryDelayMs || 0) / 1000)} 秒(剩余 ${state.value.retriesLeft ?? 0} 次)`)
  183. watch(() => ui.mode, () => { void video.close() }, { flush: 'sync' })
  184. watch(() => [state.value.ownerSource, detail.selection.deviceCode, enhancement.selected?.code], ([ownerSource, detailCode, enhancementCode]) => {
  185. const currentCode = ownerSource === 'enhancement' ? enhancementCode : detailCode
  186. if (state.value.open && currentCode !== state.value.device?.deviceCode) void video.close()
  187. }, { flush: 'sync' })
  188. let trigger
  189. watch(() => state.value.open, async (open) => {
  190. if (!open) { if (trigger?.isConnected) trigger.focus?.(); return }
  191. trigger = document.activeElement
  192. await nextTick()
  193. if (state.value.open) document.querySelector('[data-video-monitor] [aria-label="关闭监控"]')?.focus()
  194. })
  195. const keyboard = (event) => {
  196. if (!state.value.open) return
  197. if (event.key === 'Escape') { event.preventDefault(); void video.close(); return }
  198. if (event.key !== 'Tab') return
  199. const items = Array.from(document.querySelectorAll('[data-video-monitor] button:not(:disabled), [data-video-monitor] video'))
  200. if (!items.length) return
  201. const index = items.indexOf(document.activeElement)
  202. if (index < 0 || (event.shiftKey && index === 0) || (!event.shiftKey && index === items.length - 1)) {
  203. event.preventDefault(); items[event.shiftKey ? items.length - 1 : 0].focus?.()
  204. }
  205. }
  206. const hidden = () => { if (document.hidden) void video.close() }
  207. const leave = () => { void video.close() }
  208. onMounted(() => { document.addEventListener('visibilitychange', hidden); document.addEventListener('keydown', keyboard); window.addEventListener('pagehide', leave) })
  209. onBeforeUnmount(() => { document.removeEventListener('visibilitychange', hidden); document.removeEventListener('keydown', keyboard); window.removeEventListener('pagehide', leave); void video.close() })
  210. </script>
  211. <style scoped>
  212. .video-monitor-backdrop { position: fixed; inset: 0; z-index: 15000; display: grid; place-items: center; padding: 24px; background: #0009; }
  213. .video-monitor { width: min(76vw, 1400px); max-height: 92vh; overflow: auto; color: #e0f6ff; background: #092635f5; border: 1px solid #3a91a5; border-radius: 8px; padding: 20px; box-shadow: 0 20px 90px #0009; font-family: sans-serif; }
  214. .video-monitor header { display: flex; justify-content: space-between; gap: 20px; align-items: start; }
  215. .video-monitor h2, .video-monitor h3 { margin: 0 0 8px; }
  216. .video-monitor header p { margin: 0; color: #9dbbc8; overflow-wrap: anywhere; }
  217. .video-monitor button { padding: 7px 18px; color: #d8f8ff; background: #14556b; border: 1px solid #448ba0; border-radius: 4px; cursor: pointer; }
  218. .video-monitor button:disabled { color: #8399a3; background: #263c46; border-color: #49616b; cursor: not-allowed; }
  219. .video-monitor__meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 18px; margin: 8px 0 0; }
  220. .video-monitor__meta div { display: flex; gap: 8px; font-size: 13px; color: #b6d4e0; }
  221. .video-monitor__meta dt { color: #8fb4c2; margin: 0; white-space: nowrap; }
  222. .video-monitor__meta dd { margin: 0; overflow-wrap: anywhere; }
  223. .video-monitor__ptz { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
  224. .video-monitor__tabs { display: flex; gap: 20px; align-items: center; margin-top: 18px; }
  225. .video-monitor__status { color: #a3d5e3; }
  226. .video-monitor__body { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 18px; }
  227. .video-monitor aside { color: #a7c3d0; background: #09212c; padding: 15px; }
  228. .video-monitor aside p, .video-monitor footer { font-size: 13px; color: #9cb9c5; }
  229. .video-monitor__screen { min-height: 300px; aspect-ratio: 16 / 9; display: grid; place-items: center; background: #02090e; }
  230. .video-monitor__screen > :deep(*) { width: 100%; height: 100%; }
  231. .video-monitor__screen > p { display: grid; place-items: center; margin: 0; }
  232. .video-monitor__warning { color: #ffc478; }
  233. .video-monitor footer { display: flex; gap: 16px; align-items: center; margin-top: 15px; }
  234. @media (max-width: 720px) { .video-monitor { width: 100%; } .video-monitor__body { grid-template-columns: 1fr; } .video-monitor aside { display: none; } }
  235. </style>