From 9d272e79410423b8099b5d7f4aabdb3cdc03f1c5 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 12 Apr 2023 22:40:53 +0800 Subject: [PATCH] =?UTF-8?q?Vue3=20CRUD=20Schema=20=E6=A8=A1=E7=89=88?= =?UTF-8?q?=EF=BC=8Cdata=20=E5=AE=8C=E6=95=B4=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/codegen/inner/CodegenEngine.java | 2 ++ .../resources/codegen/vue3/views/index.vue.vm | 5 +++++ .../codegen/vue3_schema/views/data.ts.vm | 15 ++++++++++----- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java index 15b5ef5d3..a77502f5f 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java @@ -187,6 +187,8 @@ public class CodegenEngine { templates.forEach((vmPath, filePath) -> { filePath = formatFilePath(filePath, bindingMap); String content = templateEngine.getTemplate(vmPath).render(bindingMap); + // 去除字段后面多余的 , 逗号 + content = content.replaceAll(",\n}", "\n}").replaceAll(",\n }", "\n }"); result.put(filePath, content); }); return result; diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm index 9cce26fd2..f396dde32 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm @@ -182,7 +182,12 @@ #if ($dictMethods.size() > 0) import { DICT_TYPE#foreach ($dictMethod in $dictMethods), ${dictMethod}#end } from '@/utils/dict' #end +#foreach ($column in $columns) + #if ($column.listOperationResult && $column.htmlType == "datetime") import { dateFormatter } from '@/utils/formatTime' + #break + #end +#end import download from '@/utils/download' import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${classNameVar}' import ${simpleClassName}Form from './${simpleClassName}Form.vue' diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/views/data.ts.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/views/data.ts.vm index 0cb639901..dd5b022cb 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/views/data.ts.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_schema/views/data.ts.vm @@ -1,6 +1,10 @@ import type { CrudSchema } from '@/hooks/web/useCrudSchemas' +#foreach ($column in $columns) + #if ($column.listOperationResult && $column.htmlType == "datetime") import { dateFormatter } from '@/utils/formatTime' -const { t } = useI18n() // 国际化 + #break + #end +#end // 表单校验 export const rules = reactive({ @@ -12,7 +16,7 @@ export const rules = reactive({ #end }) -// CrudSchema +// CrudSchema https://kailong110120130.gitee.io/vue-element-plus-admin-doc/hooks/useCrudSchemas.html const crudSchemas = reactive([ #foreach($column in $columns) #if ($column.listOperation || $column.listOperationResult || $column.createOperation || $column.updateOperation) @@ -20,7 +24,7 @@ const crudSchemas = reactive([ #set ($javaField = $column.javaField) #set ($javaType = $column.javaType) { - title: '${column.columnComment}', + label: '${column.columnComment}', field: '${column.javaField}', ## ========= 字典部分 ========= #if ("" != $dictType)## 有数据字典 @@ -36,6 +40,7 @@ const crudSchemas = reactive([ ## ========= Table 表格部分 ========= #if (!$column.listOperationResult) isTable: false, + #else #if ($column.htmlType == "datetime") formatter: dateFormatter, #end @@ -51,7 +56,7 @@ const crudSchemas = reactive([ type: 'daterange', defaultTime: [new Date('1 00:00:00'), new Date('1 23:59:59')] } - } + }, #end #end ## ========= Form 表单部分 ========= @@ -82,7 +87,7 @@ const crudSchemas = reactive([ form: { component: 'Checkbox' }, - #elseif($column.htmlType == "checkbox")## 单选框 + #elseif($column.htmlType == "radio")## 单选框 form: { component: 'Radio' },