Explorar el Código

按归纳后的接口定义

zengy hace 1 día
padre
commit
e100a05088

+ 5 - 2
.env.development

@@ -9,8 +9,11 @@ VITE_APP_MINIO_BASE_URL='http://111.23.174.45:9000/pipe/'
 
 # 现有配置服务使用 VITE_COCKPIT_*,不是参考项目的 VITE_APP_BASE_API。
 VITE_COCKPIT_DATA_SOURCE='real'
-VITE_COCKPIT_API_BASE_URL='http://192.168.110.96:8301/api/cockpit/v1'
-VITE_COCKPIT_WS_URL='ws://192.168.110.96:8301/ws/deviceStatus'
+VITE_COCKPIT_API_BASE_URL='/api/cockpit/v1'
+VITE_COCKPIT_WS_URL='/ws/deviceStatus'
+
+# 仅 Node 侧 dev 代理目标,不进入浏览器产物;后端不在本机时改这里。
+COCKPIT_API_ORIGIN='http://127.0.0.1:8301'
 
 # 自动读取 public/cockpit/config.json;该文件的值优先于上述兜底值。
 # 无本机 JSON 时使用 deploy/cockpit.config.json + 本环境连接配置;GIS/模型不在 .env 重复维护。

+ 4 - 0
.env.local.example

@@ -2,3 +2,7 @@
 # 生产不使用开发中间件,须由 Nginx/CDN 挂载相同 URL 前缀。
 # 不要在 .env.local 写开发 API/WS/图片地址,以免 FES 预加载覆盖生产配置。
 COCKPIT_GIS_MOUNTS=[{"prefix":"/gis/pic-ring0","dir":"D:/GIS/cockpit-gis-v2/pic-ring0"},{"prefix":"/gis/pic-ring1","dir":"D:/GIS/cockpit-gis-v2/pic-ring1"},{"prefix":"/gis/pic-ring2","dir":"D:/GIS/cockpit-gis-v2/pic-ring2"},{"prefix":"/gis/pic-ring3","dir":"D:/GIS/cockpit-gis-v2/pic-ring3"},{"prefix":"/gis/dem-lod","dir":"D:/GIS/cockpit-gis-v2/dem"},{"prefix":"/gis/cad-bim","dir":"D:/GIS/cockpit-models/cad-bim"}]
+
+# 后端不在本机时,在本机 .env.local 覆盖 dev 代理目标(Node 侧变量,不进入浏览器产物)。
+# 默认见 .env.development 的 COCKPIT_API_ORIGIN='http://127.0.0.1:8301'。
+COCKPIT_API_ORIGIN='http://127.0.0.1:8301'

+ 12 - 10
src/common/cockpitGisProxyPlugin.js

@@ -1,22 +1,24 @@
 import { loadEnv } from 'vite'
 
 /**
- * 仅在 dev server 生效:把 /gis/... 代理到公共 GIS 静态服务。
+ * 仅在 dev server 生效:/gis 走公共 GIS 静态服务,/api 与 /ws 走驾驶舱后端。
+ * 浏览器侧一律同源,生产由 Nginx 转发,开发代理只存在于 Node 侧。
  */
 export default function cockpitGisProxy() {
     return {
-        name: 'cockpit-gis-proxy',
+        name: 'cockpit-dev-proxy',
         config(config, { mode }) {
             const env = loadEnv(mode, process.cwd(), '')
-            const target = env.COCKPIT_GIS_ORIGIN
-            if (!target) return {}
-            return {
-                server: {
-                    proxy: {
-                        '/gis': { target, changeOrigin: true },
-                    },
-                },
+            const proxy = {}
+            if (env.COCKPIT_GIS_ORIGIN) {
+                proxy['/gis'] = { target: env.COCKPIT_GIS_ORIGIN, changeOrigin: true }
             }
+            if (env.COCKPIT_API_ORIGIN) {
+                proxy['/api/cockpit/v1'] = { target: env.COCKPIT_API_ORIGIN, changeOrigin: true }
+                proxy['/ws/deviceStatus'] = { target: env.COCKPIT_API_ORIGIN, changeOrigin: true, ws: true }
+            }
+            if (!Object.keys(proxy).length) return {}
+            return { server: { proxy } }
         },
     }
 }

+ 2 - 2
src/modules/cockpit/CockpitShell.vue

@@ -1298,7 +1298,7 @@ const facilityUndergroundReady = computed(() => Boolean(
 /**
  * 设备→设施真实关联索引(维护者 2026-10-22 批准的后端契约)。
  *
- * 后端 `GET /api/cockpit/v1/device-facility-relations` 只按真实主键解析出 `deviceCode` 的行;
+ * 后端 `GET /api/cockpit/v1/equipments/facility-relations` 只按真实主键解析出 `deviceCode` 的行;
  * 当前库数据下通常为空(关联表存的是设备 id、管点 network_id 悬空、equipment_id 查不到),
  * 因此这里拿到空 Map 属**正常降级**,界面继续标「邻近设备 · 示意安装」,不伪报真实绑定。
  */
@@ -1398,7 +1398,7 @@ function selectPipeEnhancement(hit) {
  * 3D 视图按主键认回即可。管段从管线拾取链进来,`entityDetailStore` 从未被填充,
  * 资产详情因此恒空 —— 这就是「井盖能显示、管道不显示」的根源。
  *
- * 详情取数沿用既有的 `facilityPointStore.select`(同一条 `/entities/{id}/detail` 只读端点),
+ * 详情取数沿用既有的 `facilityPointStore.select`(同一条 `/infrastructure/entities/{id}/detail` 只读端点),
  * 不新造取数路径;失败按既有降级(资产详情显示取数提示,不阻塞 3D 场景)。
  */
 function loadPipeAssetDetail(kind, code) {

+ 1 - 1
src/modules/cockpit/domain/assetDetailKind.js

@@ -49,7 +49,7 @@ export function resolveAssetKind({ deviceCode = '', facilityDetail = null } = {}
  *
  * **取数主键是 `sourceId` 而不是 `code`**(实测):几何里管段的
  * `properties.code` 是业务编码(TCRQ202609080001),`properties.sourceId` 才是
- * `pipe_network_base` 的主键(raw_P11920)。用编码去查 `/entities/{id}/detail` 会 404。
+ * `pipe_network_base` 的主键(raw_P11920)。用编码去查 `/infrastructure/entities/{id}/detail` 会 404。
  *
  * @param {{kind?: string, code?: string, sourceId?: string}|null} selection `pipeEnhancementStore.selected`
  * @param {Array<object>} [visiblePipes] 当前可上图管线(用于把编码补成主键)

+ 1 - 1
src/modules/cockpit/domain/facilityPoints.js

@@ -4,7 +4,7 @@
  * 与「管线与构件」(`domain/pipeNetwork.js`)分属不同对象域,不共用口径:
  *   · 管线/构件来自 `/infrastructure/geometry`,每个 feature 带后端 `coordinateValidation`;
  *   · 设施点类型来自设施台账:`/infrastructure/operating-information` 给出可枚举的设施实体
- *     (`facilityId` + `facilityKind`),坐标取自 `/entities/{id}/detail` 的 `coordinates`。
+ *     (`facilityId` + `facilityKind`),坐标取自 `/infrastructure/entities/{id}/detail` 的 `coordinates`。
  *
  * **准入纪律(票 07 的边界,写清差异而不是假装没有)**:
  *   实体详情不带几何图层那套 `coordinateValidation`,所以本层**不做**第二套范围校核、

+ 1 - 1
src/modules/cockpit/domain/monitoringPanels.js

@@ -196,7 +196,7 @@ function toStatusCounts(raw) {
 /**
  * 监测分布的一个地图标记 → 领域行。
  *
- * **注意本端点不给设备编码列表**(那是 `/map-snapshot` 的 `CockpitMonitoringPointSummary.deviceCodes`),
+ * **注意本端点不给设备编码列表**(那是 `/map/snapshot` 的 `CockpitMonitoringPointSummary.deviceCodes`),
  * 所以台账卡片的设备徽标只能逐点位拉详情(票 18 的 Q10 裁定),不由本层伪造。
  */
 function toDistributionMarker(raw, kind) {

+ 3 - 3
src/modules/cockpit/mocks/contractMocks.js

@@ -1933,7 +1933,7 @@ function operatingInformationPayload(scenario, query = {}) {
 /**
  * 票 68:设施点图层补坐标用的实体详情样例(水厂 / 泵站各一条)。
  *
- * 形状照抄真实 `/api/cockpit/v1/entities/{id}/detail`:坐标在 `coordinates` 上
+ * 形状照抄真实 `/api/cockpit/v1/infrastructure/entities/{id}/detail`:坐标在 `coordinates` 上
  * (缺坐标即 null,前端据此把该设施进「无地图位置」清单,不补默认值)。
  * 两条样例与运行信息 mock 里带 `facilityId/facilityKind` 的指标行一一对应。
  */
@@ -2905,7 +2905,7 @@ function overviewAlarmDisposalPayload(scenario) {
 /** 各接口在五类样例下的载荷(`failed` 由处理器抛出,不在这里给载荷)。 */
 const PAYLOADS = {
     // 票 08:地图摘要按**真实分页语义**给(分页窗口横跨监测点与未关联设备、第 2 页起要求快照一致)。
-    '/map-snapshot': (s, _requested, context) => mapSnapshotPayload(s, context.path, context.mapSnapshot),
+    '/map/snapshot': (s, _requested, context) => mapSnapshotPayload(s, context.path, context.mapSnapshot),
     '/monitoring-points/*': (s, requested) => pointDetailPayload(s, requested),
     '/equipments/*/detail-aggregate': (s, requested) => equipmentAggregate(s, requested),
     '/equipments/*/collection-records': (s, requested) => collectionRecordsPayload(s, requested),
@@ -2967,7 +2967,7 @@ const PAYLOADS = {
     // 票 24:设施点位与管线几何读模型(票 30 的真实端点 `/infrastructure/geometry`,免鉴权)。
     '/infrastructure/geometry': (s, _requested, context) => pipeNetworkPayload(s, context.query),
     // 票 68:四类设施点的实体详情(设施点图层补坐标;查询串 `category` 与真接口同形)。
-    '/entities/*/detail': (s, requested, context) => facilityEntityDetailPayload(s, requested, context.query),
+    '/infrastructure/entities/*/detail': (s, requested, context) => facilityEntityDetailPayload(s, requested, context.query),
 }
 
 /**

+ 1 - 1
src/modules/cockpit/mocks/index.js

@@ -8,7 +8,7 @@
  * 场景覆盖(走查与人工演示都用同一套开关,无需改代码重新构建):
  *   `window.__COCKPIT_MOCK_SCENARIO__` = `success`(默认)| `empty` | `degraded` | `stale` | `failed` | `unauthorized`
  *       票 09 追加 `point-statuses`:后端六态 + 未关联设备 + 一个前端不认识的状态,全部可上图。
- *       它只影响 `/map-snapshot` 的样例内容,不改默认场景的任何数字(票 07/08 的断言依赖那些数)。
+ *       它只影响 `/map/snapshot` 的样例内容,不改默认场景的任何数字(票 07/08 的断言依赖那些数)。
  *       票 10 追加 `point-detail-order`:设备卡片逆状态优先级排列,验「顺序由后端返回顺序决定」。
  *       票 11 追加 `equipment-partial`:设备详情**分区级部分失败**(档案/工单/图片各自 FAILED,
  *       指标/预警/报警照常 SUCCESS),验「任一分区失败不遮盖其它成功分区」。它与 `failed` 不同:

+ 1 - 1
src/modules/cockpit/services/cockpitApi.js

@@ -134,7 +134,7 @@ async function readJsonPayload(response) {
  * 从后端错误载荷里取业务失效态(票 08)。
  *
  * 后端把「快照失效」放在 400 响应体 `AjaxResult.data.category`(`CockpitErrorCategory` 的**大写枚举**
- * `SNAPSHOT_EXPIRED`,见 `CockpitMapSnapshotController` 的异常处理),**不在 HTTP 状态码里**——
+ * `SNAPSHOT_EXPIRED`,见 `CockpitMapController` 的异常处理),**不在 HTTP 状态码里**——
  * 只看状态码会把它和「分页参数不合法」(`INVALID_REQUEST`)混成同一个原因,界面就只能笼统说
  * 「数据不可用」,而值班人员真正需要的是「刷新一下」。
  *

+ 2 - 2
src/modules/cockpit/services/deviceFacilityRelations.js

@@ -1,7 +1,7 @@
 /**
  * 设备→设施真实关联读模型(维护者 2026-10-22 批准的后端契约落地)。
  *
- * 端点:`GET /api/cockpit/v1/device-facility-relations`(免认证只读,提交 `83bd5ee`)。
+ * 端点:`GET /api/cockpit/v1/equipments/facility-relations`(免认证只读)。
  * 响应:`{ generatedAt, readOnly, relations: [{ deviceId, deviceCode, facilityCode, facilityKind, relationType }], statistics }`
  *
  * **为什么仍要降级**(2026-10-22 实测,勿把「契约已就绪」当成「真实关联已生效」):
@@ -17,7 +17,7 @@
 import { fetchSection } from './domainRequest.js'
 import { SECTION_STATE } from '../domain/sectionState.js'
 
-export const DEVICE_FACILITY_RELATION_PATH = '/device-facility-relations'
+export const DEVICE_FACILITY_RELATION_PATH = '/equipments/facility-relations'
 
 function toRelationData(payload) {
     const rows = Array.isArray(payload?.relations) ? payload.relations : []

+ 2 - 2
src/modules/cockpit/services/entityDetailApi.js

@@ -4,9 +4,9 @@ import { ENTITY_DETAIL_KIND, entityIdentity, normalizeEntityDetail } from '../do
 
 export const ENTITY_DETAIL_PATHS = Object.freeze({
     [ENTITY_DETAIL_KIND.FACILITY]: (id, target) => target.category
-        ? `/entities/${encodeURIComponent(id)}/detail?category=${encodeURIComponent(target.category)}` : '',
+        ? `/infrastructure/entities/${encodeURIComponent(id)}/detail?category=${encodeURIComponent(target.category)}` : '',
     [ENTITY_DETAIL_KIND.EMERGENCY]: (id, target) => target.category
-        ? `/entities/${encodeURIComponent(id)}/detail?category=${encodeURIComponent(target.category)}` : '',
+        ? `/infrastructure/entities/${encodeURIComponent(id)}/detail?category=${encodeURIComponent(target.category)}` : '',
     [ENTITY_DETAIL_KIND.EVENT]: (id, target) => target.family
         ? `/events/${encodeURIComponent(id)}/detail?family=${encodeURIComponent(target.family)}` : '',
     [ENTITY_DETAIL_KIND.WORK_ORDER]: (id) => `/work-orders/${encodeURIComponent(id)}/detail`,

+ 1 - 1
src/modules/cockpit/services/facilityPointService.js

@@ -4,7 +4,7 @@
  * 为什么是两跳(而不是一条几何端点):
  *   · cockpit 没有「设施列表」端点,四类设施的实体标识只出现在
  *     `/infrastructure/operating-information` 的指标行上(`facilityId` + `facilityKind`);
- *   · 坐标只出现在 `/entities/{id}/detail?category=…` 的 `coordinates` 上。
+ *   · 坐标只出现在 `/infrastructure/entities/{id}/detail?category=…` 的 `coordinates` 上。
  *   两条都是 `GET /api/cockpit/v1/**` 免鉴权只读端点,不碰业务 GIS 路径(ADR 0005)。
  *   **契约缺口**(票 68 登记):实体详情不带几何图层那套 `coordinateValidation`,
  *   基础设施也还没进 `/infrastructure/geometry` —— 后端补齐后可去掉这层两跳拼装。

+ 5 - 5
src/modules/cockpit/services/mapApi.js

@@ -7,10 +7,10 @@
  * 关于**分页与快照**:票 05 只定「一页怎么翻成领域批次」,不持状态——
  * 「同一批加载用同一快照、刷新换新快照」是票 08 的活,所以这里只把 `snapshotAt` 如实带出。
  *
- * 票 18 补上**全局筛选落到地图**(票 25 第 3 节冻结的路径①:以 `map-snapshot` 为准):
+ * 票 18 补上**全局筛选落到地图**(票 25 第 3 节冻结的路径①:以 `/map/snapshot` 为准):
  * 端点收 industry/district/deviceType;片区按 0/1/2/UNASSIGNED 直接下发,无部署映射。
  *
- * 票 14(决策 02/规格 07):`map-snapshot` **收多值 `pointStatus`**(八桶:六态 + UNKNOWN +
+ * 票 14(决策 02/规格 07):`/map/snapshot` **收多值 `pointStatus`**(八桶:六态 + UNKNOWN +
  * UNASSOCIATED,逗号分隔、OR)。旧注释「本端点不收该入参、状态筛选不作用到一张图」的
  * 缺口已由后端契约修订关闭——前端白名单先挡认不出的桶,不拿脏值去换 400。
  */
@@ -39,7 +39,7 @@ export function fetchMapSnapshot(options = {}) {
         return points === 0 && equipment === 0 && Number(payload && payload.total) === 0
     })
 
-    return fetchSection('/map-snapshot', {
+    return fetchSection('/map/snapshot', {
         params: {
             page: options.page,
             pageSize: options.pageSize,
@@ -57,11 +57,11 @@ export function fetchMapSnapshot(options = {}) {
 }
 
 /**
- * 基础帧(`/foundation`):地图能不能画、数据新不新鲜。
+ * 基础帧(`/map/foundation`):地图能不能画、数据新不新鲜。
  * 票 05 只交这一条读取路径,引导页与全域提示归后续票。
  */
 export async function fetchFoundation(options = {}) {
-    const result = await fetchSection('/foundation', {
+    const result = await fetchSection('/map/foundation', {
         toData: (payload) => ({
             mapFrame: (payload && payload.mapFrame) || null,
             freshness: (payload && payload.freshness) || null,

+ 1 - 1
src/modules/cockpit/stores/monitoringStore.js

@@ -358,7 +358,7 @@ export const useMonitoringStore = defineStore('monitoringStore', () => {
      * 补拉一个点位的设备徽标(Q10:走 N+1,Q14:卡片进视口才拉)。
      *
      * 为什么不能从已有数据算:`/monitoring/distribution` 的 marker **不给设备编码列表**
-     * (那是 `/map-snapshot` 的 `deviceCodes`),所以徽标只能问详情端点要设备计数
+     * (那是 `/map/snapshot` 的 `deviceCodes`),所以徽标只能问详情端点要设备计数
      * (`domain/pointDetail.js` 已把它翻成 `statistics`,本文件只见这个领域字段)。
      * **一台失败不影响其它卡片**:失败记成 `failed` 状态,
      * 界面显示占位符而不是 0(0 是"确实没有设备",与"没取到"是两件事)。

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

@@ -104,7 +104,7 @@ async function mountRoot({ positioned = false, underground = false } = {}) {
         requests.push({ url, path, body, options })
         if (url.origin !== 'http://fixture.invalid') { unexpected.push(url.href); throw new Error('Offline origin rejected') }
         assert.equal(new Headers(options.headers).get('authorization'), null)
-        if (path === '/map-snapshot') {
+        if (path === '/map/snapshot') {
             if (server.snapshotGate) await server.snapshotGate
             return envelope({ page: 1, pageSize: 100, snapshotAt: '2026-11-11T00:00:00Z',
                 batchUpdatedAt: '2026-11-11T00:00:00Z', total: 1, complete: true,
@@ -125,7 +125,7 @@ async function mountRoot({ positioned = false, underground = false } = {}) {
                 diameter: 300, material: '钢', coordinateValidation: { renderable: true } },
             geometry: { type: 'LineString', coordinates: [[110.3998, 28.4], [110.4008, 28.4]] },
         }] : [] })
-        if (path === '/device-facility-relations') return envelope({ rows: [] })
+        if (path === '/equipments/facility-relations') return envelope({ rows: [] })
         if (path.startsWith('/equipments/') && path.endsWith('/detail-aggregate')) return envelope({ ...aggregate, archive: { state: 'SUCCESS', data: selectedCamera } })
         if (path.startsWith('/equipments/') && path.endsWith('/collection-records')) return envelope({ deviceCode: cameraCode,
             state: 'EMPTY', recordView: { columns: [], rows: [] } })
@@ -634,10 +634,10 @@ test('三宿主同设备刷新保持同一媒体;浮动锚点暂隐不释放
             let releaseSnapshot, releasePoint
             page.server.snapshotGate = new Promise((resolve) => { releaseSnapshot = resolve })
             page.server.pointGate = new Promise((resolve) => { releasePoint = resolve })
-            const before = page.requests.filter((request) => request.path === '/map-snapshot').length
+            const before = page.requests.filter((request) => request.path === '/map/snapshot').length
             const beforeDetails = page.requests.filter((request) => request.path.endsWith('/detail-aggregate')).length
             page.host.querySelector('[data-map-refresh]').click(); await settle()
-            assert.equal(page.requests.filter((request) => request.path === '/map-snapshot').length, before + 1)
+            assert.equal(page.requests.filter((request) => request.path === '/map/snapshot').length, before + 1)
             assert.ok(document.querySelector('[data-video-monitor] video') === media, `${host}: 摘要刷新等待期保留媒体`)
             releaseSnapshot(); page.server.snapshotGate = null; await settle()
             assert.ok(document.querySelector('[data-video-monitor] video') === media, `${host}: 设备清单等待期保留媒体`)