2025-04-18 20:09:21 +08:00
|
|
|
<template>
|
2025-04-20 19:46:51 +08:00
|
|
|
<div class="mode-selector" :class="{ 'collapsed': settingsStore.sidebarCollapsed }">
|
2025-04-18 20:09:21 +08:00
|
|
|
<div class="mode-header">
|
|
|
|
<h3 class="mode-title">对话场景</h3>
|
2025-04-20 19:46:51 +08:00
|
|
|
<div class="header-actions">
|
|
|
|
<HistoryButton v-if="!settingsStore.sidebarCollapsed" :icon-only="true" />
|
|
|
|
<el-button
|
|
|
|
class="collapse-btn"
|
|
|
|
:icon="settingsStore.sidebarCollapsed ? Expand : Fold"
|
|
|
|
text
|
|
|
|
bg
|
|
|
|
@click="settingsStore.toggleSidebar"
|
|
|
|
/>
|
|
|
|
</div>
|
2025-04-18 20:09:21 +08:00
|
|
|
</div>
|
|
|
|
<div class="mode-list">
|
|
|
|
<div
|
|
|
|
v-for="mode in chatModes"
|
|
|
|
:key="mode.id"
|
|
|
|
:class="['mode-item', { active: chatStore.currentMode === mode.id }]"
|
|
|
|
@click="selectMode(mode.id)"
|
|
|
|
>
|
2025-04-20 19:46:51 +08:00
|
|
|
<span class="emoji-icon">{{ mode.icon }}</span>
|
|
|
|
<span v-if="!settingsStore.sidebarCollapsed" class="mode-name">{{ mode.name }}</span>
|
|
|
|
<ModeSetting v-if="!settingsStore.sidebarCollapsed" @command="(cmd) => handleModeSettings(cmd, mode.id)">
|
|
|
|
<el-dropdown-item command="edit">
|
|
|
|
<el-icon><EditPen /></el-icon>
|
|
|
|
编辑设置
|
|
|
|
</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="reset">
|
|
|
|
<el-icon><RefreshRight /></el-icon>
|
|
|
|
重置设置
|
|
|
|
</el-dropdown-item>
|
|
|
|
<el-dropdown-item command="delete" divided>
|
|
|
|
<el-icon><Delete /></el-icon>
|
|
|
|
删除场景
|
|
|
|
</el-dropdown-item>
|
|
|
|
</ModeSetting>
|
2025-04-18 20:09:21 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
|
|
import { useChatStore } from '@/store/chat'
|
2025-04-20 19:46:51 +08:00
|
|
|
import { useSettingsStore } from '@/store/settings'
|
|
|
|
import { computed } from 'vue'
|
|
|
|
import { Delete, EditPen, RefreshRight, Expand, Fold } from '@element-plus/icons-vue'
|
2025-04-18 20:09:21 +08:00
|
|
|
import { ElDropdown, ElDropdownMenu, ElDropdownItem, ElButton, ElMessageBox } from 'element-plus'
|
2025-04-20 19:46:51 +08:00
|
|
|
import ModeSetting from '@/components/chat/ModeSetting.vue'
|
|
|
|
import HistoryButton from '@/components/chat/HistoryButton.vue'
|
2025-04-18 20:09:21 +08:00
|
|
|
|
|
|
|
const chatStore = useChatStore()
|
2025-04-20 19:46:51 +08:00
|
|
|
const settingsStore = useSettingsStore()
|
2025-04-18 20:09:21 +08:00
|
|
|
|
|
|
|
const chatModes = computed(() => {
|
|
|
|
return Object.keys(chatStore.chatModes).map(key => ({
|
|
|
|
id: key,
|
|
|
|
name: chatStore.chatModes[key].name,
|
|
|
|
icon: chatStore.chatModes[key].icon
|
|
|
|
}))
|
|
|
|
})
|
|
|
|
|
|
|
|
// 获取当前模式下的历史会话
|
|
|
|
const currentModeHistory = computed(() => {
|
|
|
|
return chatStore.conversations.filter(chat => chat.mode === chatStore.currentMode)
|
|
|
|
})
|
|
|
|
|
|
|
|
// 格式化会话标题
|
|
|
|
const formatChatTitle = (chat) => {
|
|
|
|
// 使用第一条消息作为标题,如果没有则使用默认标题
|
|
|
|
if (chat.messages && chat.messages.length > 0) {
|
|
|
|
const firstMessage = chat.messages[0].question
|
|
|
|
return firstMessage.length > 20 ? firstMessage.substring(0, 20) + '...' : firstMessage
|
|
|
|
}
|
|
|
|
return `会话 ${chat.conversationId.substring(0, 8)}`
|
|
|
|
}
|
|
|
|
|
|
|
|
const selectMode = (modeId) => {
|
|
|
|
chatStore.setCurrentMode(modeId)
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleHistorySelect = (conversationId) => {
|
|
|
|
chatStore.switchConversation(conversationId)
|
|
|
|
}
|
|
|
|
|
|
|
|
const handleDelete = async (conversationId) => {
|
|
|
|
try {
|
|
|
|
await ElMessageBox.confirm(
|
|
|
|
'确定要删除这个会话吗?删除后无法恢复。',
|
|
|
|
'删除确认',
|
|
|
|
{
|
|
|
|
confirmButtonText: '确定',
|
|
|
|
cancelButtonText: '取消',
|
|
|
|
type: 'warning',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
chatStore.deleteConversation(conversationId)
|
|
|
|
} catch {
|
|
|
|
// 用户取消删除
|
|
|
|
}
|
|
|
|
}
|
2025-04-20 19:46:51 +08:00
|
|
|
|
|
|
|
const handleModeSettings = (command, modeId) => {
|
|
|
|
switch (command) {
|
|
|
|
case 'edit':
|
|
|
|
// TODO: 实现编辑设置的逻辑
|
|
|
|
console.log('编辑设置:', modeId)
|
|
|
|
break
|
|
|
|
case 'reset':
|
|
|
|
// TODO: 实现重置设置的逻辑
|
|
|
|
console.log('重置设置:', modeId)
|
|
|
|
break
|
|
|
|
case 'delete':
|
|
|
|
// TODO: 实现删除场景的逻辑
|
|
|
|
console.log('删除场景:', modeId)
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2025-04-18 20:09:21 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
$primary-color: #4CAF50;
|
|
|
|
$text-color: #333;
|
|
|
|
$text-color-dark: #fff;
|
|
|
|
$background-color: #ffffff;
|
|
|
|
$background-color-dark: #1e1e1e;
|
|
|
|
$border-color: #e0e0e0;
|
|
|
|
$border-color-dark: #333;
|
|
|
|
$hover-color: #f5f5f5;
|
|
|
|
$hover-color-dark: #2d2d2d;
|
|
|
|
|
|
|
|
.mode-selector {
|
|
|
|
width: 240px;
|
|
|
|
min-width: 240px;
|
|
|
|
background: $background-color;
|
|
|
|
border-right: 1px solid $border-color;
|
|
|
|
height: 100%;
|
2025-04-20 19:46:51 +08:00
|
|
|
padding: 0;
|
2025-04-18 20:09:21 +08:00
|
|
|
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.1);
|
2025-04-20 19:46:51 +08:00
|
|
|
transition: all 0.3s ease;
|
|
|
|
|
|
|
|
&.collapsed {
|
|
|
|
width: 64px;
|
|
|
|
min-width: 64px;
|
|
|
|
|
|
|
|
.mode-title {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
.mode-item {
|
|
|
|
padding: 15px;
|
|
|
|
justify-content: center;
|
|
|
|
|
|
|
|
.mode-name {
|
|
|
|
display: none;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.header-actions {
|
|
|
|
width: 100%;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
}
|
2025-04-18 20:09:21 +08:00
|
|
|
|
|
|
|
.mode-header {
|
|
|
|
padding: 0 20px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
gap: 10px;
|
2025-04-20 19:46:51 +08:00
|
|
|
height: 60px;
|
|
|
|
border-bottom: 1px solid #e5e5e5;
|
|
|
|
|
|
|
|
.header-actions {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
gap: 8px;
|
|
|
|
}
|
2025-04-18 20:09:21 +08:00
|
|
|
|
|
|
|
.mode-title {
|
|
|
|
color: $text-color;
|
|
|
|
font-size: 16px;
|
2025-04-20 19:46:51 +08:00
|
|
|
font-weight: 500;
|
2025-04-18 20:09:21 +08:00
|
|
|
margin: 0;
|
2025-04-20 19:46:51 +08:00
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
2025-04-18 20:09:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
.history-btn {
|
|
|
|
font-size: 14px;
|
|
|
|
height: 32px;
|
|
|
|
padding: 4px 12px;
|
|
|
|
color: $text-color;
|
|
|
|
transition: all 0.3s ease;
|
2025-04-20 19:46:51 +08:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
gap: 4px;
|
2025-04-18 20:09:21 +08:00
|
|
|
|
|
|
|
&:hover {
|
2025-04-20 19:46:51 +08:00
|
|
|
color: #07c160;
|
|
|
|
background: rgba(7, 193, 96, 0.1);
|
2025-04-18 20:09:21 +08:00
|
|
|
}
|
|
|
|
|
2025-04-20 19:46:51 +08:00
|
|
|
:deep(.el-icon) {
|
|
|
|
font-size: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.collapse-btn {
|
|
|
|
font-size: 14px;
|
|
|
|
height: 32px;
|
|
|
|
width: 32px;
|
|
|
|
padding: 0;
|
|
|
|
color: $text-color;
|
|
|
|
transition: all 0.3s ease;
|
|
|
|
border: none !important;
|
|
|
|
background: transparent !important;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
color: $primary-color;
|
|
|
|
background: transparent !important;
|
2025-04-18 20:09:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
&:focus {
|
|
|
|
outline: none;
|
|
|
|
box-shadow: none;
|
|
|
|
}
|
|
|
|
|
|
|
|
:deep(.el-icon) {
|
|
|
|
font-size: 16px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
.mode-list {
|
2025-04-20 19:46:51 +08:00
|
|
|
padding: 0 0 20px 0;
|
2025-04-18 20:09:21 +08:00
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
gap: 5px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.mode-item {
|
|
|
|
padding: 15px 20px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
gap: 10px;
|
|
|
|
cursor: pointer;
|
|
|
|
transition: all 0.3s ease;
|
|
|
|
color: $text-color;
|
2025-04-20 19:46:51 +08:00
|
|
|
position: relative;
|
2025-04-18 20:09:21 +08:00
|
|
|
|
|
|
|
&:hover {
|
|
|
|
background: $hover-color;
|
2025-04-20 19:46:51 +08:00
|
|
|
|
|
|
|
:deep(.setting-btn) {
|
|
|
|
opacity: 1;
|
|
|
|
transform: translateX(0);
|
|
|
|
}
|
2025-04-18 20:09:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
&.active {
|
|
|
|
background: $primary-color;
|
|
|
|
color: white;
|
|
|
|
}
|
|
|
|
|
2025-04-20 19:46:51 +08:00
|
|
|
.emoji-icon {
|
|
|
|
font-size: 20px;
|
2025-04-18 20:09:21 +08:00
|
|
|
width: 24px;
|
|
|
|
text-align: center;
|
2025-04-20 19:46:51 +08:00
|
|
|
line-height: 1;
|
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
flex-shrink: 0;
|
2025-04-18 20:09:21 +08:00
|
|
|
}
|
|
|
|
|
2025-04-20 19:46:51 +08:00
|
|
|
.mode-name {
|
2025-04-18 20:09:21 +08:00
|
|
|
font-size: 14px;
|
2025-04-20 19:46:51 +08:00
|
|
|
flex: 1;
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
}
|
|
|
|
|
|
|
|
:deep(.mode-setting) {
|
|
|
|
margin-left: auto;
|
2025-04-18 20:09:21 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
:deep(.el-dropdown-menu__item) {
|
|
|
|
font-size: 13px;
|
|
|
|
padding: 8px 16px;
|
|
|
|
line-height: 1.4;
|
|
|
|
max-width: 300px;
|
|
|
|
overflow-x: hidden;
|
|
|
|
|
|
|
|
&:hover .delete-btn {
|
|
|
|
opacity: 1;
|
|
|
|
transform: translateX(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
:deep(.el-dropdown-menu) {
|
|
|
|
min-width: 200px;
|
|
|
|
max-width: 300px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.history-content {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
gap: 8px;
|
|
|
|
width: 100%;
|
|
|
|
position: relative;
|
|
|
|
min-width: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.history-title {
|
|
|
|
flex: 1;
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
margin-right: 24px;
|
|
|
|
min-width: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.delete-btn {
|
|
|
|
position: absolute;
|
|
|
|
right: -8px;
|
|
|
|
opacity: 0;
|
|
|
|
transform: translateX(10px);
|
|
|
|
transition: all 0.3s ease;
|
|
|
|
height: 24px;
|
|
|
|
width: 24px;
|
|
|
|
padding: 0;
|
|
|
|
color: #f56c6c;
|
|
|
|
flex-shrink: 0;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
color: #f56c6c;
|
|
|
|
background-color: rgba(245, 108, 108, 0.1);
|
|
|
|
}
|
|
|
|
|
|
|
|
:deep(.el-icon) {
|
|
|
|
font-size: 14px;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-04-20 19:46:51 +08:00
|
|
|
// @media (prefers-color-scheme: dark) {
|
|
|
|
// .mode-selector {
|
|
|
|
// background: $background-color-dark;
|
|
|
|
// border-right-color: $border-color-dark;
|
2025-04-18 20:09:21 +08:00
|
|
|
|
2025-04-20 19:46:51 +08:00
|
|
|
// .mode-title {
|
|
|
|
// color: $text-color-dark;
|
|
|
|
// }
|
2025-04-18 20:09:21 +08:00
|
|
|
|
2025-04-20 19:46:51 +08:00
|
|
|
// .mode-item {
|
|
|
|
// color: $text-color-dark;
|
2025-04-18 20:09:21 +08:00
|
|
|
|
2025-04-20 19:46:51 +08:00
|
|
|
// &:hover {
|
|
|
|
// background: $hover-color-dark;
|
|
|
|
// }
|
|
|
|
// }
|
2025-04-18 20:09:21 +08:00
|
|
|
|
2025-04-20 19:46:51 +08:00
|
|
|
// .history-btn {
|
|
|
|
// color: $text-color-dark;
|
2025-04-18 20:09:21 +08:00
|
|
|
|
2025-04-20 19:46:51 +08:00
|
|
|
// &:hover {
|
|
|
|
// color: $primary-color;
|
|
|
|
// background: rgba($primary-color, 0.15);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
|
|
|
|
// .delete-btn {
|
|
|
|
// &:hover {
|
|
|
|
// background-color: rgba(245, 108, 108, 0.15);
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// }
|
2025-04-18 20:09:21 +08:00
|
|
|
</style>
|