feat: 对话逻辑调整、历史对话接口联调
This commit is contained in:
@ -4,11 +4,13 @@ import { BubbleList } from '@/components/xt-chat/xt-bubble';
|
||||
import SenderInput from '../sender-input/index.vue';
|
||||
import { Typography } from 'ant-design-vue';
|
||||
import RightView from './rightView.vue';
|
||||
import type { Ref } from 'vue';
|
||||
|
||||
import { useRoute } from 'vue-router';
|
||||
import markdownit from 'markdown-it';
|
||||
import { useClipboard } from '@vueuse/core';
|
||||
import { genRandomId } from '@/utils/tools';
|
||||
import { useChatStore } from '@/stores/modules/chat';
|
||||
import type { BubbleListProps } from '@/components/xt-chat/xt-bubble/types';
|
||||
|
||||
const QUESTION_ROLE = 'question';
|
||||
@ -16,6 +18,8 @@ const ANSWER_ROLE = 'text';
|
||||
|
||||
export default {
|
||||
setup(props, { emit, expose }) {
|
||||
const chatStore = useChatStore();
|
||||
|
||||
const route = useRoute();
|
||||
const { copy } = useClipboard();
|
||||
|
||||
@ -187,6 +191,20 @@ export default {
|
||||
},
|
||||
};
|
||||
|
||||
const initSse = () => {
|
||||
console.log('initSse', { agentInfo: chatStore.agentInfo, searchValue: chatStore.searchValue });
|
||||
};
|
||||
const closeSse = () => {
|
||||
console.log('closeSse');
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
initSse();
|
||||
});
|
||||
onUnmounted(() => {
|
||||
closeSse();
|
||||
});
|
||||
|
||||
return () => (
|
||||
<div class="conversation-detail-wrap w-full h-full flex">
|
||||
<section class="flex-1 flex flex-col pt-20px justify-center relative px-16px">
|
||||
@ -203,7 +221,7 @@ export default {
|
||||
v-model={searchValue.value}
|
||||
onSubmit={handleSubmit}
|
||||
onCancel={handleCancel}
|
||||
data-ne='123'
|
||||
data-ne="123"
|
||||
/>
|
||||
<p class="cts !color-#939499 text-12px !lh-20px my-4px">内容由AI生成,仅供参考</p>
|
||||
</div>
|
||||
|
||||
@ -3,25 +3,21 @@ import { message } from 'ant-design-vue';
|
||||
import ExpandableTags from '@/components/expandable-tags/index.vue';
|
||||
import SenderInput from '../sender-input/index.vue';
|
||||
|
||||
import { useSharedDataStore } from '@/stores/modules/share-data';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { handleUserHome } from '@/utils/user';
|
||||
import { useChatStore } from '@/stores/modules/chat';
|
||||
|
||||
export default {
|
||||
setup(props, { emit, expose }) {
|
||||
const router = useRouter();
|
||||
const senderRef = ref(null);
|
||||
const searchValue = ref('');
|
||||
const sharedDataStore = useSharedDataStore();
|
||||
const chatStore = useChatStore();
|
||||
|
||||
const handleSubmit = () => {
|
||||
handleSearch();
|
||||
};
|
||||
|
||||
const handleSearch = () => {
|
||||
console.log('searchValue.value', searchValue.value);
|
||||
// const conversationId = searchValue.value;
|
||||
// handleUserHome({conversationId})
|
||||
const handleSearch = async () => {
|
||||
chatStore.setSearchValue(searchValue.value);
|
||||
chatStore.onCreateSession();
|
||||
};
|
||||
|
||||
const tagList = [
|
||||
@ -48,13 +44,7 @@ export default {
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
const params = sharedDataStore.routeParams;
|
||||
if (params) {
|
||||
searchValue.value = params.keyWord;
|
||||
sharedDataStore.clearRouteParams();
|
||||
|
||||
handleSearch();
|
||||
}
|
||||
chatStore.clearSearchValue();
|
||||
});
|
||||
|
||||
return () => (
|
||||
|
||||
@ -15,7 +15,7 @@
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { deleteTask, deleteBatchTasks } from '@/api/all/common';
|
||||
import { deleteHistoryItem } from '@/api/all/chat';
|
||||
import icon1 from '@/assets/img/media-account/icon-warn-1.png';
|
||||
|
||||
const emits = defineEmits(['update', 'close', 'batchUpdate']);
|
||||
@ -32,6 +32,7 @@ function onClose() {
|
||||
}
|
||||
|
||||
const open = (record) => {
|
||||
console.log({record})
|
||||
const { id = null } = record;
|
||||
chatId.value = id;
|
||||
|
||||
@ -39,7 +40,7 @@ const open = (record) => {
|
||||
};
|
||||
|
||||
async function onDelete() {
|
||||
const { code } = await deleteTask(chatId.value);
|
||||
const { code } = await deleteHistoryItem(chatId.value);
|
||||
if (code === 200) {
|
||||
AMessage.success('删除成功');
|
||||
emits('delete', chatId.value);
|
||||
|
||||
@ -1,41 +1,64 @@
|
||||
<script lang="jsx">
|
||||
import { Drawer } from 'ant-design-vue';
|
||||
import { Drawer, message } from 'ant-design-vue';
|
||||
import TextoverTips from '@/components/text-over-tips';
|
||||
import Conversations from '@/components/xt-chat/xt-conversations';
|
||||
import SvgIcon from '@/components/svg-icon';
|
||||
import { Button, Flex, Input } from 'ant-design-vue';
|
||||
import DeleteChatModal from './delete-chat-modal.vue';
|
||||
import NoData from '@/components/no-data/index.vue';
|
||||
|
||||
import { handleUserHome } from '@/utils/user';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { getAgentHistory, postUpdateSessionTitle, postUpdateSessionSort } from '@/api/all/chat';
|
||||
import { useChatStore } from '@/stores/modules/chat';
|
||||
|
||||
export default {
|
||||
setup(props, { emit, expose }) {
|
||||
const router = useRouter();
|
||||
const chatStore = useChatStore();
|
||||
|
||||
const open = ref(false);
|
||||
const dataSource = ref([]);
|
||||
const activeKey = ref('');
|
||||
const deleteChatModalRef = ref(null);
|
||||
|
||||
const showDrawer = () => {
|
||||
const showDrawer = (id) => {
|
||||
getData();
|
||||
open.value = true;
|
||||
};
|
||||
const getData = () => {
|
||||
dataSource.value = Array.from({ length: 4 }).map((conversation, index) => ({
|
||||
id: `${index + 1}`,
|
||||
key: `item${index + 1}`,
|
||||
label: `Conversation Item ${index + 1}Conversation Item 1`,
|
||||
}));
|
||||
const getData = async () => {
|
||||
const { code, data } = await getAgentHistory(chatStore.agentInfo.agent_id);
|
||||
if (code === 200) {
|
||||
dataSource.value = data.map((item) => ({
|
||||
...item,
|
||||
key: item.id,
|
||||
label: item.title,
|
||||
}));
|
||||
}
|
||||
};
|
||||
const onPin = async (item) => {
|
||||
const { id, sort } = item;
|
||||
// sort大于0就是已置顶
|
||||
const is_top = sort > 0 ? 0 : 1;
|
||||
const { code } = await postUpdateSessionSort({
|
||||
id,
|
||||
is_top,
|
||||
agent_id: chatStore.agentInfo.agent_id,
|
||||
});
|
||||
if (code === 200) {
|
||||
message.success(is_top === 0 ? '取消置顶成功' : '置顶成功');
|
||||
getData();
|
||||
}
|
||||
};
|
||||
const onClose = () => {
|
||||
activeKey.value = '';
|
||||
dataSource.value = [];
|
||||
open.value = false;
|
||||
};
|
||||
const handleMenuClick = (menuInfo) => {
|
||||
const { item, key } = menuInfo;
|
||||
switch (key) {
|
||||
const handleMenuClick = async ({ menuInfo, item }) => {
|
||||
switch (menuInfo.key) {
|
||||
case 'pin':
|
||||
console.log('置顶');
|
||||
onPin(item);
|
||||
break;
|
||||
case 'rename':
|
||||
item.editing = true;
|
||||
@ -45,8 +68,15 @@ export default {
|
||||
break;
|
||||
}
|
||||
};
|
||||
const handleRename = (item) => {
|
||||
console.log('handleRename', item);
|
||||
const handleRename = async (item) => {
|
||||
const { id, label } = item;
|
||||
const { code } = await postUpdateSessionTitle({
|
||||
id,
|
||||
title: label,
|
||||
});
|
||||
if (code === 200) {
|
||||
message.success('重命名成功');
|
||||
}
|
||||
};
|
||||
const handleActiveChange = (item) => {
|
||||
const { id } = item;
|
||||
@ -60,18 +90,23 @@ export default {
|
||||
return () => (
|
||||
<Drawer width={240} rootClassName="ct-history-conversation-drawer" v-model:open={open.value} onClose={onClose}>
|
||||
<header class="header h-40px px-12px flex justify-between items-center">
|
||||
<span class="s1">历史对话</span>
|
||||
<span class="text-16px font-400 color-#211F24 font-family-medium">历史对话</span>
|
||||
<icon-close size={16} class="color-#211F24 cursor-pointer" onClick={onClose} />
|
||||
</header>
|
||||
<section class="flex-1 overflow-y-auto content p-12px">
|
||||
<Conversations
|
||||
v-model={activeKey.value}
|
||||
dataSource={dataSource.value}
|
||||
onMenuClick={handleMenuClick}
|
||||
onRename={handleRename}
|
||||
onActiveChange={handleActiveChange}
|
||||
/>
|
||||
</section>
|
||||
{dataSource.value.length === 0 ? (
|
||||
<NoData text="暂无历史对话" />
|
||||
) : (
|
||||
<section class="flex-1 overflow-y-auto content p-12px">
|
||||
<Conversations
|
||||
v-model={activeKey.value}
|
||||
dataSource={dataSource.value}
|
||||
onMenuClick={handleMenuClick}
|
||||
onRename={handleRename}
|
||||
onActiveChange={handleActiveChange}
|
||||
/>
|
||||
</section>
|
||||
)}
|
||||
|
||||
<DeleteChatModal ref={deleteChatModalRef} />
|
||||
</Drawer>
|
||||
);
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 1px;
|
||||
margin: 0 16px;
|
||||
background: #f2f3f5;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
<script lang="tsx">
|
||||
import { useRoute } from 'vue-router';
|
||||
import { ref, computed } from 'vue';
|
||||
import { getAgentInfo } from '@/api/all/chat';
|
||||
import { useChatStore } from '@/stores/modules/chat';
|
||||
|
||||
import HistoryConversationDrawer from './components/history-conversation-drawer/index.vue';
|
||||
import ConversationDetail from './components/conversation-detail/index.vue';
|
||||
@ -9,13 +11,24 @@ import ConversationCreate from './components/created/index.vue';
|
||||
export default {
|
||||
setup(props, { emit, expose }) {
|
||||
const route = useRoute();
|
||||
|
||||
const chatStore = useChatStore();
|
||||
const historyConversationDrawerRef = ref(null);
|
||||
|
||||
const conversationId = computed(() => {
|
||||
return route.params.conversationId;
|
||||
});
|
||||
|
||||
const getAgentData = async () => {
|
||||
const { code, data } = await getAgentInfo();
|
||||
if (code === 200) {
|
||||
chatStore.setAgentInfo(data);
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
getAgentData();
|
||||
});
|
||||
|
||||
return () => (
|
||||
<div class="chat-wrap rounded-12px w-full h-full">
|
||||
{conversationId.value ? <ConversationDetail /> : <ConversationCreate />}
|
||||
|
||||
Reference in New Issue
Block a user