优化ai编码字典生成

This commit is contained in:
神仙都没用 2024-07-20 16:08:54 +08:00
parent b472769132
commit a975a1d91a
4 changed files with 60 additions and 25 deletions

View File

@ -1,4 +1,4 @@
import { App } from "vue";
import type { App } from "vue";
import { useComponent } from "./components";
import { useProvide } from "./provide";
import global from "./utils/global";

View File

@ -1,4 +1,4 @@
import { App, reactive } from "vue";
import { type App, reactive } from "vue";
import { mitt } from "./utils/mitt";
import { emitter } from "./emitter";
import { locale } from "./locale";

View File

@ -1,4 +1,4 @@
import { isFunction, isRegExp, isString } from "lodash-es";
import { isEmpty, isFunction, isRegExp, isString } from "lodash-es";
import { PropRules } from "../dict";
import type { EpsColumn, EpsModule } from "../types";
@ -10,7 +10,7 @@ export function useCode() {
const [label, ...arr] = comment.split(" ");
// 选项列表
const list = arr.map((e) => {
const list: any[] = arr.map((e) => {
const [value, label] = e.split("-");
return {
@ -19,6 +19,17 @@ export function useCode() {
};
});
// boolean
if (list.length == 2) {
list.forEach((e) => {
if (e.value == 1) {
e.type = "success";
} else {
e.type = "danger";
}
});
}
const d = {
table: {
label,
@ -194,6 +205,9 @@ export function useCode() {
columns: [] as DeepPartial<ClTable.Column>[]
};
// 选项
const options = {};
// 遍历
columns.forEach((e) => {
// 创建组件
@ -209,6 +223,21 @@ export function useCode() {
item.required = true;
}
// 字典
const dict = item.component?.options || column.dict;
if (dict) {
options[item.prop] = dict;
const str = `$$options.${item.prop}$$`;
if (!column.component) {
column.dict = str;
}
item.component.options = str;
}
// 表单忽略
if (!["createTime", "updateTime", "id", "endTime", "endDate"].includes(item.prop)) {
upsert.items.push(item);
@ -216,6 +245,11 @@ export function useCode() {
// 表格忽略
if (!["id"].includes(item.prop)) {
// 默认排序
if (item.prop == "createTime") {
column.sortable = "desc";
}
table.columns.push(column);
}
@ -292,29 +326,15 @@ export function useCode() {
// 筛选
const clFilter = fieldEq
.map((field) => {
const item = table.columns.find((e) => e.prop == field);
const item = upsert.items.find((e) => e.prop == field);
if (item) {
if (!item.dict) {
item.dict = [];
}
if (item.component?.name == "cl-switch") {
item.dict = [
{ label: "是", value: 1 },
{ label: "否", value: 0 }
];
}
return `<!-- 筛选${item.label} -->\n<cl-filter label="${
item.label
}">\n<cl-select prop="${field}" :options='${toCodeString(
item.dict
)}' />\n</cl-filter>`;
return `<!-- 筛选${item.label} -->\n<cl-filter label="${item.label}">\n<cl-select prop="${field}" :options="options.${field}" />\n</cl-filter>`;
} else {
return "";
}
})
.filter(Boolean)
.join("\n");
// 关键字搜索
@ -325,8 +345,22 @@ export function useCode() {
.filter((e) => !!e)
.join("、");
// 选项
const ConstOptions = `${
isEmpty(options)
? ""
: "\n// 选项\nconst options = reactive(" + toCodeString(options) + ")\n"
}`;
// Vue 依赖
let ImportVue = "";
if (ConstOptions) {
ImportVue = "import { reactive } from 'vue';\n";
}
// 代码模板
return `<template>
const temp = `<template>
<cl-crud ref="Crud">
<cl-row>
<!-- -->
@ -358,9 +392,9 @@ export function useCode() {
<script lang="ts" name="${router.replace(/^\//, "").replace(/\//g, "-")}" setup>
import { useCrud, useTable, useUpsert } from "@cool-vue/crud";
import { useCool } from "/@/cool";
${ImportVue}
const { service } = useCool();
${ConstOptions}
// cl-upsert
const Upsert = useUpsert(${toCodeString(upsert)});
@ -382,6 +416,8 @@ function refresh(params?: any) {
Crud.value?.refresh(params);
}
</script>`;
return temp.replace(/"\$\$|\$\$"/g, "");
}
// 转成代码字符串

View File

@ -6,7 +6,6 @@ import compression from "vite-plugin-compression";
import { visualizer } from "rollup-plugin-visualizer";
import { proxy } from "./src/config/proxy";
import { cool } from "@cool-vue/vite-plugin";
import { constants } from "crypto";
function resolve(dir: string) {
return path.resolve(__dirname, ".", dir);