feat: 增加AI生成字典功能,支持用户输入描述生成字典

This commit is contained in:
piexlMax(奇淼 2025-11-27 14:43:50 +08:00
parent b86f7412d1
commit 3722a8e7f3
2 changed files with 81 additions and 1 deletions

View File

@ -162,7 +162,6 @@ export const butler = (data) => {
})
}
export const eye = (data) => {
return service({
url: '/autoCode/llmAuto',

View File

@ -37,6 +37,7 @@
></el-button>
<el-button type="success" @click="openImportDialog" :icon="Upload">
</el-button>
<el-button type="warning" @click="openAiDialog">AI</el-button>
<el-button type="primary" @click="openDrawer" :icon="Plus">
</el-button>
</div>
@ -264,6 +265,30 @@
</div>
</el-drawer>
<!-- AI 对话框 -->
<el-dialog
v-model="aiDialogVisible"
title="AI 生成字典"
width="520px"
:before-close="closeAiDialog"
>
<el-input
v-model="aiPrompt"
type="textarea"
:rows="6"
placeholder="请输入生成字典的描述,例如:生成一个用户状态字典(启用/禁用)"
@keydown.ctrl.enter="handleAiGenerate"
/>
<template #footer>
<div class="dialog-footer">
<el-button @click="closeAiDialog"> </el-button>
<el-button type="primary" @click="handleAiGenerate" :loading="aiGenerating">
</el-button>
</div>
</template>
</el-dialog>
</div>
</template>
@ -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
}
}
</script>
<style scoped>