feat(@vben/web-antd): 优化会话记录获取和展示逻辑

- 使用用户信息替代固定用户 ID
-调整聊天记录默认展示数量- 添加切换聊天记录功能
- 优化新建会话和删除记录后的处理流程
- 改进消息列表组件,支持动态选中第一个会话
- 更新工作区组件,支持发送消息后更新会话列表
This commit is contained in:
Kven 2025-06-16 19:38:46 +08:00
parent 931db0235f
commit 1a9351b176
4 changed files with 43 additions and 31 deletions

View File

@ -29,7 +29,6 @@ const defaultConversationsItems = computed(() => {
});
const conversationsItems = ref(defaultConversationsItems);
const activeKey = ref(defaultConversationsItems.value[0]?.key);
// props.items key=id, label=name, title=name
const transformItems = computed(() => {
return props.temp.map((item) => ({
@ -92,7 +91,7 @@ watch(
() => itemsData.value,
(newVal) => {
if (newVal && newVal.length > 0) {
selectedKeys.value = [newVal[0].key]; //
selectedKeys.value = [newVal[0].key];
handleMenuClick(newVal[0]);
}
},

View File

@ -49,7 +49,7 @@ defineOptions({ name: 'WordWorkView' });
const props = withDefaults(defineProps<Props>(), {
item: () => null,
itemMessage: () => null,
itemMessage: Array,
paramsData: () => null,
runChatflow: () => async () => ({
data: {
@ -66,6 +66,8 @@ const props = withDefaults(defineProps<Props>(), {
}),
});
const emit = defineEmits(['history']);
// markdown
const md = markdownit({ html: true, breaks: true });
@ -179,21 +181,6 @@ function openPreviewDrawer(
}
// ==================== Event ====================
function extractDocxInfo(
markdownLink: string,
): null | { filename: string; url: string } {
const fileRegex = /\[(.*?)\]/;
const urlRegex = /\((.*?)\)/;
const fileMatch = markdownLink.match(fileRegex);
const urlMatch = markdownLink.match(urlRegex);
if (fileMatch && urlMatch) {
const filename = fileMatch[1]; // [filename]
const url = urlMatch[1] || ''; // (url)
return { filename, url };
}
return null;
}
const startFetching = async () => {
if (projectInfo.value.projectName === '') {
open.value = true;
@ -231,12 +218,12 @@ const startFetching = async () => {
content: content.value || '',
});
content.value = '';
// const { answer } = res;
if (conversationId.value === '') {
emit('history', props.item.id);
}
conversationId.value = res.conversationId;
const docxInfo = extractDocxInfo(res.answer);
if (docxInfo) {
if (res.messageFiles) {
const { id, url } = res.messageFiles[0];
resultItems.value.push({
key: resultItems.value.length + 1,
@ -298,6 +285,7 @@ watch(
(newVal) => {
resultItems.value = [];
content.value = '';
conversationId.value = newVal[1]?.content.conversationId || '';
if (newVal && newVal.length > 0) {
newVal.forEach((msg) => {
if (msg.role === 'user') {

View File

@ -5,6 +5,8 @@ import type { PPTTempItem } from '#/views/ppt/typing';
import { onMounted, ref } from 'vue';
import { useUserStore } from '@vben/stores';
import { message, notification } from 'ant-design-vue';
import {
@ -24,6 +26,7 @@ const hitsory = ref([]);
const loading = ref(true);
const params = ref({});
const projectInfo = ref({});
const userStore = useUserStore();
const getLogs = async (appid: string) => {
loading.value = true;
@ -32,17 +35,12 @@ const getLogs = async (appid: string) => {
appid,
},
{
userId: '1562',
userId: userStore.userInfo?.userId || '',
lastId: '',
sortBy: '',
limit: '5',
limit: '9',
},
);
// const res = await getChatList({
// appid,
// limit: 5,
// page: 1,
// });
hitsory.value = res.data;
loading.value = false;
@ -57,6 +55,7 @@ const getTemp = async () => {
};
const currentTemp = ref<null | PPTTempItem>(null);
const activeKey = ref('');
function handleClickMode(item: WordTempItem) {
notification.success({
@ -69,6 +68,22 @@ function handleClickMode(item: WordTempItem) {
getParameters(item.id);
}
async function changeLogs(id: string) {
const res = await getChatList(
{
appid: id,
},
{
userId: '1562',
lastId: '',
sortBy: '',
limit: '9',
},
);
hitsory.value = res.data;
activeKey.value = res.data[0].id;
}
function handleNewConversation() {
//
projectInfo.value = {
@ -92,7 +107,8 @@ async function deleteLog(item: any) {
});
if (res.message === '删除成功') {
message.success('删除成功');
getLogs(currentTemp.value.id);
await getLogs(currentTemp.value.id);
handleNewConversation();
} else {
message.error('删除失败');
}
@ -147,6 +163,7 @@ onMounted(() => {
:temp="temp"
:items="hitsory"
:loading="loading"
:key="activeKey"
@click-mode="handleClickMode"
@click="handleClick"
@delete="deleteLog"
@ -159,6 +176,7 @@ onMounted(() => {
:run-chatflow="sendWord"
:item-message="itemMessage"
:project-info="projectInfo"
@history="changeLogs"
/>
</div>
</template>

View File

@ -34,6 +34,12 @@ interface WorkflowContext {
interface WorkflowResult {
conversationId: string;
answer: object;
messageFiles?: [
{
id: string;
url: string;
},
];
data: {
outputs: {
result: string;
@ -41,7 +47,7 @@ interface WorkflowResult {
};
}
interface Props {
itemMessage?: ResultItem;
itemMessage?: ResultItem[];
item?: WordTempItem;
paramsData?: object;
runChatflow?: (
@ -54,6 +60,7 @@ interface Props {
interface PropsHistory {
temp: any;
items?: WordHistoryItem[];
key?: string;
title: string;
loading: boolean;
}