feat: add delete button to persona management dialog (#4978)

* Initial plan

* feat: add delete button to persona management dialog

- Added delete button to PersonaForm dialog (only visible when editing)
- Implemented deletePersona method with confirmation dialog
- Connected delete event to PersonaManager for proper handling
- Button positioned on left side of dialog actions for clear separation
- Uses existing i18n translations for delete button and messages

Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>

* fix: use finally block to ensure saving state is reset

- Moved `this.saving = false` to finally block in deletePersona
- Ensures UI doesn't stay in saving state after errors
- Follows best practices for state management

Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com>
This commit is contained in:
Copilot
2026-02-09 11:59:28 +08:00
committed by GitHub
parent ce65491d55
commit 9c12803ddd
2 changed files with 36 additions and 2 deletions
@@ -289,6 +289,9 @@
</v-card-text>
<v-card-actions>
<v-btn v-if="editingPersona" color="error" variant="text" @click="deletePersona">
{{ tm('buttons.delete') }}
</v-btn>
<v-spacer />
<v-btn color="grey" variant="text" @click="closeDialog">
{{ tm('buttons.cancel') }}
@@ -325,7 +328,7 @@ export default {
default: null
}
},
emits: ['update:modelValue', 'saved', 'error'],
emits: ['update:modelValue', 'saved', 'error', 'deleted'],
setup() {
const { tm } = useModuleI18n('features/persona');
return { tm };
@@ -591,6 +594,32 @@ export default {
this.saving = false;
},
async deletePersona() {
if (!this.editingPersona) return;
if (!confirm(this.tm('messages.deleteConfirm', { id: this.editingPersona.persona_id }))) {
return;
}
this.saving = true;
try {
const response = await axios.post('/api/persona/delete', {
persona_id: this.editingPersona.persona_id
});
if (response.data.status === 'ok') {
this.$emit('deleted', response.data.message || this.tm('messages.deleteSuccess'));
this.closeDialog();
} else {
this.$emit('error', response.data.message || this.tm('messages.deleteError'));
}
} catch (error) {
this.$emit('error', error.response?.data?.message || this.tm('messages.deleteError'));
} finally {
this.saving = false;
}
},
addDialogPair() {
this.personaForm.begin_dialogs.push('', '');
// 自动展开预设对话面板
@@ -110,7 +110,7 @@
<!-- 创建/编辑 Persona 对话框 -->
<PersonaForm v-model="showPersonaDialog" :editing-persona="editingPersona ?? undefined"
:current-folder-id="currentFolderId ?? undefined" :current-folder-name="currentFolderName ?? undefined"
@saved="handlePersonaSaved" @error="showError" />
@saved="handlePersonaSaved" @deleted="handlePersonaDeleted" @error="showError" />
<!-- 查看 Persona 详情对话框 -->
<v-dialog v-model="showViewDialog" max-width="700px">
@@ -414,6 +414,11 @@ export default defineComponent({
this.refreshCurrentFolder();
},
handlePersonaDeleted(message: string) {
this.showSuccess(message);
this.refreshCurrentFolder();
},
async confirmDeletePersona(persona: Persona) {
if (!confirm(this.tm('messages.deleteConfirm', { id: persona.persona_id }))) {
return;