feat: add edit button to persona selector dialog (#4826)
* Initial plan * feat: add edit persona functionality in chatui selector dialog Co-authored-by: Soulter <37870767+Soulter@users.noreply.github.com> * fix: address code review feedback - improve null checks and i18n consistency 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:
@@ -119,8 +119,17 @@
|
||||
</v-list-item-subtitle>
|
||||
|
||||
<template v-slot:append>
|
||||
<v-icon v-if="selectedItemId === getItemId(item)"
|
||||
color="primary" size="22">mdi-check-circle</v-icon>
|
||||
<div class="d-flex align-center ga-1">
|
||||
<v-btn v-if="showEditButton && !isDefaultItem(item)"
|
||||
icon="mdi-pencil"
|
||||
size="small"
|
||||
variant="text"
|
||||
@click.stop="handleEditItem(item)"
|
||||
:title="labels.editButton || 'Edit'"
|
||||
/>
|
||||
<v-icon v-if="selectedItemId === getItemId(item)"
|
||||
color="primary" size="22">mdi-check-circle</v-icon>
|
||||
</div>
|
||||
</template>
|
||||
</v-list-item>
|
||||
</template>
|
||||
@@ -197,6 +206,11 @@ export default defineComponent({
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 是否显示编辑按钮
|
||||
showEditButton: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
},
|
||||
// 默认项(如 "默认人格")
|
||||
defaultItem: {
|
||||
type: Object as PropType<SelectableItem | null>,
|
||||
@@ -221,7 +235,7 @@ export default defineComponent({
|
||||
default: null
|
||||
}
|
||||
},
|
||||
emits: ['update:modelValue', 'navigate', 'create'],
|
||||
emits: ['update:modelValue', 'navigate', 'create', 'edit'],
|
||||
data() {
|
||||
return {
|
||||
dialog: false,
|
||||
@@ -370,6 +384,17 @@ export default defineComponent({
|
||||
cancelSelection() {
|
||||
this.selectedItemId = this.modelValue || '';
|
||||
this.dialog = false;
|
||||
},
|
||||
|
||||
isDefaultItem(item: SelectableItem): boolean {
|
||||
if (this.defaultItem === null) {
|
||||
return false;
|
||||
}
|
||||
return this.getItemId(item) === this.getItemId(this.defaultItem);
|
||||
},
|
||||
|
||||
handleEditItem(item: SelectableItem) {
|
||||
this.$emit('edit', item);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -241,6 +241,7 @@ export interface FolderItemSelectorLabels {
|
||||
|
||||
// 按钮
|
||||
createButton?: string;
|
||||
editButton?: string;
|
||||
confirmButton?: string;
|
||||
cancelButton?: string;
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
:items-loading="itemsLoading"
|
||||
:labels="labels"
|
||||
:show-create-button="true"
|
||||
:show-edit-button="true"
|
||||
:default-item="defaultPersona"
|
||||
item-id-field="persona_id"
|
||||
item-name-field="persona_id"
|
||||
@@ -15,15 +16,16 @@
|
||||
:display-value-formatter="formatDisplayValue"
|
||||
@navigate="handleNavigate"
|
||||
@create="openCreatePersona"
|
||||
@edit="openEditPersona"
|
||||
/>
|
||||
|
||||
<!-- 创建人格对话框 -->
|
||||
<!-- 创建/编辑人格对话框 -->
|
||||
<PersonaForm
|
||||
v-model="showCreateDialog"
|
||||
:editing-persona="undefined"
|
||||
v-model="showPersonaDialog"
|
||||
:editing-persona="editingPersona ?? undefined"
|
||||
:current-folder-id="currentFolderId ?? undefined"
|
||||
:current-folder-name="currentFolderName ?? undefined"
|
||||
@saved="handlePersonaCreated"
|
||||
@saved="handlePersonaSaved"
|
||||
@error="handleError" />
|
||||
</template>
|
||||
|
||||
@@ -62,7 +64,8 @@ const folderTree = ref<FolderTreeNode[]>([])
|
||||
const currentPersonas = ref<Persona[]>([])
|
||||
const treeLoading = ref(false)
|
||||
const itemsLoading = ref(false)
|
||||
const showCreateDialog = ref(false)
|
||||
const showPersonaDialog = ref(false)
|
||||
const editingPersona = ref<Persona | null>(null)
|
||||
const currentFolderId = ref<string | null>(null)
|
||||
|
||||
// 默认人格
|
||||
@@ -104,6 +107,7 @@ const labels = computed(() => ({
|
||||
defaultItem: tm('personaSelector.defaultPersona'),
|
||||
noDescription: tm('personaSelector.noDescription'),
|
||||
createButton: tm('personaSelector.createPersona'),
|
||||
editButton: tm('personaSelector.editPersona') || 'Edit',
|
||||
confirmButton: t('core.common.confirm'),
|
||||
cancelButton: t('core.common.cancel'),
|
||||
rootFolder: tm('personaSelector.rootFolder') || '全部人格',
|
||||
@@ -171,13 +175,21 @@ async function handleNavigate(folderId: string | null) {
|
||||
|
||||
// 打开创建人格对话框
|
||||
function openCreatePersona() {
|
||||
showCreateDialog.value = true
|
||||
editingPersona.value = null
|
||||
showPersonaDialog.value = true
|
||||
}
|
||||
|
||||
// 人格创建成功
|
||||
async function handlePersonaCreated(message: string) {
|
||||
console.log('人格创建成功:', message)
|
||||
showCreateDialog.value = false
|
||||
// 打开编辑人格对话框
|
||||
function openEditPersona(persona: Persona) {
|
||||
editingPersona.value = persona
|
||||
showPersonaDialog.value = true
|
||||
}
|
||||
|
||||
// 人格保存成功(创建或编辑)
|
||||
async function handlePersonaSaved(message: string) {
|
||||
console.log('人格保存成功:', message)
|
||||
showPersonaDialog.value = false
|
||||
editingPersona.value = null
|
||||
// 刷新当前文件夹的人格列表
|
||||
await loadPersonasInFolder(currentFolderId.value)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user