This commit is contained in:
神仙都没用 2024-07-01 16:32:16 +08:00
parent b84785f5e6
commit d110ad119b
7 changed files with 228 additions and 1331 deletions

1410
build/cool/eps.d.ts vendored

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,7 +1,7 @@
export const proxy = {
"/dev/": {
target: "http://127.0.0.1:8001",
// target: "http://192.168.0.112:8001",
// target: "http://127.0.0.1:8001",
target: "http://192.168.0.119:8001",
// target: "https://dev-admin.cool-js.cloud",
changeOrigin: true,
rewrite: (path: string) => path.replace(/^\/dev/, "")

View File

@ -21,7 +21,7 @@ import { useForm } from "@cool-vue/crud";
import { deepPaths } from "/@/cool/utils";
import { computed, onMounted } from "vue";
import { useMenu, useAi } from "../../hooks";
import type { EpsData } from "../../types";
import type { EpsColumn, EpsData } from "../../types";
const { service, mitt } = useCool();
const menu = useMenu();
@ -193,7 +193,15 @@ function open() {
// ai
if (data.isAi) {
await ai.matchType({ columns, name: data.name });
await ai
.invokeFlow("comm-parse-column", {
entity: JSON.stringify(columns)
})
.then((res) => {
columns.forEach((e: EpsColumn) => {
e.component = res.columns[e.propertyName] || "input";
});
});
}
menu.create({

View File

@ -1,5 +1,3 @@
import { request } from "../utils";
import type { EpsColumn } from "../types";
import { module } from "/@/cool";
import { useBase } from "/$/base";
@ -98,42 +96,7 @@ export function useAi() {
});
}
// 匹配组件类型
async function matchType({ columns, name }: { columns: EpsColumn[]; name: string }) {
return new Promise((resolve, reject) => {
const fields = columns.filter((e) => {
return !["id", "crateTime", "updateTime"].includes(e.propertyName);
});
request({
url: "/open/code/eps/matchType",
method: "POST",
data: {
fields: fields.map((e) => {
return {
type: e.type,
field: e.propertyName,
description: e.comment
};
}),
func: name
}
})
.then((res) => {
const names = res.split(",");
fields.forEach((e, i) => {
e.component = names[i];
});
resolve(fields);
})
.catch(reject);
});
}
return {
matchType,
invokeFlow
};
}

View File

@ -323,7 +323,7 @@ const form = reactive({
//
const step = reactive({
loading: false,
value: "coding",
value: "start",
list: ["start", "enter", "form", "coding"],
async next() {
@ -505,6 +505,8 @@ const code = reactive({
code.data.prefix = entityData.path;
code.data.fileName = entityData.fileName;
code.parseColumn();
code.tips("Service 代码生成中");
// service
@ -544,7 +546,7 @@ const code = reactive({
code.data.fieldEq = controllerData.fieldEq;
code.data.keyWordLikeFields = controllerData.keyWordLikeFields;
await code.createVue();
await code.createVue(false);
code.tips("编码完成");
@ -563,8 +565,48 @@ const code = reactive({
}
},
//
async parseColumn() {
const a = ai.invokeFlow("comm-parse-entity-column", {
entity: code.getContent("node-entity")
});
const b = ai.invokeFlow("comm-parse-column", {
entity: code.getContent("node-entity")
});
await Promise.all([a, b]).then((res) => {
if (res[0]?.columns) {
code.data.columns = res[0].columns.map((e: EpsColumn) => {
if (res[1]?.columns) {
e.component = res[1].columns[e.propertyName] || "input";
}
return e;
});
code.data.columns.push({
comment: "更新时间",
length: 0,
component: "datetime",
nullable: false,
propertyName: "updateTime",
type: "datetime"
});
code.data.columns.push({
comment: "创建时间",
length: 0,
component: "datetime",
nullable: false,
propertyName: "createTime",
type: "datetime"
});
}
});
},
// vue
async createVue() {
async createVue(isParse: boolean = true) {
const item = code.add("Vue 页面", "vue");
item.content = "";
@ -573,25 +615,10 @@ const code = reactive({
code.tips("Vue 代码开始生成");
code.tips("AI 分析中");
await ai
.invokeFlow("comm-parse-entity-column", {
entity: code.getContent("node-entity")
})
.then((res) => {
code.data.columns = res.columns || [];
});
await ai
.invokeFlow("comm-parse-column", {
entity: code.getContent("node-entity")
})
.then((res) => {
code.data.columns.forEach((e) => {
e.component = res[e.propertyName];
});
});
if (isParse) {
code.tips("AI 分析中");
await code.parseColumn();
}
//
item.content = menu.createVue({
@ -692,7 +719,11 @@ const code = reactive({
copy() {
copy(code.getContent(code.active)!);
ElMessage.success("复制成功");
code.save();
// 便
storage.set("ai-code.list", code.list);
storage.set("ai-code.data", code.data);
storage.set("ai-code.form", form);
},
//
@ -700,14 +731,6 @@ const code = reactive({
code.loading = true;
await code.createVue();
code.loading = false;
},
//
save() {
console.log(code);
storage.set("ai-code.list", code.list);
storage.set("ai-code.data", code.data);
storage.set("ai-code.form", form);
}
});
@ -932,6 +955,7 @@ function toBack() {
onMounted(() => {
desc.init();
//
if (step.value == "coding") {
code.list = storage.get("ai-code.list") || [];

View File

@ -31,14 +31,16 @@ export function useFormat() {
async provideDocumentFormattingEdits(model) {
let text = model.getValue();
const parser = options[i].parser;
try {
text = await prettier.format(text, {
parser: options[i].parser,
parser,
plugins: options[i].plugins,
semi: true,
printWidth: 100,
tabWidth: 4,
useTabs: true,
tabWidth: parser == "html" ? 4 : 2,
useTabs: parser == "html",
singleQuote: true,
trailingComma: "none"
});