Browse Source

fix(cockpit): 监控入口并入最新指标并常驻云台按能力灰

按排水子系统参照的四点调整(未见其源码,仅按维护者要求):
1. 回放改走 WebRTC 播放器并关闭原生控件,seek 携带所选时段内位置值;
2. 云台方向/变倍/停止按钮常驻,未确认能力或无权限时置灰并说明原因;
3. 面板展示设备名称、业务设备编码、接入方式、国标设备/通道、安装位置、厂商;
4. 监控入口移入最新指标卡片内部,空数据给中性提示,失败仍如实说明,避免误报红。

离线 journey 16/16、hosts 15/15 通过;另补 hosts 缺失的 /dict/pump_station_type 白名单,
修复他人提交引入的基线回归。按 AGENTS.md 跳过 build/dev/浏览器验证。
ChenJZ 5 giờ trước cách đây
mục cha
commit
8a566e20b5

+ 16 - 5
src/modules/cockpit/components/EquipmentDetailSections.vue

@@ -55,7 +55,6 @@
         -->
         <p v-if="aggregate?.retained" class="equipment-section__hint" data-detail-refresh-retained>本次详情更新未完成,保留上次已加载内容。</p>
         <div class="equipment-tab__body" role="tabpanel" data-equipment-tab-body>
-            <VideoMonitorEntry v-if="activeTab === 'metrics'" :device-code="deviceCode" :monitor-source="monitorSource" />
             <section
                 v-for="panel in activePanels"
                 :key="panel.name"
@@ -75,7 +74,7 @@
             </p>
 
             <!-- ---------- 有内容:按 kind 分派 ---------- -->
-            <template v-if="panel.hasContent">
+            <template v-if="panel.kind === 'metrics' || panel.hasContent">
                 <!--
                     票 46:分类查询条 —— 预警/报警/工单**共用这一块**(同一组绑定只写一处)。
                     分类归组在 domain(等级复用票 13 词表、工单复用 0–7 字典),组件只画 chips;
@@ -109,6 +108,19 @@
 
                 <!-- 采集记录:最近50行;分页后只合并当前页相同采集时间。 -->
                 <div v-else-if="panel.kind === 'metrics'" class="equipment-section__list" data-collection-records>
+                    <!-- 监控入口属于最新指标卡片本身,不再与指标框并列(维护者 2026-11-18)。 -->
+                    <VideoMonitorEntry :device-code="deviceCode" :monitor-source="monitorSource" />
+                    <!-- A failed section keeps its own honest wording; only a genuinely empty one is neutral here. -->
+                    <p v-if="panel.section.state === 'failed'" class="equipment-section__hint" data-metrics-failed>
+                        该分区加载失败(其它分区不受影响)
+                    </p>
+                    <p v-else-if="panel.section.state === 'unavailable'" class="equipment-section__hint" data-metrics-unavailable>
+                        该分区数据不可用(其它分区不受影响)
+                    </p>
+                    <p v-else-if="!recordTableOf(panel).total" class="equipment-section__hint" data-metrics-empty>
+                        暂无采集记录,可继续查看监控画面
+                    </p>
+                    <template v-else>
                     <p class="equipment-section__note">采集记录(最近50条)</p>
                     <div class="collection-table-wrap">
                         <table v-if="recordTableOf(panel).total" class="collection-table" data-collection-table aria-label="设备最近采集记录">
@@ -169,16 +181,15 @@
                             </tbody>
                         </table>
                     </div>
-                    <p v-if="!recordTableOf(panel).total" class="equipment-section__hint" data-section-empty-list>暂无采集记录</p>
-                    <p v-else-if="recordTableOf(panel).assessmentNote" class="equipment-section__hint" data-collection-assessment-note>{{ recordTableOf(panel).assessmentNote }}</p>
+                    <p v-if="recordTableOf(panel).assessmentNote" class="equipment-section__hint" data-collection-assessment-note>{{ recordTableOf(panel).assessmentNote }}</p>
                     <PagerNav
-                        v-if="recordTableOf(panel).total"
                         :page="recordTableOf(panel).page"
                         :page-count="recordTableOf(panel).pageCount"
                         :total="recordTableOf(panel).total"
                         list-name="采集记录"
                         @page="(target) => gotoPage(panel, target)"
                     />
+                    </template>
                 </div>
 
                 <!--

+ 88 - 6
src/modules/cockpit/components/VideoMonitorPanel.vue

@@ -3,7 +3,18 @@
         <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>
                 <header>
-                    <div><h2 id="video-monitor-title">{{ state.device?.deviceName || '视频监控设备' }}</h2><p>{{ state.device?.deviceCode }}</p></div>
+                    <div>
+                        <h2 id="video-monitor-title">{{ state.device?.deviceName || '视频监控设备' }}</h2>
+                        <!-- The six fields the operator checks on a monitor device (维护者 2026-11-18). -->
+                        <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>
                     <button type="button" aria-label="关闭监控" @click="video.close">关闭</button>
                 </header>
                 <div class="video-monitor__tabs">
@@ -26,6 +37,16 @@
                             <button type="button" @click="playRecord(record)">播放</button>
                         </li>
                     </ul>
+                    <!-- Volume and fullscreen are not device capabilities, so they stay usable here;
+                         the native bar was removed only to stop pause/seek bypassing the grey gate. -->
+                    <div v-if="state.playbackMedia" class="video-monitor__playback-controls" data-playback-surface>
+                        <button type="button" data-playback-mute :aria-pressed="playbackMuted"
+                                @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 /> 秒
+                        </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
@@ -36,12 +57,27 @@
                 <p class="video-monitor__status" role="status">{{ labels[state.phase] || '未播放' }}</p>
                 <p v-if="retryNote" class="video-monitor__status" role="status">{{ retryNote }}</p>
                 <div class="video-monitor__body">
-                    <aside><h3>云台控制</h3><button type="button" disabled title="停止保障尚未验证,不提供物理控制">方向/变倍</button><p>能力尚未开放</p></aside>
+                    <aside data-ptz-panel>
+                        <h3>云台控制</h3>
+                        <!-- Buttons always exist; an absent capability or permission only greys them (维护者 2026-11-18). -->
+                        <div class="video-monitor__ptz" role="group" aria-label="云台控制">
+                            <button v-for="key in PTZ_DIRECTIONS" :key="key" type="button" :data-ptz-direction="key"
+                                    :disabled="!ptzEnabled" :title="ptzEnabled ? '' : ptzReason">{{ ptzLabel(key) }}</button>
+                        </div>
+                        <div class="video-monitor__ptz" role="group" aria-label="云台变倍">
+                            <button type="button" data-ptz-zoom="in" :disabled="!ptzEnabled" :title="ptzEnabled ? '' : ptzReason">放大</button>
+                            <button type="button" data-ptz-zoom="out" :disabled="!ptzEnabled" :title="ptzEnabled ? '' : ptzReason">缩小</button>
+                        </div>
+                        <button type="button" data-ptz-stop :disabled="!ptzEnabled" :title="ptzEnabled ? '' : ptzReason">停止</button>
+                        <p v-if="!ptzEnabled" data-ptz-hint>{{ ptzReason }}</p>
+                    </aside>
                     <div class="video-monitor__screen">
                         <VideoPlayer v-if="state.media" :media="state.media" :options="playerOptions" @ready="video.ready" @error="video.fail" />
-                        <video v-else-if="state.playbackMedia" :src="state.playbackMedia.url" controls autoplay muted playsinline
-                               controlslist="nodownload noremoteplayback noplaybackrate" disablepictureinpicture disableremoteplayback
-                               aria-label="历史录像画面" @contextmenu.prevent />
+                        <!-- A GB28181 playback publishes WebRTC signalling, so it uses the same player
+                             as live video; native controls would also bypass the grey gate. -->
+                        <VideoPlayer v-else-if="state.playbackMedia" :media="state.playbackMedia" :options="playerOptions"
+                                     label="历史录像画面" :controls="false"
+                                     @ready="video.readyPlayback" @error="video.failPlayback" />
                         <p v-else-if="state.phase === 'retrying'">等待自动重连…</p>
                         <p v-else>{{ state.error || '等待视频连接' }}</p>
                     </div>
@@ -71,6 +107,26 @@ const labels = { idle: '未播放', starting: '正在建立视频会话', connec
 // Switching tabs ends the current stream but must keep the monitor open.
 const mode = ref('live')
 const range = reactive(video.historyWindow())
+// PTZ panel: the buttons are always present; only capability/permission greys them out.
+const PTZ_DIRECTIONS = ['up', 'down', 'left', 'right', 'up-left', 'up-right', 'down-left', 'down-right']
+const PTZ_LABELS = { up: '上', down: '下', left: '左', right: '右', 'up-left': '左上', 'up-right': '右上', 'down-left': '左下', 'down-right': '右下' }
+const ptzLabel = (key) => PTZ_LABELS[key]
+// Real device PTZ control is ticket 06; until the device confirms it, the buttons stay grey with a reason.
+const PTZ_UNCONFIRMED = '设备未确认云台能力或当前无控制权限'
+const ptzEnabled = computed(() => {
+    const device = state.value.device
+    return Boolean(device?.capabilities?.ptz) && !state.value.cleanupError
+})
+const ptzReason = computed(() => state.value.cleanupError ? '会话释放未确认,暂停控制' : PTZ_UNCONFIRMED)
+// Access mode and GB identifiers come straight from the binding; blanks show as a dash.
+const ACCESS_TEXT = { GB28181: '国标接入', MANUAL: '手工接入' }
+const accessTypeText = computed(() => ACCESS_TEXT[state.value.device?.accessType] || state.value.device?.accessType || '—')
+const gbText = computed(() => {
+    const device = state.value.device
+    return device?.gbDeviceId || device?.gbChannelId
+        ? `${device.gbDeviceId || '—'} / ${device.gbChannelId || '—'}`
+        : '—'
+})
 const switchMode = async (next) => {
     if (next === mode.value) return
     if (next === 'history') {
@@ -95,8 +151,29 @@ const playbackControls = computed(() => {
         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('')
 // A disabled control must not reach the server even when activated programmatically.
-const runControl = (control) => { if (control.enabled) void video.controlPlayback(control.key) }
+const runControl = (control) => {
+    if (!control.enabled) return
+    if (control.key === 'seek') {
+        const seconds = Number(playbackPosition.value)
+        if (!Number.isFinite(seconds)) return
+        void video.controlPlayback('seek', seconds)
+        return
+    }
+    void video.controlPlayback(control.key)
+}
+// Local presentation only: the player starts muted, and neither action is a device capability.
+const playbackMuted = ref(true)
+const playbackVideo = () => document.querySelector('[data-video-monitor] video[aria-label="历史录像画面"]')
+const togglePlaybackMute = () => {
+    const element = playbackVideo()
+    if (!element) return
+    playbackMuted.value = !playbackMuted.value
+    element.muted = playbackMuted.value
+}
+const enterPlaybackFullscreen = () => { void playbackVideo()?.requestFullscreen?.() }
 const retryNote = computed(() => state.value.phase !== 'retrying' || !state.value.retryAttempt
     ? ''
     : `第 ${state.value.retryAttempt} 次自动重试,等待 ${Math.round((state.value.retryDelayMs || 0) / 1000)} 秒(剩余 ${state.value.retriesLeft ?? 0} 次)`)
@@ -136,6 +213,11 @@ onBeforeUnmount(() => { document.removeEventListener('visibilitychange', hidden)
 .video-monitor header p { margin: 0; color: #9dbbc8; overflow-wrap: anywhere; }
 .video-monitor button { padding: 7px 18px; color: #d8f8ff; background: #14556b; border: 1px solid #448ba0; border-radius: 4px; cursor: pointer; }
 .video-monitor button:disabled { color: #8399a3; background: #263c46; border-color: #49616b; cursor: not-allowed; }
+.video-monitor__meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 18px; margin: 8px 0 0; }
+.video-monitor__meta div { display: flex; gap: 8px; font-size: 13px; color: #b6d4e0; }
+.video-monitor__meta dt { color: #8fb4c2; margin: 0; white-space: nowrap; }
+.video-monitor__meta dd { margin: 0; overflow-wrap: anywhere; }
+.video-monitor__ptz { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
 .video-monitor__tabs { display: flex; gap: 20px; align-items: center; margin-top: 18px; }
 .video-monitor__status { color: #a3d5e3; }
 .video-monitor__body { display: grid; grid-template-columns: 150px minmax(0, 1fr); gap: 18px; }

+ 5 - 2
src/modules/cockpit/components/VideoPlayer.vue

@@ -2,8 +2,8 @@
     <video
         ref="video"
         class="cockpit-video-player"
-        aria-label="实时视频画面"
-        controls autoplay muted playsinline
+        :aria-label="label"
+        :controls="controls" autoplay muted playsinline
         controlslist="nodownload noremoteplayback noplaybackrate"
         disablepictureinpicture disableremoteplayback
         @contextmenu.prevent
@@ -17,6 +17,9 @@ import { createVideoPlayer } from '../services/videoPlayer.js'
 const props = defineProps({
     media: { type: Object, default: null },
     options: { type: Object, default: () => ({}) },
+    // Playback reuses this player but must keep every control on the server side.
+    label: { type: String, default: '实时视频画面' },
+    controls: { type: Boolean, default: true },
 })
 const emit = defineEmits(['ready', 'error'])
 const video = shallowRef(null)

+ 28 - 4
src/modules/cockpit/services/videoPlaybackSession.js

@@ -34,6 +34,13 @@ function validate(from, to) {
     return { start, end }
 }
 
+/** A seek is only meaningful inside the recording the viewer chose, not the whole day. */
+function insideWindow(owned, seconds) {
+    const span = owned.span
+    if (!span || !Number.isFinite(seconds) || seconds < 0 || seconds > span.seconds) return false
+    return true
+}
+
 /** Only explicitly confirmed controls are enabled; anything unreported stays unconfirmed. */
 function normalizeControls(reported) {
     const source = reported && typeof reported === 'object' ? reported : {}
@@ -106,6 +113,8 @@ export function createVideoPlaybackSession(api, update, timers = globalThis) {
             return false
         }
         identity = { sessionId: started.sessionId, sessionToken: started.sessionToken, deviceCode, mode: 'PLAYBACK',
+            // The chosen span bounds every seek; it is never the query window from the input fields.
+            span: { start: instant(startTime), end: instant(endTime), seconds: (instant(endTime) - instant(startTime)) / 1000 },
             // A device that reported confirmed controls keeps them; the default confirms nothing.
             controls: normalizeControls(started.controls) }
         current = identity
@@ -113,8 +122,11 @@ export function createVideoPlaybackSession(api, update, timers = globalThis) {
         return true
     }
 
-    /** Only a control the device confirmed may be sent; everything else is refused locally. */
-    async function control(key) {
+    /**
+     * Only a control the device confirmed may be sent; everything else is refused locally.
+     * `seconds` is the offset inside the chosen recording, required for seek.
+     */
+    async function control(key, seconds) {
         const owned = current
         const match = /^(pause|resume|seek|speed-(0\.25|0\.5|1|2|4))$/.exec(String(key))
         if (!owned || !match) return false
@@ -123,7 +135,11 @@ export function createVideoPlaybackSession(api, update, timers = globalThis) {
         const allowed = action === 'speed' ? granted.speed : granted[action]
         if (allowed !== true) return false
         // The control API takes an action plus its value; a rate key carries the rate as its value.
-        const value = action === 'speed' ? Number(match[2]) : undefined
+        if (action === 'seek' && !insideWindow(owned, seconds)) {
+            publish({ error: '跳转位置必须是所选时段内的秒数' })
+            return false
+        }
+        const value = action === 'speed' ? Number(match[2]) : action === 'seek' ? seconds : undefined
         try {
             await api.control(owned, action, value)
             return true
@@ -156,6 +172,14 @@ export function createVideoPlaybackSession(api, update, timers = globalThis) {
         return clean
     }
 
+    /** Player callbacks: a playback failure belongs to the history surface, never the live one. */
+    const ready = () => { if (!disposed && current) publish({ error: '' }) }
+    const fail = (error) => {
+        if (disposed) return
+        const message = typeof error === 'string' ? error : error?.message
+        publish({ error: message || '历史录像画面播放失败' })
+    }
+
     async function dispose() { await stop(); disposed = true }
-    return { query, play, control, stop, dispose, records: () => records, current: () => current }
+    return { query, play, control, stop, dispose, ready, fail, records: () => records, current: () => current }
 }

+ 5 - 2
src/modules/cockpit/stores/videoStore.js

@@ -75,7 +75,10 @@ export const useVideoStore = defineStore('cockpitVideo', () => {
     }
     async function stopPlayback() { if (history) await history.stop(); publish({ playbackMedia: null, playbackControls: {} }) }
     /** Only a confirmed control may be sent; the panel greys the rest out. */
-    async function controlPlayback(key) { return history ? history.control(key) : false }
+    async function controlPlayback(key, seconds) { return history ? history.control(key, seconds) : false }
+    // Playback keeps its own failure surface: never routed through the live controller.
+    const readyPlayback = () => history?.ready()
+    const failPlayback = (error) => history?.fail(error)
     const historyWindow = (now) => defaultHistoryWindow(now)
     async function retry() { if (state.value.device) await session().start(state.value.device.deviceCode) }
     async function retryCleanup() { if (controller) await controller.stop() }
@@ -86,5 +89,5 @@ export const useVideoStore = defineStore('cockpitVideo', () => {
         else controller?.fail(error instanceof Error ? error : error?.message || '视频播放失败')
     }
     return { state, playerOptions, configure, loadDevice, open, close, retry, retryCleanup, ready, fail,
-        stopLive, startLive, queryHistory, play, stopPlayback, controlPlayback, historyWindow }
+        stopLive, startLive, queryHistory, play, stopPlayback, controlPlayback, historyWindow, readyPlayback, failPlayback }
 })

+ 13 - 0
tests/cockpit-video/hosts.mjs

@@ -129,6 +129,9 @@ async function mountRoot({ positioned = false, underground = false } = {}) {
             state: 'EMPTY', recordView: { columns: [], rows: [] } })
         if (path.startsWith('/equipments/') && path.endsWith('/freshness')) return envelope({})
         if (emptyEndpoints.has(path)) return envelope({})
+        if (path === '/dict/pump_station_type') return envelope([
+            { dictType: 'pump_station_type', dictValue: '0', dictLabel: '供水泵站' },
+            { dictType: 'pump_station_type', dictValue: '1', dictLabel: '排水泵站' }])
         if (path === '/video/device') { assert.equal(url.searchParams.get('deviceCode'), cameraCode); return envelope(device) }
         if (path === '/video/records') {
             assert.equal(url.searchParams.get('deviceCode'), cameraCode)
@@ -221,6 +224,12 @@ for (const positioned of [false, true]) test(`${positioned ? '浮动' : '无地
         assert.equal(panels.length, 1)
         const dialog = panels[0]
         assert.ok(dialog.textContent.includes(cameraCode))
+        // PTZ buttons must always exist; an unconfirmed capability only greys them (维护者 2026-11-18).
+        assert.ok(dialog.querySelector('[data-ptz-panel]'), '云台区常驻')
+        const ptzButtons = [...dialog.querySelectorAll('[data-ptz-panel] button')]
+        assert.ok(ptzButtons.length >= 10, '云台按钮组齐全,实际 ' + ptzButtons.length)
+        assert.ok(ptzButtons.every((button) => button.disabled), '未确认云台能力时全部置灰')
+        assert.ok(dialog.querySelector('[data-ptz-hint]'), '置灰需带原因')
         assert.ok(dialog.querySelector('video'), JSON.stringify({ text: dialog.textContent, unexpected: page.unexpected, errors: page.errors.map((error) => error.message) }))
         dialog.querySelector('video').dispatchEvent(new Event('playing')); await settle()
         assert.ok(dialog.textContent.includes('正在播放'))
@@ -295,6 +304,10 @@ test('历史录像TAB不关闭面板,列片后才起流,占用不抢停别
         assert.ok(play); play.click(); await settle()
         assert.equal(page.requests.filter((request) => request.path.endsWith('/playback')).length, 1)
         assert.ok(dialog().querySelector('video[aria-label="历史录像画面"]'), '应展示回放画面')
+        // Pause/seek must stay on our own gated buttons, never the native bar.
+        assert.ok(dialog().querySelector('[data-playback-control]'), '回放控制走自绘按钮')
+        assert.ok(dialog().querySelector('[data-playback-mute]'), '回放仍需可调音')
+        assert.ok(dialog().querySelector('[data-playback-fullscreen]'), '回放仍需可全屏')
         // Closing releases the playback session and never leaves the panel half-open.
         dialog().querySelector('[aria-label="关闭监控"]').click(); await settle()
         assert.equal(document.querySelector('[data-video-monitor]'), null)