From 3722a8e7f3ab157146d1c79e46db846b8049e564 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?piexlMax=28=E5=A5=87=E6=B7=BC?= Date: Thu, 27 Nov 2025 14:43:50 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0AI=E7=94=9F=E6=88=90?= =?UTF-8?q?=E5=AD=97=E5=85=B8=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=BE=93=E5=85=A5=E6=8F=8F=E8=BF=B0=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=AD=97=E5=85=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/src/api/autoCode.js | 1 - .../superAdmin/dictionary/sysDictionary.vue | 81 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) diff --git a/web/src/api/autoCode.js b/web/src/api/autoCode.js index cb3443f1d..1ee16fcd1 100644 --- a/web/src/api/autoCode.js +++ b/web/src/api/autoCode.js @@ -162,7 +162,6 @@ export const butler = (data) => { }) } - export const eye = (data) => { return service({ url: '/autoCode/llmAuto', diff --git a/web/src/view/superAdmin/dictionary/sysDictionary.vue b/web/src/view/superAdmin/dictionary/sysDictionary.vue index 7c1bd8a4a..9fb2b339e 100644 --- a/web/src/view/superAdmin/dictionary/sysDictionary.vue +++ b/web/src/view/superAdmin/dictionary/sysDictionary.vue @@ -37,6 +37,7 @@ > + AI @@ -264,6 +265,30 @@ + + + + + + @@ -277,6 +302,7 @@ exportSysDictionary, importSysDictionary } from '@/api/sysDictionary' // 此处请自行替换地址 + import { butler } from '@/api/autoCode' import WarningBar from '@/components/warningBar/warningBar.vue' import { ref, computed, watch } from 'vue' import { ElMessage, ElMessageBox } from 'element-plus' @@ -338,6 +364,11 @@ const isDragging = ref(false) const fileInputRef = ref(null) + // AI 相关 + const aiDialogVisible = ref(false) + const aiPrompt = ref('') + const aiGenerating = ref(false) + // 监听JSON文本变化,实时预览 watch(importJsonText, (newVal) => { if (!newVal.trim()) { @@ -627,6 +658,56 @@ importing.value = false } } + + // 打开 AI 对话框 + const openAiDialog = () => { + aiDialogVisible.value = true + aiPrompt.value = '' + } + + // 关闭 AI 对话框 + const closeAiDialog = () => { + aiDialogVisible.value = false + aiPrompt.value = '' + } + + // 处理 AI 生成 + const handleAiGenerate = async () => { + if (!aiPrompt.value.trim()) { + ElMessage.warning('请输入描述内容') + return + } + try { + aiGenerating.value = true + const aiRes = await butler({ + prompt: aiPrompt.value, + command: 'dict' + }) + if (aiRes && aiRes.code === 0) { + ElMessage.success('AI 生成成功') + try { + // 将 AI 返回的数据填充到导入文本框(支持字符串或对象) + if (typeof aiRes.data === 'string') { + importJsonText.value = aiRes.data + } else { + importJsonText.value = JSON.stringify(aiRes.data, null, 2) + } + // 清除可能的解析错误并打开导入抽屉 + jsonPreviewError.value = '' + importDrawerVisible.value = true + closeAiDialog() + } catch (e) { + ElMessage.error('处理 AI 返回结果失败: ' + (e.message || e)) + } + } else { + ElMessage.error(aiRes.msg || 'AI 生成失败') + } + } catch (err) { + ElMessage.error('AI 调用失败: ' + (err.message || err)) + } finally { + aiGenerating.value = false + } + }