Ver código fonte

feat(cockpit): 回放控制接通并可验证,修复历史模式双流与重复属性

票11:监控面板按大华结构复刻功能(实时/历史/控制/六字段)。

- 前端:回放会话发布 durationSeconds,seek 输入按所选录像时长设上限;
- 修复控制按钮重复 data-playback-control 属性导致键值恒为空串(选择器/测试因此失真);
- 修复历史模式下页脚「重新播放」会启动实时流、与回放并存的缺陷(仅实时模式显示);
- 空输入不再被当成 seek 0;控制成功清除上一次拒绝提示;释放时清空时长;
- 测试:确认控制可用且 seek 上限=录像时长、越界跳转不发请求、界内转发;六字段有值/缺值为「—」。

离线 journey 17/17、hosts 17/17 通过。按 AGENTS.md 跳过 build。
ChenJZ 31 minutos atrás
pai
commit
3e511c9a9b

+ 12 - 4
src/modules/cockpit/components/VideoMonitorPanel.vue

@@ -44,12 +44,14 @@
                                 @click="togglePlaybackMute">{{ playbackMuted ? '取消静音' : '静音' }}</button>
                         <button type="button" data-playback-fullscreen @click="enterPlaybackFullscreen">全屏</button>
                         <label v-if="state.playbackControls?.seek" class="video-monitor__seek">
-                            跳到 <input v-model="playbackPosition" type="number" min="0" step="1" data-playback-position /> 秒
+                            跳到 <input v-model="playbackPosition" type="number" min="0" step="1"
+                                       :max="playbackDuration" data-playback-position /> 秒
+                            <span v-if="playbackDuration" class="video-monitor__seek-max">(本段共 {{ playbackDuration }} 秒)</span>
                         </label>
                     </div>
                     <!-- Unconfirmed playback controls stay visible but grey, each stating why. -->
                     <div v-if="state.playbackMedia" class="video-monitor__playback-controls">
-                        <button v-for="control in playbackControls" :key="control.key" type="button" data-playback-control
+                        <button v-for="control in playbackControls" :key="control.key" type="button"
                                 :data-playback-control="control.key" :disabled="!control.enabled"
                                 :title="control.enabled ? '' : control.reason" @click="runControl(control)">{{ control.label }}</button>
                     </div>
@@ -85,7 +87,9 @@
                 <p v-if="state.error && state.media" role="alert">{{ state.error }}</p>
                 <p v-if="state.cleanupError" class="video-monitor__warning" role="alert">{{ state.cleanupError }}</p>
                 <footer>
-                    <button v-if="!state.media && !['starting','connecting','retrying'].includes(state.phase)" type="button" :disabled="Boolean(state.cleanupError)" @click="video.retry">重新播放</button>
+                    <!-- Live-only: in history mode this would start a live stream beside the playback. -->
+                    <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>
                 </footer>
@@ -145,7 +149,7 @@ const switchMode = async (next) => {
 const playRecord = (record) => video.play(record.startTime, record.endTime)
 // Every playback control is advertised with its real availability. Until a device is confirmed,
 // each stays grey with a stated reason instead of silently disappearing.
-const CONTROL_REASON = '真实设备未确认此控制能力,暂不开放'
+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.
@@ -156,10 +160,14 @@ const playbackControls = computed(() => {
 })
 // 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)

+ 7 - 3
src/modules/cockpit/services/videoPlaybackSession.js

@@ -118,7 +118,9 @@ export function createVideoPlaybackSession(api, update, timers = globalThis) {
             // A device that reported confirmed controls keeps them; the default confirms nothing.
             controls: normalizeControls(started.controls) }
         current = identity
-        publish({ phase: 'playing', media, window: { startTime, endTime }, controls: identity.controls })
+        // durationSeconds lets the panel bound the seek input to the chosen recording, not the day.
+        publish({ phase: 'playing', media, window: { startTime, endTime },
+            durationSeconds: identity.span.seconds, controls: identity.controls })
         return true
     }
 
@@ -142,6 +144,8 @@ export function createVideoPlaybackSession(api, update, timers = globalThis) {
         const value = action === 'speed' ? Number(match[2]) : action === 'seek' ? seconds : undefined
         try {
             await api.control(owned, action, value)
+            // A previous rejection must not linger after a control the server accepted.
+            publish({ error: '' })
             return true
         } catch (error) {
             publish({ error: error?.message || '回放控制失败' })
@@ -165,8 +169,8 @@ export function createVideoPlaybackSession(api, update, timers = globalThis) {
         ++generation
         const owned = identity
         identity = null; current = null
-        // A released session must not carry its capabilities into the next one.
-        publish({ media: null, phase: 'idle', controls: {} })
+        // A released session must not carry its capabilities or duration into the next one.
+        publish({ media: null, phase: 'idle', controls: {}, durationSeconds: 0 })
         const clean = await release(owned)
         if (!clean) publish({ phase: 'failed', error: cleanupMessage })
         return clean

+ 89 - 4
tests/cockpit-video/hosts.mjs

@@ -19,7 +19,9 @@ const point = { pointCode: 'P-FIXED', pointName: '无位置摄像机监测点',
 const camera = { deviceCode: cameraCode, deviceName: '无位置现场摄像机', deviceType: '20', deviceTypeName: '视频监控设备',
     deviceStatus: 'NORMAL', industry: 'DRAINAGE', longitude: null, latitude: null, coordinateValidation: coordinate }
 const device = { deviceCode: cameraCode, deviceName: camera.deviceName, typeCode: '20', bound: true,
-    capabilities: { live: true, records: true, playback: true, playbackControl: false } }
+    businessCode: cameraCode, sourceType: 'GB28181', gbDeviceId: '34020000002000000001',
+    gbChannelId: '34020000001320000001', manufacturer: 'Dahua', location: '测试安装位置',
+    capabilities: { live: true, records: true, playback: true, playbackControl: true } }
 const aggregate = { deviceCode: cameraCode, aggregateState: 'READY',
     archive: { state: 'SUCCESS', data: camera }, metrics: { state: 'EMPTY', data: null },
     warnings: { state: 'EMPTY', data: [] }, alarms: { state: 'EMPTY', data: [] }, workOrders: { state: 'EMPTY', data: null },
@@ -95,7 +97,7 @@ async function mountRoot({ positioned = false, underground = false } = {}) {
     const selectedCamera = { ...camera, longitude: selectedPoint.longitude, latitude: selectedPoint.latitude, coordinateValidation: location }
     const requests = [], unexpected = [], errors = []
     const server = { snapshotGate: null, pointGate: null, pointFails: false, cameraPresent: true, liveFailures: 0,
-        recordings: [], recordsFail: false, playbackBusy: false }
+        recordings: [], recordsFail: false, playbackBusy: false, playbackControls: undefined }
     const fetchImpl = async (address, options = {}) => {
         const url = new URL(address), path = url.pathname.replace('/api/cockpit/v1', '')
         const body = options.body ? JSON.parse(options.body) : null
@@ -147,7 +149,8 @@ async function mountRoot({ positioned = false, underground = false } = {}) {
             return envelope({ deviceCode: cameraCode, deviceName: device.deviceName,
                 sessionId: 'session-pb', sessionToken: 'owner-pb', mode: 'PLAYBACK',
                 startTime: body.startTime, endTime: body.endTime,
-                media: { native: true, url: 'https://media.invalid/playback.mp4' } })
+                media: { native: true, url: 'https://media.invalid/playback.mp4' },
+                ...(server.playbackControls ? { controls: server.playbackControls } : {}) })
         }
         if (path === '/video/sessions/prepare') {
             assert.deepEqual(body, { deviceCode: cameraCode })
@@ -167,6 +170,10 @@ async function mountRoot({ positioned = false, underground = false } = {}) {
             assert.deepEqual(body, { sessionToken: 'owner-host' })
             return envelope({ sessionId: 'session-host', deviceCode: cameraCode, mode: 'LIVE', status: 'STOPPED' })
         }
+        if (path === '/video/sessions/session-pb/control') {
+            assert.deepEqual(body.sessionToken, 'owner-pb')
+            return envelope({ sessionId: 'session-pb', status: 'ACTIVE' })
+        }
         if (path === '/video/sessions/session-pb/stop' || path === '/video/sessions/session-pb/status') {
             assert.deepEqual(body, { sessionToken: 'owner-pb' })
             return envelope({ sessionId: 'session-pb', deviceCode: cameraCode, mode: 'PLAYBACK', status: 'STOPPED' })
@@ -317,6 +324,84 @@ test('历史录像TAB不关闭面板,列片后才起流,占用不抢停别
     } finally { await page.dispose() }
 })
 
+test('确认过的回放控制可用,且跳转上限等于所选录像时长', async () => {
+    const page = await mountRoot()
+    try {
+        page.server.recordings = [{ name: 'CAM/03', startTime: '2026-11-10 01:00:00', endTime: '2026-11-10 01:30:00', type: 'time' }]
+        // A confirmed session advertises the controls the playback seam really implements.
+        page.server.playbackControls = { pause: true, resume: true, speed: true, seek: true }
+        const detail = await openMainDetail(page)
+        detail.querySelector('[data-video-open]').click(); await settle()
+        const dialog = () => document.querySelector('[data-video-monitor]')
+        const tabs = [...dialog().querySelectorAll('button')].filter((button) => ['实时视频', '历史录像'].includes(button.textContent.trim()))
+        tabs[1].click(); await settle()
+        const play = [...dialog().querySelectorAll('button')].find((button) => button.textContent.trim() === '播放')
+        play.click(); await settle()
+        const controls = [...dialog().querySelectorAll('[data-playback-control]')]
+        assert.ok(controls.length >= 6, 'pause/resume and 0.25/0.5/1/2/4x plus seek must all be rendered')
+        for (const control of controls) {
+            assert.equal(control.disabled, false, `${control.dataset.playbackControl} 确认后必须可用`)
+        }
+        // The seek input is bounded by the chosen recording (30 minutes), not by the whole day.
+        const position = dialog().querySelector('[data-playback-position]')
+        assert.ok(position, '确认 seek 后必须出现位置输入')
+        assert.equal(position.getAttribute('max'), '1800')
+        // Pressing a confirmed control reaches the owned session.
+        const pause = controls.find((control) => control.getAttribute('data-playback-control') === 'pause')
+        pause.click(); await settle()
+        assert.equal(page.requests.filter((request) => request.path.endsWith('/control')).length, 1)
+        // A seek beyond the chosen recording is refused locally and never reaches the server.
+        const setPosition = (value) => {
+            position.value = value
+            position.dispatchEvent(new Event('input'))
+        }
+        setPosition('1801')
+        controls.find((control) => control.getAttribute('data-playback-control') === 'seek').click(); await settle()
+        assert.equal(page.requests.filter((request) => request.path.endsWith('/control')).length, 1,
+            '越界跳转不得发出控制请求')
+        // A position inside the recording is forwarded.
+        setPosition('900')
+        controls.find((control) => control.getAttribute('data-playback-control') === 'seek').click(); await settle()
+        assert.equal(page.requests.filter((request) => request.path.endsWith('/control')).length, 2)
+        assert.deepEqual(page.errors, [])
+        assert.deepEqual(page.unexpected, [])
+    } finally { await page.dispose() }
+})
+
+test('监控面板展示六项设备基础信息,缺值显示为破折号', async () => {
+    const page = await mountRoot()
+    try {
+        const open = async () => {
+            const detail = await openMainDetail(page)
+            detail.querySelector('[data-video-open]').click(); await settle()
+            return document.querySelector('[data-video-meta]')
+        }
+        const field = (meta, key) => meta.querySelector(`[data-video-meta-field="${key}"]`).textContent.trim()
+        let meta = await open()
+        assert.ok(meta, '监控面板必须展示设备基础信息')
+        assert.equal(field(meta, 'deviceName'), '无位置现场摄像机')
+        assert.equal(field(meta, 'businessCode'), cameraCode)
+        assert.equal(field(meta, 'accessType'), '国标接入')
+        assert.equal(field(meta, 'gb'), '34020000002000000001 / 34020000001320000001')
+        assert.equal(field(meta, 'location'), '测试安装位置')
+        assert.equal(field(meta, 'manufacturer'), 'Dahua')
+        document.querySelector('[data-video-monitor] [aria-label="关闭监控"]').click(); await settle()
+        // Missing values must read as an em dash, never as "undefined" or a blank cell.
+        const savedLocation = device.location, savedManufacturer = device.manufacturer
+        try {
+            device.location = null; delete device.manufacturer
+            meta = await open()
+            assert.equal(field(meta, 'location'), '—')
+            assert.equal(field(meta, 'manufacturer'), '—')
+        } finally {
+            device.location = savedLocation; device.manufacturer = savedManufacturer
+        }
+        document.querySelector('[data-video-monitor] [aria-label="关闭监控"]').click(); await settle()
+        assert.deepEqual(page.errors, [])
+        assert.deepEqual(page.unexpected, [])
+    } finally { await page.dispose() }
+})
+
 test('历史回放占用时提示占用且不释放他人回放', async () => {
     const page = await mountRoot()
     try {
@@ -589,4 +674,4 @@ test('地下管线详情:真实Root列表点设备经Latest TAB打开唯一监
         assert.deepEqual(page.unexpected, [])
         assert.deepEqual(page.errors, [])
     } finally { await page.dispose() }
-})
+})