From 2d708ae88849b6f4213ce0c168237844d3423699 Mon Sep 17 00:00:00 2001
From: liudong <liudong>
Date: 星期六, 24 八月 2024 14:44:44 +0800
Subject: [PATCH] agent名称修改
---
src/views/sessionManager/index.vue | 240 +++++++++++++++++++----------------------------------------
1 files changed, 78 insertions(+), 162 deletions(-)
diff --git a/src/views/sessionManager/index.vue b/src/views/sessionManager/index.vue
index ae0b24f..b8c8822 100644
--- a/src/views/sessionManager/index.vue
+++ b/src/views/sessionManager/index.vue
@@ -1,5 +1,5 @@
<template>
- <div class="container">
+ <div class="container" id="container">
<!-- <AddSession-->
<!-- :modalObj="modalObj"-->
<!-- @addSession="addSession"-->
@@ -58,9 +58,11 @@
style="
width: 80%;
overflow: auto;
- height: calc(100vh - 380px);
margin: 0px auto 20px;
"
+ :style="{
+ height:uploaditemList.length > 0 ? 'calc(100vh - 480px)' : 'calc(100vh - 380px)'
+ }"
>
<div
class="chat-item"
@@ -219,7 +221,7 @@
v-model="inputMsg"
@keydown.shift.enter="handleShiftEnter"
@keydown.enter="sendMessage"
- placeholder="杈撳叆鎮ㄦ兂浜嗚В鐨勫唴瀹癸紝Shift+Enter鎹㈣锛孍nter鍙戦��"
+ :placeholder="uploaditemList.length>0?'鏁寸悊杩欎簺鏂囦欢鐨勬牳蹇冨唴瀹�':'杈撳叆鎮ㄦ兂浜嗚В鐨勫唴瀹癸紝Shift+Enter鎹㈣锛孍nter鍙戦��'"
allow-clear
show-word-limit
:disabled="chatDis"
@@ -234,26 +236,7 @@
}"
/>
<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>
+ <updataFile ref="fileInput" :sessionId="activeSessionId" @selectFileCallback="selectFileCallback"></updataFile>
<a-button
:disabled="chatDis"
@click="sentClick"
@@ -264,62 +247,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-->
- <!-- ref="uploadRef"-->
- <!-- :file-list="uploadList"-->
- <!-- :limit="1"-->
- <!-- multiple-->
- <!-- :custom-request="customRequest"-->
- <!-- style="font-size: 24px;margin-bottom: 10px;position: relative;width: 200px">-->
- <!-- <template #upload-button>-->
- <!-- <icon-attachment style="color: #0960bd;position: absolute;top:-50px;left: 20px;z-index: 10000"/>-->
- <!-- </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>-->
- <div class="uploadFileList">
+ <div class="uploadFileList" v-if="uploaditemList.length > 0">
<div
class="files"
v-for="(item, index) in uploaditemList"
:key="index"
- style="position: relative; width: 200px; margin-top: 10px"
+ style="position: relative; width: 200px; margin-top: 10px;margin-right: 20px"
>
<a-comment
:author="item.name"
- :content="(item.size/1024).toFixed(2) + 'K'"
+ :content="item.size"
style="
background: var(--color-bg-2);
padding: 10px;
@@ -337,9 +275,10 @@
</template>
</a-spin>
<!-- <a-button type="text" :loading="onFileSelectedLoading" v-if="onFileSelectedLoading"></a-button>-->
- <a-avatar v-if="!onFileSelectedLoading">
- <icon-file style="color: #0960bd" />
- </a-avatar>
+<!-- <a-avatar v-if="!onFileSelectedLoading">-->
+<!-- <icon-file style="color: #0960bd" />-->
+<!-- </a-avatar>-->
+ <img :src="getIconByExtension(item.name)" alt="" />
</template>
</a-comment>
<icon-close-circle-fill
@@ -414,11 +353,6 @@
</div>
</template>
<script setup lang="ts">
- import {
- IconClose,
- IconSearch,
- IconTiktokColor,
- } from '@arco-design/web-vue/es/icon';
import { useAppStore, useUserStore } from '@/store';
import {
computed,
@@ -439,7 +373,7 @@
import agentSession from '@/views/sessionManager/components/agentSession.vue';
import historySession from '@/views/sessionManager/components/historySession.vue';
import smartAi from '@/views/sessionManager/components/smartAi.vue';
- import setName from '@/views/sessionManager/components/setName.vue';
+ import updataFile from '@/views/sessionManager/components/updataFile.vue';
import EventBus from '@/utils/EventBus';
import {
addSessionApi,
@@ -496,6 +430,7 @@
const fileInput = ref(null);
const chatDataMeg = reactive({});
const visible = ref(false);
+ let toStop = false;
const rules = {
name: [
@@ -522,13 +457,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 = [];
@@ -539,7 +471,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) => {
@@ -577,43 +537,16 @@
// formRef.value.resetFields();
};
- const selectFile = () => {
- fileInput.value.click();
+ const selectFileCallback = (data) => {
+ console.log(data, 'selectFileCallback');
+ uploaditemList.value = data;
};
let onFileSelectedLoading = ref(false);
- const onFileSelected = (event) => {
- const file = event.target.files[0];
- uploaditemList.value = [
- {
- name: file.name,
- size: file.size,
- },
- ];
- if (file) {
- onFileSelectedLoading.value = true;
- const formData = new FormData();
- formData.append('file', file);
- formData.append('conversation_id', activeSessionId.value);
- uploadWithoutKb(formData).then((res) => {
- // console.log(res);
- if (res.code == 200) {
- console.log(res);
- console.log(uploaditemList.value);
- onFileSelectedLoading.value = false;
- fileInput.value.value = '';
- uploaditemList.value = [];
- Message.success('涓婁紶鎴愬姛');
- } else {
- Message.error('涓婁紶澶辫触');
- }
- });
- }
- };
const deleteFile = (item) => {
console.log(uploaditemList.value);
- uploaditemList.value = [];
+ uploaditemList.value.splice(item.index,1);
};
const { toClipboard } = useClipboard();
@@ -621,31 +554,7 @@
await toClipboard(text); //鍙傛暟涓鸿澶嶅埗鐨勬枃鏈�
};
- const onChange = (fileList) => {
- // files.value = fileList;
- };
- // 涓婁紶鏂囦欢
- const customRequest = async (option) => {
- const { onProgress, onError, onSuccess, fileItem, name } = option;
- fileItem.status = 'ready';
- if (fileItem.file) {
- const formData = new FormData();
- formData.append('file', fileItem.file);
- formData.append('conversation_id', activeSessionId.value);
- uploadWithoutKb(formData).then((res) => {
- // console.log(res);
- if (res.code == 200) {
- console.log(res);
- console.log(uploadList.value);
- fileItem.status = 'done';
- // uploadList.value = [];
- } else {
- fileItem.status = 'error';
- }
- });
- }
- };
const DialogList = async () => {
const { code, data } = await getDialogListApi();
@@ -713,26 +622,6 @@
event.preventDefault();
inputMsg.value += '\n';
};
- const dialogChange = (val) => {
- // 鍒ゆ柇褰撳墠鏄櫤鑳戒綋鎴朼gent
- // console.log(val, 'val');
- dialogId.value = val;
- dialogs.value.forEach((item) => {
- if (item.id === val) {
- Object.assign(dialogObj, item);
- }
- });
- console.log(dialogObj.type, 'dialogObj');
- if (dialogObj.type == 1) {
- agentType.value = '1';
- querySessionList();
- } else {
- agentType.value = '2';
- queryAgentSessionList();
- }
-
- // querySessionList();
- };
// 鍙戦��
const sentClick = () => {
@@ -778,6 +667,7 @@
const startChat = async (valMsg) => {
chatDis.value = true;
loading.value = true;
+ toStop = false;
sessionDetailList.value.push({
content: valMsg,
role: 'user',
@@ -805,6 +695,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;
@@ -847,6 +742,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');
@@ -967,6 +863,11 @@
createSession('');
});
onMounted(() => {
+ let container = document.getElementById('container');
+ container.addEventListener('click', () => {
+ fileInput.value.cancel();
+
+ })
EventBus.on('newChat', () => {
agentType.value = '1';
createSession('');
@@ -1328,4 +1229,19 @@
:deep(.arco-upload-list-item-operation) {
//display: none;
}
+ .uploadFileList{
+ width: 100%;
+ max-height: 140px;
+ overflow-y: auto;
+ padding: 10px;
+ display: flex;
+ flex-wrap: wrap;
+ :deep(.arco-comment-author) {
+ width: 100px;
+ display: inline-block;
+ overflow: hidden; /* 闅愯棌瓒呭嚭鐨勫唴瀹� */
+ text-overflow: ellipsis; /* 浣跨敤鐪佺暐鍙锋潵浠f浛琚殣钘忕殑鏂囧瓧 */
+ white-space: nowrap; /* 涓嶆崲琛岋紝浣垮唴瀹瑰湪涓�琛屽唴鏄剧ず */
+ }
+ }
</style>
--
Gitblit v1.8.0