This commit is contained in:
神仙都没用 2024-07-13 18:14:11 +08:00
parent 8323a4f8ba
commit 27e1db40bd
2 changed files with 160 additions and 38 deletions

View File

@ -148,7 +148,7 @@
<el-input v-model="form.column" maxlength="200" placeholder="请输入" /> <el-input v-model="form.column" maxlength="200" placeholder="请输入" />
</div> </div>
<div class="row"> <div class="row" v-if="lang.value == 'Node'">
<div class="label"> <div class="label">
其他你想做的事 其他你想做的事
@ -238,7 +238,7 @@
theme: 'ai-code--dark' theme: 'ai-code--dark'
}" }"
:key="activeCode.value" :key="activeCode.value"
:language="activeCode.value == 'vue' ? 'html' : 'typescript'" :language="activeCode.value == 'vue' ? 'html' : lang.tpl"
v-if="activeCode" v-if="activeCode"
/> />
</div> </div>
@ -375,9 +375,30 @@ const step = reactive({
} }
}); });
//
const lang = reactive({
value: "Node" as "Node" | "Java" | "Go" | "Python",
async get() {
lang.value = await service.base.comm.program();
code.active = lang.value.toLocaleLowerCase() + "-entity";
},
get tpl() {
const d = {
Node: "typescript",
Java: "java",
Go: "go",
Python: "python"
};
return d[lang.value];
}
});
// //
const code = reactive({ const code = reactive({
active: "node-entity", active: "",
// //
list: [] as CodeItem[], list: [] as CodeItem[],
@ -459,32 +480,8 @@ const code = reactive({
}); });
}, },
// // Node
async create() { async createNode() {
if (!form.entity) {
return ElMessage.warning("请填写实体名称");
}
if (!form.module) {
return ElMessage.warning("请填写模块");
}
if (!form.column) {
return ElMessage.warning("请填写字段");
}
code.loading = true;
//
code.clear();
//
step.next();
code.tips("AI 开始编码");
await sleep(300);
code.tips("Entity 代码生成中"); code.tips("Entity 代码生成中");
// entity // entity
@ -537,6 +534,7 @@ const code = reactive({
// controller // controller
const controllerData = await ai.invokeFlow("comm-parse-controller", { const controllerData = await ai.invokeFlow("comm-parse-controller", {
entity,
controller controller
}); });
@ -544,6 +542,115 @@ const code = reactive({
code.data.fieldEq = controllerData.fieldEq; code.data.fieldEq = controllerData.fieldEq;
code.data.keyWordLikeFields = controllerData.keyWordLikeFields; code.data.keyWordLikeFields = controllerData.keyWordLikeFields;
},
// Java
async createJava() {
code.tips("Entity 代码生成中");
// entity
const entity = await code.setContent("Entity 实体", "java-entity");
code.tips("Entity 生成成功,开始解析");
// entity
const entityData = await ai.invokeFlow("comm-parse-entity", {
entity,
module: form.module
});
code.tips(`Entity 解析成功,${JSON.stringify(entityData)}`);
code.data.router = entityData.path.replace("/admin", "");
code.data.prefix = entityData.path;
code.data.fileName = entityData.fileName;
code.parseColumn();
code.tips("Mapper 代码生成中");
// mapper
await code.setContent("Mapper 映射", "java-mapper", {
...entityData,
entity
});
code.tips("Mapper 生成成功");
code.tips("Service 代码生成中");
// service
const _service = await code.setContent("Service 接口类", "java-service", {
...entityData,
entity
});
// service
const service = await code.setContent("Service 实现类", "java-service-impl", {
...entityData,
entity,
service: _service
});
code.tips("Service 生成成功,开始解析");
// service
const serviceData = await ai.invokeFlow("comm-parse-service", {
service
});
code.tips(`Service 解析成功,${JSON.stringify(serviceData)}`);
code.tips("Controller 代码生成中");
// controller
const controller = await code.setContent("Controller 控制器", "java-controller", {
...serviceData,
...entityData,
service,
entity
});
code.tips("Controller 生成成功,开始解析");
// controller
const controllerData = await ai.invokeFlow("comm-parse-controller", {
controller
});
code.tips(`Controller 解析成功,${JSON.stringify(controllerData)}`);
code.data.fieldEq = controllerData.fieldEq;
code.data.keyWordLikeFields = controllerData.keyWordLikeFields;
},
//
async create() {
if (!form.entity) {
return ElMessage.warning("请填写实体名称");
}
if (!form.module) {
return ElMessage.warning("请填写模块");
}
if (!form.column) {
return ElMessage.warning("请填写字段");
}
code.loading = true;
//
code.clear();
//
step.next();
code.tips("AI 开始编码");
await sleep(300);
await code[`create${lang.value}`]();
await code.createVue(false); await code.createVue(false);
@ -567,11 +674,11 @@ const code = reactive({
// //
async parseColumn() { async parseColumn() {
const a = ai.invokeFlow("comm-parse-entity-column", { const a = ai.invokeFlow("comm-parse-entity-column", {
entity: code.getContent("node-entity") entity: code.getContent(`${lang.value}-entity`)
}); });
const b = ai.invokeFlow("comm-parse-column", { const b = ai.invokeFlow("comm-parse-column", {
entity: code.getContent("node-entity") entity: code.getContent(`${lang.value}-entity`)
}); });
await Promise.all([a, b]).then((res) => { await Promise.all([a, b]).then((res) => {
@ -660,7 +767,9 @@ const code = reactive({
// //
getContent(value: string) { getContent(value: string) {
return code.list.find((e) => e.value == value)?.content; return code.list.find(
(e) => e.value == value || e.value.toLocaleLowerCase() == value.toLocaleLowerCase()
)?.content;
}, },
// //
@ -680,9 +789,9 @@ const code = reactive({
if (!res.isEnd) { if (!res.isEnd) {
content += res.content; content += res.content;
if (content.indexOf("```typescript\n") == 0) { if (content.indexOf(`\`\`\`${lang.tpl}\n`) == 0) {
item._content = content item._content = content
.replace(/^```typescript\n/g, "") .replace(new RegExp(`^\\\`\\\`\\\`${lang.tpl}\\n`, "g"), "")
.replace(/```$/, ""); .replace(/```$/, "");
} }
} }
@ -902,13 +1011,23 @@ function createFile() {
name: form.entity name: form.entity
}) })
.then((create) => { .then((create) => {
const files = {};
//
code.list.forEach((e) => {
const i = e.value.indexOf("-");
let k = e.value;
if (i >= 0) {
k = k.substring(i + 1, k.length);
files[k] = code.getContent(e.value);
}
});
// //
service.base.sys.menu.create({ service.base.sys.menu.create({
...form, ...form,
...code.data, ...code.data,
controller: code.getContent("node-controller"), ...files
entity: code.getContent("node-entity"),
service: code.getContent("node-service")
}); });
// 3s // 3s
@ -952,6 +1071,7 @@ function toBack() {
} }
onMounted(() => { onMounted(() => {
lang.get();
desc.init(); desc.init();
// //

View File

@ -29,6 +29,7 @@
placeholder="搜索关键字" placeholder="搜索关键字"
v-model="keyWord" v-model="keyWord"
clearable clearable
:prefix-icon="Search"
@change=" @change="
refresh({ refresh({
page: 1 page: 1
@ -161,7 +162,8 @@ import {
ArrowRight, ArrowRight,
ArrowRightBold, ArrowRightBold,
Refresh as IconRefresh, Refresh as IconRefresh,
Plus Plus,
Search
} from "@element-plus/icons-vue"; } from "@element-plus/icons-vue";
import { useBrowser, useCool } from "/@/cool"; import { useBrowser, useCool } from "/@/cool";
import { ContextMenu, useForm } from "@cool-vue/crud"; import { ContextMenu, useForm } from "@cool-vue/crud";