VideoMonitorEntry.vue 5.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <template>
  2. <div v-if="loading || error || device?.typeCode === '20' || video.state.cleanupError" class="video-entry" data-video-entry>
  3. <p v-if="loading" class="video-entry__hint">正在确认视频能力…</p>
  4. <template v-else-if="device?.typeCode === '20'">
  5. <button type="button" class="video-entry__open" data-video-open aria-label="监控面板入口"
  6. :disabled="entryDisabled" :title="disabledReason || '查看实时画面与已有录像'" @click="video.open(device, monitorSource)">
  7. <span class="video-entry__camera" aria-hidden="true">
  8. <svg viewBox="0 0 32 32" fill="none"><rect x="4" y="9" width="17" height="14" rx="3" /><path d="m21 13 7-4v14l-7-4M9 5h8" /></svg>
  9. </span>
  10. <span class="video-entry__copy"><strong>监控面板入口</strong><span>实时画面 · 已有录像</span></span>
  11. <span class="video-entry__status" data-video-entry-status><i aria-hidden="true"></i>{{ entryDisabled ? '暂不可用' : '可查看' }}</span>
  12. <svg class="video-entry__arrow" viewBox="0 0 24 24" fill="none" aria-hidden="true"><path d="M4 12h15m-6-6 6 6-6 6" /></svg>
  13. </button>
  14. <span v-if="disabledReason && !video.state.cleanupError" class="video-entry__hint" data-video-unavailable>{{ disabledReason }}</span>
  15. </template>
  16. <p v-if="error" class="video-entry__hint" role="status">{{ error }} <button type="button" class="video-entry__retry" @click="load">重查视频能力</button></p>
  17. <p v-if="video.state.cleanupError" class="video-entry__hint" role="alert">{{ video.state.cleanupError }} <button type="button" class="video-entry__retry" @click="video.retryCleanup">重试清理</button></p>
  18. </div>
  19. </template>
  20. <script setup>
  21. import { computed, ref, watch, onBeforeUnmount } from 'vue'
  22. import { useVideoStore } from '../stores/videoStore.js'
  23. const props = defineProps({ deviceCode: { type: String, required: true }, monitorSource: { type: String, default: 'detail' } })
  24. const emit = defineEmits(['device-resolved'])
  25. const video = useVideoStore()
  26. const device = ref(null), loading = ref(false), error = ref('')
  27. const entryDisabled = computed(() => device.value?.bound !== true || device.value?.capabilities?.live !== true || Boolean(video.state.cleanupError))
  28. const disabledReason = computed(() => {
  29. if (video.state.cleanupError) return video.state.cleanupError
  30. if (device.value?.bound !== true) return device.value?.unavailableReason || '视频设备尚未完成有效绑定'
  31. if (device.value?.capabilities?.live !== true) return device.value?.unavailableReason || '实时视频能力尚未确认'
  32. return ''
  33. })
  34. let generation = 0
  35. async function load() {
  36. const version = ++generation
  37. device.value = null; error.value = ''; loading.value = Boolean(props.deviceCode)
  38. if (!props.deviceCode) return
  39. try {
  40. const result = await video.loadDevice(props.deviceCode)
  41. if (version === generation) {
  42. device.value = result
  43. emit('device-resolved', result)
  44. }
  45. } catch (failure) { if (version === generation) error.value = failure.message || '视频能力暂不可用' }
  46. finally { if (version === generation) loading.value = false }
  47. }
  48. watch(() => props.deviceCode, load, { immediate: true })
  49. onBeforeUnmount(() => { generation += 1 })
  50. </script>
  51. <style scoped>
  52. .video-entry { display: grid; gap: calc(6 * var(--u, 1px)); min-width: 0; padding: calc(4 * var(--u, 1px)) 0; }
  53. .video-entry__open {
  54. display: grid;
  55. grid-template-columns: auto minmax(0, 1fr) auto auto;
  56. align-items: center;
  57. gap: calc(8 * var(--u, 1px));
  58. width: 100%;
  59. padding: calc(10 * var(--u, 1px));
  60. color: #d9f9ff;
  61. background: linear-gradient(110deg, #062b3f, #0a3a52);
  62. border: 1px solid #35d6e8;
  63. border-radius: calc(6 * var(--u, 1px));
  64. text-align: left;
  65. font: inherit;
  66. cursor: pointer;
  67. transition: border-color .15s, box-shadow .15s;
  68. }
  69. .video-entry__open:hover:not(:disabled) { border-color: #9ef4ff; box-shadow: inset 0 0 18px #35d6e820; }
  70. .video-entry__open:focus-visible, .video-entry__retry:focus-visible { outline: 2px solid #35d6e8; outline-offset: 3px; }
  71. .video-entry__camera { display: grid; place-items: center; width: calc(34 * var(--u, 1px)); height: calc(34 * var(--u, 1px)); border-radius: calc(5 * var(--u, 1px)); color: #35d6e8; background: #35d6e81a; }
  72. .video-entry__camera svg { width: 80%; height: 80%; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  73. .video-entry__copy { display: grid; gap: calc(3 * var(--u, 1px)); min-width: 0; }
  74. .video-entry__copy strong { font-size: var(--fs-body, 13px); }
  75. .video-entry__copy > span { color: #a7c9d6; font-size: var(--fs-caption, 10.5px); }
  76. .video-entry__status { display: inline-flex; align-items: center; gap: calc(4 * var(--u, 1px)); color: #35d6e8; font-size: var(--fs-caption, 10.5px); white-space: nowrap; }
  77. .video-entry__status i { width: calc(5 * var(--u, 1px)); height: calc(5 * var(--u, 1px)); border-radius: 50%; background: currentColor; }
  78. .video-entry__arrow { width: calc(20 * var(--u, 1px)); height: calc(20 * var(--u, 1px)); color: #35d6e8; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  79. .video-entry__open:disabled { color: #82949c; background: #062b3f; border-color: #45616a; cursor: not-allowed; }
  80. .video-entry__open:disabled .video-entry__camera { background: #82949c14; }
  81. .video-entry__open:disabled .video-entry__camera, .video-entry__open:disabled .video-entry__status, .video-entry__open:disabled .video-entry__arrow, .video-entry__open:disabled .video-entry__copy > span { color: #82949c; }
  82. .video-entry__retry { color: #c6f7ff; background: #0a3a52; border: 1px solid #35d6e8; border-radius: 4px; padding: 4px 10px; font: inherit; cursor: pointer; }
  83. .video-entry__hint { margin: 0; color: #a7bdc7; font-size: 0.85em; overflow-wrap: anywhere; }
  84. @media (prefers-reduced-motion: reduce) { .video-entry__open { transition: none; } }
  85. </style>