liudong
2024-08-23 38e9abbd9e89ccf14389e90fa94b4b8ea36fa60d
src/views/sessionManager/index.vue
@@ -24,7 +24,13 @@
                <a-popover position="bottom" trigger="click">
                  <a-button border
                    >{{ agentTitle }}
                    >
                    <span style="
                       width: 100px;
                      overflow: hidden;
                      text-overflow: ellipsis;
                      white-space: nowrap;
                    ">{{ from.name }}</span>
                    <icon-down style="margin-left: 4px" />
                  </a-button>
                  <template #content>
@@ -386,11 +392,11 @@
      <a-form
        ref="formRef"
        :rules="rules"
        :model="chatObj"
        :model="from"
        @submit="handleSubmit"
      >
        <a-form-item field="name" label="名称">
          <a-input v-model="agentTitle" placeholder="请输入名称" />
          <a-input v-model="from.name" placeholder="请输入名称" />
        </a-form-item>
        <a-form-item>
          <div style="width: 100%; text-align: right">
@@ -465,6 +471,9 @@
  const agentType = ref('1');
  const agentTitle = ref('未命名会话');
  let chatObj = reactive({});
  let from = reactive({
    name:'未命名会话',
  });
  const isStopChat = ref(false);
  const currIndex = ref(0);
  const displayedText = ref(''); // 正在显示的文字
@@ -487,6 +496,7 @@
  const fileInput = ref(null);
  const chatDataMeg = reactive({});
  const visible = ref(false);
  let toStop = false;
  const rules = {
    name: [
@@ -499,12 +509,10 @@
  const handleSubmit = async ({ values, errors }) => {
    if (errors) return;
    // chatObj.name = agentTitle.value;
    // chatObj.conversation_id = chatObj.id;
    let chatData = {
      id: chatObj.id,
      conversation_id: chatObj.id,
      name: agentTitle.value,
      name: from.name,
    };
    const { code, data } = await addSessionApi(chatData);
    if (data) {
@@ -771,6 +779,7 @@
  const startChat = async (valMsg) => {
    chatDis.value = true;
    loading.value = true;
    toStop = false;
    sessionDetailList.value.push({
      content: valMsg,
      role: 'user',
@@ -798,6 +807,11 @@
      .getReader();
    currIndex.value = 0;
    while (true) {
      if (toStop) {
        displayedText.value = '';
        setChatDataMeg(chatDataMeg);
        break;
      }
      const x = await reader?.read();
      if (x) {
        const { done, value } = x;
@@ -840,6 +854,7 @@
    loading.value = false;
    chatDis.value = false;
    isStopChat.value = true;
    toStop = true;
    console.log('stopChat');
    console.log(displayedText.value, 'displayedText');
    console.log(sessionDetailList.value, 'sessionDetailList');
@@ -890,6 +905,7 @@
      sessionDetailList.value = data.message;
      messagenList.value = data;
      agentTitle.value = data.name;
      from.name = data.name;
      refreshScroll(); //刷新滚动条位置
      isStopChat.value = false;
    }
@@ -903,6 +919,7 @@
  const querySessionDetail = async (session) => {
    sectionList.value = session;
    activeSessionId.value = session.id;
    from.name = session.name;
    const { code, data } = await getSessionDetailsApi(session.id);
    if (code === 200) {
      sessionDetailList.value = data.message;