Przeglądaj źródła

[Mod 0000]修改AI助手二维面板显示逻辑

wangkeyi 1 tydzień temu
rodzic
commit
22a467e031

+ 6 - 0
src/views/ventAI/manageAssistent/components/AiAssistantModal.vue

@@ -443,6 +443,12 @@
         modelPreview.ownerSessionId = currentSessionKey();
         lastModelLocateSignature = '';
         modelPreview.loaded = true;
+
+        // 子应用只靠模型 id 不会主动加载模型;首次打开必须补发一次链接里的定位消息,
+        // 由子应用在 locate 处理里完成“加载模型 + 定位”。等 ModalPreview 挂载/注册桥接后再发,
+        // 未 ready 时桥接会自动排队,ready 后补发。
+        await nextTick();
+        applyModelLocate(target);
       }
     })().finally(() => {
       modelPreviewTransition = null;

+ 13 - 7
src/views/ventAI/manageAssistent/components/resource/ModalPreview.vue

@@ -228,6 +228,19 @@
     startLoadTimeout();
   };
 
+  // 必须在 iframe 渲染前注册监听:子应用启动后会立刻向上发 ready,
+  // 若等 onMounted 才注册,第一次打开的 ready 会丢失,token 和排队的定位消息就永远不会补发,
+  // 表现为首次打开模型一直停在子应用加载态,点第二个模型触发重新 ready 后才恢复。
+  bridgeOrigin.value = resolveOrigin(entry);
+  if (entry) {
+    // 传函数而非 window 引用:iframe 会被 v-if 重建,contentWindow 会变
+    registerPreviewBridge(
+      () => iframeRef.value?.contentWindow ?? null,
+      bridgeOrigin.value,
+      () => userStore.getToken
+    );
+  }
+
   onMounted(() => {
     if (!entry) {
       // VITE_APP_SUB_APP 中没配该子应用:直接进错误态,不必空等超时
@@ -236,13 +249,6 @@
       logLoadError('MicroApp Not Configured', `子应用 ${APP_NAME} 未在 VITE_APP_SUB_APP 中配置`, 'apps.ts 未解析到该子应用的 entry');
       return;
     }
-    // 传函数而非 window 引用:iframe 会被 v-if 重建,contentWindow 会变
-    bridgeOrigin.value = resolveOrigin(entry);
-    registerPreviewBridge(
-      () => iframeRef.value?.contentWindow ?? null,
-      bridgeOrigin.value,
-      () => userStore.getToken
-    );
     startLoadTimeout();
 
     if (bridgeTestEnabled) {

+ 32 - 2
src/views/ventAI/manageAssistent/lib/modalPreviewBridge.ts

@@ -183,11 +183,41 @@ const send = (message: BaseToPreviewMessage) => {
   return post(message);
 };
 
+/**
+ * 子应用只识别不带后缀的设备类型组(windrect / fanlocal / gate / window ...)。
+ * 后端链接里常带业务子类型(如 windrect_ds_two、fanlocal_hx),直接透传会让子应用去错误的图层里找。
+ * 这里统一归一到子应用认识的类型组;人员/车辆类型保持原样,由子应用转去人员定位系统。
+ */
+const DEVICE_TYPE_PREFIXES = ['fanlocal', 'fanmain', 'windrect', 'gate', 'window', 'modelsensor', 'speedStation', 'obfurage', 'sys'];
+
+export const normalizeDeviceType = (deviceType?: string | null): string => {
+  const raw = (deviceType || '').trim();
+  if (!raw) return '';
+  if (/^(location|vehicle|cheliang)/i.test(raw)) return raw;
+
+  const lower = raw.toLowerCase();
+  const exact = DEVICE_TYPE_PREFIXES.find((prefix) => prefix.toLowerCase() === lower);
+  if (exact) return exact;
+
+  const matched = DEVICE_TYPE_PREFIXES.find((prefix) => lower.startsWith(`${prefix.toLowerCase()}_`));
+  return matched || raw;
+};
+
 /** 定位巷道:{ model_id, tunid, deviceType } */
 export const locateTunnel = (payload: LocateTunnelPayload) => send({ from: SOURCE_BASE, type: 'locate-tunnel', payload });
 
 /** 定位设备:{ model_id, deviceType, locationId } */
-export const locateDevice = (payload: LocateDevicePayload) => send({ from: SOURCE_BASE, type: 'locate-device', payload });
+export const locateDevice = (payload: LocateDevicePayload) =>
+  send({
+    from: SOURCE_BASE,
+    type: 'locate-device',
+    payload: { ...payload, deviceType: normalizeDeviceType(payload.deviceType) },
+  });
 
 /** 定位设备报表(按安装位置名称):{ model_id, deviceType, locationName } */
-export const locateDeviceReport = (payload: LocateDeviceReportPayload) => send({ from: SOURCE_BASE, type: 'locate-device-report', payload });
+export const locateDeviceReport = (payload: LocateDeviceReportPayload) =>
+  send({
+    from: SOURCE_BASE,
+    type: 'locate-device-report',
+    payload: { ...payload, deviceType: normalizeDeviceType(payload.deviceType) },
+  });