zhangxiao
2024-08-30 5e6e726564e5cf1520f95b7f4f13707a39da4bad
src/views/sessionManager/components/seniorAgentSession.vue
@@ -3,7 +3,6 @@
  <div class="header___section">
    <div class="chatHeader">
      <div class="chatHeaderBox">
        <!--        <span class="title">{{agentTitle}}</span>-->
        <a-popover position="bottom" trigger="click">
          <a-button border>
            <span
@@ -37,7 +36,7 @@
  </div>
  <a-scrollbar
    ref="scrollbar"
    id="agentHome"
    id="chatAgentHome"
    class="chat-list"
    style="
      width: 80%;
@@ -125,8 +124,17 @@
            <div class="codeStle">
              <div class="language">python</div>
              <pre
                style="
                  background: #2c2c36;
                  padding: 10px;
                  margin-top: 0;
                  margin-bottom: 0;
                "
              ><code class="language-js line-numbers">{{ sessionDetail.code}}</code></pre>
              <div class="language">SQL</div>
              <pre
                style="background: #2c2c36; padding: 10px; margin-top: 0"
              ><code class="language-js line-numbers">{{ sessionDetail.code+ sessionDetail.sql}}</code></pre>
              ><code class="language-js line-numbers">{{sessionDetail.sql}}</code></pre>
            </div>
            <a-image
@@ -134,7 +142,10 @@
              :src="getImg(sessionDetail)"
              alt=""
            />
            <div class="uploadFileList fileList" v-if="sessionDetail?.excel_name">
            <div
              class="uploadFileList fileList"
              v-if="sessionDetail?.excel_name"
            >
              <a-comment
                :content="sessionDetail.excel_name"
                style="
@@ -286,6 +297,8 @@
          v-if="!getAent"
          ref="fileInput"
          :sessionId="activeSessionId"
          :handleRemove="handleRemove"
          :typeXLse="false"
          @selectFileCallback="selectFileCallback"
        ></uploadFile>
        <a-button
@@ -337,14 +350,14 @@
        >
          <template #avatar>
            <a-spin
              :loading="onFileSelectedLoading"
              v-if="onFileSelectedLoading"
              :loading="item.onFileSelectedLoading"
              v-if="item.onFileSelectedLoading"
            >
              <template #icon>
                <icon-sync />
              </template>
              <template #tip>
                <div style="font-size: 12px">{{ textName }}</div>
                <div style="font-size: 12px">{{ item.textName }}</div>
              </template>
            </a-spin>
            <!--                    <a-button type="text" :loading="onFileSelectedLoading" v-if="onFileSelectedLoading"></a-button>-->
@@ -352,6 +365,9 @@
            <!--                      <icon-file style="color: #0960bd" />-->
            <!--                    </a-avatar>-->
            <img :src="getIconByExtension(item.name)" alt="" />
            <div v-show="!item.onFileSelectedLoading" style="font-size: 12px">{{
              item.textName
            }}</div>
          </template>
        </a-comment>
        <icon-close-circle-fill
@@ -547,6 +563,7 @@
    prompts.value = session.prompts;
    activeSessionId.value = '';
    EventBus.emit('queryAgent', uploaditemList.value);
    uploaditemList.value = [];
    console.log(12123);
    getAentId(session.id);
@@ -694,8 +711,9 @@
    conversation_id.value = session.id;
    activeSessionId.value = session.id;
    dialog_id.value = session.dialog_id;
    EventBus.emit('queryAgent', uploaditemList.value);
    uploaditemList.value = [];
    getAentId(session.dialog_id);
    from.name = session.name;
    const { code, data } = await getSessionDetailsApi(session.id);
@@ -739,43 +757,7 @@
          event.preventDefault(); // 阻止默认行为,即不换行
        }
        // chatDis.value = true;
        // loading.value = true;
        // if (!agentObj.id) {
        //   Message.warning('请选择会话');
        //   chatDis.value = false;
        //   loading.value = false;
        //   return;
        // }
        // if (displayedText.value) {
        //   querySessionList();
        // }
        if (inputMsg.value) {
          //   const res = await addSessionApi({
          //     dialog_id: '',
          //     conversation_desc: inputMsg.value,
          //   });
          //   // console.log(res, "res");
          //   if (res.code == 200) {
          //     // console.log(res.data.conversation_id);
          //     activeSessionId.value = res.data?.conversation_id;
          //     const { code, data } = await getSessionDetailsApi(
          //       res.data?.conversation_id
          //     );
          //     if (code === 200) {
          //       console.log(data, '新建会话详情');
          //       Object.assign(chatObj, data);
          //       startChat(inputMsg.value);
          //       inputMsg.value = '';
          //     }
          //   } else {
          //     Message.error('创建会话失败,请重试');
          //   }
          //   startChat(inputMsg.value);
          //   inputMsg.value = '';
          createSession('');
          uploaditemList.value = [];
        } else {
@@ -859,29 +841,42 @@
    try {
      const formData = new FormData();
      uploaditemList.value = resData;
      uploaditemList.value.map((item) => {
        if (item.name == file[0].file.name) {
          item.onFileSelectedLoading = true;
          item.textName = '上传中';
        }
        return item;
      });
      if (!activeSessionId.value) {
        await createSession(resData);
      }
      onFileSelectedLoading.value = true;
      textName.value = '上传中';
      //   for (let i = 0; i < file.length; i++) {
      //     formData.append('files', file[i].file);
      //     formData.append('conversation_id', activeSessionId.value);
      //     formData.append('app_id', agentObj.id);
      //   }
      // onFileSelectedLoading.value = true;
      // textName.value = '上传中';
      formData.append('files', file[0].file);
      formData.append('conversation_id', activeSessionId.value);
      formData.append('app_id', agentObj.id);
      console.log(formData, 'formData');
      const { data, code } = await agentUploadApi(formData);
      if (code === 200) {
        onFileSelectedLoading.value = false;
        textName.value = '上传成功';
        uploaditemList.value.map((item) => {
          item.onFileSelectedLoading = false;
          item.textName = '上传成功';
          return item;
        });
        // onFileSelectedLoading.value = false;
        // textName.value = '上传成功';
      }
    } catch (err) {
      onFileSelectedLoading.value = false;
      textName.value = '上传失败';
      uploaditemList.value.map((item) => {
        item.onFileSelectedLoading = false;
        item.textName = '上传失败';
        return item;
      });
      // onFileSelectedLoading.value = false;
      // textName.value = '上传失败';
      Message.error('上传失败');
    }
  };
@@ -899,13 +894,15 @@
    return type;
  };
  let onFileSelectedLoading = ref(true);
  const textName = ref('上传成功');
  // let onFileSelectedLoading = ref(true);
  // const textName = ref('上传成功');
  const deleteFile = (item) => {
    console.log(uploaditemList.value);
    uploaditemList.value.splice(item.index, 1);
    EventBus.emit('queryAgent', item);
  };
  const getIconByExtension = computed(() => (extension) => {
    const fileExtension = ref('');
    fileExtension.value = extension.split('.').pop();
@@ -962,7 +959,7 @@
      const x = await reader?.read();
      if (x) {
        const { done, value } = x;
        // console.log(x, 999);
        console.log(x, 999);
        if (value && value?.event == 'message') {
          try {
@@ -975,9 +972,9 @@
              if (d?.content) {
                streamStr.value = d.content;
              } else {
                streamStr.value = d.code;
                streamStr.value = d.code + d.sql;
              }
              EventBus.emit('queryAgent', uploaditemList.value);
              startDisplayStr();
            }
          } catch (e) {
@@ -1079,7 +1076,7 @@
  const scrollbar = ref(null);
  const refreshScroll = () => {
    nextTick(() => {
      const container = document.getElementById('agentHome');
      const container = document.getElementById('chatAgentHome');
      scrollbar.value.scrollTop(container.scrollHeight);
    });
  };
@@ -1288,6 +1285,9 @@
          }
        }
      }
      :deep(.arco-spin-loading .arco-spin-mask-icon) {
        left: 10%;
      }
    }
  }
  .header___section {