From d15995e7f9ed2eb0b16023df89cba7f2364bd973 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 19 Mar 2023 20:57:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=20Vue3=20=E6=A0=87=E5=87=86=E6=A8=A1?= =?UTF-8?q?=E7=89=88=E7=9A=84=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/codegen/inner/CodegenEngine.java | 4 +- .../main/resources/codegen/vue3/api/api.ts.vm | 41 +-- .../resources/codegen/vue3/views/form.vue.vm | 165 +++++++++ .../resources/codegen/vue3/views/index.vue.vm | 348 +++++++++++------- .../resources/codegen/vue3_vxe/api/api.ts.vm | 74 ++++ .../{vue3 => vue3_vxe}/views/data.ts.vm | 0 .../codegen/vue3_vxe/views/index.vue.vm | 160 ++++++++ 7 files changed, 616 insertions(+), 176 deletions(-) create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vxe/api/api.ts.vm rename yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/{vue3 => vue3_vxe}/views/data.ts.vm (100%) create mode 100644 yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vxe/views/index.vue.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 20fd7e67d..258dceb3c 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 @@ -105,8 +105,8 @@ public class CodegenEngine { // Vue3 .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/index.vue"), vue3FilePath("views/${table.moduleName}/${classNameVar}/index.vue")) - .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/data.ts"), - vue3FilePath("views/${table.moduleName}/${classNameVar}/${classNameVar}.data.ts")) +// .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/data.ts"), +// vue3FilePath("views/${table.moduleName}/${classNameVar}/${classNameVar}.data.ts")) .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("api/api.ts"), vue3FilePath("api/${table.moduleName}/${classNameVar}/index.ts")) .build(); 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 df49a002b..eaab40703 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 @@ -14,61 +14,32 @@ export interface ${simpleClassName}VO { #end } -export interface ${simpleClassName}PageReqVO extends PageParam { -#foreach ($column in $columns) -#if (${column.listOperation})##查询操作 -#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") - ${column.javaField}?: number -#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime") - ${column.javaField}?: Date[] -#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.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") - ${column.javaField}?: number -#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime") - ${column.javaField}?: Date[] -#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) => { +export const get${simpleClassName}Page = async (params: ${simpleClassName}PageReqVO) => { return await request.get({ url: '${baseURL}/page', params }) } // 查询${table.classComment}详情 -export const get${simpleClassName}Api = async (id: number) => { +export const get${simpleClassName} = async (id: number) => { return await request.get({ url: '${baseURL}/get?id=' + id }) } // 新增${table.classComment} -export const create${simpleClassName}Api = async (data: ${simpleClassName}VO) => { +export const create${simpleClassName} = async (data: ${simpleClassName}VO) => { return await request.post({ url: '${baseURL}/create', data }) } // 修改${table.classComment} -export const update${simpleClassName}Api = async (data: ${simpleClassName}VO) => { +export const update${simpleClassName} = async (data: ${simpleClassName}VO) => { return await request.put({ url: '${baseURL}/update', data }) } // 删除${table.classComment} -export const delete${simpleClassName}Api = async (id: number) => { +export const delete${simpleClassName} = async (id: number) => { return await request.delete({ url: '${baseURL}/delete?id=' + id }) } // 导出${table.classComment} Excel -export const export${simpleClassName}Api = async (params: ${simpleClassName}ExcelReqVO) => { +export const export${simpleClassName}Api = async (params) => { return await request.download({ url: '${baseURL}/export-excel', params }) } diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm new file mode 100644 index 000000000..366fcb86b --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm @@ -0,0 +1,165 @@ + + + + #foreach($column in $columns) + #if ($column.createOperation || $column.updateOperation) + #set ($dictType = $column.dictType) + #set ($javaField = $column.javaField) + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) + #set ($comment = $column.columnComment) + #if ($column.htmlType == "input") + #if (!$column.primaryKey)## 忽略主键,不用在表单里 + + + + #end + #elseif($column.htmlType == "imageUpload")## 图片上传 + #set ($hasImageUploadColumn = true) + + + + #elseif($column.htmlType == "fileUpload")## 文件上传 + #set ($hasFileUploadColumn = true) + + + + #elseif($column.htmlType == "editor")## 文本编辑器 + #set ($hasEditorColumn = true) + + + + #elseif($column.htmlType == "select")## 下拉框 + + + #if ("" != $dictType)## 有数据字典 + + #else##没数据字典 + + #end + + + #elseif($column.htmlType == "checkbox")## 多选框 + + + #if ("" != $dictType)## 有数据字典 + {{dict.label}} + #else##没数据字典 + 请选择字典生成 + #end + + + #elseif($column.htmlType == "radio")## 单选框 + + + #if ("" != $dictType)## 有数据字典 + {{dict.label}} + #else##没数据字典 + 请选择字典生成 + #end + + + #elseif($column.htmlType == "datetime")## 时间框 + + + + #elseif($column.htmlType == "textarea")## 文本框 + + + + #end + #end + #end + + + + + +// 弹出层标题 +title: "", +// 是否显示弹出层 +open: false, + +// 表单参数 +form: {}, +// 表单校验 +rules: { +#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 }], + #end +#end +} + + +/** 表单重置 */ +reset() { +this.form = { +#foreach ($column in $columns) + #if ($column.createOperation || $column.updateOperation) + #if ($column.htmlType == "checkbox") + $column.javaField: [], + #else + $column.javaField: undefined, + #end + #end +#end +}; +this.resetForm("form"); +}, + +/** 新增按钮操作 */ +handleAdd() { +this.reset(); +this.open = true; +this.title = "添加${table.classComment}"; +}, +/** 修改按钮操作 */ +handleUpdate(row) { +this.reset(); +const ${primaryColumn.javaField} = row.${primaryColumn.javaField}; +get${simpleClassName}(${primaryColumn.javaField}).then(response => { +this.form = response.data; +#foreach ($column in $columns) + #if($column.htmlType == "checkbox")## checkbox 特殊处理 + this.form.$column.javaField = this.form.${column.javaField}.split(","); + #end +#end +this.open = true; +this.title = "修改${table.classComment}"; +}); +}, +/** 提交按钮 */ +submitForm() { +this.#[[$]]#refs["form"].validate(valid => { +if (!valid) { +return; +} +#foreach ($column in $columns) +#if($column.htmlType == "checkbox") +this.form.$column.javaField = this.form.${column.javaField}.join(","); +#end +#end +// 修改的提交 +if (this.form.${primaryColumn.javaField} != null) { +update${simpleClassName}(this.form).then(response => { +this.#[[$modal]]#.msgSuccess("修改成功"); +this.open = false; +this.getList(); +}); +return; +} +// 添加的提交 +create${simpleClassName}(this.form).then(response => { +this.#[[$modal]]#.msgSuccess("新增成功"); +this.open = false; +this.getList(); +}); +}); +}, 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 389458c51..73f35856a 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,160 +1,230 @@ + diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vxe/api/api.ts.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vxe/api/api.ts.vm new file mode 100644 index 000000000..df49a002b --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vxe/api/api.ts.vm @@ -0,0 +1,74 @@ +import request from '@/config/axios' + +export interface ${simpleClassName}VO { +#foreach ($column in $columns) +#if ($column.createOperation || $column.updateOperation) +#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") + ${column.javaField}: number +#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime") + ${column.javaField}: Date +#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.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") + ${column.javaField}?: number +#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime") + ${column.javaField}?: Date[] +#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.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") + ${column.javaField}?: number +#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime") + ${column.javaField}?: Date[] +#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 }) +} + +// 查询${table.classComment}详情 +export const get${simpleClassName}Api = async (id: number) => { + return await request.get({ url: '${baseURL}/get?id=' + id }) +} + +// 新增${table.classComment} +export const create${simpleClassName}Api = async (data: ${simpleClassName}VO) => { + return await request.post({ url: '${baseURL}/create', data }) +} + +// 修改${table.classComment} +export const update${simpleClassName}Api = async (data: ${simpleClassName}VO) => { + return await request.put({ url: '${baseURL}/update', data }) +} + +// 删除${table.classComment} +export const delete${simpleClassName}Api = async (id: number) => { + return await request.delete({ url: '${baseURL}/delete?id=' + id }) +} + +// 导出${table.classComment} Excel +export const export${simpleClassName}Api = async (params: ${simpleClassName}ExcelReqVO) => { + return await request.download({ url: '${baseURL}/export-excel', params }) +} 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_vxe/views/data.ts.vm similarity index 100% rename from yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/data.ts.vm rename to yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vxe/views/data.ts.vm diff --git a/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vxe/views/index.vue.vm b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vxe/views/index.vue.vm new file mode 100644 index 000000000..389458c51 --- /dev/null +++ b/yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vxe/views/index.vue.vm @@ -0,0 +1,160 @@ + +