diff --git a/apps/web-antd/src/views/word/components/word-list-view.vue b/apps/web-antd/src/views/word/components/word-list-view.vue index 82e632d..8441d78 100644 --- a/apps/web-antd/src/views/word/components/word-list-view.vue +++ b/apps/web-antd/src/views/word/components/word-list-view.vue @@ -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]); } }, diff --git a/apps/web-antd/src/views/word/components/word-work-view.vue b/apps/web-antd/src/views/word/components/word-work-view.vue index 22cb10e..f75ab5e 100644 --- a/apps/web-antd/src/views/word/components/word-work-view.vue +++ b/apps/web-antd/src/views/word/components/word-work-view.vue @@ -49,7 +49,7 @@ defineOptions({ name: 'WordWorkView' }); const props = withDefaults(defineProps(), { item: () => null, - itemMessage: () => null, + itemMessage: Array, paramsData: () => null, runChatflow: () => async () => ({ data: { @@ -66,6 +66,8 @@ const props = withDefaults(defineProps(), { }), }); +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') { diff --git a/apps/web-antd/src/views/word/index.vue b/apps/web-antd/src/views/word/index.vue index d84db2c..0c47414 100644 --- a/apps/web-antd/src/views/word/index.vue +++ b/apps/web-antd/src/views/word/index.vue @@ -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); +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" /> diff --git a/apps/web-antd/src/views/word/typing.ts b/apps/web-antd/src/views/word/typing.ts index d5ead12..c7d39d9 100644 --- a/apps/web-antd/src/views/word/typing.ts +++ b/apps/web-antd/src/views/word/typing.ts @@ -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; }