Prechádzať zdrojové kódy

Merge remote-tracking branch 'origin/master'

ChenJZ 7 hodín pred
rodič
commit
011e250dc3

+ 8 - 3
src/modules/cockpit/CockpitShell.vue

@@ -2354,14 +2354,19 @@ onMounted(() => {
             // `__COCKPIT_FRESHNESS_FAIL__` 让走查/人工演示"周期一直失败"这条路径。
             if (action === STARTUP_ACTION.START_FRESHNESS) {
                 const failForever = typeof window !== 'undefined' && window.__COCKPIT_FRESHNESS_FAIL__ === true
+                let firstFreshnessTick = true
                 runtimeStore.startFreshness({
                     refreshSeconds: result.config.runtime ? result.config.runtime.refreshSeconds : undefined,
                     // 票 61:轮询与按钮共用同一个刷新入口(不再有第二套「换快照 + 刷面板」)。
                     // 本轮记账仍归 freshnessService 的周期(同一本账、同一判据),所以传 account:false
                     // 避免同一轮记两次;取数成败在 refreshStore.lastRun 里如实留痕。
-                    tick: () => (failForever
-                        ? { ok: false, reason: '演示:取数持续失败' }
-                        : requestRefresh({ account: false, facilityMode: 'details' })),
+                    // 启动首轮紧跟首屏设施点加载:跳过 details,避免同一批实体详情被取两遍。
+                    tick: () => {
+                        if (failForever) return { ok: false, reason: '演示:取数持续失败' }
+                        const facilityMode = firstFreshnessTick ? 'skip' : 'details'
+                        firstFreshnessTick = false
+                        return requestRefresh({ account: false, facilityMode })
+                    },
                 })
             }
         }

+ 13 - 23
src/modules/cockpit/stores/detailStore.js

@@ -45,9 +45,6 @@ import {
 } from '../domain/detailFlow.js'
 import { useMapStore } from './mapStore.js'
 
-/** 演示/联调用的参考设备(契约化 mock 里有这一台的完整档案)。 */
-export const DEMO_DEVICE_CODE = 'TC-PS-WS-202609020012'
-
 function pending() {
     return { state: SECTION_STATE.EMPTY, reason: '', mode: '', data: null, missing: [], freshness: '', retained: false, loaded: false }
 }
@@ -132,33 +129,20 @@ export const useDetailStore = defineStore('detailStore', () => {
     }
 
     /**
-     * 加载共享详情域分区。**并发取、各自成败**:一个分区失败不回滚其它已成功分区。
+     * 加载启动时共享的分区:这里只有地图摘要。
      * 地图摘要走 `mapStore` 的 refresh 链(票 14:换新快照第 1 页并**自动分批加载到完成**,
      * 决策 02 的 Q24——旧版只取第一页的手动渐进形态已由自动加载取代)。
-     * @param {object} [options] `{ deviceCode, config, fetchImpl }`
+     * 设备详情与新鲜度不再用固定演示设备预载,用户选中真实设备时再取。
+     * @param {object} [options] `{ config, fetchImpl }`
      */
     async function loadSharedSections(options = {}) {
-        const deviceCode = options.deviceCode || DEMO_DEVICE_CODE
         const shared = { config: options.config, fetchImpl: options.fetchImpl }
         configure(shared)
         loading.value = true
 
-        // 这条预载也领一个设备请求序号:用户若在预载途中就点进了某台设备的详情,
-        // 预载这份「演示设备」的载荷不得落地覆盖用户真正要看的那一台
-        // (同一条 token 纪律,见 `loadEquipmentAggregate`)。
-        deviceToken += 1
-        const mine = deviceToken
-
         mapStore.setup(shared)
-        const [, aggregate, freshness] = await Promise.all([
-            mapStore.refresh(),
-            fetchEquipmentDetailAggregate(deviceCode, shared),
-            fetchEquipmentFreshness(deviceCode, shared),
-        ])
-
+        await mapStore.refresh()
         syncMapSnapshotSection()
-        if (mine === deviceToken) setSection('equipmentAggregate', aggregate)
-        setSection('equipmentFreshness', freshness)
         loading.value = false
 
         return sections.value
@@ -233,8 +217,9 @@ export const useDetailStore = defineStore('detailStore', () => {
     }
 
     /**
-     * 加载设备详情聚合(票 11 的主路径)。一次拿到档案/指标/预警/报警/工单/时间线/图片,
-     * 每个分区独立成败(契约层保证,见 `domain/equipmentDetail.js`)。
+     * 加载设备详情聚合(票 11 的主路径)与这台设备的新鲜度。
+     * 聚合一次拿到档案/指标/预警/报警/工单/时间线/图片,每个分区独立成败
+     * (契约层保证,见 `domain/equipmentDetail.js`)。
      *
      * @param {string} deviceCode 设备编码
      * @returns {Promise<object>} 该分区(`section()`)
@@ -248,15 +233,20 @@ export const useDetailStore = defineStore('detailStore', () => {
         const active = Object.keys(options).length ? { ...requestOptions, ...options } : requestOptions
 
         try {
-            const result = await fetchEquipmentDetailAggregate(deviceCode, active)
+            const [result, freshness] = await Promise.all([
+                fetchEquipmentDetailAggregate(deviceCode, active),
+                fetchEquipmentFreshness(deviceCode, active),
+            ])
             // 迟到的响应丢弃:A 还没回来就换了 B,A 的数据不得挂在新表头下。
             if (mine !== deviceToken) return sections.value.equipmentAggregate
+            setSection('equipmentFreshness', freshness)
             return setEquipmentResult(deviceCode, result)
         } catch (error) {
             // 与点位级同款兜底:适配层不抛,但转换层万一抛了要收成一条失败分区,
             // 不能把设备详情卡在「加载中」(用户还得能看见其它已成功的区块)。
             if (mine !== deviceToken) return sections.value.equipmentAggregate
             const failed = section(SECTION_STATE.FAILED, { reason: REQUEST_REASON.UNREACHABLE, data: null })
+            setSection('equipmentFreshness', failed)
             return setEquipmentResult(deviceCode, failed)
         } finally {
             if (mine === deviceToken) deviceLoading.value = false

+ 16 - 5
src/modules/cockpit/stores/refreshStore.js

@@ -89,7 +89,8 @@ export const useRefreshStore = defineStore('refreshStore', () => {
      *   `mode` 当前一级模式(计划据此取面板清单);
      *   `account` 是否记新鲜度(默认 true;轮询那条路传 false —— 本轮记账归
      *   `freshnessService` 的周期,同一本账不重复记);
-     *   `facilityMode` 设施点刷新节奏 `full`(手动全量)/ `details`(轮询只补详情),默认 `full`。
+     *   `facilityMode` 设施点刷新节奏 `full`(手动全量)/ `details`(轮询只补详情)/
+     *   `skip`(本轮不动设施点,如启动时首轮 freshness 紧接首屏加载),默认 `full`。
      * @returns {Promise<object>} 本轮结论(`summarizeRefresh` 的结果)
      */
     function requestRefresh(options = {}) {
@@ -112,11 +113,14 @@ export const useRefreshStore = defineStore('refreshStore', () => {
     async function runOnce(current, options, mine) {
         let outcome = null
         try {
+            const skipFacility = options.facilityMode === 'skip'
             const [mapResult, facilityResult, panelResult] = await Promise.all([
                 guard(() => callDependency(deps.refreshMap, current, '地图摘要取数未接入')),
-                guard(() => callDependency(deps.refreshFacilityLayer, current, '设施点图层取数未接入', {
-                    mode: options.facilityMode === 'details' ? 'details' : 'full',
-                })),
+                skipFacility
+                    ? Promise.resolve(null)
+                    : guard(() => callDependency(deps.refreshFacilityLayer, current, '设施点图层取数未接入', {
+                        mode: options.facilityMode === 'details' ? 'details' : 'full',
+                    })),
                 guard(() => callDependency(deps.refreshPanels, current, '面板取数未接入')),
             ])
             outcome = summarizeRefresh({
@@ -124,7 +128,7 @@ export const useRefreshStore = defineStore('refreshStore', () => {
                 plan: current,
                 parts: [
                     mapPartOf(current, mapResult),
-                    facilityPartOf(current, facilityResult),
+                    skipFacility ? skippedFacilityPartOf(current) : facilityPartOf(current, facilityResult),
                     ...panelPartsOf(current, panelResult),
                 ],
             })
@@ -159,6 +163,13 @@ export const useRefreshStore = defineStore('refreshStore', () => {
         return { ...base, ...judgeMapRefresh(result.value) }
     }
 
+    /** 首轮 freshness 紧跟首屏加载时设施点不动:如实标 skipped,不算失败也不触发请求。 */
+    function skippedFacilityPartOf(current) {
+        const base = current.parts.find((part) => part.kind === REFRESH_PART.FACILITY_LAYER)
+            || { key: REFRESH_PART.FACILITY_LAYER, kind: REFRESH_PART.FACILITY_LAYER, label: '设施点' }
+        return { ...base, ok: true, state: 'skipped', reason: '' }
+    }
+
     /** 设施点图层那一项的逐项结果(取数抛错时按抛错原因记失败)。 */
     function facilityPartOf(current, result) {
         const base = current.parts.find((part) => part.kind === REFRESH_PART.FACILITY_LAYER)