diff --git a/dashboard/src/i18n/locales/en-US/features/persona.json b/dashboard/src/i18n/locales/en-US/features/persona.json index d83dc4463..451e991ed 100644 --- a/dashboard/src/i18n/locales/en-US/features/persona.json +++ b/dashboard/src/i18n/locales/en-US/features/persona.json @@ -8,6 +8,7 @@ "edit": "Edit", "delete": "Delete", "copy": "Copy JSON", + "export": "Export JSON", "import": "Import", "cancel": "Cancel", "save": "Save", diff --git a/dashboard/src/i18n/locales/zh-CN/features/persona.json b/dashboard/src/i18n/locales/zh-CN/features/persona.json index a351cafef..eb605221a 100644 --- a/dashboard/src/i18n/locales/zh-CN/features/persona.json +++ b/dashboard/src/i18n/locales/zh-CN/features/persona.json @@ -8,6 +8,7 @@ "edit": "编辑", "delete": "删除", "copy": "复制 JSON", + "export": "导出 JSON", "import": "导入", "cancel": "取消", "save": "保存", diff --git a/dashboard/src/views/PersonaPage.vue b/dashboard/src/views/PersonaPage.vue index 36d8d0f3c..9c447f54b 100644 --- a/dashboard/src/views/PersonaPage.vue +++ b/dashboard/src/views/PersonaPage.vue @@ -45,10 +45,10 @@ {{ tm('buttons.edit') }} - + mdi-content-copy - {{ tm('buttons.copy') || '复制 JSON' }} + {{ tm('buttons.export') || '导出 JSON' }} @@ -283,7 +283,7 @@ export default { this.showMessage = true; }, - async copyPersonaJson(persona) { + async downloadPersonaJson(persona) { try { // 创建清洁副本,排除系统字段 const cleanPersona = { @@ -296,14 +296,28 @@ export default { // 格式化 JSON const jsonString = JSON.stringify(cleanPersona, null, 4); - // 复制到剪贴板 - await navigator.clipboard.writeText(jsonString); + // 创建 Blob 对象 + const blob = new Blob([jsonString], { type: 'application/json' }); + + // 创建下载链接 + const url = URL.createObjectURL(blob); + const link = document.createElement('a'); + link.href = url; + link.download = `${persona.persona_id}.json`; + + // 触发下载 + document.body.appendChild(link); + link.click(); + document.body.removeChild(link); + + // 清理 URL 对象 + URL.revokeObjectURL(url); // 显示成功消息 - this.showSuccess(this.tm('messages.copySuccess') || 'Copied to clipboard'); + this.showSuccess(this.tm('messages.downloadSuccess') || 'JSON 文件已下载'); } catch (error) { // 显示错误消息 - this.showError(error.message || this.tm('messages.copyError') || 'Failed to copy JSON'); + this.showError(error.message || this.tm('messages.downloadError') || '下载 JSON 文件失败'); } },