Sfoglia il codice sorgente

fix(cockpit): locate device on scene icon click, not only from list

ChenJZ 14 ore fa
parent
commit
8bbfeeee22

+ 4 - 1
.scratch/cockpit-shell-panel-layout/verify/t23-click-flow.mjs

@@ -58,7 +58,7 @@ const context = vm.createContext({
     overlapExpandedGroup: '', overlapPreviewGroup: '', lastPicked: null,
     collapseOverlap() {}, paintPicked() {}, expandOverlap() {},
 })
-vm.runInContext(`${functions(service, ['onPipelinePick', 'pickPipelineAt', 'pickDeviceOrPointAt'])}\nglobalThis.api = { onPipelinePick, pickPipelineAt, pickDeviceOrPointAt };`, context)
+vm.runInContext(`${functions(service, ['onPipelinePick', 'pickPipelineAt', 'pickDeviceOrPointAt', 'dispatchPickResult'])}\nglobalThis.api = { onPipelinePick, pickPipelineAt, pickDeviceOrPointAt };`, context)
 // Execute the actual service registration, preserving its device/point-first branch.
 const registration = service.match(/record\.detachPickInput = attachPointPick\(record\.host,[\s\S]*?\n        \}\)/)?.[0]
 assert.ok(registration, 'map must attach its pointer input')
@@ -140,7 +140,10 @@ assert.equal(focusedDevice, 'D-real')
 await Vue.nextTick(); await Vue.nextTick()
 assert.equal(deviceStore.aggregate.data.deviceCode, 'D-real')
 assert.equal(find(root, 'data-device-detail').props['data-device-detail'], 'D-real')
+// 场景图标点击同样必须触发镜头定位(此前只有清单点击会 focus,导致「相机没动」)。
+focusedDevice = null
 devicePick(demoDevice)
+assert.equal(focusedDevice, 'D-real', '场景图标点击也必须调用 focusDevice')
 await Vue.nextTick(); await Vue.nextTick()
 assert.equal(find(root, 'data-device-detail').props['data-device-detail'], 'D-real', '场景图标射线点击直接打开设备详情')
 assert.equal(find(root, 'data-device-list') !== undefined, true, '详情覆盖层打开时清单仍保留于其下')

+ 16 - 3
src/modules/cockpit/components/PipeEnhancement.vue

@@ -109,11 +109,24 @@ let viewer = null
 let mountGeneration = 0
 const open = ref(false)
 
-function selectDevice(device) {
-    if (device.placement !== 'list-only') viewer?.focusDevice?.(device.code)
+/**
+ * 设备被选中(清单点击或场景图标点击)时的统一处理:先让镜头**飞行定位**到该设备,
+ * 再打开内部详情。
+ *
+ * 维护者 2026-10-22:「地下管线详情视图的相机位移没成功实现。」
+ * 根因是**场景图标点击**走的是 `onDevicePick`,而那条路径只 emit、从不调用 `focusDevice`,
+ * 所以只有右侧清单点击才会定位。现在两条入口共用本函数,不会再分叉。
+ */
+function pickDevice(device) {
+    // 只有能上图(有合法坐标)的设备才有可定位的模型;仅清单项没有位置可飞。
+    if (device && device.placement !== 'list-only') viewer?.focusDevice?.(device.code)
     emit('device-pick', device)
 }
 
+function selectDevice(device) {
+    pickDevice(device)
+}
+
 function disposeViewer() {
     if (viewer) viewer.destroy()
     viewer = null
@@ -127,7 +140,7 @@ async function mount() {
     await nextTick()
     if (generation !== mountGeneration || !open.value || !viewport.value) return
     viewer = mountPipeEnhancement(viewport.value, props.plan, {
-        onDevicePick: (device) => emit('device-pick', device),
+        onDevicePick: (device) => pickDevice(device),
         onObjectPick: (hit) => emit('object-pick', hit),
     })
 }