神仙 1 жил өмнө
parent
commit
76a2ac05be

+ 1 - 0
.gitignore

@@ -1,6 +1,7 @@
 .DS_Store
 node_modules/
 /dist/
+/build/
 dist-ssr/
 
 # Log files

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 41 - 697
build/cool/eps.d.ts


+ 1 - 1
package.json

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

+ 1 - 1
packages/crud/package.json

@@ -1,6 +1,6 @@
 {
 	"name": "@cool-vue/crud",
-	"version": "7.1.23",
+	"version": "7.1.24",
 	"private": false,
 	"main": "./dist/index.umd.min.js",
 	"typings": "types/index.d.ts",

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 242 - 1050
packages/crud/pnpm-lock.yaml


+ 21 - 10
packages/crud/src/hooks/crud.ts

@@ -23,26 +23,35 @@ function useParent(name: string, r: Ref) {
 }
 
 // 多事件
-function useEvent(names: string[], { r, options, clear }: any) {
-	const d: any = {};
-
+function useEvent(
+	names: string[],
+	{ r, options, clear, isChild }: { r: any; options: any; clear?: string; isChild?: boolean }
+) {
 	if (!r.__ev) r.__ev = {};
 
+	const d: { [key: string]: (args: any[]) => void } = {};
+	const ev = r.__ev as { [key: string]: { fn: any; isChild?: boolean }[] };
+
 	names.forEach((k) => {
-		if (!r.__ev[k]) r.__ev[k] = [];
+		if (!ev[k]) ev[k] = [];
 
 		if (options[k]) {
-			r.__ev[k].push(options[k]);
+			ev[k].push({
+				fn: options[k],
+				isChild
+			});
 		}
 
 		d[k] = (...args: any[]) => {
-			r.__ev[k].filter(Boolean).forEach((e: any) => {
-				e(...args);
+			ev[k].forEach((e) => {
+				if (e.fn) {
+					e.fn(...args);
+				}
 			});
 
 			if (clear == k) {
-				for (const i in r.__ev) {
-					r.__ev[i].splice(1, 999);
+				for (const i in ev) {
+					ev[i] = ev[i].filter((e) => !e.isChild);
 				}
 			}
 		};
@@ -80,6 +89,7 @@ export function useCrud(options?: ClCrud.Options, cb?: (app: ClCrud.Ref) => void
 export function useUpsert<T = any>(options?: ClUpsert.Options<T>) {
 	const Upsert = ref<ClUpsert.Ref>();
 	useParent("cl-upsert", Upsert);
+	const isChild = !!Upsert.value;
 
 	if (options) {
 		provide("useUpsert__options", options);
@@ -93,7 +103,8 @@ export function useUpsert<T = any>(options?: ClUpsert.Options<T>) {
 					const event = useEvent(["onOpen", "onOpened", "onClosed"], {
 						r: val,
 						options,
-						clear: "onClosed"
+						clear: "onClosed",
+						isChild
 					});
 
 					Object.assign(val.config, event);

+ 2 - 2
packages/crud/src/plugins/index.ts

@@ -9,7 +9,7 @@ export function setFocus(prop?: string): ClForm.Plugin {
 	const { refs, setRefs } = useRefs();
 
 	return ({ exposed, onOpen }) => {
-		const name = prop || exposed.config.items?.[0]?.prop;
+		const name = prop || exposed.config?.items?.[0]?.prop;
 		let _ref: any;
 
 		if (name) {
@@ -29,7 +29,7 @@ export function setFocus(prop?: string): ClForm.Plugin {
 				});
 			}
 
-			deep(exposed.config.items);
+			deep(exposed.config?.items || []);
 
 			onOpen(() => {
 				if (_ref) {

+ 1 - 1
src/modules/base/views/menu/index.vue

@@ -262,7 +262,7 @@ const Upsert = useUpsert({
 			label: "上级节点",
 			hook: {
 				submit(value) {
-					return value === "" ? null : value;
+					return value || null;
 				}
 			},
 			component: {

+ 1 - 0
src/modules/helper/components/auto-menu/btn.vue

@@ -27,6 +27,7 @@ function toCode() {
 	position: relative;
 	border-radius: 4px;
 	padding: 5px 10px;
+	white-space: nowrap;
 	letter-spacing: 1px;
 
 	span {

+ 2 - 2
src/modules/helper/components/auto-menu/quick.vue

@@ -26,7 +26,7 @@ import type { EpsData } from "../../types";
 const { service, mitt } = useCool();
 const menu = useMenu();
 const Form = useForm();
-const { matchType } = useAi();
+const ai = useAi();
 
 // 实体列表
 const list: any[] = [];
@@ -193,7 +193,7 @@ function open() {
 
 				// 是否需要ai分析
 				if (data.isAi) {
-					await matchType({ columns, name: data.name });
+					await ai.matchType({ columns, name: data.name });
 				}
 
 				menu.create({

+ 12 - 7
src/modules/helper/hooks/code.ts

@@ -289,19 +289,24 @@ export function useCode() {
 			});
 		}
 
+		console.log(table.columns);
 		// 筛选
-		const clFilter = fieldEq.map((field) => {
-			const item = table.columns.find((e) => e.propertyName == field);
+		const clFilter = fieldEq
+			.map((field) => {
+				const item = table.columns.find((e) => e.prop == field);
 
-			return item
-				? `<!-- 筛选${item.label} -->\n<cl-filter label="${item.label}"><cl-select options="${item.dict}" prop="${field}" /></cl-filter>`
-				: "";
-		});
+				return item
+					? `<!-- 筛选${item.label} -->\n<cl-filter label="${
+							item.label
+					  }">\n<cl-select options="${item.dict || []}" prop="${field}" />\n</cl-filter>`
+					: "";
+			})
+			.join("\n");
 
 		// 关键字搜索
 		const clSearchKeyPlaceholder = keyWordLikeFields
 			.map((field) => {
-				return table.columns.find((e) => e.propertyName == field)?.label;
+				return table.columns.find((e) => e.prop == field)?.label;
 			})
 			.filter((e) => !!e)
 			.join("、");

+ 74 - 59
src/modules/helper/views/ai-code.vue

@@ -292,7 +292,7 @@ import * as monaco from "monaco-editor";
 import { sleep, storage } from "/@/cool/utils";
 import dayjs from "dayjs";
 import { nextTick } from "vue";
-import type { CodeItem } from "../types";
+import type { CodeItem, EpsColumn } from "../types";
 import { useClipboard } from "@vueuse/core";
 
 const { service, refs, setRefs, router } = useCool();
@@ -323,7 +323,7 @@ const form = reactive({
 // 执行步骤
 const step = reactive({
 	loading: false,
-	value: "start",
+	value: "coding",
 	list: ["start", "enter", "form", "coding"],
 
 	async next() {
@@ -381,10 +381,42 @@ const code = reactive({
 	active: "node-entity",
 
 	// 代码列表
-	list: (storage.get("ai-code.list") || []) as CodeItem[],
+	list: [] as CodeItem[],
 
 	// 其他数据
-	data: (storage.get("ai-code.data") || {}) as any,
+	data: {
+		router: "",
+		prefix: "",
+		columns: [] as EpsColumn[],
+		fieldEq: [],
+		keyWordLikeFields: [],
+		api: [
+			{
+				path: "/add",
+				summary: "新增"
+			},
+			{
+				path: "/info",
+				summary: "单个信息"
+			},
+			{
+				path: "/update",
+				summary: "修改"
+			},
+			{
+				path: "/delete",
+				summary: "删除"
+			},
+			{
+				path: "/page",
+				summary: "分页查询"
+			},
+			{
+				path: "/list",
+				summary: "列表查询"
+			}
+		]
+	},
 
 	// 日志
 	logs: [] as any[],
@@ -462,11 +494,16 @@ const code = reactive({
 
 		// entity 关键数据
 		const entityData = await ai.invokeFlow("comm-parse-entity", {
-			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.columns = entityData.columns || [];
+
 		code.tips("Service 代码生成中");
 
 		// service 代码
@@ -487,14 +524,24 @@ const code = reactive({
 		code.tips("Controller 代码生成中");
 
 		// controller 代码
-		await code.setContent("Controller 控制器", "node-controller", {
+		const controller = await code.setContent("Controller 控制器", "node-controller", {
 			...serviceData,
 			...entityData,
 			service,
 			entity
 		});
 
-		code.tips("Controller 生成成功");
+		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;
 
 		await code.createVue();
 
@@ -519,65 +566,26 @@ const code = reactive({
 
 		item.content = "";
 
-		code.data = {
-			router: "",
-			prefix: "",
-			path: "",
-			fileName: "",
-			className: "",
-			columns: [],
-			api: [
-				{
-					path: "/add",
-					summary: "新增"
-				},
-				{
-					path: "/info",
-					summary: "单个信息"
-				},
-				{
-					path: "/update",
-					summary: "修改"
-				},
-				{
-					path: "/delete",
-					summary: "删除"
-				},
-				{
-					path: "/page",
-					summary: "分页查询"
-				},
-				{
-					path: "/list",
-					summary: "列表查询"
-				}
-			],
-			...form,
-			name: form.entity
-		};
+		assign(code.data, form);
 
 		code.tips("Vue 代码生成中");
 
-		// 解析
-		await service.base.sys.menu
-			.parse({
-				module: form.module,
+		// ai分析
+		await ai
+			.invokeFlow("comm-parse-column", {
 				entity: code.getContent("node-entity")
 			})
 			.then((res) => {
-				res.router = res.path.replace("/admin", "");
-				res.prefix = res.path;
-
-				assign(code.data, res);
+				(code.data.columns as EpsColumn[]).forEach((e) => {
+					e.component = res[e.propertyName];
+				});
 			});
 
-		code.tips("AI 分析字段中");
-
-		// ai分析
-		await ai.matchType({ columns: code.data.columns, name: form.entity });
-
 		// 生成内容
-		item.content = menu.createVue(code.data);
+		item.content = menu.createVue({
+			...code.data,
+			module: form.module
+		});
 
 		await sleep(300);
 
@@ -664,15 +672,15 @@ const code = reactive({
 				if (flow == code.active) {
 					refs.editor?.revealLine(99999);
 				}
-			}, 10);
+			}, 5);
 		});
 	},
 
 	// 复制
 	copy() {
 		copy(code.getContent(code.active)!);
-		code.save();
 		ElMessage.success("复制成功");
+		code.save();
 	},
 
 	// 重新生成
@@ -686,6 +694,7 @@ const code = reactive({
 	save() {
 		storage.set("ai-code.list", code.list);
 		storage.set("ai-code.data", code.data);
+		storage.set("ai-code.form", form);
 	}
 });
 
@@ -908,6 +917,12 @@ function toBack() {
 
 onMounted(() => {
 	desc.init();
+
+	if (step.value == "coding") {
+		code.list = storage.get("ai-code.list") || [];
+		code.data = storage.get("ai-code.data") || [];
+		assign(form, storage.get("ai-code.form") || {});
+	}
 });
 </script>
 

+ 2 - 2
src/plugins/crud/config.ts

@@ -1,11 +1,11 @@
 import type { Merge, ModuleConfig } from "/@/cool";
 
 // npm
-import Crud, { locale, setFocus } from "@cool-vue/crud";
+// import Crud, { locale, setFocus } from "@cool-vue/crud";
 import "@cool-vue/crud/dist/index.css";
 
 // 调试、自定义crud
-// import Crud, { locale, setFocus } from "/~/crud/src";
+import Crud, { locale, setFocus } from "/~/crud/src";
 // import "/~/crud/src/static/index.scss";
 
 export default (): Merge<ModuleConfig, CrudOptions> => {

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно