From b9d45f1ae21e52e933b2b762e2b1b8f0c63bd6b1 Mon Sep 17 00:00:00 2001 From: Junjie <540245094@qq.com> Date: 星期四, 04 七月 2024 08:07:16 +0800 Subject: [PATCH] # --- zy-asrs-framework/src/main/java/com/zy/asrs/framework/generators/VueGenerator.java | 55 +++++++++++++++++++++++++++++++++++++++++++++---------- 1 files changed, 45 insertions(+), 10 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..00495b4 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 @@ -73,6 +73,7 @@ private String itemName; private String tableColumns; private String formEditColumns; + private String formEditForeignKeyColumns; public void build() throws Exception { init(); @@ -217,6 +218,7 @@ .replaceAll("@\\{SYSTEMPACKAGE}",systemPackage) .replaceAll("@\\{TABLECOLUMNS}", tableColumns) .replaceAll("@\\{FORMEDITCOLUMNS}", formEditColumns) + .replaceAll("@\\{FORMEDITFOREIGNKEYCOLUMNS}", formEditForeignKeyColumns) ; writerFile.createNewFile(); BufferedWriter writer=new BufferedWriter(new FileWriter(writerFile)); @@ -777,7 +779,7 @@ 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: '"); if ("Date".equals(column.getType()) || !Cools.isEmpty(column.getEnums()) || !Cools.isEmpty(column.getForeignKeyMajor())){ // 鏃堕棿銆佹灇涓� 鏍煎紡鍖� 涓婚敭淇グ @@ -786,7 +788,8 @@ sb.append(column.getHumpName()); } sb.append("',\n") - .append(" width: 140,\n"); + .append(" width: 140,\n") + .append(" ellipsis: true,\n"); // if (!Cools.isEmpty(column.getEnums())) { // sb.append(" customRender: (column) => {\n"); // sb.append(" let typeMap = {"); @@ -847,7 +850,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 +862,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 +885,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 (!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().toLowerCase()).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