2025-08-19 18:01:30 +08:00
|
|
|
<script lang="jsx">
|
2025-08-22 18:28:09 +08:00
|
|
|
import { Drawer, message } from 'ant-design-vue';
|
2025-08-19 18:01:30 +08:00
|
|
|
import TextoverTips from '@/components/text-over-tips';
|
2025-08-21 10:54:18 +08:00
|
|
|
import Conversations from '@/components/xt-chat/xt-conversations';
|
2025-08-19 18:01:30 +08:00
|
|
|
import SvgIcon from '@/components/svg-icon';
|
|
|
|
|
import { Button, Flex, Input } from 'ant-design-vue';
|
|
|
|
|
import DeleteChatModal from './delete-chat-modal.vue';
|
2025-08-22 18:28:09 +08:00
|
|
|
import NoData from '@/components/no-data/index.vue';
|
2025-08-22 11:48:41 +08:00
|
|
|
|
|
|
|
|
import { handleUserHome } from '@/utils/user';
|
2025-08-20 18:17:23 +08:00
|
|
|
import { useRouter } from 'vue-router';
|
2025-08-22 18:28:09 +08:00
|
|
|
import { getAgentHistory, postUpdateSessionTitle, postUpdateSessionSort } from '@/api/all/chat';
|
|
|
|
|
import { useChatStore } from '@/stores/modules/chat';
|
2025-08-19 18:01:30 +08:00
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
setup(props, { emit, expose }) {
|
2025-08-20 18:17:23 +08:00
|
|
|
const router = useRouter();
|
2025-08-22 18:28:09 +08:00
|
|
|
const chatStore = useChatStore();
|
|
|
|
|
|
2025-08-19 18:01:30 +08:00
|
|
|
const open = ref(false);
|
|
|
|
|
const dataSource = ref([]);
|
|
|
|
|
const activeKey = ref('');
|
|
|
|
|
const deleteChatModalRef = ref(null);
|
|
|
|
|
|
2025-08-22 18:28:09 +08:00
|
|
|
const showDrawer = (id) => {
|
2025-08-19 18:01:30 +08:00
|
|
|
getData();
|
|
|
|
|
open.value = true;
|
|
|
|
|
};
|
2025-08-22 18:28:09 +08:00
|
|
|
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();
|
|
|
|
|
}
|
2025-08-19 18:01:30 +08:00
|
|
|
};
|
|
|
|
|
const onClose = () => {
|
2025-08-22 18:28:09 +08:00
|
|
|
activeKey.value = '';
|
|
|
|
|
dataSource.value = [];
|
2025-08-19 18:01:30 +08:00
|
|
|
open.value = false;
|
|
|
|
|
};
|
2025-08-22 18:28:09 +08:00
|
|
|
const handleMenuClick = async ({ menuInfo, item }) => {
|
|
|
|
|
switch (menuInfo.key) {
|
2025-08-19 18:01:30 +08:00
|
|
|
case 'pin':
|
2025-08-22 18:28:09 +08:00
|
|
|
onPin(item);
|
2025-08-19 18:01:30 +08:00
|
|
|
break;
|
|
|
|
|
case 'rename':
|
|
|
|
|
item.editing = true;
|
|
|
|
|
break;
|
|
|
|
|
case 'delete':
|
|
|
|
|
deleteChatModalRef.value.open(item);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
};
|
2025-08-22 18:28:09 +08:00
|
|
|
const handleRename = async (item) => {
|
|
|
|
|
const { id, label } = item;
|
|
|
|
|
const { code } = await postUpdateSessionTitle({
|
|
|
|
|
id,
|
|
|
|
|
title: label,
|
|
|
|
|
});
|
|
|
|
|
if (code === 200) {
|
|
|
|
|
message.success('重命名成功');
|
|
|
|
|
}
|
2025-08-19 18:01:30 +08:00
|
|
|
};
|
2025-08-20 18:17:23 +08:00
|
|
|
const handleActiveChange = (item) => {
|
|
|
|
|
const { id } = item;
|
2025-08-22 11:48:41 +08:00
|
|
|
handleUserHome({ conversationId: id });
|
2025-08-20 18:17:23 +08:00
|
|
|
};
|
2025-08-19 18:01:30 +08:00
|
|
|
|
|
|
|
|
expose({
|
|
|
|
|
showDrawer,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
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">
|
2025-08-22 18:28:09 +08:00
|
|
|
<span class="text-16px font-400 color-#211F24 font-family-medium">历史对话</span>
|
2025-08-19 18:01:30 +08:00
|
|
|
<icon-close size={16} class="color-#211F24 cursor-pointer" onClick={onClose} />
|
|
|
|
|
</header>
|
2025-08-22 18:28:09 +08:00
|
|
|
{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>
|
|
|
|
|
)}
|
|
|
|
|
|
2025-08-19 18:01:30 +08:00
|
|
|
<DeleteChatModal ref={deleteChatModalRef} />
|
|
|
|
|
</Drawer>
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
@import './style.scss';
|
|
|
|
|
</style>
|