Commit 4f00d923af25bef33fa21d64dfbc087a51e8ec85
Committed by
&wxr
1 parent
6879fcd9
代码生成:支持 Vue3 标准模版的列表
Showing
7 changed files
with
615 additions
and
175 deletions
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 { |
| 105 | 105 | // Vue3 |
| 106 | 106 | .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/index.vue"), |
| 107 | 107 | vue3FilePath("views/${table.moduleName}/${classNameVar}/index.vue")) |
| 108 | - .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/data.ts"), | |
| 109 | - vue3FilePath("views/${table.moduleName}/${classNameVar}/${classNameVar}.data.ts")) | |
| 108 | +// .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("views/data.ts"), | |
| 109 | +// vue3FilePath("views/${table.moduleName}/${classNameVar}/${classNameVar}.data.ts")) | |
| 110 | 110 | .put(CodegenFrontTypeEnum.VUE3.getType(), vue3TemplatePath("api/api.ts"), |
| 111 | 111 | vue3FilePath("api/${table.moduleName}/${classNameVar}/index.ts")) |
| 112 | 112 | .build(); | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/api/api.ts.vm
| ... | ... | @@ -14,61 +14,32 @@ export interface ${simpleClassName}VO { |
| 14 | 14 | #end |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | -export interface ${simpleClassName}PageReqVO extends PageParam { | |
| 18 | -#foreach ($column in $columns) | |
| 19 | -#if (${column.listOperation})##查询操作 | |
| 20 | -#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") | |
| 21 | - ${column.javaField}?: number | |
| 22 | -#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime") | |
| 23 | - ${column.javaField}?: Date[] | |
| 24 | -#else | |
| 25 | - ${column.javaField}?: ${column.javaType.toLowerCase()} | |
| 26 | -#end | |
| 27 | -#end | |
| 28 | -#end | |
| 29 | -} | |
| 30 | - | |
| 31 | -export interface ${simpleClassName}ExcelReqVO { | |
| 32 | -#foreach ($column in $columns) | |
| 33 | -#if (${column.listOperation})##查询操作 | |
| 34 | -#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") | |
| 35 | - ${column.javaField}?: number | |
| 36 | -#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime") | |
| 37 | - ${column.javaField}?: Date[] | |
| 38 | -#else | |
| 39 | - ${column.javaField}?: ${column.javaType.toLowerCase()} | |
| 40 | -#end | |
| 41 | -#end | |
| 42 | -#end | |
| 43 | -} | |
| 44 | -#set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}") | |
| 45 | - | |
| 46 | 17 | // 查询${table.classComment}列表 |
| 47 | -export const get${simpleClassName}PageApi = async (params: ${simpleClassName}PageReqVO) => { | |
| 18 | +export const get${simpleClassName}Page = async (params: ${simpleClassName}PageReqVO) => { | |
| 48 | 19 | return await request.get({ url: '${baseURL}/page', params }) |
| 49 | 20 | } |
| 50 | 21 | |
| 51 | 22 | // 查询${table.classComment}详情 |
| 52 | -export const get${simpleClassName}Api = async (id: number) => { | |
| 23 | +export const get${simpleClassName} = async (id: number) => { | |
| 53 | 24 | return await request.get({ url: '${baseURL}/get?id=' + id }) |
| 54 | 25 | } |
| 55 | 26 | |
| 56 | 27 | // 新增${table.classComment} |
| 57 | -export const create${simpleClassName}Api = async (data: ${simpleClassName}VO) => { | |
| 28 | +export const create${simpleClassName} = async (data: ${simpleClassName}VO) => { | |
| 58 | 29 | return await request.post({ url: '${baseURL}/create', data }) |
| 59 | 30 | } |
| 60 | 31 | |
| 61 | 32 | // 修改${table.classComment} |
| 62 | -export const update${simpleClassName}Api = async (data: ${simpleClassName}VO) => { | |
| 33 | +export const update${simpleClassName} = async (data: ${simpleClassName}VO) => { | |
| 63 | 34 | return await request.put({ url: '${baseURL}/update', data }) |
| 64 | 35 | } |
| 65 | 36 | |
| 66 | 37 | // 删除${table.classComment} |
| 67 | -export const delete${simpleClassName}Api = async (id: number) => { | |
| 38 | +export const delete${simpleClassName} = async (id: number) => { | |
| 68 | 39 | return await request.delete({ url: '${baseURL}/delete?id=' + id }) |
| 69 | 40 | } |
| 70 | 41 | |
| 71 | 42 | // 导出${table.classComment} Excel |
| 72 | -export const export${simpleClassName}Api = async (params: ${simpleClassName}ExcelReqVO) => { | |
| 43 | +export const export${simpleClassName}Api = async (params) => { | |
| 73 | 44 | return await request.download({ url: '${baseURL}/export-excel', params }) |
| 74 | 45 | } | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/form.vue.vm
0 → 100644
| 1 | +<!-- 对话框(添加 / 修改) --> | |
| 2 | +<el-dialog :title="title" :visible.sync="open" width="500px" v-dialogDrag append-to-body> | |
| 3 | + <el-form ref="form" :model="form" :rules="rules" label-width="80px"> | |
| 4 | + #foreach($column in $columns) | |
| 5 | + #if ($column.createOperation || $column.updateOperation) | |
| 6 | + #set ($dictType = $column.dictType) | |
| 7 | + #set ($javaField = $column.javaField) | |
| 8 | + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 9 | + #set ($comment = $column.columnComment) | |
| 10 | + #if ($column.htmlType == "input") | |
| 11 | + #if (!$column.primaryKey)## 忽略主键,不用在表单里 | |
| 12 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 13 | + <el-input v-model="form.${javaField}" placeholder="请输入${comment}" /> | |
| 14 | + </el-form-item> | |
| 15 | + #end | |
| 16 | + #elseif($column.htmlType == "imageUpload")## 图片上传 | |
| 17 | + #set ($hasImageUploadColumn = true) | |
| 18 | + <el-form-item label="${comment}"> | |
| 19 | + <imageUpload v-model="form.${javaField}"/> | |
| 20 | + </el-form-item> | |
| 21 | + #elseif($column.htmlType == "fileUpload")## 文件上传 | |
| 22 | + #set ($hasFileUploadColumn = true) | |
| 23 | + <el-form-item label="${comment}"> | |
| 24 | + <fileUpload v-model="form.${javaField}"/> | |
| 25 | + </el-form-item> | |
| 26 | + #elseif($column.htmlType == "editor")## 文本编辑器 | |
| 27 | + #set ($hasEditorColumn = true) | |
| 28 | + <el-form-item label="${comment}"> | |
| 29 | + <editor v-model="form.${javaField}" :min-height="192"/> | |
| 30 | + </el-form-item> | |
| 31 | + #elseif($column.htmlType == "select")## 下拉框 | |
| 32 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 33 | + <el-select v-model="form.${javaField}" placeholder="请选择${comment}"> | |
| 34 | + #if ("" != $dictType)## 有数据字典 | |
| 35 | + <el-option v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 36 | + :key="dict.value" :label="dict.label" #if ($column.javaType == "Integer" || $column.javaType == "Long"):value="parseInt(dict.value)"#else:value="dict.value"#end /> | |
| 37 | + #else##没数据字典 | |
| 38 | + <el-option label="请选择字典生成" value="" /> | |
| 39 | + #end | |
| 40 | + </el-select> | |
| 41 | + </el-form-item> | |
| 42 | + #elseif($column.htmlType == "checkbox")## 多选框 | |
| 43 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 44 | + <el-checkbox-group v-model="form.${javaField}"> | |
| 45 | + #if ("" != $dictType)## 有数据字典 | |
| 46 | + <el-checkbox v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 47 | + :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-checkbox> | |
| 48 | + #else##没数据字典 | |
| 49 | + <el-checkbox>请选择字典生成</el-checkbox> | |
| 50 | + #end | |
| 51 | + </el-checkbox-group> | |
| 52 | + </el-form-item> | |
| 53 | + #elseif($column.htmlType == "radio")## 单选框 | |
| 54 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 55 | + <el-radio-group v-model="form.${javaField}"> | |
| 56 | + #if ("" != $dictType)## 有数据字典 | |
| 57 | + <el-radio v-for="dict in this.getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 58 | + :key="dict.value" #if($column.javaType == "Integer" || $column.javaType == "Long"):label="parseInt(dict.value)"#else:label="dict.value"#end>{{dict.label}}</el-radio> | |
| 59 | + #else##没数据字典 | |
| 60 | + <el-radio label="1">请选择字典生成</el-radio> | |
| 61 | + #end | |
| 62 | + </el-radio-group> | |
| 63 | + </el-form-item> | |
| 64 | + #elseif($column.htmlType == "datetime")## 时间框 | |
| 65 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 66 | + <el-date-picker clearable v-model="form.${javaField}" type="date" value-format="timestamp" placeholder="选择${comment}" /> | |
| 67 | + </el-form-item> | |
| 68 | + #elseif($column.htmlType == "textarea")## 文本框 | |
| 69 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 70 | + <el-input v-model="form.${javaField}" type="textarea" placeholder="请输入内容" /> | |
| 71 | + </el-form-item> | |
| 72 | + #end | |
| 73 | + #end | |
| 74 | + #end | |
| 75 | + </el-form> | |
| 76 | + <div slot="footer" class="dialog-footer"> | |
| 77 | + <el-button type="primary" @click="submitForm">确 定</el-button> | |
| 78 | + <el-button @click="cancel">取 消</el-button> | |
| 79 | + </div> | |
| 80 | +</el-dialog> | |
| 81 | + | |
| 82 | + | |
| 83 | +// 弹出层标题 | |
| 84 | +title: "", | |
| 85 | +// 是否显示弹出层 | |
| 86 | +open: false, | |
| 87 | + | |
| 88 | +// 表单参数 | |
| 89 | +form: {}, | |
| 90 | +// 表单校验 | |
| 91 | +rules: { | |
| 92 | +#foreach ($column in $columns) | |
| 93 | + #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 | |
| 94 | + #set($comment=$column.columnComment) | |
| 95 | + $column.javaField: [{ required: true, message: "${comment}不能为空", trigger: #if($column.htmlType == "select")"change"#else"blur"#end }], | |
| 96 | + #end | |
| 97 | +#end | |
| 98 | +} | |
| 99 | + | |
| 100 | + | |
| 101 | +/** 表单重置 */ | |
| 102 | +reset() { | |
| 103 | +this.form = { | |
| 104 | +#foreach ($column in $columns) | |
| 105 | + #if ($column.createOperation || $column.updateOperation) | |
| 106 | + #if ($column.htmlType == "checkbox") | |
| 107 | + $column.javaField: [], | |
| 108 | + #else | |
| 109 | + $column.javaField: undefined, | |
| 110 | + #end | |
| 111 | + #end | |
| 112 | +#end | |
| 113 | +}; | |
| 114 | +this.resetForm("form"); | |
| 115 | +}, | |
| 116 | + | |
| 117 | +/** 新增按钮操作 */ | |
| 118 | +handleAdd() { | |
| 119 | +this.reset(); | |
| 120 | +this.open = true; | |
| 121 | +this.title = "添加${table.classComment}"; | |
| 122 | +}, | |
| 123 | +/** 修改按钮操作 */ | |
| 124 | +handleUpdate(row) { | |
| 125 | +this.reset(); | |
| 126 | +const ${primaryColumn.javaField} = row.${primaryColumn.javaField}; | |
| 127 | +get${simpleClassName}(${primaryColumn.javaField}).then(response => { | |
| 128 | +this.form = response.data; | |
| 129 | +#foreach ($column in $columns) | |
| 130 | + #if($column.htmlType == "checkbox")## checkbox 特殊处理 | |
| 131 | + this.form.$column.javaField = this.form.${column.javaField}.split(","); | |
| 132 | + #end | |
| 133 | +#end | |
| 134 | +this.open = true; | |
| 135 | +this.title = "修改${table.classComment}"; | |
| 136 | +}); | |
| 137 | +}, | |
| 138 | +/** 提交按钮 */ | |
| 139 | +submitForm() { | |
| 140 | +this.#[[$]]#refs["form"].validate(valid => { | |
| 141 | +if (!valid) { | |
| 142 | +return; | |
| 143 | +} | |
| 144 | +#foreach ($column in $columns) | |
| 145 | +#if($column.htmlType == "checkbox") | |
| 146 | +this.form.$column.javaField = this.form.${column.javaField}.join(","); | |
| 147 | +#end | |
| 148 | +#end | |
| 149 | +// 修改的提交 | |
| 150 | +if (this.form.${primaryColumn.javaField} != null) { | |
| 151 | +update${simpleClassName}(this.form).then(response => { | |
| 152 | +this.#[[$modal]]#.msgSuccess("修改成功"); | |
| 153 | +this.open = false; | |
| 154 | +this.getList(); | |
| 155 | +}); | |
| 156 | +return; | |
| 157 | +} | |
| 158 | +// 添加的提交 | |
| 159 | +create${simpleClassName}(this.form).then(response => { | |
| 160 | +this.#[[$modal]]#.msgSuccess("新增成功"); | |
| 161 | +this.open = false; | |
| 162 | +this.getList(); | |
| 163 | +}); | |
| 164 | +}); | |
| 165 | +}, | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/index.vue.vm
| 1 | 1 | <template> |
| 2 | - <ContentWrap> | |
| 3 | - <!-- 列表 --> | |
| 4 | - <XTable @register="registerTable"> | |
| 5 | - <template #toolbar_buttons> | |
| 6 | - <!-- 操作:新增 --> | |
| 7 | - <XButton | |
| 8 | - type="primary" | |
| 9 | - preIcon="ep:zoom-in" | |
| 10 | - :title="t('action.add')" | |
| 11 | - v-hasPermi="['${permissionPrefix}:create']" | |
| 12 | - @click="handleCreate()" | |
| 2 | + <content-wrap> | |
| 3 | + <!-- 搜索工作栏 --> | |
| 4 | + <el-form class="-mb-15px" :model="queryParams" ref="queryFormRef" :inline="true"> | |
| 5 | + #foreach($column in $columns) | |
| 6 | + #if ($column.listOperation) | |
| 7 | + #set ($dictType = $column.dictType) | |
| 8 | + #set ($javaField = $column.javaField) | |
| 9 | + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 10 | + #set ($comment = $column.columnComment) | |
| 11 | + #if ($column.htmlType == "input") | |
| 12 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 13 | + <el-input | |
| 14 | + v-model="queryParams.${javaField}" | |
| 15 | + placeholder="请输入${comment}" | |
| 16 | + clearable | |
| 17 | + @keyup.enter="handleQuery" | |
| 13 | 18 | /> |
| 14 | - <!-- 操作:导出 --> | |
| 15 | - <XButton | |
| 16 | - type="warning" | |
| 17 | - preIcon="ep:download" | |
| 18 | - :title="t('action.export')" | |
| 19 | - v-hasPermi="['${permissionPrefix}:export']" | |
| 20 | - @click="exportList('${table.classComment}.xls')" | |
| 21 | - /> | |
| 22 | - </template> | |
| 23 | - <template #actionbtns_default="{ row }"> | |
| 24 | - <!-- 操作:修改 --> | |
| 25 | - <XTextButton | |
| 26 | - preIcon="ep:edit" | |
| 27 | - :title="t('action.edit')" | |
| 28 | - v-hasPermi="['${permissionPrefix}:update']" | |
| 29 | - @click="handleUpdate(row.id)" | |
| 19 | + </el-form-item> | |
| 20 | + #elseif ($column.htmlType == "select" || $column.htmlType == "radio") | |
| 21 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 22 | + <el-select v-model="queryParams.${javaField}" placeholder="请选择${comment}" clearable> | |
| 23 | + #if ("" != $dictType)## 设置了 dictType 数据字典的情况 | |
| 24 | + <!-- TODO 芋艿:需要考虑不同类型的处理 --> | |
| 25 | + <el-option | |
| 26 | + v-for="dict in getDictDatas(DICT_TYPE.$dictType.toUpperCase())" | |
| 27 | + :key="dict.value" | |
| 28 | + :label="dict.label" | |
| 29 | + :value="dict.value" | |
| 30 | + /> | |
| 31 | + #else## 未设置 dictType 数据字典的情况 | |
| 32 | + <el-option label="请选择字典生成" value="" /> | |
| 33 | + #end | |
| 34 | + </el-select> | |
| 35 | + </el-form-item> | |
| 36 | + #elseif($column.htmlType == "datetime") | |
| 37 | + #if ($column.listOperationCondition != "BETWEEN")## 非范围 | |
| 38 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 39 | + <el-date-picker | |
| 40 | + v-model="queryParams.${javaField}" | |
| 41 | + value-format="yyyy-MM-dd" | |
| 42 | + type="date" | |
| 43 | + placeholder="选择${comment}" | |
| 44 | + clearable | |
| 30 | 45 | /> |
| 31 | - <!-- 操作:详情 --> | |
| 32 | - <XTextButton | |
| 33 | - preIcon="ep:view" | |
| 34 | - :title="t('action.detail')" | |
| 35 | - v-hasPermi="['${permissionPrefix}:query']" | |
| 36 | - @click="handleDetail(row.id)" | |
| 46 | + </el-form-item> | |
| 47 | + #else## 范围 | |
| 48 | + <el-form-item label="${comment}" prop="${javaField}"> | |
| 49 | + <el-date-picker | |
| 50 | + v-model="queryParams.${javaField}" | |
| 51 | + value-format="yyyy-MM-dd HH:mm:ss" | |
| 52 | + type="daterange" | |
| 53 | + start-placeholder="开始日期" | |
| 54 | + end-placeholder="结束日期" | |
| 55 | + :default-time="[new Date('1 00:00:00'), new Date('1 23:59:59')]" | |
| 37 | 56 | /> |
| 38 | - <!-- 操作:删除 --> | |
| 39 | - <XTextButton | |
| 40 | - preIcon="ep:delete" | |
| 41 | - :title="t('action.del')" | |
| 42 | - v-hasPermi="['${permissionPrefix}:delete']" | |
| 43 | - @click="deleteData(row.id)" | |
| 44 | - /> | |
| 45 | - </template> | |
| 46 | - </XTable> | |
| 47 | - </ContentWrap> | |
| 48 | - <!-- 弹窗 --> | |
| 49 | - <XModal id="${classNameVar}Model" :loading="modelLoading" v-model="modelVisible" :title="modelTitle"> | |
| 50 | - <!-- 表单:添加/修改 --> | |
| 51 | - <Form | |
| 52 | - ref="formRef" | |
| 53 | - v-if="['create', 'update'].includes(actionType)" | |
| 54 | - :schema="allSchemas.formSchema" | |
| 55 | - :rules="rules" | |
| 56 | - /> | |
| 57 | - <!-- 表单:详情 --> | |
| 58 | - <Descriptions | |
| 59 | - v-if="actionType === 'detail'" | |
| 60 | - :schema="allSchemas.detailSchema" | |
| 61 | - :data="detailData" | |
| 62 | - /> | |
| 63 | - <template #footer> | |
| 64 | - <!-- 按钮:保存 --> | |
| 65 | - <XButton | |
| 66 | - v-if="['create', 'update'].includes(actionType)" | |
| 67 | - type="primary" | |
| 68 | - :title="t('action.save')" | |
| 69 | - :loading="actionLoading" | |
| 70 | - @click="submitForm()" | |
| 57 | + </el-form-item> | |
| 58 | + #end | |
| 59 | + #end | |
| 60 | + #end | |
| 61 | + #end | |
| 62 | + <el-form-item> | |
| 63 | + <el-button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</el-button> | |
| 64 | + <el-button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</el-button> | |
| 65 | + <el-button type="primary" @click="openModal('create')" v-hasPermi="['${permissionPrefix}:create']"> | |
| 66 | + <Icon icon="ep:plus" class="mr-5px" /> 新增 | |
| 67 | + </el-button> | |
| 68 | + <el-button | |
| 69 | + type="success" | |
| 70 | + plain | |
| 71 | + @click="handleExport" | |
| 72 | + :loading="exportLoading" | |
| 73 | + v-hasPermi="['${permissionPrefix}:export']" | |
| 74 | + > | |
| 75 | + <Icon icon="ep:download" class="mr-5px" /> 导出 | |
| 76 | + </el-button> | |
| 77 | + </el-form-item> | |
| 78 | + </el-form> | |
| 79 | + </content-wrap> | |
| 80 | + | |
| 81 | + <!-- 列表 --> | |
| 82 | + <content-wrap> | |
| 83 | + <el-table v-loading="loading" :data="list"> | |
| 84 | + #foreach($column in $columns) | |
| 85 | + #if ($column.listOperationResult) | |
| 86 | + #set ($dictType=$column.dictType) | |
| 87 | + #set ($javaField = $column.javaField) | |
| 88 | + #set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 89 | + #set ($comment=$column.columnComment) | |
| 90 | + #if ($column.javaType == "LocalDateTime")## 时间类型 | |
| 91 | + <el-table-column | |
| 92 | + label="${comment}" | |
| 93 | + align="center" | |
| 94 | + prop="${javaField}" | |
| 95 | + :formatter="dateFormatter" | |
| 71 | 96 | /> |
| 72 | - <!-- 按钮:关闭 --> | |
| 73 | - <XButton :loading="actionLoading" :title="t('dialog.close')" @click="modelVisible = false" /> | |
| 74 | - </template> | |
| 75 | - </XModal> | |
| 97 | + #elseif("" != $column.dictType)## 数据字典 | |
| 98 | + <el-table-column label="${comment}" align="center" prop="${javaField}"> | |
| 99 | + <template #default="scope"> | |
| 100 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="scope.row.${column.javaField}" /> | |
| 101 | + </template> | |
| 102 | + </el-table-column> | |
| 103 | + #else | |
| 104 | + <el-table-column label="${comment}" align="center" prop="${javaField}" /> | |
| 105 | + #end | |
| 106 | + #end | |
| 107 | + #end | |
| 108 | + <el-table-column label="操作" align="center"> | |
| 109 | + <template #default="scope"> | |
| 110 | + <el-button | |
| 111 | + link | |
| 112 | + type="primary" | |
| 113 | + @click="openModal('update', scope.row.id)" | |
| 114 | + v-hasPermi="['${permissionPrefix}:update']" | |
| 115 | + > | |
| 116 | + 编辑 | |
| 117 | + </el-button> | |
| 118 | + <el-button | |
| 119 | + link | |
| 120 | + type="danger" | |
| 121 | + @click="handleDelete(scope.row.id)" | |
| 122 | + v-hasPermi="['${permissionPrefix}:delete']" | |
| 123 | + > | |
| 124 | + 删除 | |
| 125 | + </el-button> | |
| 126 | + </template> | |
| 127 | + </el-table-column> | |
| 128 | + </el-table> | |
| 129 | + <!-- 分页 --> | |
| 130 | + <Pagination | |
| 131 | + :total="total" | |
| 132 | + v-model:page="queryParams.pageNo" | |
| 133 | + v-model:limit="queryParams.pageSize" | |
| 134 | + @pagination="getList" | |
| 135 | + /> | |
| 136 | + </content-wrap> | |
| 76 | 137 | </template> |
| 138 | + | |
| 77 | 139 | <script setup lang="ts" name="${simpleClassName}"> |
| 78 | -import { FormExpose } from '@/components/Form' | |
| 79 | -// 业务相关的 import | |
| 80 | -import { rules, allSchemas } from './${classNameVar}.data' | |
| 140 | +import { DICT_TYPE, getDictOptions } from '@/utils/dict' | |
| 141 | +import { dateFormatter } from '@/utils/formatTime' | |
| 142 | +import download from '@/utils/download' | |
| 81 | 143 | import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${classNameVar}' |
| 82 | - | |
| 83 | -const { t } = useI18n() // 国际化 | |
| 144 | +// import ConfigForm from './form.vue' | |
| 84 | 145 | const message = useMessage() // 消息弹窗 |
| 146 | +const { t } = useI18n() // 国际化 | |
| 85 | 147 | |
| 86 | -// 列表相关的变量 | |
| 87 | -const [registerTable, { reload, deleteData, exportList }] = useXTable({ | |
| 88 | - allSchemas: allSchemas, | |
| 89 | - getListApi: ${simpleClassName}Api.get${simpleClassName}PageApi, | |
| 90 | - deleteApi: ${simpleClassName}Api.delete${simpleClassName}Api, | |
| 91 | - exportListApi: ${simpleClassName}Api.export${simpleClassName}Api | |
| 148 | +const loading = ref(true) // 列表的加载中 | |
| 149 | +const total = ref(0) // 列表的总页数 | |
| 150 | +const list = ref([]) // 列表的数据 | |
| 151 | +const queryParams = reactive({ | |
| 152 | + pageNo: 1, | |
| 153 | + pageSize: 10, | |
| 154 | + #foreach ($column in $columns) | |
| 155 | + #if ($column.listOperation) | |
| 156 | + #if ($column.listOperationCondition != 'BETWEEN') | |
| 157 | + $column.javaField: null, | |
| 158 | + #end | |
| 159 | + #if ($column.htmlType == "datetime" || $column.listOperationCondition == "BETWEEN") | |
| 160 | + $column.javaField: [], | |
| 161 | + #end | |
| 162 | + #end | |
| 163 | + #end | |
| 92 | 164 | }) |
| 165 | +const queryFormRef = ref() // 搜索的表单 | |
| 166 | +const exportLoading = ref(false) // 导出的加载中 | |
| 93 | 167 | |
| 94 | -// 弹窗相关的变量 | |
| 95 | -const modelVisible = ref(false) // 是否显示弹出层 | |
| 96 | -const modelTitle = ref('edit') // 弹出层标题 | |
| 97 | -const modelLoading = ref(false) // 弹出层loading | |
| 98 | -const actionType = ref('') // 操作按钮的类型 | |
| 99 | -const actionLoading = ref(false) // 按钮 Loading | |
| 100 | -const formRef = ref<FormExpose>() // 表单 Ref | |
| 101 | -const detailData = ref() // 详情 Ref | |
| 102 | - | |
| 103 | -// 设置标题 | |
| 104 | -const setDialogTile = (type: string) => { | |
| 105 | - modelLoading.value = true | |
| 106 | - modelTitle.value = t('action.' + type) | |
| 107 | - actionType.value = type | |
| 108 | - modelVisible.value = true | |
| 168 | +/** 查询参数列表 */ | |
| 169 | +const getList = async () => { | |
| 170 | + loading.value = true | |
| 171 | + try { | |
| 172 | + const data = await ${simpleClassName}Api.get${simpleClassName}Page(queryParams) | |
| 173 | + list.value = data.list | |
| 174 | + total.value = data.total | |
| 175 | + } finally { | |
| 176 | + loading.value = false | |
| 177 | + } | |
| 109 | 178 | } |
| 110 | 179 | |
| 111 | -// 新增操作 | |
| 112 | -const handleCreate = () => { | |
| 113 | - setDialogTile('create') | |
| 114 | - modelLoading.value = false | |
| 180 | +/** 搜索按钮操作 */ | |
| 181 | +const handleQuery = () => { | |
| 182 | + queryParams.pageNo = 1 | |
| 183 | + getList() | |
| 115 | 184 | } |
| 116 | 185 | |
| 117 | -// 修改操作 | |
| 118 | -const handleUpdate = async (rowId: number) => { | |
| 119 | - setDialogTile('update') | |
| 120 | - // 设置数据 | |
| 121 | - const res = await ${simpleClassName}Api.get${simpleClassName}Api(rowId) | |
| 122 | - unref(formRef)?.setValues(res) | |
| 123 | - modelLoading.value = false | |
| 186 | +/** 重置按钮操作 */ | |
| 187 | +const resetQuery = () => { | |
| 188 | + queryFormRef.value.resetFields() | |
| 189 | + handleQuery() | |
| 124 | 190 | } |
| 125 | 191 | |
| 126 | -// 详情操作 | |
| 127 | -const handleDetail = async (rowId: number) => { | |
| 128 | - setDialogTile('detail') | |
| 129 | - const res = await ${simpleClassName}Api.get${simpleClassName}Api(rowId) | |
| 130 | - detailData.value = res | |
| 131 | - modelLoading.value = false | |
| 192 | +/** 添加/修改操作 */ | |
| 193 | +// const modalRef = ref() | |
| 194 | +// const openModal = (type: string, id?: number) => { | |
| 195 | +// modalRef.value.openModal(type, id) | |
| 196 | +// } | |
| 197 | + | |
| 198 | +/** 删除按钮操作 */ | |
| 199 | +const handleDelete = async (id: number) => { | |
| 200 | + try { | |
| 201 | + // 删除的二次确认 | |
| 202 | + await message.delConfirm() | |
| 203 | + // 发起删除 | |
| 204 | + await ${simpleClassName}Api.delete${simpleClassName}(id) | |
| 205 | + message.success(t('common.delSuccess')) | |
| 206 | + // 刷新列表 | |
| 207 | + await getList() | |
| 208 | + } catch {} | |
| 132 | 209 | } |
| 133 | 210 | |
| 134 | -// 提交按钮 | |
| 135 | -const submitForm = async () => { | |
| 136 | - const elForm = unref(formRef)?.getElFormRef() | |
| 137 | - if (!elForm) return | |
| 138 | - elForm.validate(async (valid) => { | |
| 139 | - if (valid) { | |
| 140 | - actionLoading.value = true | |
| 141 | - // 提交请求 | |
| 142 | - try { | |
| 143 | - const data = unref(formRef)?.formModel as ${simpleClassName}Api.${simpleClassName}VO | |
| 144 | - if (actionType.value === 'create') { | |
| 145 | - await ${simpleClassName}Api.create${simpleClassName}Api(data) | |
| 146 | - message.success(t('common.createSuccess')) | |
| 147 | - } else { | |
| 148 | - await ${simpleClassName}Api.update${simpleClassName}Api(data) | |
| 149 | - message.success(t('common.updateSuccess')) | |
| 150 | - } | |
| 151 | - modelVisible.value = false | |
| 152 | - } finally { | |
| 153 | - actionLoading.value = false | |
| 154 | - // 刷新列表 | |
| 155 | - await reload() | |
| 156 | - } | |
| 157 | - } | |
| 158 | - }) | |
| 211 | +/** 导出按钮操作 */ | |
| 212 | +const handleExport = async () => { | |
| 213 | + try { | |
| 214 | + // 导出的二次确认 | |
| 215 | + await message.exportConfirm() | |
| 216 | + // 发起导出 | |
| 217 | + exportLoading.value = true | |
| 218 | + const data = await ${simpleClassName}Api.export${simpleClassName}Api(queryParams) | |
| 219 | + download.excel(data, '${table.classComment}.xls') | |
| 220 | + } catch { | |
| 221 | + } finally { | |
| 222 | + exportLoading.value = false | |
| 223 | + } | |
| 159 | 224 | } |
| 225 | + | |
| 226 | +/** 初始化 **/ | |
| 227 | +onMounted(() => { | |
| 228 | + getList() | |
| 229 | +}) | |
| 160 | 230 | </script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vxe/api/api.ts.vm
0 → 100644
| 1 | +import request from '@/config/axios' | |
| 2 | + | |
| 3 | +export interface ${simpleClassName}VO { | |
| 4 | +#foreach ($column in $columns) | |
| 5 | +#if ($column.createOperation || $column.updateOperation) | |
| 6 | +#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") | |
| 7 | + ${column.javaField}: number | |
| 8 | +#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime") | |
| 9 | + ${column.javaField}: Date | |
| 10 | +#else | |
| 11 | + ${column.javaField}: ${column.javaType.toLowerCase()} | |
| 12 | +#end | |
| 13 | +#end | |
| 14 | +#end | |
| 15 | +} | |
| 16 | + | |
| 17 | +export interface ${simpleClassName}PageReqVO extends PageParam { | |
| 18 | +#foreach ($column in $columns) | |
| 19 | +#if (${column.listOperation})##查询操作 | |
| 20 | +#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") | |
| 21 | + ${column.javaField}?: number | |
| 22 | +#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime") | |
| 23 | + ${column.javaField}?: Date[] | |
| 24 | +#else | |
| 25 | + ${column.javaField}?: ${column.javaType.toLowerCase()} | |
| 26 | +#end | |
| 27 | +#end | |
| 28 | +#end | |
| 29 | +} | |
| 30 | + | |
| 31 | +export interface ${simpleClassName}ExcelReqVO { | |
| 32 | +#foreach ($column in $columns) | |
| 33 | +#if (${column.listOperation})##查询操作 | |
| 34 | +#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") | |
| 35 | + ${column.javaField}?: number | |
| 36 | +#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdatetime") | |
| 37 | + ${column.javaField}?: Date[] | |
| 38 | +#else | |
| 39 | + ${column.javaField}?: ${column.javaType.toLowerCase()} | |
| 40 | +#end | |
| 41 | +#end | |
| 42 | +#end | |
| 43 | +} | |
| 44 | +#set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}") | |
| 45 | + | |
| 46 | +// 查询${table.classComment}列表 | |
| 47 | +export const get${simpleClassName}PageApi = async (params: ${simpleClassName}PageReqVO) => { | |
| 48 | + return await request.get({ url: '${baseURL}/page', params }) | |
| 49 | +} | |
| 50 | + | |
| 51 | +// 查询${table.classComment}详情 | |
| 52 | +export const get${simpleClassName}Api = async (id: number) => { | |
| 53 | + return await request.get({ url: '${baseURL}/get?id=' + id }) | |
| 54 | +} | |
| 55 | + | |
| 56 | +// 新增${table.classComment} | |
| 57 | +export const create${simpleClassName}Api = async (data: ${simpleClassName}VO) => { | |
| 58 | + return await request.post({ url: '${baseURL}/create', data }) | |
| 59 | +} | |
| 60 | + | |
| 61 | +// 修改${table.classComment} | |
| 62 | +export const update${simpleClassName}Api = async (data: ${simpleClassName}VO) => { | |
| 63 | + return await request.put({ url: '${baseURL}/update', data }) | |
| 64 | +} | |
| 65 | + | |
| 66 | +// 删除${table.classComment} | |
| 67 | +export const delete${simpleClassName}Api = async (id: number) => { | |
| 68 | + return await request.delete({ url: '${baseURL}/delete?id=' + id }) | |
| 69 | +} | |
| 70 | + | |
| 71 | +// 导出${table.classComment} Excel | |
| 72 | +export const export${simpleClassName}Api = async (params: ${simpleClassName}ExcelReqVO) => { | |
| 73 | + return await request.download({ url: '${baseURL}/export-excel', params }) | |
| 74 | +} | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3/views/data.ts.vm renamed to yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vxe/views/data.ts.vm
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vxe/views/index.vue.vm
0 → 100644
| 1 | +<template> | |
| 2 | + <ContentWrap> | |
| 3 | + <!-- 列表 --> | |
| 4 | + <XTable @register="registerTable"> | |
| 5 | + <template #toolbar_buttons> | |
| 6 | + <!-- 操作:新增 --> | |
| 7 | + <XButton | |
| 8 | + type="primary" | |
| 9 | + preIcon="ep:zoom-in" | |
| 10 | + :title="t('action.add')" | |
| 11 | + v-hasPermi="['${permissionPrefix}:create']" | |
| 12 | + @click="handleCreate()" | |
| 13 | + /> | |
| 14 | + <!-- 操作:导出 --> | |
| 15 | + <XButton | |
| 16 | + type="warning" | |
| 17 | + preIcon="ep:download" | |
| 18 | + :title="t('action.export')" | |
| 19 | + v-hasPermi="['${permissionPrefix}:export']" | |
| 20 | + @click="exportList('${table.classComment}.xls')" | |
| 21 | + /> | |
| 22 | + </template> | |
| 23 | + <template #actionbtns_default="{ row }"> | |
| 24 | + <!-- 操作:修改 --> | |
| 25 | + <XTextButton | |
| 26 | + preIcon="ep:edit" | |
| 27 | + :title="t('action.edit')" | |
| 28 | + v-hasPermi="['${permissionPrefix}:update']" | |
| 29 | + @click="handleUpdate(row.id)" | |
| 30 | + /> | |
| 31 | + <!-- 操作:详情 --> | |
| 32 | + <XTextButton | |
| 33 | + preIcon="ep:view" | |
| 34 | + :title="t('action.detail')" | |
| 35 | + v-hasPermi="['${permissionPrefix}:query']" | |
| 36 | + @click="handleDetail(row.id)" | |
| 37 | + /> | |
| 38 | + <!-- 操作:删除 --> | |
| 39 | + <XTextButton | |
| 40 | + preIcon="ep:delete" | |
| 41 | + :title="t('action.del')" | |
| 42 | + v-hasPermi="['${permissionPrefix}:delete']" | |
| 43 | + @click="deleteData(row.id)" | |
| 44 | + /> | |
| 45 | + </template> | |
| 46 | + </XTable> | |
| 47 | + </ContentWrap> | |
| 48 | + <!-- 弹窗 --> | |
| 49 | + <XModal id="${classNameVar}Model" :loading="modelLoading" v-model="modelVisible" :title="modelTitle"> | |
| 50 | + <!-- 表单:添加/修改 --> | |
| 51 | + <Form | |
| 52 | + ref="formRef" | |
| 53 | + v-if="['create', 'update'].includes(actionType)" | |
| 54 | + :schema="allSchemas.formSchema" | |
| 55 | + :rules="rules" | |
| 56 | + /> | |
| 57 | + <!-- 表单:详情 --> | |
| 58 | + <Descriptions | |
| 59 | + v-if="actionType === 'detail'" | |
| 60 | + :schema="allSchemas.detailSchema" | |
| 61 | + :data="detailData" | |
| 62 | + /> | |
| 63 | + <template #footer> | |
| 64 | + <!-- 按钮:保存 --> | |
| 65 | + <XButton | |
| 66 | + v-if="['create', 'update'].includes(actionType)" | |
| 67 | + type="primary" | |
| 68 | + :title="t('action.save')" | |
| 69 | + :loading="actionLoading" | |
| 70 | + @click="submitForm()" | |
| 71 | + /> | |
| 72 | + <!-- 按钮:关闭 --> | |
| 73 | + <XButton :loading="actionLoading" :title="t('dialog.close')" @click="modelVisible = false" /> | |
| 74 | + </template> | |
| 75 | + </XModal> | |
| 76 | +</template> | |
| 77 | +<script setup lang="ts" name="${simpleClassName}"> | |
| 78 | +import { FormExpose } from '@/components/Form' | |
| 79 | +// 业务相关的 import | |
| 80 | +import { rules, allSchemas } from './${classNameVar}.data' | |
| 81 | +import * as ${simpleClassName}Api from '@/api/${table.moduleName}/${classNameVar}' | |
| 82 | + | |
| 83 | +const { t } = useI18n() // 国际化 | |
| 84 | +const message = useMessage() // 消息弹窗 | |
| 85 | + | |
| 86 | +// 列表相关的变量 | |
| 87 | +const [registerTable, { reload, deleteData, exportList }] = useXTable({ | |
| 88 | + allSchemas: allSchemas, | |
| 89 | + getListApi: ${simpleClassName}Api.get${simpleClassName}PageApi, | |
| 90 | + deleteApi: ${simpleClassName}Api.delete${simpleClassName}Api, | |
| 91 | + exportListApi: ${simpleClassName}Api.export${simpleClassName}Api | |
| 92 | +}) | |
| 93 | + | |
| 94 | +// 弹窗相关的变量 | |
| 95 | +const modelVisible = ref(false) // 是否显示弹出层 | |
| 96 | +const modelTitle = ref('edit') // 弹出层标题 | |
| 97 | +const modelLoading = ref(false) // 弹出层loading | |
| 98 | +const actionType = ref('') // 操作按钮的类型 | |
| 99 | +const actionLoading = ref(false) // 按钮 Loading | |
| 100 | +const formRef = ref<FormExpose>() // 表单 Ref | |
| 101 | +const detailData = ref() // 详情 Ref | |
| 102 | + | |
| 103 | +// 设置标题 | |
| 104 | +const setDialogTile = (type: string) => { | |
| 105 | + modelLoading.value = true | |
| 106 | + modelTitle.value = t('action.' + type) | |
| 107 | + actionType.value = type | |
| 108 | + modelVisible.value = true | |
| 109 | +} | |
| 110 | + | |
| 111 | +// 新增操作 | |
| 112 | +const handleCreate = () => { | |
| 113 | + setDialogTile('create') | |
| 114 | + modelLoading.value = false | |
| 115 | +} | |
| 116 | + | |
| 117 | +// 修改操作 | |
| 118 | +const handleUpdate = async (rowId: number) => { | |
| 119 | + setDialogTile('update') | |
| 120 | + // 设置数据 | |
| 121 | + const res = await ${simpleClassName}Api.get${simpleClassName}Api(rowId) | |
| 122 | + unref(formRef)?.setValues(res) | |
| 123 | + modelLoading.value = false | |
| 124 | +} | |
| 125 | + | |
| 126 | +// 详情操作 | |
| 127 | +const handleDetail = async (rowId: number) => { | |
| 128 | + setDialogTile('detail') | |
| 129 | + const res = await ${simpleClassName}Api.get${simpleClassName}Api(rowId) | |
| 130 | + detailData.value = res | |
| 131 | + modelLoading.value = false | |
| 132 | +} | |
| 133 | + | |
| 134 | +// 提交按钮 | |
| 135 | +const submitForm = async () => { | |
| 136 | + const elForm = unref(formRef)?.getElFormRef() | |
| 137 | + if (!elForm) return | |
| 138 | + elForm.validate(async (valid) => { | |
| 139 | + if (valid) { | |
| 140 | + actionLoading.value = true | |
| 141 | + // 提交请求 | |
| 142 | + try { | |
| 143 | + const data = unref(formRef)?.formModel as ${simpleClassName}Api.${simpleClassName}VO | |
| 144 | + if (actionType.value === 'create') { | |
| 145 | + await ${simpleClassName}Api.create${simpleClassName}Api(data) | |
| 146 | + message.success(t('common.createSuccess')) | |
| 147 | + } else { | |
| 148 | + await ${simpleClassName}Api.update${simpleClassName}Api(data) | |
| 149 | + message.success(t('common.updateSuccess')) | |
| 150 | + } | |
| 151 | + modelVisible.value = false | |
| 152 | + } finally { | |
| 153 | + actionLoading.value = false | |
| 154 | + // 刷新列表 | |
| 155 | + await reload() | |
| 156 | + } | |
| 157 | + } | |
| 158 | + }) | |
| 159 | +} | |
| 160 | +</script> | ... | ... |