feat(@vben/web-antd): 优化会话记录获取和展示逻辑
- 使用用户信息替代固定用户 ID -调整聊天记录默认展示数量- 添加切换聊天记录功能 - 优化新建会话和删除记录后的处理流程 - 改进消息列表组件,支持动态选中第一个会话 - 更新工作区组件,支持发送消息后更新会话列表
This commit is contained in:
parent
931db0235f
commit
1a9351b176
@ -29,7 +29,6 @@ const defaultConversationsItems = computed(() => {
|
|||||||
});
|
});
|
||||||
const conversationsItems = ref(defaultConversationsItems);
|
const conversationsItems = ref(defaultConversationsItems);
|
||||||
const activeKey = ref(defaultConversationsItems.value[0]?.key);
|
const activeKey = ref(defaultConversationsItems.value[0]?.key);
|
||||||
|
|
||||||
// 将 props.items 映射为 key=id, label=name, title=name 的结构
|
// 将 props.items 映射为 key=id, label=name, title=name 的结构
|
||||||
const transformItems = computed(() => {
|
const transformItems = computed(() => {
|
||||||
return props.temp.map((item) => ({
|
return props.temp.map((item) => ({
|
||||||
@ -92,7 +91,7 @@ watch(
|
|||||||
() => itemsData.value,
|
() => itemsData.value,
|
||||||
(newVal) => {
|
(newVal) => {
|
||||||
if (newVal && newVal.length > 0) {
|
if (newVal && newVal.length > 0) {
|
||||||
selectedKeys.value = [newVal[0].key]; // 默认选中第一个菜单项
|
selectedKeys.value = [newVal[0].key];
|
||||||
handleMenuClick(newVal[0]);
|
handleMenuClick(newVal[0]);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -49,7 +49,7 @@ defineOptions({ name: 'WordWorkView' });
|
|||||||
|
|
||||||
const props = withDefaults(defineProps<Props>(), {
|
const props = withDefaults(defineProps<Props>(), {
|
||||||
item: () => null,
|
item: () => null,
|
||||||
itemMessage: () => null,
|
itemMessage: Array,
|
||||||
paramsData: () => null,
|
paramsData: () => null,
|
||||||
runChatflow: () => async () => ({
|
runChatflow: () => async () => ({
|
||||||
data: {
|
data: {
|
||||||
@ -66,6 +66,8 @@ const props = withDefaults(defineProps<Props>(), {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const emit = defineEmits(['history']);
|
||||||
|
|
||||||
// 初始化 markdown 解析器
|
// 初始化 markdown 解析器
|
||||||
const md = markdownit({ html: true, breaks: true });
|
const md = markdownit({ html: true, breaks: true });
|
||||||
|
|
||||||
@ -179,21 +181,6 @@ function openPreviewDrawer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ==================== Event ====================
|
// ==================== 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 () => {
|
const startFetching = async () => {
|
||||||
if (projectInfo.value.projectName === '') {
|
if (projectInfo.value.projectName === '') {
|
||||||
open.value = true;
|
open.value = true;
|
||||||
@ -231,12 +218,12 @@ const startFetching = async () => {
|
|||||||
content: content.value || '',
|
content: content.value || '',
|
||||||
});
|
});
|
||||||
content.value = '';
|
content.value = '';
|
||||||
// const { answer } = res;
|
if (conversationId.value === '') {
|
||||||
|
emit('history', props.item.id);
|
||||||
|
}
|
||||||
conversationId.value = res.conversationId;
|
conversationId.value = res.conversationId;
|
||||||
|
|
||||||
const docxInfo = extractDocxInfo(res.answer);
|
if (res.messageFiles) {
|
||||||
|
|
||||||
if (docxInfo) {
|
|
||||||
const { id, url } = res.messageFiles[0];
|
const { id, url } = res.messageFiles[0];
|
||||||
resultItems.value.push({
|
resultItems.value.push({
|
||||||
key: resultItems.value.length + 1,
|
key: resultItems.value.length + 1,
|
||||||
@ -298,6 +285,7 @@ watch(
|
|||||||
(newVal) => {
|
(newVal) => {
|
||||||
resultItems.value = [];
|
resultItems.value = [];
|
||||||
content.value = '';
|
content.value = '';
|
||||||
|
conversationId.value = newVal[1]?.content.conversationId || '';
|
||||||
if (newVal && newVal.length > 0) {
|
if (newVal && newVal.length > 0) {
|
||||||
newVal.forEach((msg) => {
|
newVal.forEach((msg) => {
|
||||||
if (msg.role === 'user') {
|
if (msg.role === 'user') {
|
||||||
|
@ -5,6 +5,8 @@ import type { PPTTempItem } from '#/views/ppt/typing';
|
|||||||
|
|
||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useUserStore } from '@vben/stores';
|
||||||
|
|
||||||
import { message, notification } from 'ant-design-vue';
|
import { message, notification } from 'ant-design-vue';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@ -24,6 +26,7 @@ const hitsory = ref([]);
|
|||||||
const loading = ref(true);
|
const loading = ref(true);
|
||||||
const params = ref({});
|
const params = ref({});
|
||||||
const projectInfo = ref({});
|
const projectInfo = ref({});
|
||||||
|
const userStore = useUserStore();
|
||||||
|
|
||||||
const getLogs = async (appid: string) => {
|
const getLogs = async (appid: string) => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
@ -32,17 +35,12 @@ const getLogs = async (appid: string) => {
|
|||||||
appid,
|
appid,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
userId: '1562',
|
userId: userStore.userInfo?.userId || '',
|
||||||
lastId: '',
|
lastId: '',
|
||||||
sortBy: '',
|
sortBy: '',
|
||||||
limit: '5',
|
limit: '9',
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
// const res = await getChatList({
|
|
||||||
// appid,
|
|
||||||
// limit: 5,
|
|
||||||
// page: 1,
|
|
||||||
// });
|
|
||||||
hitsory.value = res.data;
|
hitsory.value = res.data;
|
||||||
|
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
@ -57,6 +55,7 @@ const getTemp = async () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const currentTemp = ref<null | PPTTempItem>(null);
|
const currentTemp = ref<null | PPTTempItem>(null);
|
||||||
|
const activeKey = ref('');
|
||||||
|
|
||||||
function handleClickMode(item: WordTempItem) {
|
function handleClickMode(item: WordTempItem) {
|
||||||
notification.success({
|
notification.success({
|
||||||
@ -69,6 +68,22 @@ function handleClickMode(item: WordTempItem) {
|
|||||||
getParameters(item.id);
|
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() {
|
function handleNewConversation() {
|
||||||
// 清空项目信息
|
// 清空项目信息
|
||||||
projectInfo.value = {
|
projectInfo.value = {
|
||||||
@ -92,7 +107,8 @@ async function deleteLog(item: any) {
|
|||||||
});
|
});
|
||||||
if (res.message === '删除成功') {
|
if (res.message === '删除成功') {
|
||||||
message.success('删除成功');
|
message.success('删除成功');
|
||||||
getLogs(currentTemp.value.id);
|
await getLogs(currentTemp.value.id);
|
||||||
|
handleNewConversation();
|
||||||
} else {
|
} else {
|
||||||
message.error('删除失败');
|
message.error('删除失败');
|
||||||
}
|
}
|
||||||
@ -147,6 +163,7 @@ onMounted(() => {
|
|||||||
:temp="temp"
|
:temp="temp"
|
||||||
:items="hitsory"
|
:items="hitsory"
|
||||||
:loading="loading"
|
:loading="loading"
|
||||||
|
:key="activeKey"
|
||||||
@click-mode="handleClickMode"
|
@click-mode="handleClickMode"
|
||||||
@click="handleClick"
|
@click="handleClick"
|
||||||
@delete="deleteLog"
|
@delete="deleteLog"
|
||||||
@ -159,6 +176,7 @@ onMounted(() => {
|
|||||||
:run-chatflow="sendWord"
|
:run-chatflow="sendWord"
|
||||||
:item-message="itemMessage"
|
:item-message="itemMessage"
|
||||||
:project-info="projectInfo"
|
:project-info="projectInfo"
|
||||||
|
@history="changeLogs"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
@ -34,6 +34,12 @@ interface WorkflowContext {
|
|||||||
interface WorkflowResult {
|
interface WorkflowResult {
|
||||||
conversationId: string;
|
conversationId: string;
|
||||||
answer: object;
|
answer: object;
|
||||||
|
messageFiles?: [
|
||||||
|
{
|
||||||
|
id: string;
|
||||||
|
url: string;
|
||||||
|
},
|
||||||
|
];
|
||||||
data: {
|
data: {
|
||||||
outputs: {
|
outputs: {
|
||||||
result: string;
|
result: string;
|
||||||
@ -41,7 +47,7 @@ interface WorkflowResult {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
interface Props {
|
interface Props {
|
||||||
itemMessage?: ResultItem;
|
itemMessage?: ResultItem[];
|
||||||
item?: WordTempItem;
|
item?: WordTempItem;
|
||||||
paramsData?: object;
|
paramsData?: object;
|
||||||
runChatflow?: (
|
runChatflow?: (
|
||||||
@ -54,6 +60,7 @@ interface Props {
|
|||||||
interface PropsHistory {
|
interface PropsHistory {
|
||||||
temp: any;
|
temp: any;
|
||||||
items?: WordHistoryItem[];
|
items?: WordHistoryItem[];
|
||||||
|
key?: string;
|
||||||
title: string;
|
title: string;
|
||||||
loading: boolean;
|
loading: boolean;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user