| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- <template>
- <div v-if="loading || error || device?.typeCode === '20' || video.state.cleanupError" class="video-entry" data-video-entry>
- <p v-if="loading" class="video-entry__hint">正在确认视频能力…</p>
- <template v-else-if="device?.typeCode === '20'">
- <button type="button" class="video-entry__open" data-video-open aria-label="监控面板入口"
- :disabled="entryDisabled" :title="disabledReason || '查看实时画面与已有录像'" @click="video.open(device, monitorSource)">
- <span class="video-entry__camera" aria-hidden="true">
- <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>
- </span>
- <span class="video-entry__copy"><strong>监控面板入口</strong><span>实时画面 · 已有录像</span></span>
- <span class="video-entry__status" data-video-entry-status><i aria-hidden="true"></i>{{ entryDisabled ? '暂不可用' : '可查看' }}</span>
- <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>
- </button>
- <span v-if="disabledReason && !video.state.cleanupError" class="video-entry__hint" data-video-unavailable>{{ disabledReason }}</span>
- </template>
- <p v-if="error" class="video-entry__hint" role="status">{{ error }} <button type="button" class="video-entry__retry" @click="load">重查视频能力</button></p>
- <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>
- </div>
- </template>
- <script setup>
- import { computed, ref, watch, onBeforeUnmount } from 'vue'
- import { useVideoStore } from '../stores/videoStore.js'
- const props = defineProps({ deviceCode: { type: String, required: true }, monitorSource: { type: String, default: 'detail' } })
- const emit = defineEmits(['device-resolved'])
- const video = useVideoStore()
- const device = ref(null), loading = ref(false), error = ref('')
- const entryDisabled = computed(() => device.value?.bound !== true || device.value?.capabilities?.live !== true || Boolean(video.state.cleanupError))
- const disabledReason = computed(() => {
- if (video.state.cleanupError) return video.state.cleanupError
- if (device.value?.bound !== true) return device.value?.unavailableReason || '视频设备尚未完成有效绑定'
- if (device.value?.capabilities?.live !== true) return device.value?.unavailableReason || '实时视频能力尚未确认'
- return ''
- })
- let generation = 0
- async function load() {
- const version = ++generation
- device.value = null; error.value = ''; loading.value = Boolean(props.deviceCode)
- if (!props.deviceCode) return
- try {
- const result = await video.loadDevice(props.deviceCode)
- if (version === generation) {
- device.value = result
- emit('device-resolved', result)
- }
- } catch (failure) { if (version === generation) error.value = failure.message || '视频能力暂不可用' }
- finally { if (version === generation) loading.value = false }
- }
- watch(() => props.deviceCode, load, { immediate: true })
- onBeforeUnmount(() => { generation += 1 })
- </script>
- <style scoped>
- .video-entry { display: grid; gap: calc(6 * var(--u, 1px)); min-width: 0; padding: calc(4 * var(--u, 1px)) 0; }
- .video-entry__open {
- display: grid;
- grid-template-columns: auto minmax(0, 1fr) auto auto;
- align-items: center;
- gap: calc(8 * var(--u, 1px));
- width: 100%;
- padding: calc(10 * var(--u, 1px));
- color: #d9f9ff;
- background: linear-gradient(110deg, #062b3f, #0a3a52);
- border: 1px solid #35d6e8;
- border-radius: calc(6 * var(--u, 1px));
- text-align: left;
- font: inherit;
- cursor: pointer;
- transition: border-color .15s, box-shadow .15s;
- }
- .video-entry__open:hover:not(:disabled) { border-color: #9ef4ff; box-shadow: inset 0 0 18px #35d6e820; }
- .video-entry__open:focus-visible, .video-entry__retry:focus-visible { outline: 2px solid #35d6e8; outline-offset: 3px; }
- .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; }
- .video-entry__camera svg { width: 80%; height: 80%; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
- .video-entry__copy { display: grid; gap: calc(3 * var(--u, 1px)); min-width: 0; }
- .video-entry__copy strong { font-size: var(--fs-body, 13px); }
- .video-entry__copy > span { color: #a7c9d6; font-size: var(--fs-caption, 10.5px); }
- .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; }
- .video-entry__status i { width: calc(5 * var(--u, 1px)); height: calc(5 * var(--u, 1px)); border-radius: 50%; background: currentColor; }
- .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; }
- .video-entry__open:disabled { color: #82949c; background: #062b3f; border-color: #45616a; cursor: not-allowed; }
- .video-entry__open:disabled .video-entry__camera { background: #82949c14; }
- .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; }
- .video-entry__retry { color: #c6f7ff; background: #0a3a52; border: 1px solid #35d6e8; border-radius: 4px; padding: 4px 10px; font: inherit; cursor: pointer; }
- .video-entry__hint { margin: 0; color: #a7bdc7; font-size: 0.85em; overflow-wrap: anywhere; }
- @media (prefers-reduced-motion: reduce) { .video-entry__open { transition: none; } }
- </style>
|