From d1c012269112d9fac808a0e5f2cb57a58b9e1024 Mon Sep 17 00:00:00 2001 From: Sjshi763 Date: Sat, 17 Jan 2026 13:22:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E4=B8=BA=E7=9B=B4=E6=8E=A5=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../i18n/locales/en-US/features/persona.json | 1 + .../i18n/locales/zh-CN/features/persona.json | 1 + dashboard/src/views/PersonaPage.vue | 28 ++++++++++++++----- 3 files changed, 23 insertions(+), 7 deletions(-) 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 文件失败'); } },