File size: 4,918 Bytes
8ede856
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<template>
    <div>
        <!-- 项目按钮 -->
        <div style="padding: 0 8px 0px 8px; opacity: 0.6;">
            <v-btn block variant="text" class="project-btn" @click="toggleExpanded" prepend-icon="mdi-folder-outline">
                {{ tm('project.title') }}
                <template v-slot:append>
                    <v-icon size="small">{{ expanded ? 'mdi-chevron-up' : 'mdi-chevron-down' }}</v-icon>
                </template>
            </v-btn>
        </div>

        <!-- 项目列表 -->
        <v-expand-transition>
            <div v-show="expanded" style="padding: 0 8px;">
                <v-list density="compact" nav class="project-list" style="background-color: transparent;">
                    <v-list-item @click="$emit('createProject')" class="create-project-item" rounded="lg">
                        <template v-slot:prepend>
                            <span class="project-emoji"><v-icon size="small">mdi-plus</v-icon></span>
                        </template>
                        <v-list-item-title style="font-size: 13px;">{{ tm('project.create') }}</v-list-item-title>
                    </v-list-item>
                    <v-list-item v-for="project in projects" :key="project.project_id"
                        @click="$emit('selectProject', project.project_id)" rounded="lg" class="project-item">
                        <template v-slot:prepend>
                            <span class="project-emoji">{{ project.emoji || '📁' }}</span>
                        </template>
                        <v-list-item-title class="project-title">{{ project.title }}</v-list-item-title>
                        <template v-slot:append>
                            <div class="project-actions">
                                <v-btn icon="mdi-pencil" size="x-small" variant="text" class="edit-project-btn"
                                    @click.stop="$emit('editProject', project)" />
                                <v-btn icon="mdi-delete" size="x-small" variant="text" class="delete-project-btn"
                                    color="error" @click.stop="handleDeleteProject(project)" />
                            </div>
                        </template>
                    </v-list-item>
                </v-list>
            </div>
        </v-expand-transition>
    </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useModuleI18n } from '@/i18n/composables';
import { askForConfirmation, useConfirmDialog } from '@/utils/confirmDialog';

export interface Project {
    project_id: string;
    title: string;
    emoji?: string;
    description?: string;
    created_at: string;
    updated_at: string;
}

interface Props {
    projects: Project[];
    initialExpanded?: boolean;
}

const props = withDefaults(defineProps<Props>(), {
    initialExpanded: false
});

const emit = defineEmits<{
    selectProject: [projectId: string];
    createProject: [];
    editProject: [project: Project];
    deleteProject: [projectId: string];
}>();

const { tm } = useModuleI18n('features/chat');

const confirmDialog = useConfirmDialog();

const expanded = ref(props.initialExpanded);

// 从 localStorage 读取项目展开状态
const savedProjectsExpandedState = localStorage.getItem('projectsExpanded');
if (savedProjectsExpandedState !== null) {
    expanded.value = JSON.parse(savedProjectsExpandedState);
}

function toggleExpanded() {
    expanded.value = !expanded.value;
    localStorage.setItem('projectsExpanded', JSON.stringify(expanded.value));
}

async function handleDeleteProject(project: Project) {
    const message = tm('project.confirmDelete', { title: project.title });
    if (await askForConfirmation(message, confirmDialog)) {
        emit('deleteProject', project.project_id);
    }
}
</script>

<style scoped>
.project-btn {
    justify-content: flex-start;
    background-color: transparent !important;
    border-radius: 20px;
    padding: 8px 16px !important;
    text-transform: none;
}

.project-item {
    border-radius: 16px !important;
    padding: 4px 12px !important;
    margin-bottom: 2px;
}

.project-item:hover {
    background-color: rgba(103, 58, 183, 0.05);
}

.project-item:hover .project-actions {
    opacity: 1;
    visibility: visible;
}

.project-emoji {
    font-size: 16px;
    margin-right: 6px;
}

.project-title {
    font-size: 13px;
    font-weight: 500;
}

.project-actions {
    display: flex;
    gap: 2px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s ease;
}

.edit-project-btn,
.delete-project-btn {
    opacity: 0.7;
    transition: opacity 0.2s ease;
}

.edit-project-btn:hover,
.delete-project-btn:hover {
    opacity: 1;
}

.create-project-item {
    border-radius: 16px !important;
    padding: 4px 12px !important;
    opacity: 0.7;
}

.create-project-item:hover {
    background-color: rgba(103, 58, 183, 0.08);
    opacity: 1;
}
</style>