wujingjing
2025-01-19 6d279e10194646139fb63bf8fddded84dfbc4777
src/components/chat/smallChat/index.vue
@@ -84,7 +84,7 @@
import { AssistantContent } from './types';
import { agentStreamByPost } from '/@/api/ai/chat';
import { Logger } from '/@/model/logger/Logger';
import type { OLMap } from '/@/model/map/OLMap';
import { GaoDeSourceType, gaoDeSourceTypeMap, type OLMap } from '/@/model/map/OLMap';
import assistantPic from '/static/images/role/assistant-200x192.png';
import userPic from '/static/images/role/user-200x206.png';
import { useDrag } from '/@/hooks/useDrag';
@@ -103,7 +103,11 @@
const chatContainerRef = ref<HTMLDivElement>(null);
const { startDrag, style: chatContainerStyle, handleStyle } = useDrag({
const {
   startDrag,
   style: chatContainerStyle,
   handleStyle,
} = useDrag({
   handle: chatHeaderRef,
});
@@ -118,10 +122,35 @@
   return result as ChatMessage<AssistantContent>;
};
const mockCommand = (question: string) => {
   if (question === `切换${gaoDeSourceTypeMap[GaoDeSourceType.Vector]}`) {
      handleMapCommand({ operate: '切换标准地图' });
      return;
   } else if (question === `切换${gaoDeSourceTypeMap[GaoDeSourceType.Satellite]}`) {
      handleMapCommand({ operate: '切换卫星地图' });
      return;
   } else if (question === `切换${gaoDeSourceTypeMap[GaoDeSourceType.SatelliteRoad]}`) {
      handleMapCommand({ operate: '切换路网地图' });
      return;
   } else if (question === '显示设备') {
      handleMapCommand({ operate: '显示设备' });
      return;
   } else if (question === '隐藏设备') {
      handleMapCommand({ operate: '隐藏设备' });
      return;
   } else if (question === '聚焦设备') {
      handleMapCommand({ operate: '聚焦设备' });
      return;
   }
}
const startStream = (question: string) => {
   if (lastIsInit) {
      showHistory.value = false;
   }
   // mockCommand(question);
   // return;
   let haveMapOperate = false;
   agentStreamByPost(
      {
@@ -157,6 +186,7 @@
      last.content.isLoading = content.isLoading;
   }
};
const handleMapCommand = (command: any) => {
   if (!command) return;
   switch (command.operate) {
@@ -166,6 +196,26 @@
      case '缩小':
         props.olMap.zoomOut();
         break;
      case `切换${gaoDeSourceTypeMap[GaoDeSourceType.Vector]}`:
         props.olMap.setSourceType(GaoDeSourceType.Vector);
         break;
      case `切换${gaoDeSourceTypeMap[GaoDeSourceType.Satellite]}`:
         props.olMap.setSourceType(GaoDeSourceType.Satellite);
         break;
      case `切换${gaoDeSourceTypeMap[GaoDeSourceType.SatelliteRoad]}`:
         props.olMap.setSourceType(GaoDeSourceType.SatelliteRoad);
         break;
      case '显示设备':
         props.olMap.toggleMarkerOverlayVisible(true);
         break;
      case '隐藏设备':
         props.olMap.toggleMarkerOverlayVisible(false);
         break;
      case '聚焦设备':
         props.olMap.adjustViewToMarkers();
         break;
   }
   refreshAssistantMessage({ value: `已执行操作: ${command.operate}` });
@@ -215,7 +265,7 @@
   const [userMessage, assistantMessage] = applyMessage();
   const question = inputText.value;
   inputText.value = '';
   startStream(question);
};