liudong
2024-08-15 2542ae393e12cee28b2ffd81a3e6723386c58492
src/views/sessionManager/index.vue
@@ -5,67 +5,69 @@
      @addSession="addSession"
      :dialogId="dialogId"
    ></AddSession>
    <a-card class="top-title">AI会话记录</a-card>
    <a-row :gutter="[5, 5]" style="margin-top: 3px">
      <a-col :span="6">
        <a-card class="left-select">
          <a-select
            v-model="selectValue"
            :options="dialogs"
            :field-names="fieldNames"
            @change="dialogChange"
          >
          </a-select>
        </a-card>
        <a-card style="height: 50px">
          <template #cover>
            <div style="display: flex; justify-content: space-between">
              <a-button
                type="primary"
                shape="round"
                class="card-btn-1"
                @click="modalObj.add = true"
              >
                +新建会话
              </a-button>
              <!-- <a-button type="text" shape="circle" class="card-btn-2">
                <icon-search />
              </a-button> -->
            </div>
          </template>
        </a-card>
        <a-card class="left">
          <a-scrollbar
            class="left-list"
            style="
              height: calc(100vh - 350px);
              overflow-y: auto;
              overflow-x: hidden;
            "
          >
            <div
              class="item left-list-item"
              v-for="session in sessionList"
              @click="querySessionDetail(session)"
              :class="{ isLeftActive: activeSessionId === session.id }"
            >
              <div class="text" :class="{ time: theme === 'dark' }"
                >{{ session.name }}
              </div>
              <div class="time"
                >{{
                  moment(new Date(session.create_time)).format(
                    'YYYY-MM-DD HH:mm:ss'
                  )
                }}
              </div>
            </div>
          </a-scrollbar>
        </a-card>
    <!--    <a-card class="top-title">AI会话记录</a-card>-->
    <a-row :gutter="[5, 5]" style="margin-top: 3px;">
      <!--      <a-col :span="6">-->
      <!--        <a-card class="left-select">-->
      <!--          <a-select-->
      <!--            v-model="selectValue"-->
      <!--            :options="dialogs"-->
      <!--            :field-names="fieldNames"-->
      <!--            @change="dialogChange"-->
      <!--          >-->
      <!--          </a-select>-->
      <!--        </a-card>-->
      <!--        <a-card style="height: 50px">-->
      <!--          <template #cover>-->
      <!--            <div style="display: flex; justify-content: space-between">-->
      <!--              <a-button-->
      <!--                type="primary"-->
      <!--                shape="round"-->
      <!--                class="card-btn-1"-->
      <!--                @click="modalObj.add = true"-->
      <!--              >-->
      <!--                +新建会话-->
      <!--              </a-button>-->
      <!--              &lt;!&ndash; <a-button type="text" shape="circle" class="card-btn-2">-->
      <!--                <icon-search />-->
      <!--              </a-button> &ndash;&gt;-->
      <!--            </div>-->
      <!--          </template>-->
      <!--        </a-card>-->
      <!--        <a-card class="left">-->
      <!--          <a-scrollbar-->
      <!--            class="left-list"-->
      <!--            style="-->
      <!--              height: calc(100vh - 350px);-->
      <!--              overflow-y: auto;-->
      <!--              overflow-x: hidden;-->
      <!--            "-->
      <!--          >-->
      <!--            <div-->
      <!--              class="item left-list-item"-->
      <!--              v-for="session in sessionList"-->
      <!--              @click="querySessionDetail(session)"-->
      <!--              :class="{ isLeftActive: activeSessionId === session.id }"-->
      <!--            >-->
      <!--              <div class="text" :class="{ time: theme === 'dark' }"-->
      <!--                >{{ session.name }}-->
      <!--              </div>-->
      <!--              <div class="time"-->
      <!--                >{{-->
      <!--                  moment(new Date(session.create_time)).format(-->
      <!--                    'YYYY-MM-DD HH:mm:ss'-->
      <!--                  )-->
      <!--                }}-->
      <!--              </div>-->
      <!--            </div>-->
      <!--          </a-scrollbar>-->
      <!--        </a-card>-->
      <!--      </a-col>-->
      <a-col :span="1">
        <chatMenu></chatMenu>
      </a-col>
      <!--      智能体会话-->
      <a-col :span="18" v-show="agentType == '1'">
        <a-card class="center">
      <a-col :span="23" v-show="agentType == '1'">
          <!-- <div
            v-if="sessionDetailList.length === 0"
            style="
@@ -142,6 +144,7 @@
              </a-col>
            </a-row>
          </div> -->
        <div class="center">
          <a-scrollbar
            ref="scrollbar"
            id="home"
@@ -149,7 +152,7 @@
            style="
              width: 90%;
              overflow: auto;
              height: calc(100vh - 380px);
              height: calc(100vh - 300px);
              margin: 0px auto 20px;
            "
          >
@@ -243,17 +246,18 @@
                  style="border-radius: 24px"
                  :loading="loading"
                  size="large"
                  >发送</a-button
                >发送
                </a-button
                >
              </div>
            </div>
          </div>
        </a-card>
        </div>
      </a-col>
      <a-col :span="18" v-show="agentType == '2'">
        <a-card class="center">
      <a-col :span="23" v-show="agentType == '2'">
        <div class="center">
          <agentSession :modalObj="agentObj"></agentSession>
        </a-card>
        </div>
      </a-col>
      <!-- <a-col :span="5">
@@ -323,46 +327,47 @@
  import {
    IconClose,
    IconSearch,
    IconTiktokColor,
  } from '@arco-design/web-vue/es/icon';
  import { useAppStore, useUserStore } from '@/store';
  import { computed, nextTick, onMounted, watch, reactive, ref } from 'vue';
  IconTiktokColor
} from "@arco-design/web-vue/es/icon";
import { useAppStore, useUserStore } from "@/store";
import { computed, nextTick, onMounted, watch, reactive, ref } from "vue";
  import { Message } from '@arco-design/web-vue';
  import { EventSourceParserStream } from 'eventsource-parser/stream';
  import moment from 'moment';
  import AddSession from '@/views/sessionManager/components/addSession.vue';
  import agentSession from '@/views/sessionManager/components/agentSession.vue';
import { Message } from "@arco-design/web-vue";
import { EventSourceParserStream } from "eventsource-parser/stream";
import moment from "moment";
import chatMenu from "@/views/sessionManager/components/chatMenu.vue";
import AddSession from "@/views/sessionManager/components/addSession.vue";
import agentSession from "@/views/sessionManager/components/agentSession.vue";
  import {
    chatApi,
    getDialogListApi,
    getSessionDetailsApi,
    sessionListApi,
  } from '@/api/session';
  import { getAuthorization } from '@/utils/auth';
  import { queryCanvasList } from '@/api/Agent';
  import { getAgentSessionDetailsApi } from '@/api/agentSession';
  sessionListApi
} from "@/api/session";
import { getAuthorization } from "@/utils/auth";
import { queryCanvasList } from "@/api/Agent";
import { getAgentSessionDetailsApi } from "@/api/agentSession";
  const sessionDetailList = ref([]); //根据会话id出来的会话详情
  const sessionList = ref([]); //会话列表
  const modalObj = reactive({ add: false });
  const dialogId = ref('');
const dialogId = ref("");
  const chatDis = ref(false);
  const loading = ref(false);
  const agentType = ref('1');
const agentType = ref("1");
  const currIndex = ref(0);
  const displayedText = ref(''); // 正在显示的文字
const displayedText = ref(""); // 正在显示的文字
  let timer: number | null = null;
  const streamStr = ref('');
  const inputMsg = ref('');
  const activeSessionId = ref('');
  const fieldNames = { value: 'id', label: 'name' };
const streamStr = ref("");
const inputMsg = ref("");
const activeSessionId = ref("");
const fieldNames = { value: "id", label: "name" };
  const dialogs = ref([]);
  const dialogObj = reactive({});
  const agentObj = reactive({});
  const agentList = ref([]);
  const selectValue = ref('');
const selectValue = ref("");
  const sectionList = ref({});
  const DialogList = async () => {
    const { code, data } = await getDialogListApi();
@@ -372,10 +377,10 @@
        dialogs.value = data.map((item) => {
          return {
            ...item,
            type: 1, //智能体
          type: 1 //智能体
          };
        });
        console.log(data, 'dialogs');
      console.log(data, "dialogs");
        queryCanvas();
        // querySessionList();
      }
@@ -385,12 +390,12 @@
  const queryCanvas = async (params = {}) => {
    try {
      const { data } = await queryCanvasList(params);
      console.log(data, 'agent');
    console.log(data, "agent");
      agentList.value = data.map((item) => {
        return {
          ...item,
          name: item.title,
          type: 2, //agent
        type: 2 //agent
        };
      });
      // 合并数组
@@ -409,7 +414,7 @@
  const handleShiftEnter = (event) => {
    event.preventDefault();
    inputMsg.value += '\n';
  inputMsg.value += "\n";
  };
  const dialogChange = (val) => {
    // 判断当前是智能体或agent
@@ -420,7 +425,7 @@
        Object.assign(dialogObj, item);
      }
    });
    console.log(dialogObj.type, 'dialogObj');
  console.log(dialogObj.type, "dialogObj");
    if (dialogObj.type == 1) {
      agentType.value = 1;
      querySessionList();
@@ -432,20 +437,20 @@
    // querySessionList();
  };
  const sentClick = () => {
    sendMessage('click');
  sendMessage("click");
  };
  const sendMessage = async (event) => {
    if (event.keyCode == 13 || event === 'click') {
  if (event.keyCode == 13 || event === "click") {
      if (!event.shiftKey) {
        //只有enter没有shift,或进行你的其他逻辑
        if (event !== 'click') {
      if (event !== "click") {
          event.preventDefault(); // 阻止默认行为,即不换行
        }
        chatDis.value = true;
        loading.value = true;
        if (!activeSessionId.value) {
          Message.warning('请选择会话');
        Message.warning("请选择会话");
          chatDis.value = false;
          loading.value = false;
          return;
@@ -458,22 +463,22 @@
        if (inputMsg.value) {
          sessionDetailList.value.push({
            content: inputMsg.value,
            role: 'user',
          role: "user"
          });
          sessionDetailList.value.push({ role: 'last' });
        sessionDetailList.value.push({ role: "last" });
          refreshScroll();
          const response = await fetch(
            '/api/tech/cloudminds/query?modeltype=localragflow',
          "/api/tech/cloudminds/query?modeltype=localragflow",
            {
              method: 'POST',
            method: "POST",
              headers: {
                'Authorization': getAuthorization(),
                'Content-Type': 'application/json',
              "Authorization": getAuthorization(),
              "Content-Type": "application/json"
              },
              body: JSON.stringify({
                conversation_id: activeSessionId.value,
                messages: inputMsg.value,
              }),
              messages: inputMsg.value
            })
            }
          );
@@ -488,10 +493,10 @@
              const { done, value } = x;
              console.log(x, 999);
              try {
                const val = JSON.parse(value?.data || '');
              const val = JSON.parse(value?.data || "");
                const d = val?.data;
                if (typeof d !== 'boolean') {
                  console.info('data:', d);
              if (typeof d !== "boolean") {
                console.info("data:", d);
                  streamStr.value = d.content;
                  startDisplayStr();
                }
@@ -499,8 +504,8 @@
                console.warn(e);
              }
              if (done) {
                console.info('done');
                displayedText.value = '';
              console.info("done");
              displayedText.value = "";
                querySessionDetail(sectionList.value);
                break;
              }
@@ -509,9 +514,9 @@
          querySessionList();
          chatDis.value = false;
          loading.value = false;
          inputMsg.value = '';
        inputMsg.value = "";
        } else {
          Message.warning('消息不能为空');
        Message.warning("消息不能为空");
          chatDis.value = false;
          loading.value = false;
        }
@@ -538,7 +543,7 @@
  const scrollbar = ref(null);
  const refreshScroll = () => {
    nextTick(() => {
      const container = document.getElementById('home');
    const container = document.getElementById("home");
      scrollbar.value.scrollTop(container.scrollHeight);
    });
  };
@@ -550,7 +555,7 @@
      activeSessionId.value = data[0].id; //默认选择第一个
      querySessionDetail(data[0]);
    } else {
      Message.warning('查询失败');
    Message.warning("查询失败");
    }
  };
@@ -600,9 +605,11 @@
  .isLeftActive {
    background-color: #ededf5;
  }
  .left-list-item {
    margin-bottom: 2px;
  }
  .left-list-item:hover {
    background-color: #ededf5;
  }
@@ -617,6 +624,7 @@
      font-size: 16px;
      color: #333;
    }
    .left-select {
      :deep(.arco-select-view-single) {
        border-radius: 5px;
@@ -657,6 +665,7 @@
        }
      }
    }
    .card-btn-1 {
      margin: 8px 15px;
      width: 100%;
@@ -666,16 +675,19 @@
    .card-btn-2 {
      margin: 10px 10px;
    }
    .chatItemAnswer {
      box-sizing: border-box;
      background: #f1f1f1;
      border-radius: 14px;
      .light {
        box-sizing: border-box;
        background: #f1f1f1;
        border-radius: 14px;
      }
    }
    .textItemAnswer {
      background-color: #373739;
    }
@@ -709,6 +721,7 @@
          margin-right: 20px;
        }
      }
      .center-list {
        margin-top: 10px;
@@ -718,9 +731,11 @@
          padding: 10px;
          min-height: 120px;
          background-color: #e9f3ff;
          .item-content {
            color: #666;
          }
          .item-title {
            text-align: center;
            line-height: 40px;
@@ -730,6 +745,7 @@
          }
        }
      }
      .chartStart {
        color: #4955f5;
        cursor: pointer;
@@ -737,9 +753,11 @@
        font-size: 12px;
        font-weight: 500;
      }
      .chat_bottom {
        display: flex;
        align-items: center;
        .center-bottom {
          // position: absolute;
          // width: 90%;
@@ -764,28 +782,34 @@
            bottom: 10px;
            z-index: 10;
          }
          :deep(.arco-btn-size-large) {
            height: 28px;
            width: 60px;
          }
        }
        :deep(.arco-textarea-wrapper) {
          padding-top: 5px;
        }
      }
    }
    .chat-item {
      padding: 10px 0;
      .chartUserText {
        font-weight: 600;
        font-size: 14px;
        color: #333;
        margin-top: 4px;
      }
      .icon-user-jpg {
        border: 1px solid #d9d9d9;
      }
    }
    .right {
      .right-top {
        display: flex;
@@ -802,13 +826,16 @@
          top: 0px;
        }
      }
      .right-tag {
        margin-top: 20px;
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;
        :deep(.arco-btn-primary) {
          margin-bottom: 10px !important;
          &:hover {
            background-color: #e9f3ff;
            color: rgb(22, 93, 255);