feat: save session with name prompt

- Save button now prompts for session name
- Uses same rename dialog with different labels
- confirmSaveSession saves messages to MarkBase SQLite
- Session appears in history list after save
This commit is contained in:
2026-10-27 17:14:19 +08:00
parent 1b9f0850e8
commit 69b83e212b

View File

@@ -57,11 +57,11 @@
</div>
<div v-if="renamingSession" class="rename-overlay" @click.self="cancelRename">
<div class="rename-dialog">
<div class="rename-label">Rename conversation</div>
<input class="rename-input" v-model="renameValue" @keyup.enter="confirmRename" ref="renameInputEl" />
<div class="rename-label">{{ currentSession?.id === renamingSession?.id ? 'Save Session' : 'Rename Session' }}</div>
<input class="rename-input" v-model="renameValue" @keyup.enter="currentSession?.id === renamingSession?.id ? confirmSaveSession() : confirmRename()" ref="renameInputEl" />
<div class="rename-actions">
<button class="rename-cancel" @click="cancelRename">Cancel</button>
<button class="rename-confirm" @click="confirmRename">Save</button>
<button class="rename-confirm" @click="currentSession?.id === renamingSession?.id ? confirmSaveSession() : confirmRename()">{{ currentSession?.id === renamingSession?.id ? 'Save' : 'Rename' }}</button>
</div>
</div>
</div>
@@ -755,27 +755,39 @@ async function saveCurrentSession() {
return
}
// If no current session, create one
// If no current session, create one with temp name
if (!currentSession.value) {
const now = new Date()
const timeStr = `${now.getFullYear()}/${(now.getMonth()+1).toString().padStart(2,'0')}/${now.getDate().toString().padStart(2,'0')} ${now.getHours().toString().padStart(2,'0')}:${now.getMinutes().toString().padStart(2,'0')}`
const newSession = await createSession(timeStr, mode.value)
const newSession = await createSession('未命名', mode.value)
if (newSession) {
setCurrentSession(newSession)
}
}
// Save all messages to current session
// Show rename dialog for session name
if (currentSession.value) {
renamingSession.value = currentSession.value
renameValue.value = currentSession.value.title === '未命名' ? '' : currentSession.value.title
nextTick(() => renameInputEl.value?.focus())
}
}
async function confirmSaveSession() {
if (!renamingSession.value) return
// Update session title
const title = renameValue.value || `Session ${new Date().toLocaleString()}`
await renameSession(renamingSession.value.id, title)
// Save all messages to current session
for (const msg of messages.value) {
if (msg.role === 'user' && msg.query) {
await saveMessage(currentSession.value.id, {
await saveMessage(renamingSession.value.id, {
role: 'user',
content: msg.query,
mode: msg.mode || mode.value
})
} else if (msg.role === 'assistant') {
await saveMessage(currentSession.value.id, {
await saveMessage(renamingSession.value.id, {
role: 'assistant',
content: msg.message || msg.answer || '',
mode: msg.mode || mode.value,
@@ -783,9 +795,10 @@ async function saveCurrentSession() {
})
}
}
renamingSession.value = null
renameValue.value = ''
await loadSessions()
alert('Session saved!')
}
}
function toggleSessionMenu(id: string) {