This commit is contained in:
神仙 2024-06-27 22:31:30 +08:00
parent 2eea120fe8
commit 33e0159956
2 changed files with 300 additions and 1591 deletions

1772
build/cool/eps.d.ts vendored

File diff suppressed because it is too large Load Diff

View File

@ -5,7 +5,7 @@
<div class="b"></div> <div class="b"></div>
</div> </div>
<div class="back" @click="router.back"> <div class="back" @click="toBack">
<el-icon> <el-icon>
<back /> <back />
</el-icon> </el-icon>
@ -45,7 +45,7 @@
<loading /> <loading />
</el-icon> </el-icon>
<cl-svg class="icon" name="enter" v-else /> <cl-svg class="icon" name="enter" v-else @click="step.next" />
</div> </div>
<div <div
@ -218,7 +218,7 @@
<div class="tabs"> <div class="tabs">
<div <div
class="item" class="item"
v-for="(item, index) in code.tabs" v-for="(item, index) in code.list"
:key="index" :key="index"
:class="{ :class="{
active: code.active == item.value active: code.active == item.value
@ -232,7 +232,7 @@
{{ item.label }} {{ item.label }}
</div> </div>
<div class="op" v-if="!isEmpty(code.tabs) && !code.loading"> <div class="op" v-if="!isEmpty(code.list) && !code.loading">
<el-tooltip content="创建文件"> <el-tooltip content="创建文件">
<el-icon @click="createFile"> <el-icon @click="createFile">
<download /> <download />
@ -244,15 +244,15 @@
<div class="code"> <div class="code">
<cl-editor-monaco <cl-editor-monaco
:ref="setRefs('editor')" :ref="setRefs('editor')"
v-model="codeData.content" v-model="activeCode.content"
height="100%" height="100%"
:border="false" :border="false"
:options="{ :options="{
theme: 'ai-code--dark' theme: 'ai-code--dark'
}" }"
:key="codeData.value" :key="activeCode.value"
:language="codeData.value == 'vue' ? 'html' : 'typescript'" :language="activeCode.value == 'vue' ? 'html' : 'typescript'"
v-if="codeData" v-if="activeCode"
/> />
</div> </div>
@ -295,7 +295,7 @@ import {
CirclePlusFilled, CirclePlusFilled,
QuestionFilled QuestionFilled
} from "@element-plus/icons-vue"; } from "@element-plus/icons-vue";
import { ElLoading, ElMessage } from "element-plus"; import { ElMessage, ElMessageBox } from "element-plus";
import { assign, isEmpty } from "lodash-es"; import { assign, isEmpty } from "lodash-es";
import { useMenu, useAi } from "../hooks"; import { useMenu, useAi } from "../hooks";
import { isDev } from "/@/config"; import { isDev } from "/@/config";
@ -323,7 +323,7 @@ monaco.editor.defineTheme("ai-code--dark", {
// //
const form = reactive({ const form = reactive({
entity: "收货地址", entity: "",
module: "user", module: "user",
other: "", other: "",
column: "用户ID、用户名、收货人、手机号、收货地址、是否默认" column: "用户ID、用户名、收货人、手机号、收货地址、是否默认"
@ -358,6 +358,11 @@ const step = reactive({
break; break;
case "form": case "form":
if (!form.entity) {
step.loading = false;
return false;
}
await code.getColumns(); await code.getColumns();
break; break;
} }
@ -378,11 +383,23 @@ const step = reactive({
} }
}); });
interface CodeItem {
label: string;
value: string;
content: string;
[key: string]: any;
}
// //
const code = reactive({ const code = reactive({
tabs: [] as { label: string; value: string; content: string }[],
active: "", active: "",
//
list: [] as CodeItem[],
//
data: {} as any,
// //
logs: [] as any[], logs: [] as any[],
@ -402,7 +419,7 @@ const code = reactive({
// //
clear() { clear() {
code.tabs = []; code.list = [];
code.logs = []; code.logs = [];
}, },
@ -495,7 +512,9 @@ const code = reactive({
// vue // vue
async createVue() { async createVue() {
const data = { const item = code.add("Vue 页面", "vue");
code.data = {
...form, ...form,
router: "", router: "",
prefix: "", prefix: "",
@ -533,8 +552,6 @@ const code = reactive({
] ]
}; };
const item = code.add("Vue 页面", "vue");
code.tips("Vue 代码生成中"); code.tips("Vue 代码生成中");
// //
@ -544,19 +561,19 @@ const code = reactive({
entity: code.getContent("node-entity") entity: code.getContent("node-entity")
}) })
.then((res) => { .then((res) => {
assign(data, res); assign(code.data, res);
data.router = res.path.replace("/admin", ""); code.data.router = res.path.replace("/admin", "");
data.prefix = res.path; code.data.prefix = res.path;
}); });
code.tips("AI 字段分析中"); code.tips("AI 字段分析中");
// ai // ai
await ai.matchType({ columns: data.columns, name: form.entity }); await ai.matchType({ columns: code.data.columns, name: form.entity });
// //
item.content = menu.createVue(data); item.content = menu.createVue(code.data);
code.tips("Vue 生成成功"); code.tips("Vue 生成成功");
@ -568,7 +585,7 @@ const code = reactive({
// tab // tab
add(label: string, flow: string) { add(label: string, flow: string) {
const item = reactive({ const item = reactive<CodeItem>({
label, label,
value: flow, value: flow,
content: "", content: "",
@ -576,14 +593,19 @@ const code = reactive({
}); });
code.active = flow; code.active = flow;
code.tabs.push(item); code.list.push(item);
return item; return item;
}, },
//
get(value: string) {
return code.list.find((e) => e.value == value)!;
},
// //
getContent(value: string) { getContent(value: string) {
return code.tabs.find((e) => e.value == value)?.content; return code.list.find((e) => e.value == value)?.content;
}, },
// //
@ -633,8 +655,8 @@ const code = reactive({
} }
}); });
const codeData = computed(() => { const activeCode = computed(() => {
return code.tabs.find((e) => e.value == code.active); return code.list.find((e) => e.value == code.active);
}); });
// //
@ -787,27 +809,30 @@ function createFile() {
}, },
on: { on: {
submit(data, { close, done }) { submit(data, { close, done }) {
const loader = ElLoading.service({ code.tips("创建 Vue 文件中,过程可能会发生页面及服务重启");
text: "创建文件中,过程可能会发生页面及服务重启"
});
// //
menu.create({ menu.create({
code: codes.vue, code: code.getContent("vue"),
...temp.data, ...code.data,
...data ...data
}) })
.then((create) => { .then((create) => {
code.tips("创建后端文件中");
// //
service.base.sys.menu.create({ service.base.sys.menu.create({
...form, ...form,
...temp.data, ...code.data,
controller: codes.controller, controller: code.getContent("node-controller"),
entity: codes.entity entity: code.getContent("node-entity"),
service: code.getContent("node-service")
}); });
// 3s // 3s
const timer = setInterval(() => { const timer = setInterval(() => {
code.tips("检测服务中");
service service
.request({ .request({
url: "/" url: "/"
@ -815,14 +840,12 @@ function createFile() {
.then(() => { .then(() => {
ElMessage.success("文件创建成功"); ElMessage.success("文件创建成功");
clearInterval(timer); clearInterval(timer);
loader.close();
close(); close();
create(); create();
}); });
}, 3000); }, 3000);
}) })
.catch(() => { .catch(() => {
loader.close();
done(); done();
}); });
} }
@ -835,6 +858,17 @@ function toDoc() {
window.open("https://cool-js.com/"); window.open("https://cool-js.com/");
} }
//
function toBack() {
ElMessageBox.confirm("确定要返回吗?", "提示", {
type: "warning"
})
.then(() => {
router.back();
})
.catch(() => {});
}
onMounted(() => { onMounted(() => {
desc.init(); desc.init();
}); });
@ -918,7 +952,7 @@ $color: #41d1ff;
padding: 6px 13px 6px 10px; padding: 6px 13px 6px 10px;
cursor: pointer; cursor: pointer;
transition: all 0.2s; transition: all 0.2s;
font-size: 14px; font-size: 12px;
.el-icon { .el-icon {
font-size: 16px; font-size: 16px;
@ -1069,10 +1103,16 @@ $color: #41d1ff;
.el-button { .el-button {
height: 40px; height: 40px;
background-color: #fff; background-color: #fff;
border-radius: 8px;
} }
.go { .go {
width: 140px; width: 140px;
.el-icon {
margin-left: 5px;
color: #444;
}
} }
.doc { .doc {
@ -1109,8 +1149,13 @@ $color: #41d1ff;
.icon { .icon {
position: absolute; position: absolute;
right: 18px; right: 18px;
color: #fff; color: #ccc;
font-size: 18px; font-size: 18px;
cursor: pointer;
&:hover {
color: #fff;
}
} }
} }