From 47f3c560fad2b8f98dea8784445592cf51cde565 Mon Sep 17 00:00:00 2001 From: xingyu4j Date: Wed, 16 Nov 2022 18:01:36 +0800 Subject: [PATCH] feat: vue3 codegen --- .../service/codegen/inner/CodegenEngine.java | 2 - .../main/resources/codegen/vue3/api/api.ts.vm | 43 ++- .../resources/codegen/vue3/api/types.ts.vm | 41 --- .../resources/codegen/vue3/views/data.ts.vm | 90 +++--- .../resources/codegen/vue3/views/index.vue.vm | 283 ++++++++---------- .../infra/codegen/components/Preview.vue | 20 +- .../src/views/system/post/index.vue | 5 +- yudao-ui-admin-vue3/use.md | 2 +- 8 files changed, 216 insertions(+), 270 deletions(-) delete mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/types.ts.vm 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 cec246bfc..132e903d9 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 @@ -91,8 +91,6 @@ public class CodegenEngine { vue3FilePath("views/${table.moduleName}/${classNameVar}/${classNameVar}.data.ts")) .put(vue3TemplatePath("api/api.ts"), vue3FilePath("api/${table.moduleName}/${classNameVar}/index.ts")) - .put(vue3TemplatePath("api/types.ts"), - vue3FilePath("api/${table.moduleName}/${classNameVar}/types.ts")) // SQL .put("codegen/sql/sql.vm", "sql/sql.sql") .put("codegen/sql/h2.vm", "sql/h2.sql") diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/api.ts.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/api.ts.vm index d1099ecbf..b42c2e011 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/api.ts.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/api.ts.vm @@ -1,7 +1,48 @@ import request from '@/config/axios' -import { ${simpleClassName}VO, ${simpleClassName}PageReqVO, ${simpleClassName}ExcelReqVO } from './types' +export interface ${simpleClassName}VO { +#foreach ($column in $columns) +#if ($column.createOperation || $column.updateOperation) +#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer") + ${column.javaField}?: number +#elseif(${column.javaType.toLowerCase()} == "date") + ${column.javaField}?: string +#else + ${column.javaField}?: ${column.javaType.toLowerCase()} +#end +#end +#end +} + +export interface ${simpleClassName}PageReqVO extends PageParam { +#foreach ($column in $columns) +#if (${column.listOperation})##查询操作 +#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer") + ${column.javaField}?: number +#elseif(${column.javaType.toLowerCase()} == "date") + ${column.javaField}?: string +#else + ${column.javaField}?: ${column.javaType.toLowerCase()} +#end +#end +#end +} + +export interface ${simpleClassName}ExcelReqVO { + #foreach ($column in $columns) + #if (${column.listOperation})##查询操作 + #if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer") + ${column.javaField}: number + #elseif(${column.javaType.toLowerCase()} == "date") + ${column.javaField}: string + #else + ${column.javaField}: ${column.javaType.toLowerCase()} + #end + #end + #end +} #set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}") + // 查询${table.classComment}列表 export const get${simpleClassName}PageApi = async (params: ${simpleClassName}PageReqVO) => { return await request.get({ url: '${baseURL}/page', params }) diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/types.ts.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/types.ts.vm deleted file mode 100644 index 54ab47e02..000000000 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/types.ts.vm +++ /dev/null @@ -1,41 +0,0 @@ -export type ${simpleClassName}VO = { -#foreach ($column in $columns) -#if ($column.createOperation || $column.updateOperation) -#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer") - ${column.javaField}: number -#elseif(${column.javaType.toLowerCase()} == "date") - ${column.javaField}: string -#else - ${column.javaField}: ${column.javaType.toLowerCase()} -#end -#end -#end -} - -export type ${simpleClassName}PageReqVO = { -#foreach ($column in $columns) -#if (${column.listOperation})##查询操作 -#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer") - ${column.javaField}: number -#elseif(${column.javaType.toLowerCase()} == "date") - ${column.javaField}: string -#else - ${column.javaField}: ${column.javaType.toLowerCase()} -#end -#end -#end -} - -export type ${simpleClassName}ExcelReqVO = { -#foreach ($column in $columns) -#if (${column.listOperation})##查询操作 -#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer") - ${column.javaField}: number -#elseif(${column.javaType.toLowerCase()} == "date") - ${column.javaField}: string -#else - ${column.javaField}: ${column.javaType.toLowerCase()} -#end -#end -#end -} \ No newline at end of file diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/data.ts.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/data.ts.vm index fa64bc883..37c436246 100644 --- a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/data.ts.vm +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/data.ts.vm @@ -1,51 +1,51 @@ import { reactive } from 'vue' import { useI18n } from '@/hooks/web/useI18n' -import { CrudSchema, useCrudSchemas } from '@/hooks/web/useCrudSchemas' import { DICT_TYPE } from '@/utils/dict' +import { required } from '@/utils/formRules' +import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas' const { t } = useI18n() // 国际化 // 表单校验 export const rules = reactive({ #foreach ($column in $columns) #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 #set($comment=$column.columnComment) - $column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == "select")'change'#else'blur'#end }], + $column.javaField: [required], #end #end }) // CrudSchema -const crudSchemas = reactive([ +const crudSchemas = reactive({ + primaryKey: 'id', // 默认的主键ID + primaryTitle: t('common.index'), // 默认显示的值 + primaryType: 'seq', // 默认为seq,序号模式 + action: true, + actionWidth: '200', // 3个按钮默认200,如有删减对应增减即可 + columns: [ #foreach($column in $columns) #if ($column.listOperation || $column.listOperationResult || $column.createOperation || $column.updateOperation) #set ($dictType = $column.dictType) + #if(!$column.primaryKey) { - label: '${column.columnComment}', + title: '${column.columnComment}', field: '${column.javaField}', #if ("" != $dictType)## 有数据字典 dictType: DICT_TYPE.$dictType.toUpperCase(), #end - #if($column.primaryKey) - type: 'index', - form: { - show: false - }, - detail: { - show: false - } - #else #if (!$column.createOperation && !$column.updateOperation) - form: { - show: false - }, + isForm: false #elseif(!("" != $column.dictType)) + #if ($column.htmlType == "datetime")## 时间框 form: { show: true, - #if ($column.htmlType == "datetime")## 时间框 component: 'DatePicker', componentProps: { type: 'datetime', valueFormat: 'YYYY-MM-DD HH:mm:ss' } - #elseif($column.htmlType == "editor")## 文本编辑器 + } + #elseif($column.htmlType == "editor")## 文本编辑器 + form: { + show: true, component: 'Editor', colProps: { span: 24 @@ -53,7 +53,10 @@ const crudSchemas = reactive([ componentProps: { valueHtml: '' } - #elseif($column.htmlType == "textarea")## 文本框 + } + #elseif($column.htmlType == "textarea")## 文本框 + form: { + show: true, component: 'Input', componentProps: { type: 'textarea', @@ -62,50 +65,27 @@ const crudSchemas = reactive([ colProps: { span: 24 } - #end - }, + } + #end #end #if ($column.listOperationResult) + #if($column.htmlType == "input") + isSearch: true + #elseif("" != $dictType) + isSearch: true + #elseif($column.htmlType == "datetime") search: { - #if($column.htmlType == "input") - show: true - #else - #if($column.htmlType == "datetime") show: true, - component: 'DatePicker', - componentProps: { - type: 'datetimerange', - valueFormat: 'YYYY-MM-DD HH:mm:ss' + itemRender: { + name: 'XDataTimePicker' } - #elseif($column.htmlType == "select" || $column.htmlType == "radio") - #if ("" == $dictType)## 没有数据字典 - show: true, - component: 'Select', - componentProps: { - option: [{'','请选择字典生成'}] - } - #else - show: true - #end - #end - #end } #end #end + #end }, #end #end - { - label: t('table.action'), - field: 'action', - width: '240px', - form: { - show: false - }, - detail: { - show: false - } - } -]) - -export const { allSchemas } = useCrudSchemas(crudSchemas) \ No newline at end of file + ] +}) +export const { allSchemas } = useVxeCrudSchemas(crudSchemas) \ No newline at end of file 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 509f1493f..5c25f9a76 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 @@ -1,51 +1,151 @@ + - diff --git a/yudao-ui-admin-vue3/src/views/infra/codegen/components/Preview.vue b/yudao-ui-admin-vue3/src/views/infra/codegen/components/Preview.vue index 4d5dfc90e..2f8117404 100644 --- a/yudao-ui-admin-vue3/src/views/infra/codegen/components/Preview.vue +++ b/yudao-ui-admin-vue3/src/views/infra/codegen/components/Preview.vue @@ -117,15 +117,17 @@ defineExpose({
- + + + diff --git a/yudao-ui-admin-vue3/src/views/system/post/index.vue b/yudao-ui-admin-vue3/src/views/system/post/index.vue index 83a40b24e..82b0b20bf 100644 --- a/yudao-ui-admin-vue3/src/views/system/post/index.vue +++ b/yudao-ui-admin-vue3/src/views/system/post/index.vue @@ -1,7 +1,7 @@