yxl
2025-02-10 ee07b9f5e0ca5344bf5b78fcf87355d065d8c2b7
src/views/chartView/index.vue
@@ -22,12 +22,14 @@
  getAgentIntention,
  getAgentLayerList,
  getAgentThistorySave,
  getRagAgentIntention,
} from "../../api/api.js";
import mapSetFunc from "../../assets/js/mapSetFunc.js";
import { nanoid } from "nanoid";
import mapServer from "../../assets/js/map/mapServer.js";
import mapImg from "../../assets/js/map/mapImg.js";
import mapModel from "../../assets/js/map/mapModel.js";
import { marked } from "marked";
export default {
  name: "jwChat",
@@ -50,6 +52,7 @@
        dept: "最简单、最便捷",
        callback: this.bindCover,
      },
      closeMap: false,
    };
  },
  computed: {
@@ -130,7 +133,10 @@
        // console.log('Received message:', event.data);
        console.log(event);
        if (event.data != "连接成功") {
        if (
          event.data != "连接成功" ||
          event.data.indexOf("收到消息,消息内容:心跳包检测") <= 0
        ) {
          console.log(event.data);
          const val = JSON.parse(event.data);
          if (val.session_id == this.uuid) {
@@ -140,6 +146,15 @@
      };
    },
    async getQueryLayerList() {
      const item = {
        sourceType: "Tileset",
        name: "MilitaryFacilities",
        url: "/data-api/gisserver/c3dserver/sedb_DESKTOP-15DOTHJ_SEM4550/tileset.json",
      };
      setTimeout(() => {
        mapServer.addServer(item);
      }, 1000);
      return;
      getAgentLayerList().then((response) => {
        if (response.code != 200) return;
        const items = response.data;
@@ -192,51 +207,210 @@
      }
    },
    async setMsgStart(res) {
      console.log("res----", res);
      //输入@map打开地图
      if (res == "@map") {
        var rolMsg = [
          {
            type: "text",
            val: "地图已打开",
          },
        ];
        this.refashMsg(rolMsg);
        //打开地图
        this.$store.state.setScreenFlag = true;
        this.closeMap = true;
        earthCtrl.viewer.camera.flyTo({
          destination: {
            x: -1803769.3854512463,
            y: 29158371.286777183,
            z: 13465105.223495383,
          },
          orientation: {
            heading: 6.283185307179586,
            pitch: -1.5707963267948966,
            roll: 0,
          },
        });
      }
      //有map关键字定位
      else if (res.indexOf("@map") > -1) {
        this.closeMap = true;
        window.earthCtrl.camera.flyTo(
          121.5898036178841,
          23.93799083591751,
          2732.163687177577,
          4.501790216143808,
          -32.230361363631324,
          0.001313831409284339,
          2
        );
      }
      mapImg.removeInit();
      mapSetFunc.removeAll();
      this.$store.state.setListColor = [];
      this.$store.state.showLenged = false;
      window.earthCtrl.camera.flyTo(
        121.5898036178841,
        23.93799083591751,
        2732.163687177577,
        4.501790216143808,
        -32.230361363631324,
        0.001313831409284339,
        2
      );
      this.$store.state.showRelationBox = false;
      // const formData = new FormData();
      // formData.append("message", res);
      // formData.append("lib_id", "No1");
      // formData.append("session_id", this.uuid.toString());
      const formData = {
        message: res,
        message: res.replace(/\s+/g, ""),
        lib_id: "No1",
        session_id: this.uuid.toString(),
      };
      var obj = {
        ai: "",
        create_time: msgData.getDate1(),
        human: res,
        sessionid: this.uuid,
        update_time: "",
        userid: 0,
      };
      if (formData.message.indexOf("@map") > -1) {
        var obj = {
          ai: "",
          create_time: msgData.getDate1(),
          human: res,
          sessionid: this.uuid,
          update_time: "",
          userid: 0,
        };
        getAgentThistorySave(obj).then((response) => {
          if (response.code == 200) {
            obj.id = response.id;
            this.obj = obj;
          }
          this.setAgentIntention(obj, formData);
        });
      } else {
        this.setRagAgentIntention(formData);
      }
      getAgentThistorySave(obj).then((response) => {
        if (response.code == 200) {
          obj.id = response.id;
          this.obj = obj;
        }
        this.setAgentIntention(obj, formData);
      });
      // var obj = {
      //   ai: "",
      //   create_time: msgData.getDate1(),
      //   human: res,
      //   sessionid: this.uuid,
      //   update_time: "",
      //   userid: 0,
      // };
      // getAgentThistorySave(obj).then((response) => {
      //   if (response.code == 200) {
      //     obj.id = response.id;
      //     this.obj = obj;
      //   }
      //   this.setAgentIntention(obj, formData);
      // });
    },
    //地图相关问答
    async setAgentIntention(obj, formData) {
      getAgentIntention(formData).then((response) => {
        if (response.code != 200) {
      console.log("obj", formData);
      if (formData.message.indexOf("@map") > -1) {
        getAgentIntention(formData)
          .then((response) => {
            if (response.code != 200) {
              if (formData.message != "@map") {
                var rolMsg = [
                  {
                    type: "text",
                    val: "未查询到相关信息。",
                  },
                ];
                this.refashMsg(rolMsg);
              }
              return;
            }
            const type = response.type;
            //普通对话信息查询
            if (type == "message" || type == "Rag") {
              //关闭地图
              if (!this.closeMap) {
                this.$store.state.setScreenFlag = false;
              }
              var rolMsg = [
                {
                  type: "text",
                  val: type == "Rag" ? response.content : response.msg,
                },
              ];
              this.refashMsg(rolMsg);
            }
            //地图查询
            else {
              //打开地图
              this.$store.state.setScreenFlag = true;
              this.setMapfunc(response.content, obj);
            }
          })
          .catch((error) => {
            var rolMsg = [
              {
                type: "text",
                val: "未查询到相关信息。",
              },
            ];
            this.refashMsg(rolMsg);
          });
      } else {
        getRagAgentIntention(formData).then((res) => {});
      }
      // getAgentIntention(formData)
      //   .then((response) => {
      //     if (response.code != 200) {
      //       if (formData.message != "@map") {
      //         var rolMsg = [
      //           {
      //             type: "text",
      //             val: "未查询到相关信息。",
      //           },
      //         ];
      //         this.refashMsg(rolMsg);
      //       }
      //       return;
      //     }
      //     const type = response.type;
      //     //普通对话信息查询
      //     if (type == "message" || type == "Rag") {
      //       //关闭地图
      //       if (!this.closeMap) {
      //         this.$store.state.setScreenFlag = false;
      //       }
      //       var rolMsg = [
      //         {
      //           type: "text",
      //           val: type == "Rag" ? response.content : response.msg,
      //         },
      //       ];
      //       this.refashMsg(rolMsg);
      //     }
      //     //地图查询
      //     else {
      //       //打开地图
      //       this.$store.state.setScreenFlag = true;
      //       this.setMapfunc(response.content, obj);
      //     }
      //   })
      //   .catch((error) => {
      //     var rolMsg = [
      //       {
      //         type: "text",
      //         val: "抱歉,服务器似乎出了点问题,我们正在修复中。",
      //       },
      //     ];
      //     this.refashMsg(rolMsg);
      //   });
    },
    //普通对话问答
    async setRagAgentIntention(formData) {
      try {
        // 发送请求
        const params = new URLSearchParams(formData);
        const url = `/rag-api/rag?${params.toString()}`;
        let response = await fetch(url, {
          method: "get",
          responseType: "stream",
          headers: {
            "Content-Type": "application/json",
          },
        });
        // ok字段判断是否成功获取到数据流
        if (!response.ok) {
          var rolMsg = [
            {
              type: "text",
@@ -246,16 +420,53 @@
          this.refashMsg(rolMsg);
          return;
        }
        const type = response.type;
        if (type == "Map") {
          this.setMapfunc(response.content, obj);
        } else if (type == "Rag") {
          this.setMapRag(response, obj);
        } else {
          this.setMapfunc(response.content, obj);
        // 用来获取一个可读的流的读取器(Reader)以流的方式处理响应体数据
        const reader = response.body.getReader();
        // 将流中的字节数据解码为文本字符串
        const textDecoder = new TextDecoder();
        let result = true;
        let sendMsg = true;
        let sqlValue = "";
        while (result) {
          // done表示流是否已经完成读取  value包含读取到的数据块
          const { done, value } = await reader.read();
          if (done) {
            result = false;
            break;
          }
          let resText = textDecoder.decode(value);
          //包含<think>停止输出
          //包含</think>继续输出
          console.log(resText, "返回的数据");
          if (resText.indexOf("<think>") > -1) {
            sendMsg = false;
          }
          if (resText.indexOf("</think>") > -1) {
            sendMsg = true;
            let position = resText.indexOf('</think>');
            resText = resText.substring(position + "</think>".length);
          }
          if (sendMsg) {
            sqlValue += resText;
            var rolMsg = [
              {
                type: "stream",
                val: marked(sqlValue),
              },
            ];
            this.refashMsg(rolMsg);
          }
        }
      });
        // console.log(sqlValue, "输出所有返回数据");
      } catch (err) {
        var rolMsg = [
          {
            type: "text",
            val: "未查询到相关信息。",
          },
        ];
        this.refashMsg(rolMsg);
      }
    },
    setMapfunc(res, obj) {
      this.$store.state.showLenged = false;
@@ -270,7 +481,6 @@
          } else {
            roleMsg = msgData.getAffairsData([{ type: "text", val: res.msg }]);
          }
          this.refashMsg(roleMsg.list);
          break;
        case "queryMeta":
@@ -313,40 +523,39 @@
          var roleMsg = msgData.getAffairsData([
            { type: "text", val: "地图已显示" },
          ]);
          console.log("roleMsg----", roleMsg);
          this.refashMsg(roleMsg.list);
          break;
        case "aroundPoi":
          let dataList = [
            {
              type: "可打击目标",
              color:'#FF3366',
              color: "#FF3366",
              list: [],
            },
            {
              type: "不可打击目标",
              color:'#33FF66',
              color: "#33FF66",
              list: [],
            },
            {
              type: "其他",
              color:'#3366FF',
              color: "#3366FF",
              list: [],
            },
          ];
          res.data.forEach((item) => {
            if (item.ifstrike === "1") {
              dataList[0].list.push(item.seid);
              dataList[0].list.push(item.uuid);
            } else if (item.ifstrike === "2") {
              dataList[1].list.push(item.seid);
              dataList[1].list.push(item.uuid);
            } else {
              dataList[2].list.push(item.seid);
              dataList[2].list.push(item.uuid);
            }
          });
          const resultData = dataList
            .map((item) => `| ${item.type} | ${item.list.length} |`)
            .join("\n");
          var a = `| 数据类型 | 数据量 |\n|------|------|\n`+resultData;
          var a = `| 数据类型 | 数据量 |\n|------|------|\n` + resultData;
          console.log("aaa", a);
          this.setUpdateHistoryInFor(obj, a);
          var roleMsg = msgData.getMdData("markdown", a);
@@ -354,15 +563,102 @@
          const finalData = {
            func: "aroundPoi",
            data: dataList,
          }
          };
          mapSetFunc.init(finalData);
          break;
        case "getStrike":
          let dataList1 = [
            {
              type: "可打击目标",
              color: "#FF3366",
              list: [],
            },
            {
              type: "不可打击目标",
              color: "#33FF66",
              list: [],
            },
            {
              type: "其他",
              color: "#3366FF",
              list: [],
            },
          ];
          res.data.forEach((item) => {
            if (item.ifstrike === "1") {
              dataList1[0].list.push(item.uuid);
            } else if (item.ifstrike === "2") {
              dataList1[1].list.push(item.uuid);
            } else {
              dataList1[2].list.push(item.uuid);
            }
          });
          const resultData1 = dataList1
            .map((item) => `| ${item.type} | ${item.list.length} |`)
            .join("\n");
          var a = `| 数据类型 | 数据量 |\n|------|------|\n` + resultData1;
          console.log("aaa", a);
          this.setUpdateHistoryInFor(obj, a);
          var roleMsg = msgData.getMdData("markdown", a);
          this.refashMsg(roleMsg.list);
          const finalData1 = {
            func: "aroundPoi",
            data: dataList1,
          };
          mapSetFunc.init(finalData1);
          break;
        case "getParam":
          mapSetFunc.init(res);
          console.log("res.data.targetinfo", res);
          this.setUpdateHistoryInFor(obj, res.msg);
          if (res.data.length === 1) {
            var roleMsg = msgData.getAffairsData([
              { type: "text", val: res.data[0].targetinfo },
            ]);
            this.refashMsg(roleMsg.list);
          } else {
            const markData = res.data
              .map((item) => `| ${item.name} | ${item.targetinfo} |`)
              .join("\n");
            let markAttr = `| 名称 | 属性信息 |\n|------|------|\n` + markData;
            var roleMsg = msgData.getMdData("markdown", markAttr);
            this.refashMsg(roleMsg.list);
          }
          break;
        case "aroundPoi_2":
          mapSetFunc.init(res);
          console.log("res.data.targetinfo", res);
          const resData = res.data
            .map((item) => `| ${item.name} | ${item.targetinfo} |`)
            .join("\n");
          var attr = `| 名称 | 属性信息 |\n|------|------|\n` + resData;
          console.log("aaa", attr);
          var roleMsg = msgData.getMdData("markdown", attr);
          this.setUpdateHistoryInFor(obj, res.msg);
          this.refashMsg(roleMsg.list);
          break;
        case "attackentity":
          mapSetFunc.init(res);
          this.setUpdateHistoryInFor(obj, res.msg);
          if (res.data.length === 1) {
            var roleMsg = msgData.getAffairsData([
              { type: "text", val: res.data[0].targetinfo },
            ]);
            this.refashMsg(roleMsg.list);
          } else {
            const markData = res.data
              .map((item) => `| ${item.name} | ${item.targetinfo} |`)
              .join("\n");
            let markAttr = `| 名称 | 属性信息 |\n|------|------|\n` + markData;
            var roleMsg = msgData.getMdData("markdown", markAttr);
            this.refashMsg(roleMsg.list);
          }
          break;
        case "getRelatedEntity":
          this.setUpdateHistoryInFor(obj, res.msg);
          this.handleRelationData(res.data);
          var roleMsg = msgData.getAffairsData([
            { type: "text", val: res.data[0].targetinfo },
            { type: "text", val: "页面已显示" },
          ]);
          this.refashMsg(roleMsg.list);
          break;
@@ -437,6 +733,76 @@
      this.loading = false;
      this.list[this.list.length - 1].list = res;
    },
    //关系数据处理
    handleRelationData(data) {
      // 准备节点和边
      let graphData = [];
      let links = [];
      // 处理主类型(mainType)
      Object.keys(data.mainType).forEach((main) => {
        graphData.push({
          name: main,
          category: "mainType",
          symbolSize: 70,
          itemStyle: {
            color: "#4169E1",
          },
        });
        data.mainType[main].forEach((sec) => {
          graphData.push({
            name: sec,
            category: "secType",
            symbolSize: 60,
            itemStyle: {
              color: "#87CEFA",
            },
          });
          // 处理子类型(secType)
          if (data.secType[sec]) {
            data.secType[sec].forEach((sub) => {
              graphData.push({
                name: sub,
                category: "subType",
                symbolSize: 50,
                itemStyle: {
                  color: "#30ECA6",
                },
              });
              // 处理具体项(subtype)
              if (data.subtype[sub]) {
                data.subtype[sub].forEach((item) => {
                  graphData.push({
                    name: item.name,
                    category: "subTypeItem",
                    symbolSize: 50,
                    itemStyle: {
                      color: "#00BFFF",
                    },
                    uuid: item.uuid,
                    lontitude: item.lontitude,
                    lattitude: item.lattitude,
                  });
                  links.push({ source: sub, target: item.name });
                });
              }
              // 父子节点连接
              links.push({ source: sec, target: sub });
            });
          }
          // 父子节点连接
          links.push({ source: main, target: sec });
        });
      });
      console.log("nodes---", graphData, "links---", links);
      this.$store.state.showRelationBox = true;
      this.$store.state.relationData = {
        nodes: graphData,
        links: links,
      };
    },
  },
};
</script>