Skip to content

Commit 3722a8e

Browse files
author
piexlMax(奇淼
committed
feat: 增加AI生成字典功能,支持用户输入描述生成字典
1 parent b86f741 commit 3722a8e

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

web/src/api/autoCode.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@ export const butler = (data) => {
162162
})
163163
}
164164

165-
166165
export const eye = (data) => {
167166
return service({
168167
url: '/autoCode/llmAuto',

web/src/view/superAdmin/dictionary/sysDictionary.vue

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
></el-button>
3838
<el-button type="success" @click="openImportDialog" :icon="Upload">
3939
</el-button>
40+
<el-button type="warning" @click="openAiDialog">AI</el-button>
4041
<el-button type="primary" @click="openDrawer" :icon="Plus">
4142
</el-button>
4243
</div>
@@ -264,6 +265,30 @@
264265

265266
</div>
266267
</el-drawer>
268+
269+
<!-- AI 对话框 -->
270+
<el-dialog
271+
v-model="aiDialogVisible"
272+
title="AI 生成字典"
273+
width="520px"
274+
:before-close="closeAiDialog"
275+
>
276+
<el-input
277+
v-model="aiPrompt"
278+
type="textarea"
279+
:rows="6"
280+
placeholder="请输入生成字典的描述,例如:生成一个用户状态字典(启用/禁用)"
281+
@keydown.ctrl.enter="handleAiGenerate"
282+
/>
283+
<template #footer>
284+
<div class="dialog-footer">
285+
<el-button @click="closeAiDialog">取 消</el-button>
286+
<el-button type="primary" @click="handleAiGenerate" :loading="aiGenerating">
287+
确 定
288+
</el-button>
289+
</div>
290+
</template>
291+
</el-dialog>
267292
</div>
268293
</template>
269294

@@ -277,6 +302,7 @@
277302
exportSysDictionary,
278303
importSysDictionary
279304
} from '@/api/sysDictionary' // 此处请自行替换地址
305+
import { butler } from '@/api/autoCode'
280306
import WarningBar from '@/components/warningBar/warningBar.vue'
281307
import { ref, computed, watch } from 'vue'
282308
import { ElMessage, ElMessageBox } from 'element-plus'
@@ -338,6 +364,11 @@
338364
const isDragging = ref(false)
339365
const fileInputRef = ref(null)
340366
367+
// AI 相关
368+
const aiDialogVisible = ref(false)
369+
const aiPrompt = ref('')
370+
const aiGenerating = ref(false)
371+
341372
// 监听JSON文本变化,实时预览
342373
watch(importJsonText, (newVal) => {
343374
if (!newVal.trim()) {
@@ -627,6 +658,56 @@
627658
importing.value = false
628659
}
629660
}
661+
662+
// 打开 AI 对话框
663+
const openAiDialog = () => {
664+
aiDialogVisible.value = true
665+
aiPrompt.value = ''
666+
}
667+
668+
// 关闭 AI 对话框
669+
const closeAiDialog = () => {
670+
aiDialogVisible.value = false
671+
aiPrompt.value = ''
672+
}
673+
674+
// 处理 AI 生成
675+
const handleAiGenerate = async () => {
676+
if (!aiPrompt.value.trim()) {
677+
ElMessage.warning('请输入描述内容')
678+
return
679+
}
680+
try {
681+
aiGenerating.value = true
682+
const aiRes = await butler({
683+
prompt: aiPrompt.value,
684+
command: 'dict'
685+
})
686+
if (aiRes && aiRes.code === 0) {
687+
ElMessage.success('AI 生成成功')
688+
try {
689+
// 将 AI 返回的数据填充到导入文本框(支持字符串或对象)
690+
if (typeof aiRes.data === 'string') {
691+
importJsonText.value = aiRes.data
692+
} else {
693+
importJsonText.value = JSON.stringify(aiRes.data, null, 2)
694+
}
695+
// 清除可能的解析错误并打开导入抽屉
696+
jsonPreviewError.value = ''
697+
importDrawerVisible.value = true
698+
closeAiDialog()
699+
} catch (e) {
700+
ElMessage.error('处理 AI 返回结果失败: ' + (e.message || e))
701+
}
702+
} else {
703+
ElMessage.error(aiRes.msg || 'AI 生成失败')
704+
}
705+
} catch (err) {
706+
ElMessage.error('AI 调用失败: ' + (err.message || err))
707+
} finally {
708+
aiGenerating.value = false
709+
}
710+
}
630711
</script>
631712
632713
<style scoped>

0 commit comments

Comments
 (0)