2025-05-15 22:34:32 +08:00
|
|
|
<template>
|
2025-05-18 17:58:27 +08:00
|
|
|
<div class="chat-sidebar" :class="{'sidebar-open': isSidebarOpen, 'no-transition': isInitialRender}">
|
2025-05-15 22:34:32 +08:00
|
|
|
<div class="sidebar-header">
|
|
|
|
|
<div class="header-title">{{ currentAgentId }}</div>
|
|
|
|
|
<div class="header-actions">
|
|
|
|
|
<div class="toggle-sidebar nav-btn" v-if="isSidebarOpen" @click="toggleCollapse">
|
2025-05-20 20:49:50 +08:00
|
|
|
<PanelLeftClose size="20" color="var(--gray-800)"/>
|
2025-05-15 22:34:32 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="conversation-list-top">
|
2025-05-20 20:49:50 +08:00
|
|
|
<button type="text" @click="createNewChat" class="new-chat-btn">
|
2025-07-30 11:00:50 +08:00
|
|
|
<MessageSquarePlus size="20" /> 创建新对话
|
2025-05-20 20:49:50 +08:00
|
|
|
</button>
|
2025-05-15 22:34:32 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="conversation-list">
|
|
|
|
|
<a-spin v-if="loading" />
|
2025-07-30 11:00:50 +08:00
|
|
|
<template v-else-if="Object.keys(groupedChats).length > 0">
|
|
|
|
|
<div v-for="(group, groupName) in groupedChats" :key="groupName" class="chat-group">
|
|
|
|
|
<div class="chat-group-title">{{ groupName }}</div>
|
|
|
|
|
<div
|
|
|
|
|
v-for="chat in group"
|
|
|
|
|
:key="chat.id"
|
|
|
|
|
class="conversation-item"
|
|
|
|
|
:class="{ 'active': currentChatId === chat.id }"
|
|
|
|
|
@click="selectChat(chat)"
|
|
|
|
|
>
|
2025-08-09 23:18:19 +08:00
|
|
|
<div class="conversation-title">{{ chat.title || '新的对话' }}</div>
|
2025-07-30 11:00:50 +08:00
|
|
|
<div class="actions-mask"></div>
|
|
|
|
|
<div class="conversation-actions">
|
|
|
|
|
<a-dropdown :trigger="['click']" @click.stop>
|
|
|
|
|
<template #overlay>
|
|
|
|
|
<a-menu>
|
|
|
|
|
<a-menu-item key="rename" @click.stop="renameChat(chat.id)">
|
|
|
|
|
<EditOutlined /> 重命名
|
|
|
|
|
</a-menu-item>
|
|
|
|
|
<a-menu-item key="delete" @click.stop="deleteChat(chat.id)" v-if="chat.id !== currentChatId">
|
|
|
|
|
<DeleteOutlined /> 删除
|
|
|
|
|
</a-menu-item>
|
|
|
|
|
</a-menu>
|
|
|
|
|
</template>
|
|
|
|
|
<a-button type="text" class="more-btn" @click.stop>
|
|
|
|
|
<MoreOutlined />
|
|
|
|
|
</a-button>
|
|
|
|
|
</a-dropdown>
|
|
|
|
|
</div>
|
2025-05-15 22:34:32 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2025-07-30 11:00:50 +08:00
|
|
|
<div v-else class="empty-list">
|
|
|
|
|
暂无对话历史
|
|
|
|
|
</div>
|
2025-05-15 22:34:32 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2025-07-30 11:00:50 +08:00
|
|
|
import { ref, computed, h } from 'vue';
|
2025-05-15 22:34:32 +08:00
|
|
|
import {
|
|
|
|
|
DeleteOutlined,
|
|
|
|
|
EditOutlined,
|
|
|
|
|
MoreOutlined
|
|
|
|
|
} from '@ant-design/icons-vue';
|
|
|
|
|
import { message, Modal } from 'ant-design-vue';
|
2025-05-20 20:49:50 +08:00
|
|
|
import { PanelLeftClose, MessageSquarePlus } from 'lucide-vue-next';
|
2025-07-30 11:00:50 +08:00
|
|
|
import dayjs from 'dayjs';
|
|
|
|
|
import 'dayjs/locale/zh-cn';
|
|
|
|
|
import relativeTime from 'dayjs/plugin/relativeTime';
|
|
|
|
|
|
|
|
|
|
dayjs.extend(relativeTime);
|
|
|
|
|
dayjs.locale('zh-cn');
|
2025-05-15 22:34:32 +08:00
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
|
|
|
currentAgentId: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: null
|
|
|
|
|
},
|
|
|
|
|
currentChatId: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: null
|
|
|
|
|
},
|
|
|
|
|
chatsList: {
|
|
|
|
|
type: Array,
|
|
|
|
|
default: () => []
|
|
|
|
|
},
|
|
|
|
|
isSidebarOpen: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
2025-05-18 17:58:27 +08:00
|
|
|
},
|
|
|
|
|
isInitialRender: {
|
|
|
|
|
type: Boolean,
|
|
|
|
|
default: false
|
2025-05-15 22:34:32 +08:00
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const emit = defineEmits(['create-chat', 'select-chat', 'delete-chat', 'rename-chat', 'toggle-sidebar']);
|
|
|
|
|
|
|
|
|
|
const loading = ref(false);
|
|
|
|
|
|
2025-07-30 11:00:50 +08:00
|
|
|
const groupedChats = computed(() => {
|
|
|
|
|
const groups = {
|
|
|
|
|
'今天': [],
|
|
|
|
|
'七天内': [],
|
|
|
|
|
'三十天内': [],
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const now = dayjs();
|
|
|
|
|
const today = now.startOf('day');
|
|
|
|
|
const sevenDaysAgo = now.subtract(7, 'day').startOf('day');
|
|
|
|
|
const thirtyDaysAgo = now.subtract(30, 'day').startOf('day');
|
|
|
|
|
|
|
|
|
|
// Sort chats by creation date, newest first
|
|
|
|
|
const sortedChats = [...props.chatsList].sort((a, b) => dayjs(b.create_at).diff(dayjs(a.create_at)));
|
|
|
|
|
|
|
|
|
|
sortedChats.forEach(chat => {
|
|
|
|
|
const chatDate = dayjs(chat.create_at);
|
|
|
|
|
if (chatDate.isAfter(today)) {
|
|
|
|
|
groups['今天'].push(chat);
|
|
|
|
|
} else if (chatDate.isAfter(sevenDaysAgo)) {
|
|
|
|
|
groups['七天内'].push(chat);
|
|
|
|
|
} else if (chatDate.isAfter(thirtyDaysAgo)) {
|
|
|
|
|
groups['三十天内'].push(chat);
|
|
|
|
|
} else {
|
|
|
|
|
const monthKey = chatDate.format('YYYY-MM');
|
|
|
|
|
if (!groups[monthKey]) {
|
|
|
|
|
groups[monthKey] = [];
|
|
|
|
|
}
|
|
|
|
|
groups[monthKey].push(chat);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Remove empty groups
|
|
|
|
|
for (const key in groups) {
|
|
|
|
|
if (groups[key].length === 0) {
|
|
|
|
|
delete groups[key];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return groups;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
2025-05-15 22:34:32 +08:00
|
|
|
const createNewChat = () => {
|
|
|
|
|
emit('create-chat');
|
|
|
|
|
};
|
|
|
|
|
|
2025-07-30 11:00:50 +08:00
|
|
|
const selectChat = (chat) => {
|
|
|
|
|
console.log(chat);
|
|
|
|
|
emit('select-chat', chat.id);
|
2025-05-15 22:34:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const deleteChat = (chatId) => {
|
|
|
|
|
emit('delete-chat', chatId);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const renameChat = async (chatId) => {
|
|
|
|
|
try {
|
|
|
|
|
const chat = props.chatsList.find(c => c.id === chatId);
|
|
|
|
|
if (!chat) return;
|
|
|
|
|
|
2025-07-30 11:00:50 +08:00
|
|
|
let newTitle = chat.title;
|
|
|
|
|
Modal.confirm({
|
|
|
|
|
title: '重命名对话',
|
|
|
|
|
content: h('div', { style: { marginTop: '12px' } }, [
|
|
|
|
|
h('input', {
|
|
|
|
|
value: newTitle,
|
|
|
|
|
style: { width: '100%', padding: '4px 8px', border: '1px solid #d9d9d9', borderRadius: '4px' },
|
|
|
|
|
onInput: (e) => { newTitle = e.target.value; }
|
|
|
|
|
})
|
|
|
|
|
]),
|
|
|
|
|
okText: '确认',
|
|
|
|
|
cancelText: '取消',
|
|
|
|
|
onOk: () => {
|
|
|
|
|
if (!newTitle.trim()) {
|
|
|
|
|
message.warning('标题不能为空');
|
|
|
|
|
return Promise.reject();
|
2025-05-15 22:34:32 +08:00
|
|
|
}
|
2025-07-30 11:00:50 +08:00
|
|
|
emit('rename-chat', { chatId, title: newTitle });
|
|
|
|
|
},
|
|
|
|
|
onCancel: () => {}
|
2025-05-15 22:34:32 +08:00
|
|
|
});
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('重命名对话失败:', error);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const toggleCollapse = () => {
|
|
|
|
|
emit('toggle-sidebar');
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang="less" scoped>
|
|
|
|
|
.chat-sidebar {
|
2025-05-18 17:58:27 +08:00
|
|
|
width: 0;
|
2025-05-15 22:34:32 +08:00
|
|
|
height: 100%;
|
2025-06-17 10:54:45 +08:00
|
|
|
background-color: var(--bg-sider);
|
2025-05-15 22:34:32 +08:00
|
|
|
transition: all 0.3s ease;
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
2025-05-18 17:58:27 +08:00
|
|
|
border: none;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
|
|
&.no-transition {
|
|
|
|
|
transition: none !important;
|
|
|
|
|
}
|
2025-05-15 22:34:32 +08:00
|
|
|
|
2025-05-18 17:58:27 +08:00
|
|
|
&.sidebar-open {
|
|
|
|
|
width: 280px;
|
|
|
|
|
max-width: 300px;
|
2025-07-30 11:00:50 +08:00
|
|
|
border-right: 1px solid var(--gray-200);
|
2025-05-15 22:34:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.sidebar-header {
|
|
|
|
|
height: var(--header-height);
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: space-between;
|
|
|
|
|
padding: 0 16px;
|
2025-07-30 11:00:50 +08:00
|
|
|
border-bottom: 1px solid var(--gray-200);
|
|
|
|
|
flex-shrink: 0;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
|
|
|
|
.header-title {
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
font-size: 16px;
|
|
|
|
|
color: var(--gray-900);
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
flex: 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.header-actions {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: 8px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.conversation-list-top {
|
2025-07-30 11:00:50 +08:00
|
|
|
padding: 8px 12px;
|
2025-08-08 22:57:14 +08:00
|
|
|
// border-bottom: 1px solid var(--gray-200);
|
2025-05-15 22:34:32 +08:00
|
|
|
|
|
|
|
|
.new-chat-btn {
|
|
|
|
|
width: 100%;
|
2025-07-30 11:00:50 +08:00
|
|
|
padding: 8px 12px;
|
|
|
|
|
border-radius: 6px;
|
2025-08-09 23:18:19 +08:00
|
|
|
background-color: var(--gray-50);
|
2025-05-15 22:34:32 +08:00
|
|
|
color: var(--main-color);
|
2025-05-20 20:49:50 +08:00
|
|
|
border: none;
|
2025-05-15 22:34:32 +08:00
|
|
|
transition: all 0.2s ease;
|
2025-05-20 20:49:50 +08:00
|
|
|
font-weight: 500;
|
2025-07-30 11:00:50 +08:00
|
|
|
cursor: pointer;
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
gap: 8px;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
|
|
|
|
&:hover {
|
2025-07-30 11:00:50 +08:00
|
|
|
background-color: var(--main-100);
|
2025-05-15 22:34:32 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.conversation-list {
|
|
|
|
|
flex: 1;
|
|
|
|
|
overflow-y: auto;
|
2025-07-30 11:00:50 +08:00
|
|
|
padding: 8px;
|
|
|
|
|
|
|
|
|
|
.chat-group {
|
|
|
|
|
margin-bottom: 16px;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.chat-group-title {
|
|
|
|
|
padding: 4px 8px;
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
color: var(--gray-500);
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
text-transform: uppercase;
|
|
|
|
|
}
|
2025-05-15 22:34:32 +08:00
|
|
|
|
|
|
|
|
.conversation-item {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
2025-07-30 11:00:50 +08:00
|
|
|
padding: 8px 12px;
|
|
|
|
|
border-radius: 6px;
|
|
|
|
|
margin: 4px 0;
|
2025-05-15 22:34:32 +08:00
|
|
|
cursor: pointer;
|
2025-07-30 11:00:50 +08:00
|
|
|
transition: background-color 0.2s ease;
|
|
|
|
|
position: relative;
|
|
|
|
|
overflow: hidden;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
2025-07-30 11:00:50 +08:00
|
|
|
.conversation-title {
|
|
|
|
|
flex: 1;
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
color: var(--gray-800);
|
|
|
|
|
white-space: nowrap;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
|
transition: color 0.2s ease;
|
|
|
|
|
}
|
2025-05-15 22:34:32 +08:00
|
|
|
|
2025-07-30 11:00:50 +08:00
|
|
|
.actions-mask {
|
|
|
|
|
position: absolute;
|
|
|
|
|
right: 0;
|
|
|
|
|
top: 0;
|
|
|
|
|
bottom: 0;
|
|
|
|
|
width: 60px;
|
|
|
|
|
background: linear-gradient(to right, transparent, var(--bg-sider) 20px);
|
|
|
|
|
opacity: 0;
|
|
|
|
|
transition: opacity 0.3s ease;
|
|
|
|
|
pointer-events: none;
|
2025-05-15 22:34:32 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-30 11:00:50 +08:00
|
|
|
.conversation-actions {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
position: absolute;
|
|
|
|
|
right: 8px;
|
|
|
|
|
top: 50%;
|
|
|
|
|
transform: translateY(-50%);
|
|
|
|
|
opacity: 0;
|
|
|
|
|
transition: opacity 0.3s ease;
|
2025-05-15 22:34:32 +08:00
|
|
|
|
2025-07-30 11:00:50 +08:00
|
|
|
.more-btn {
|
|
|
|
|
color: var(--gray-600);
|
|
|
|
|
background-color: transparent !important;
|
|
|
|
|
&:hover {
|
|
|
|
|
color: var(--main-500);
|
|
|
|
|
background-color: transparent !important;
|
|
|
|
|
}
|
2025-05-15 22:34:32 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 11:00:50 +08:00
|
|
|
&:hover {
|
2025-08-09 23:18:19 +08:00
|
|
|
background-color: var(--gray-50);
|
2025-05-15 22:34:32 +08:00
|
|
|
|
2025-07-30 11:00:50 +08:00
|
|
|
.actions-mask {
|
|
|
|
|
background: linear-gradient(to right, transparent, var(--gray-100) 20px);
|
2025-05-15 22:34:32 +08:00
|
|
|
}
|
|
|
|
|
|
2025-07-30 11:00:50 +08:00
|
|
|
.actions-mask, .conversation-actions {
|
|
|
|
|
opacity: 1;
|
2025-05-15 22:34:32 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 11:00:50 +08:00
|
|
|
&.active {
|
2025-08-09 23:18:19 +08:00
|
|
|
background-color: var(--gray-100);
|
2025-05-15 22:34:32 +08:00
|
|
|
|
2025-07-30 11:00:50 +08:00
|
|
|
.conversation-title {
|
|
|
|
|
color: var(--main-600);
|
|
|
|
|
font-weight: 500;
|
|
|
|
|
}
|
|
|
|
|
.actions-mask {
|
2025-08-09 23:18:19 +08:00
|
|
|
background: linear-gradient(to right, transparent, var(--gray-100) 20px);
|
2025-05-15 22:34:32 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.empty-list {
|
2025-07-30 11:00:50 +08:00
|
|
|
text-align: center;
|
|
|
|
|
margin-top: 20px;
|
2025-05-15 22:34:32 +08:00
|
|
|
color: var(--gray-500);
|
|
|
|
|
font-size: 14px;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 11:00:50 +08:00
|
|
|
// Scrollbar styling
|
2025-05-15 22:34:32 +08:00
|
|
|
.conversation-list::-webkit-scrollbar {
|
2025-07-30 11:00:50 +08:00
|
|
|
width: 5px;
|
2025-05-15 22:34:32 +08:00
|
|
|
}
|
|
|
|
|
.conversation-list::-webkit-scrollbar-track {
|
|
|
|
|
background: transparent;
|
|
|
|
|
}
|
|
|
|
|
.conversation-list::-webkit-scrollbar-thumb {
|
|
|
|
|
background: var(--gray-300);
|
2025-07-30 11:00:50 +08:00
|
|
|
border-radius: 5px;
|
2025-05-15 22:34:32 +08:00
|
|
|
}
|
|
|
|
|
.conversation-list::-webkit-scrollbar-thumb:hover {
|
|
|
|
|
background: var(--gray-400);
|
|
|
|
|
}
|
|
|
|
|
|
2025-07-30 11:00:50 +08:00
|
|
|
.toggle-sidebar.nav-btn {
|
2025-05-15 22:34:32 +08:00
|
|
|
cursor: pointer;
|
2025-07-30 11:00:50 +08:00
|
|
|
height: 2.5rem;
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
color: var(--gray-900);
|
|
|
|
|
padding: 0.5rem;
|
|
|
|
|
transition: background-color 0.3s;
|
|
|
|
|
&:hover {
|
|
|
|
|
background-color: var(--gray-100);
|
2025-05-15 22:34:32 +08:00
|
|
|
}
|
|
|
|
|
}
|
2025-07-30 11:00:50 +08:00
|
|
|
</style>
|