From 59e5a6fd8371ff62cd0bce7ce8d04bb4f6e705c1 Mon Sep 17 00:00:00 2001 From: Sjshi763 Date: Sat, 17 Jan 2026 13:03:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=85=A5=EF=BC=88dev?= 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 | 56 ++++++++++++++++++- 3 files changed, 57 insertions(+), 1 deletion(-) diff --git a/dashboard/src/i18n/locales/en-US/features/persona.json b/dashboard/src/i18n/locales/en-US/features/persona.json index c9ba4453f..d83dc4463 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", + "import": "Import", "cancel": "Cancel", "save": "Save", "addDialogPair": "Add Dialog Pair" diff --git a/dashboard/src/i18n/locales/zh-CN/features/persona.json b/dashboard/src/i18n/locales/zh-CN/features/persona.json index 7c45a237d..a351cafef 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", + "import": "导入", "cancel": "取消", "save": "保存", "addDialogPair": "添加对话对" diff --git a/dashboard/src/views/PersonaPage.vue b/dashboard/src/views/PersonaPage.vue index 9d87f4317..a4f03a1bd 100644 --- a/dashboard/src/views/PersonaPage.vue +++ b/dashboard/src/views/PersonaPage.vue @@ -11,11 +11,16 @@ {{ tm('page.description') }}

-
+
+ + {{ tm('buttons.import') || '导入' }} + {{ tm('buttons.create') }} +
@@ -300,6 +305,55 @@ export default { // 显示错误消息 this.showError(error.message || this.tm('messages.copyError') || 'Failed to copy JSON'); } + }, + + triggerImport() { + this.$refs.importInput.click(); + }, + + async handleImport(event) { + const file = event.target.files[0]; + if (!file) return; + + try { + const text = await file.text(); + const parsedData = JSON.parse(text); + + // 验证必需字段 + if (!parsedData.persona_id || !parsedData.system_prompt) { + this.showError('人格 JSON 缺少必需字段喵!'); + event.target.value = ''; + return; + } + + // 检查重复 ID + const id = parsedData.persona_id; + const exists = this.personas.some(persona => persona.persona_id === id); + if (exists) { + this.showError('人格 ID [' + id + '] 已存在喵!'); + event.target.value = ''; + return; + } + + // 调用 API 保存 + const response = await axios.post('/api/persona/save', parsedData); + + if (response.data.status === 'ok') { + this.showSuccess(response.data.message || '导入成功喵!'); + await this.loadPersonas(); + } else { + this.showError(response.data.message || '导入失败喵!'); + } + } catch (error) { + if (error instanceof SyntaxError) { + this.showError('JSON 格式错误喵!'); + } else { + this.showError(error.response?.data?.message || '导入失败喵!'); + } + } + + // 清理文件输入 + event.target.value = ''; } } }