This commit is contained in:
神仙都没用 2024-06-28 14:25:48 +08:00
parent 02fa9f7f44
commit 5a77ce7f12
5 changed files with 3490 additions and 3977 deletions

1529
build/cool/eps.d.ts vendored

File diff suppressed because it is too large Load Diff

View File

@ -9,7 +9,7 @@
"lint:eslint": "eslint \"./src/**/*.{vue,ts,tsx}\" --fix"
},
"dependencies": {
"@cool-vue/crud": "^7.1.18",
"@cool-vue/crud": "^7.1.23",
"@element-plus/icons-vue": "^2.3.1",
"@vueuse/core": "^10.4.0",
"@wangeditor/editor": "^5.1.23",

File diff suppressed because it is too large Load Diff

View File

@ -308,61 +308,61 @@ export function useCode() {
// 代码模板
return `<template>
<cl-crud ref="Crud">
<cl-row>
<!-- -->
<cl-refresh-btn />
${perms.add ? "<!-- 新增按钮 -->\n<cl-add-btn />" : ""}
${perms.del ? "<!-- 删除按钮 -->\n<cl-multi-delete-btn />" : ""}
${clFilter}
<cl-flex1 />
<!-- -->
<cl-search-key placeholder="搜索${clSearchKeyPlaceholder || "关键字"}" />
</cl-row>
<cl-crud ref="Crud">
<cl-row>
<!-- -->
<cl-refresh-btn />
${perms.add ? "<!-- 新增按钮 -->\n <cl-add-btn />" : ""}
${perms.del ? "<!-- 删除按钮 -->\n <cl-multi-delete-btn />" : ""}
${clFilter}
<cl-flex1 />
<!-- -->
<cl-search-key placeholder="搜索${clSearchKeyPlaceholder || "关键字"}" />
</cl-row>
<cl-row>
<!-- -->
<cl-table ref="Table" />
</cl-row>
<cl-row>
<!-- -->
<cl-table ref="Table" />
</cl-row>
<cl-row>
<cl-flex1 />
<!-- -->
<cl-pagination />
</cl-row>
<cl-row>
<cl-flex1 />
<!-- -->
<cl-pagination />
</cl-row>
<!-- -->
<cl-upsert ref="Upsert" />
</cl-crud>
</template>
<!-- -->
<cl-upsert ref="Upsert" />
</cl-crud>
</template>
<script lang="ts" name="${router.replace(/^\//, "").replace(/\//g, "-")}" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";
<script lang="ts" name="${router.replace(/^\//, "").replace(/\//g, "-")}" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";
const { service } = useCool();
const { service } = useCool();
// cl-upsert
const Upsert = useUpsert(${toCodeString(upsert)});
// cl-upsert
const Upsert = useUpsert(${toCodeString(upsert)});
// cl-table
const Table = useTable(${toCodeString(table)});
// cl-table
const Table = useTable(${toCodeString(table)});
// cl-crud
const Crud = useCrud(
{
service: ${service.join(".")}
},
(app) => {
app.refresh();
}
);
// cl-crud
const Crud = useCrud(
{
service: ${service.join(".")}
},
(app) => {
app.refresh();
}
);
// 刷新
function refresh(params?: any) {
Crud.value?.refresh(params);
}
</script>`;
// 刷新
function refresh(params?: any) {
Crud.value?.refresh(params);
}
</script>`;
}
// 转成代码字符串

View File

@ -182,9 +182,7 @@
<span
@click="
() => {
if (!code.loading) {
step.prev();
}
step.prev();
}
"
></span>
@ -212,9 +210,15 @@
</div>
<div class="op" v-if="!isEmpty(code.list) && !code.loading">
<el-tooltip content="重新生成" v-if="code.active == 'vue'">
<el-icon @click="code.refresh()">
<refresh />
</el-icon>
</el-tooltip>
<el-tooltip content="复制代码">
<el-icon @click="code.copy()">
<copy-document />
<document-copy />
</el-icon>
</el-tooltip>
@ -277,8 +281,9 @@ import {
Back,
ArrowRightBold,
Loading,
CopyDocument,
QuestionFilled
DocumentCopy,
QuestionFilled,
Refresh
} from "@element-plus/icons-vue";
import { ElMessage, ElMessageBox } from "element-plus";
import { assign, isEmpty } from "lodash-es";
@ -320,7 +325,7 @@ const form = reactive({
//
const step = reactive({
loading: false,
value: "start",
value: "coding",
list: ["start", "enter", "form", "coding"],
async next() {
@ -373,7 +378,7 @@ const step = reactive({
//
const code = reactive({
active: "",
active: "node-entity",
//
list: (storage.get("ai-code.list") || []) as CodeItem[],
@ -464,7 +469,8 @@ const code = reactive({
// service
const service = await code.setContent("Service 服务层", "node-service", {
...entityData
...entityData,
entity
});
code.tips("Service 生成成功,开始解析");
@ -509,6 +515,8 @@ const code = reactive({
async createVue() {
const item = code.add("Vue 页面", "vue");
item.content = "";
code.data = {
router: "",
prefix: "",
@ -555,13 +563,13 @@ const code = reactive({
entity: code.getContent("node-entity")
})
.then((res) => {
assign(code.data, res);
res.router = res.path.replace("/admin", "");
res.prefix = res.path;
code.data.router = res.path.replace("/admin", "");
code.data.prefix = res.path;
assign(code.data, res);
});
code.tips("AI 字段分析中");
code.tips("AI 分析字段中");
// ai
await ai.matchType({ columns: code.data.columns, name: form.entity });
@ -569,25 +577,30 @@ const code = reactive({
//
item.content = menu.createVue(code.data);
code.tips("Vue 生成成功");
await sleep(300);
//
refs.editor.formatCode();
code.tips("Vue 生成成功");
},
// tab
add(label: string, flow: string) {
const item = reactive<CodeItem>({
label,
value: flow,
content: "",
_content: ""
});
let item = code.list.find((e) => e.value == flow);
if (!item) {
item = reactive<CodeItem>({
label,
value: flow,
content: "",
_content: ""
});
code.list.push(item);
}
code.active = flow;
code.list.push(item);
return item;
},
@ -628,6 +641,11 @@ const code = reactive({
});
const timer = setInterval(() => {
if (step.value != "coding") {
clearInterval(timer);
return;
}
const v = item._content[item.content.length] || "";
if (isEnd) {
@ -642,18 +660,27 @@ const code = reactive({
//
if (flow == code.active) {
refs.editor.revealLine(99999);
refs.editor?.revealLine(99999);
}
}, 10);
});
},
//
copy() {
copy(code.getContent(code.active)!);
code.save();
ElMessage.success("复制成功");
},
//
async refresh() {
code.loading = true;
await code.createVue();
code.loading = false;
},
//
save() {
storage.set("ai-code.list", code.list);
storage.set("ai-code.data", code.data);
@ -1301,11 +1328,9 @@ $color: #41d1ff;
height: 100vh;
width: 100%;
animation: coding 0.3s forwards;
border-top: 5px solid rgba(255, 255, 255, 0.1);
box-sizing: border-box;
opacity: 0;
z-index: 10;
transform: translateY(10vh);
.editor {
height: 100%;
@ -1363,7 +1388,7 @@ $color: #41d1ff;
height: 30px;
width: 30px;
color: #fff;
font-size: 18px;
font-size: 15px;
cursor: pointer;
border-radius: 5px;
@ -1382,6 +1407,7 @@ $color: #41d1ff;
height: 150px;
padding: 5px 0;
box-sizing: border-box;
border-top: 1px solid #2f3447;
.item {
font-size: 12px;