From 4f113d1862ee978e7d0756f31af79ad73b1dc6d7 Mon Sep 17 00:00:00 2001 From: Junjie <540245094@qq.com> Date: 星期四, 12 九月 2024 16:33:39 +0800 Subject: [PATCH] # --- zy-asrs-framework/src/main/java/com/zy/asrs/framework/generators/VueGenerator.java | 66 ++++++++++++++++++++++++++------ 1 files changed, 53 insertions(+), 13 deletions(-) diff --git a/zy-asrs-framework/src/main/java/com/zy/asrs/framework/generators/VueGenerator.java b/zy-asrs-framework/src/main/java/com/zy/asrs/framework/generators/VueGenerator.java index 3fe2222..e04e49e 100644 --- a/zy-asrs-framework/src/main/java/com/zy/asrs/framework/generators/VueGenerator.java +++ b/zy-asrs-framework/src/main/java/com/zy/asrs/framework/generators/VueGenerator.java @@ -42,6 +42,7 @@ public String password; public String table; public String tableName; + public String rootPackagePath; public String packagePath; public boolean controller = true; public boolean service = true; @@ -73,6 +74,7 @@ private String itemName; private String tableColumns; private String formEditColumns; + private String formEditForeignKeyColumns; public void build() throws Exception { init(); @@ -200,6 +202,7 @@ .replaceAll("@\\{SIMPLEENTITYNAME}", simpleEntityName) .replaceAll("@\\{UENTITYNAME}", simpleEntityName) .replaceAll("@\\{COMPANYNAME}",packagePath) + .replaceAll("@\\{ROOTPACKAGEPATH}",rootPackagePath) .replaceAll("@\\{ITEMNAME}",itemName) // .replaceAll("@\\{XMLCONTENT}", xmlContent) .replaceAll("@\\{HTMLCONTENT}", htmlContent) @@ -217,6 +220,7 @@ .replaceAll("@\\{SYSTEMPACKAGE}",systemPackage) .replaceAll("@\\{TABLECOLUMNS}", tableColumns) .replaceAll("@\\{FORMEDITCOLUMNS}", formEditColumns) + .replaceAll("@\\{FORMEDITFOREIGNKEYCOLUMNS}", formEditForeignKeyColumns) ; writerFile.createNewFile(); BufferedWriter writer=new BufferedWriter(new FileWriter(writerFile)); @@ -777,16 +781,20 @@ continue; } sb.append(" {\n") - .append(" title: '").append(column.getComment()).append("',\n") + .append(" title: formatMessage('db.").append(table).append(".").append(column.getName()).append("', '").append(column.getComment()).append("'),").append("\n") .append(" dataIndex: '"); + StringBuilder rowKey = new StringBuilder(); if ("Date".equals(column.getType()) || !Cools.isEmpty(column.getEnums()) || !Cools.isEmpty(column.getForeignKeyMajor())){ // 鏃堕棿銆佹灇涓� 鏍煎紡鍖� 涓婚敭淇グ - sb.append(column.getHumpName()).append("\\$"); + rowKey.append(column.getHumpName()).append("\\$"); } else { - sb.append(column.getHumpName()); + rowKey.append(column.getHumpName()); } + sb.append(rowKey); sb.append("',\n") - .append(" width: 140,\n"); + .append(" width: 140,\n") + .append(" ellipsis: true,\n") + .append(" ...getColumnSearchProps('").append(rowKey).append("'),\n"); // if (!Cools.isEmpty(column.getEnums())) { // sb.append(" customRender: (column) => {\n"); // sb.append(" let typeMap = {"); @@ -847,7 +855,10 @@ private String createFormEditColumns() { StringBuilder sb = new StringBuilder(); + StringBuilder sb2 = new StringBuilder(); + ArrayList<String> foreignKeyContains = new ArrayList<>(); for (Column column : columns) { + boolean has = true; if (column.isPrimaryKey() || column.getHumpName().equals("deleted") || column.getHumpName().equals("hostId") @@ -856,7 +867,7 @@ } sb.append(" <a-form-item \n"); - sb.append(" label=\"").append(column.getComment()).append("\" \n"); + sb.append(" :label=\"formatMessage('db.").append(table).append(".").append(column.getName()).append("', '").append(column.getComment()).append("') ").append("\" \n"); sb.append(" name=\"").append(column.getHumpName()).append("\" \n"); sb.append(" style=\"width: 250px;\" \n"); @@ -879,31 +890,60 @@ sb.append(" ]\"\n"); sb.append(" >\n"); sb.append(" </a-select>\n"); + has = false; } // 鏃堕棿 if ("Date".equals(column.getType())) { - sb.append(" <a-select \n"); + sb.append(" <a-date-picker \n"); sb.append(" v-model:value=\"formData.").append(column.getHumpName()).append("\" \n"); sb.append(" show-time \n"); sb.append(" format=\"YYYY-MM-DD HH:mm:ss\" \n"); sb.append(" value-format=\"YYYY-MM-DD HH:mm:ss\" \n"); sb.append(" /> \n"); + has = false; } // 鍏宠仈琛� - if (!Cools.isEmpty(column.getForeignKey())) { -// sb.append(" showSearch\n") -// .append(" debounceTime={300}\n") -// .append(" request={async ({ keyWords }) => {\n") -// .append(" const resp = await Http.doPostForm('api/").append(GeneratorUtils.firstCharConvert(column.getForeignKey())).append("/query', { condition: keyWords });\n") -// .append(" return resp.data;\n") -// .append(" }}\n"); + if (!Cools.isEmpty(column.getForeignKey$())) { + if (!foreignKeyContains.contains(column.getForeignKey$())) { + sb2.append("const ").append(column.getForeignKey$()).append("QueryList = ref(null); \n"); + sb2.append(column.getForeignKey$()).append("Query();\n"); + sb2.append("function ").append(column.getForeignKey$()).append("Query() { \n"); + sb2.append(" postForm('/api/").append(column.getForeignKey$()).append("/query', {}).then(resp => { \n"); + sb2.append(" let result = resp.data;\n"); + sb2.append(" ").append(column.getForeignKey$()).append("QueryList.value = result.data;\n"); + sb2.append(" })\n"); + sb2.append("}\n"); + + foreignKeyContains.add(column.getForeignKey$()); + } + + sb.append(" <a-select \n"); + sb.append(" v-model:value=\"formData.").append(column.getHumpName()).append("\" \n"); + sb.append(" :placeholder=\"formatMessage('common.select', '璇烽�夋嫨')\" \n"); + sb.append(" style=\"width: 100%\" \n"); + sb.append(" show-search \n"); + sb.append(" :options=\"").append(column.getForeignKey$()).append("QueryList\" \n"); + sb.append(" optionFilterProp=\"label\" \n"); + sb.append(" optionLabelProp=\"label\" \n"); + sb.append(" > \n"); + sb.append(" </a-select>\n"); + has = false; + } + + if (has) { + sb.append(" <a-input \n"); + sb.append(" v-model:value=\"formData.").append(column.getHumpName()).append("\" \n"); + sb.append(" /> \n"); + has = false; } sb.append(" </a-form-item>\n"); } + + formEditForeignKeyColumns = sb2.toString(); return sb.toString(); } -- Gitblit v1.9.1