zhangxiao
2024-08-23 b3b34fa409762b44e6fd3c89e651f8c465556a48
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>
@@ -227,8 +233,27 @@
                  maxRows: 5,
                }"
              />
              <div class="btn-send">
              <div style="width: 100%;display: flex;justify-content: space-between">
                <a-button
                  :disabled="onFileSelectedLoading"
                  @click="selectFile"
                  type="text"
                  style="border-radius: 24px"
                >
                  <icon-attachment
                    size="28"
                    style="color: #0960bd"
                  />
                  <input
                    ref="fileInput"
                    type="file"
                    style="display: none"
                    @change="onFileSelected"
                  />
                </a-button>
                  <span
                    style="cursor: pointer;margin-left: 20px;">
                </span>
                <a-button
                  :disabled="chatDis"
                  @click="sentClick"
@@ -239,6 +264,17 @@
                  <icon-send size="32" style="color: #0960bd" />
                </a-button>
              </div>
<!--              <div class="btn-send">-->
<!--                <a-button-->
<!--                  :disabled="chatDis"-->
<!--                  @click="sentClick"-->
<!--                  type="text"-->
<!--                  style="border-radius: 24px"-->
<!--                  :loading="loading"-->
<!--                >-->
<!--                  <icon-send size="32" style="color: #0960bd" />-->
<!--                </a-button>-->
<!--              </div>-->
            </div>
            <!--            <div style="margin-top: 0px">-->
            <!--              <a-upload-->
@@ -253,27 +289,27 @@
            <!--                </template>-->
            <!--              </a-upload>-->
            <!--            </div>-->
            <span
              style="
                position: absolute;
                top: 94px;
                left: 20px;
                z-index: 999;
                cursor: pointer;
              "
            >
              <icon-attachment
                size="28"
                @click="selectFile"
                style="color: #0960bd"
              />
              <input
                ref="fileInput"
                type="file"
                style="display: none"
                @change="onFileSelected"
              />
            </span>
<!--            <span-->
<!--              style="-->
<!--                position: absolute;-->
<!--                top: 94px;-->
<!--                left: 20px;-->
<!--                z-index: 999;-->
<!--                cursor: pointer;-->
<!--              "-->
<!--            >-->
<!--              <icon-attachment-->
<!--                size="28"-->
<!--                @click="selectFile"-->
<!--                style="color: #0960bd"-->
<!--              />-->
<!--              <input-->
<!--                ref="fileInput"-->
<!--                type="file"-->
<!--                style="display: none"-->
<!--                @change="onFileSelected"-->
<!--              />-->
<!--            </span>-->
            <div class="uploadFileList">
              <div
                class="files"
@@ -283,11 +319,12 @@
              >
                <a-comment
                  :author="item.name"
                  :content="item.size + ''"
                  :content="(item.size/1024).toFixed(2) + 'K'"
                  style="
                    background: var(--color-bg-2);
                    padding: 10px;
                    border-radius: 10px;
                    font-size: 12px;
                  "
                >
                  <template #avatar>
@@ -355,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">
@@ -434,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(''); // 正在显示的文字
@@ -456,6 +496,7 @@
  const fileInput = ref(null);
  const chatDataMeg = reactive({});
  const visible = ref(false);
  let toStop = false;
  const rules = {
    name: [
@@ -468,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) {
@@ -484,13 +523,10 @@
  };
  let dataItem = [];
  const getTxt = (data, role, message, index) => {
    if (/##0\$\$/.test(message)) {
    if (/##[0-9]\$\$/.test(message)) {
      if (role == 'assistant' && index) {
        data.forEach((item) => {
          if (Object.keys(item).length !== 0 && item?.doc_aggs.length > 0) {
            dataItem = item.doc_aggs;
          }
        });
        let i = index / 2 - 1 > 0 ? index / 2 - 1 : 0;
        dataItem = data[i].doc_aggs;
      }
    } else {
      dataItem = [];
@@ -501,7 +537,35 @@
  const clickHref = (item) => {
    // return Message.warning('暂无法查看');
    window.open(`/api/v1/document/show/${item.doc_id}`, '_blank');
    // window.open(`/api/v1/document/get/${item.doc_id}`, '_blank');
    downloadFile({
      url: `/api/v1/document/get/${item.doc_id}`,
      filename: item.doc_name,
    });
  };
   const downloadFile = ({
                                 url,
                                 filename,
                                 target,
                               }: {
    url: string;
    filename?: string;
    target?: string;
  }) => {
    const downloadElement = document.createElement('a');
    downloadElement.style.display = 'none';
    downloadElement.href = url;
    if (target) {
      downloadElement.target = '_blank';
    }
    downloadElement.rel = 'noopener noreferrer';
    if (filename) {
      downloadElement.download = filename;
    }
    document.body.appendChild(downloadElement);
    downloadElement.click();
    document.body.removeChild(downloadElement);
  };
  const getIconByExtension = computed(() => (extension) => {
@@ -740,6 +804,7 @@
  const startChat = async (valMsg) => {
    chatDis.value = true;
    loading.value = true;
    toStop = false;
    sessionDetailList.value.push({
      content: valMsg,
      role: 'user',
@@ -767,6 +832,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;
@@ -809,6 +879,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');
@@ -859,6 +930,7 @@
      sessionDetailList.value = data.message;
      messagenList.value = data;
      agentTitle.value = data.name;
      from.name = data.name;
      refreshScroll(); //刷新滚动条位置
      isStopChat.value = false;
    }
@@ -872,6 +944,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;