神仙都没用 1 년 전
부모
커밋
e117cdde4f
3개의 변경된 파일54개의 추가작업 그리고 9개의 파일을 삭제
  1. 32 2
      src/modules/helper/hooks/code.ts
  2. 2 0
      src/modules/helper/types/index.d.ts
  3. 20 7
      src/modules/helper/views/ai-code.vue

+ 32 - 2
src/modules/helper/hooks/code.ts

@@ -176,7 +176,14 @@ export function useCode() {
 	}
 
 	// 创建 vue 代码
-	function createVue({ router = "", columns = [], prefix = "", api = [] }: EpsModule) {
+	function createVue({
+		router = "",
+		columns = [],
+		prefix = "",
+		api = [],
+		fieldEq = [],
+		keyWordLikeFields = []
+	}: EpsModule) {
 		// 新增、编辑
 		const upsert = {
 			items: [] as DeepPartial<ClForm.Item>[]
@@ -282,6 +289,23 @@ export function useCode() {
 			});
 		}
 
+		// 筛选
+		const clFilter = fieldEq.map((field) => {
+			const item = table.columns.find((e) => e.propertyName == field);
+
+			return item
+				? `<!-- 筛选${item.label} -->\n<cl-filter label="${item.label}"><cl-select options="${item.dict}" prop="${field}" /></cl-filter>`
+				: "";
+		});
+
+		// 关键字搜索
+		const clSearchKeyPlaceholder = keyWordLikeFields
+			.map((field) => {
+				return table.columns.find((e) => e.propertyName == field)?.label;
+			})
+			.filter((e) => !!e)
+			.join("、");
+
 		// 代码模板
 		return `<template>
             <cl-crud ref="Crud">
@@ -290,9 +314,10 @@ export function useCode() {
                     <cl-refresh-btn />
                     ${perms.add ? "<!-- 新增按钮 -->\n<cl-add-btn />" : ""}
                     ${perms.del ? "<!-- 删除按钮 -->\n<cl-multi-delete-btn />" : ""}
+					${clFilter}
                     <cl-flex1 />
                     <!-- 关键字搜索 -->
-                    <cl-search-key />
+                    <cl-search-key placeholder="搜索${clSearchKeyPlaceholder || "关键字"}" />
                 </cl-row>
         
                 <cl-row>
@@ -332,6 +357,11 @@ export function useCode() {
                 app.refresh();
             }
         );
+
+		// 刷新
+		function refresh(params?: any) {
+			Crud.value?.refresh(params);
+		}
         </script>`;
 	}
 

+ 2 - 0
src/modules/helper/types/index.d.ts

@@ -23,6 +23,8 @@ export declare interface EpsModule {
 	prefix: string;
 	router: string;
 	module: string;
+	fieldEq?: string[];
+	keyWordLikeFields?: string[];
 	[key: string]: any;
 }
 

+ 20 - 7
src/modules/helper/views/ai-code.vue

@@ -212,17 +212,17 @@
 							</div>
 
 							<div class="op" v-if="!isEmpty(code.list) && !code.loading">
-								<el-tooltip content="创建文件">
-									<el-icon @click="createFile">
-										<download />
-									</el-icon>
-								</el-tooltip>
-
 								<el-tooltip content="复制代码">
 									<el-icon @click="code.copy()">
 										<copy-document />
 									</el-icon>
 								</el-tooltip>
+
+								<el-tooltip content="创建文件">
+									<el-icon @click="createFile">
+										<download />
+									</el-icon>
+								</el-tooltip>
 							</div>
 						</div>
 
@@ -442,6 +442,8 @@ const code = reactive({
 		// 下一步
 		step.next();
 
+		code.tips("AI 开始编码");
+
 		await sleep(300);
 
 		code.tips("Entity 代码生成中");
@@ -479,7 +481,8 @@ const code = reactive({
 		// controller 代码
 		await code.setContent("Controller 控制器", "node-controller", {
 			...serviceData,
-			...entityData
+			...entityData,
+			service
 		});
 
 		code.tips("Controller 生成成功");
@@ -489,6 +492,16 @@ const code = reactive({
 		code.tips("编码完成");
 
 		code.loading = false;
+
+		ElMessageBox.confirm("编码完成,是否创建文件?", "提示", {
+			type: "success",
+			confirmButtonText: "开始创建",
+			cancelButtonText: "稍后再看"
+		})
+			.then(() => {
+				createFile();
+			})
+			.catch(() => null);
 	},
 
 	// 创建vue