|
37 | 37 | ></el-button> |
38 | 38 | <el-button type="success" @click="openImportDialog" :icon="Upload"> |
39 | 39 | </el-button> |
| 40 | + <el-button type="warning" @click="openAiDialog">AI</el-button> |
40 | 41 | <el-button type="primary" @click="openDrawer" :icon="Plus"> |
41 | 42 | </el-button> |
42 | 43 | </div> |
|
264 | 265 |
|
265 | 266 | </div> |
266 | 267 | </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> |
267 | 292 | </div> |
268 | 293 | </template> |
269 | 294 |
|
|
277 | 302 | exportSysDictionary, |
278 | 303 | importSysDictionary |
279 | 304 | } from '@/api/sysDictionary' // 此处请自行替换地址 |
| 305 | + import { butler } from '@/api/autoCode' |
280 | 306 | import WarningBar from '@/components/warningBar/warningBar.vue' |
281 | 307 | import { ref, computed, watch } from 'vue' |
282 | 308 | import { ElMessage, ElMessageBox } from 'element-plus' |
|
338 | 364 | const isDragging = ref(false) |
339 | 365 | const fileInputRef = ref(null) |
340 | 366 |
|
| 367 | + // AI 相关 |
| 368 | + const aiDialogVisible = ref(false) |
| 369 | + const aiPrompt = ref('') |
| 370 | + const aiGenerating = ref(false) |
| 371 | +
|
341 | 372 | // 监听JSON文本变化,实时预览 |
342 | 373 | watch(importJsonText, (newVal) => { |
343 | 374 | if (!newVal.trim()) { |
|
627 | 658 | importing.value = false |
628 | 659 | } |
629 | 660 | } |
| 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 | + } |
630 | 711 | </script> |
631 | 712 |
|
632 | 713 | <style scoped> |
|
0 commit comments