Commit c26a46da66c08f9cd0c708404c22583301602c25
1 parent
32bdc20a
【功能新增】INFRA:代码生成 vben5 antd 模版 50%
Showing
11 changed files
with
1591 additions
and
0 deletions
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/enums/codegen/CodegenFrontTypeEnum.java
| ... | ... | @@ -16,6 +16,7 @@ public enum CodegenFrontTypeEnum { |
| 16 | 16 | VUE3_ELEMENT_PLUS(20), // Vue3 Element Plus 标准模版 |
| 17 | 17 | VUE3_VBEN2_ANTD_SCHEMA(30), // Vue3 VBEN2 + ANTD + Schema 模版 |
| 18 | 18 | VUE3_VBEN5_ANTD_SCHEMA(40), // Vue3 VBEN5 + ANTD + schema 模版 |
| 19 | + VUE3_VBEN5_ANTD(50), // Vue3 VBEN5 + ANTD 模版 | |
| 19 | 20 | ; |
| 20 | 21 | |
| 21 | 22 | /** | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/java/cn/iocoder/yudao/module/infra/service/codegen/inner/CodegenEngine.java
| ... | ... | @@ -163,6 +163,23 @@ public class CodegenEngine { |
| 163 | 163 | vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-list.vue")) |
| 164 | 164 | .put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD_SCHEMA.getType(), vue3Vben5AntdSchemaTemplatePath("views/modules/list_sub_erp.vue"), // 特殊:主子表专属逻辑 |
| 165 | 165 | vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-list.vue")) |
| 166 | + // VUE3_VBEN5_ANTD | |
| 167 | + .put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD.getType(), vue3Vben5AntdGeneralTemplatePath("views/index.vue"), | |
| 168 | + vue3FilePath("views/${table.moduleName}/${table.businessName}/index.vue")) | |
| 169 | + .put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD.getType(), vue3Vben5AntdGeneralTemplatePath("views/form.vue"), | |
| 170 | + vue3FilePath("views/${table.moduleName}/${table.businessName}/form.vue")) | |
| 171 | + .put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD.getType(), vue3Vben5AntdGeneralTemplatePath("views/modules/form_sub_normal.vue"), // 特殊:主子表专属逻辑 | |
| 172 | + vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-form.vue")) | |
| 173 | + .put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD.getType(), vue3Vben5AntdGeneralTemplatePath("views/modules/form_sub_inner.vue"), // 特殊:主子表专属逻辑 | |
| 174 | + vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-form.vue")) | |
| 175 | + .put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD.getType(), vue3Vben5AntdGeneralTemplatePath("views/modules/form_sub_erp.vue"), // 特殊:主子表专属逻辑 | |
| 176 | + vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-form.vue")) | |
| 177 | + .put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD.getType(), vue3Vben5AntdGeneralTemplatePath("views/modules/list_sub_inner.vue"), // 特殊:主子表专属逻辑 | |
| 178 | + vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-list.vue")) | |
| 179 | + .put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD.getType(), vue3Vben5AntdGeneralTemplatePath("views/modules/list_sub_erp.vue"), // 特殊:主子表专属逻辑 | |
| 180 | + vue3FilePath("views/${table.moduleName}/${table.businessName}/modules/${subSimpleClassName_strikeCase}-list.vue")) | |
| 181 | + .put(CodegenFrontTypeEnum.VUE3_VBEN5_ANTD.getType(), vue3Vben5AntdGeneralTemplatePath("api/api.ts"), | |
| 182 | + vue3FilePath("api/${table.moduleName}/${table.businessName}/index.ts")) | |
| 166 | 183 | .build(); |
| 167 | 184 | |
| 168 | 185 | @Resource | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/general/api/api.ts.vm
0 → 100644
| 1 | +import type { PageParam, PageResult } from '@vben/request'; | |
| 2 | + | |
| 3 | +import { requestClient } from '#/api/request'; | |
| 4 | +#set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}") | |
| 5 | + | |
| 6 | +export namespace ${simpleClassName}Api { | |
| 7 | + ## 特殊:主子表专属逻辑 | |
| 8 | + #foreach ($subTable in $subTables) | |
| 9 | + #set ($index = $foreach.count - 1) | |
| 10 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | |
| 11 | + #set ($subColumns = $subColumnsList.get($index))##当前字段数组 | |
| 12 | + /** ${subTable.classComment}信息 */ | |
| 13 | + export interface ${subSimpleClassName} { | |
| 14 | + #foreach ($column in $subColumns) | |
| 15 | + #if ($column.createOperation || $column.updateOperation) | |
| 16 | + #if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "short" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") | |
| 17 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: number; // ${column.columnComment} | |
| 18 | + #elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdate" || ${column.javaType.toLowerCase()} == "localdatetime") | |
| 19 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: Date; // ${column.columnComment} | |
| 20 | + #else | |
| 21 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: ${column.javaType.toLowerCase()}; // ${column.columnComment} | |
| 22 | + #end | |
| 23 | + #end | |
| 24 | + #end | |
| 25 | + } | |
| 26 | + | |
| 27 | + #end | |
| 28 | + /** ${table.classComment}信息 */ | |
| 29 | + export interface ${simpleClassName} { | |
| 30 | + #foreach ($column in $columns) | |
| 31 | + #if ($column.createOperation || $column.updateOperation) | |
| 32 | + #if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "short" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") | |
| 33 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: number; // ${column.columnComment} | |
| 34 | + #elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdate" || ${column.javaType.toLowerCase()} == "localdatetime") | |
| 35 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: Date; // ${column.columnComment} | |
| 36 | + #else | |
| 37 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: ${column.javaType.toLowerCase()}; // ${column.columnComment} | |
| 38 | + #end | |
| 39 | + #end | |
| 40 | + #end | |
| 41 | + #if ( $table.templateType == 2 ) | |
| 42 | + children?: ${simpleClassName}[]; | |
| 43 | + #end | |
| 44 | + ## 特殊:主子表专属逻辑 | |
| 45 | + #if ( $table.templateType == 10 || $table.templateType == 12 ) | |
| 46 | + #foreach ($subTable in $subTables) | |
| 47 | + #set ($index = $foreach.count - 1) | |
| 48 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | |
| 49 | + #if ( $subTable.subJoinMany ) | |
| 50 | + ${subSimpleClassName.toLowerCase()}s?: ${subSimpleClassName}[] | |
| 51 | + #else | |
| 52 | + ${subSimpleClassName.toLowerCase()}?: ${subSimpleClassName} | |
| 53 | + #end | |
| 54 | + #end | |
| 55 | + #end | |
| 56 | + } | |
| 57 | +} | |
| 58 | + | |
| 59 | +#if ( $table.templateType != 2 ) | |
| 60 | +/** 查询${table.classComment}分页 */ | |
| 61 | +export function get${simpleClassName}Page(params: PageParam) { | |
| 62 | + return requestClient.get<PageResult<${simpleClassName}Api.${simpleClassName}>>('${baseURL}/page', { params }); | |
| 63 | +} | |
| 64 | +#else | |
| 65 | +/** 查询${table.classComment}列表 */ | |
| 66 | +export function get${simpleClassName}List(params: any) { | |
| 67 | + return requestClient.get<${simpleClassName}Api.${simpleClassName}[]>('${baseURL}/list', { params }); | |
| 68 | +} | |
| 69 | +#end | |
| 70 | + | |
| 71 | +/** 查询${table.classComment}详情 */ | |
| 72 | +export function get${simpleClassName}(id: number) { | |
| 73 | + return requestClient.get<${simpleClassName}Api.${simpleClassName}>(`${baseURL}/get?id=${id}`); | |
| 74 | +} | |
| 75 | + | |
| 76 | +/** 新增${table.classComment} */ | |
| 77 | +export function create${simpleClassName}(data: ${simpleClassName}Api.${simpleClassName}) { | |
| 78 | + return requestClient.post('${baseURL}/create', data); | |
| 79 | +} | |
| 80 | + | |
| 81 | +/** 修改${table.classComment} */ | |
| 82 | +export function update${simpleClassName}(data: ${simpleClassName}Api.${simpleClassName}) { | |
| 83 | + return requestClient.put('${baseURL}/update', data); | |
| 84 | +} | |
| 85 | + | |
| 86 | +/** 删除${table.classComment} */ | |
| 87 | +export function delete${simpleClassName}(id: number) { | |
| 88 | + return requestClient.delete(`${baseURL}/delete?id=${id}`); | |
| 89 | +} | |
| 90 | + | |
| 91 | +/** 导出${table.classComment} */ | |
| 92 | +export function export${simpleClassName}(params: any) { | |
| 93 | + return requestClient.download('${baseURL}/export-excel', params); | |
| 94 | +} | |
| 95 | + | |
| 96 | +## 特殊:主子表专属逻辑 | |
| 97 | +#foreach ($subTable in $subTables) | |
| 98 | + #set ($index = $foreach.count - 1) | |
| 99 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | |
| 100 | + #set ($subPrimaryColumn = $subPrimaryColumns.get($index))##当前 primary 字段 | |
| 101 | + #set ($subJoinColumn = $subJoinColumns.get($index))##当前 join 字段 | |
| 102 | + #set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | |
| 103 | + #set ($subSimpleClassName_strikeCase = $subSimpleClassName_strikeCases.get($index)) | |
| 104 | + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index)) | |
| 105 | + #set ($subClassNameVar = $subClassNameVars.get($index)) | |
| 106 | + | |
| 107 | +// ==================== 子表($subTable.classComment) ==================== | |
| 108 | + | |
| 109 | + ## 情况一:MASTER_ERP 时,需要分查询页子表 | |
| 110 | + #if ( $table.templateType == 11 ) | |
| 111 | + /** 获得${subTable.classComment}分页 */ | |
| 112 | + export function get${subSimpleClassName}Page(params: PageParam) { | |
| 113 | + return requestClient.get<PageResult<${simpleClassName}Api.${subSimpleClassName}>>(`${baseURL}/${subSimpleClassName_strikeCase}/page`, { params }); | |
| 114 | + } | |
| 115 | + ## 情况二:非 MASTER_ERP 时,需要列表查询子表 | |
| 116 | + #else | |
| 117 | + #if ( $subTable.subJoinMany ) | |
| 118 | + /** 获得${subTable.classComment}列表 */ | |
| 119 | + export function get${subSimpleClassName}ListBy${SubJoinColumnName}(${subJoinColumn.javaField}: number) { | |
| 120 | + return requestClient.get<${simpleClassName}Api.${subSimpleClassName}[]>(`${baseURL}/${subSimpleClassName_strikeCase}/list-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=${${subJoinColumn.javaField}}`); | |
| 121 | + } | |
| 122 | + #else | |
| 123 | + /** 获得${subTable.classComment} */ | |
| 124 | + export function get${subSimpleClassName}By${SubJoinColumnName}(${subJoinColumn.javaField}: number) { | |
| 125 | + return requestClient.get<${simpleClassName}Api.${subSimpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get-by-${subJoinColumn_strikeCase}?${subJoinColumn.javaField}=${${subJoinColumn.javaField}}`); | |
| 126 | + } | |
| 127 | + #end | |
| 128 | + #end | |
| 129 | + ## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作 | |
| 130 | + #if ( $table.templateType == 11 ) | |
| 131 | + /** 新增${subTable.classComment} */ | |
| 132 | + export function create${subSimpleClassName}(data: ${simpleClassName}Api.${subSimpleClassName}) { | |
| 133 | + return requestClient.post(`${baseURL}/${subSimpleClassName_strikeCase}/create`, data); | |
| 134 | + } | |
| 135 | + | |
| 136 | + /** 修改${subTable.classComment} */ | |
| 137 | + export function update${subSimpleClassName}(data: ${simpleClassName}Api.${subSimpleClassName}) { | |
| 138 | + return requestClient.put(`${baseURL}/${subSimpleClassName_strikeCase}/update`, data); | |
| 139 | + } | |
| 140 | + | |
| 141 | + /** 删除${subTable.classComment} */ | |
| 142 | + export function delete${subSimpleClassName}(id: number) { | |
| 143 | + return requestClient.delete(`${baseURL}/${subSimpleClassName_strikeCase}/delete?id=${id}`); | |
| 144 | + } | |
| 145 | + | |
| 146 | + /** 获得${subTable.classComment} */ | |
| 147 | + export function get${subSimpleClassName}(id: number) { | |
| 148 | + return requestClient.get<${simpleClassName}Api.${subSimpleClassName}>(`${baseURL}/${subSimpleClassName_strikeCase}/get?id=${id}`); | |
| 149 | + } | |
| 150 | + #end | |
| 151 | +#end | |
| 0 | 152 | \ No newline at end of file | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/general/index.vue.vm deleted
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/general/views/form.vue.vm
0 → 100644
| 1 | +<template> | |
| 2 | + <Dialog :title="dialogTitle" v-model="dialogVisible"> | |
| 3 | + <Form | |
| 4 | + ref="formRef" | |
| 5 | + :model="formData" | |
| 6 | + :rules="formRules" | |
| 7 | + label-col="{ span: 6 }" | |
| 8 | + :loading="formLoading" | |
| 9 | + > | |
| 10 | +#foreach($column in $columns) | |
| 11 | + #if ($column.createOperation || $column.updateOperation) | |
| 12 | + #set ($dictType = $column.dictType) | |
| 13 | + #set ($javaField = $column.javaField) | |
| 14 | + #set ($javaType = $column.javaType) | |
| 15 | + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 16 | + #set ($comment = $column.columnComment) | |
| 17 | + #set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法 | |
| 18 | + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short") | |
| 19 | + #set ($dictMethod = "getIntDictOptions") | |
| 20 | + #elseif ($javaType == "String") | |
| 21 | + #set ($dictMethod = "getStrDictOptions") | |
| 22 | + #elseif ($javaType == "Boolean") | |
| 23 | + #set ($dictMethod = "getBoolDictOptions") | |
| 24 | + #end | |
| 25 | + #if ( $table.templateType == 2 && $column.id == $treeParentColumn.id ) | |
| 26 | + <FormItem label="${comment}" name="${javaField}"> | |
| 27 | + <TreeSelect | |
| 28 | + v-model:value="formData.${javaField}" | |
| 29 | + :treeData="${classNameVar}Tree" | |
| 30 | + #if ($treeNameColumn.javaField == "name") | |
| 31 | + :fieldNames="defaultProps" | |
| 32 | + #else | |
| 33 | + :fieldNames="{...defaultProps, label: '$treeNameColumn.javaField'}" | |
| 34 | + #end | |
| 35 | + checkable | |
| 36 | + treeDefaultExpandAll | |
| 37 | + placeholder="请选择${comment}" | |
| 38 | + /> | |
| 39 | + </FormItem> | |
| 40 | + #elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 | |
| 41 | + <FormItem label="${comment}" name="${javaField}"> | |
| 42 | + <Input v-model:value="formData.${javaField}" placeholder="请输入${comment}" /> | |
| 43 | + </FormItem> | |
| 44 | + #elseif($column.htmlType == "imageUpload")## 图片上传 | |
| 45 | + <FormItem label="${comment}" name="${javaField}"> | |
| 46 | + <UploadImg v-model:value="formData.${javaField}" /> | |
| 47 | + </FormItem> | |
| 48 | + #elseif($column.htmlType == "fileUpload")## 文件上传 | |
| 49 | + <FormItem label="${comment}" name="${javaField}"> | |
| 50 | + <UploadFile v-model:value="formData.${javaField}" /> | |
| 51 | + </FormItem> | |
| 52 | + #elseif($column.htmlType == "editor")## 文本编辑器 | |
| 53 | + <FormItem label="${comment}" name="${javaField}"> | |
| 54 | + <Editor v-model:value="formData.${javaField}" height="150px" /> | |
| 55 | + </FormItem> | |
| 56 | + #elseif($column.htmlType == "select")## 下拉框 | |
| 57 | + <FormItem label="${comment}" name="${javaField}"> | |
| 58 | + <Select v-model:value="formData.${javaField}" placeholder="请选择${comment}"> | |
| 59 | + #if ("" != $dictType)## 有数据字典 | |
| 60 | + <SelectOption | |
| 61 | + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())" | |
| 62 | + :key="dict.value" | |
| 63 | + :label="dict.label" | |
| 64 | + :value="dict.value" | |
| 65 | + /> | |
| 66 | + #else##没数据字典 | |
| 67 | + <SelectOption label="请选择字典生成" value="" /> | |
| 68 | + #end | |
| 69 | + </Select> | |
| 70 | + </FormItem> | |
| 71 | + #elseif($column.htmlType == "checkbox")## 多选框 | |
| 72 | + <FormItem label="${comment}" name="${javaField}"> | |
| 73 | + <CheckboxGroup v-model:value="formData.${javaField}"> | |
| 74 | + #if ("" != $dictType)## 有数据字典 | |
| 75 | + <Checkbox | |
| 76 | + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())" | |
| 77 | + :key="dict.value" | |
| 78 | + :label="dict.label" | |
| 79 | + :value="dict.value" | |
| 80 | + /> | |
| 81 | + #else##没数据字典 | |
| 82 | + <Checkbox label="请选择字典生成" /> | |
| 83 | + #end | |
| 84 | + </CheckboxGroup> | |
| 85 | + </FormItem> | |
| 86 | + #elseif($column.htmlType == "radio")## 单选框 | |
| 87 | + <FormItem label="${comment}" name="${javaField}"> | |
| 88 | + <RadioGroup v-model:value="formData.${javaField}"> | |
| 89 | + #if ("" != $dictType)## 有数据字典 | |
| 90 | + <Radio | |
| 91 | + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())" | |
| 92 | + :key="dict.value" | |
| 93 | + :value="dict.value" | |
| 94 | + > | |
| 95 | + {{ dict.label }} | |
| 96 | + </Radio> | |
| 97 | + #else##没数据字典 | |
| 98 | + <Radio value="1">请选择字典生成</Radio> | |
| 99 | + #end | |
| 100 | + </RadioGroup> | |
| 101 | + </FormItem> | |
| 102 | + #elseif($column.htmlType == "datetime")## 时间框 | |
| 103 | + <FormItem label="${comment}" name="${javaField}"> | |
| 104 | + <DatePicker | |
| 105 | + v-model:value="formData.${javaField}" | |
| 106 | + valueFormat="x" | |
| 107 | + placeholder="选择${comment}" | |
| 108 | + /> | |
| 109 | + </FormItem> | |
| 110 | + #elseif($column.htmlType == "textarea")## 文本框 | |
| 111 | + <FormItem label="${comment}" name="${javaField}"> | |
| 112 | + <Textarea v-model:value="formData.${javaField}" placeholder="请输入${comment}" /> | |
| 113 | + </FormItem> | |
| 114 | + #end | |
| 115 | + #end | |
| 116 | +#end | |
| 117 | + </Form> | |
| 118 | +## 特殊:主子表专属逻辑 | |
| 119 | +#if ( $table.templateType == 10 || $table.templateType == 12 ) | |
| 120 | + <!-- 子表的表单 --> | |
| 121 | + <Tabs v-model:activeKey="subTabsName"> | |
| 122 | + #foreach ($subTable in $subTables) | |
| 123 | + #set ($index = $foreach.count - 1) | |
| 124 | + #set ($subClassNameVar = $subClassNameVars.get($index)) | |
| 125 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | |
| 126 | + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index)) | |
| 127 | + <TabPane key="$subClassNameVar" tab="${subTable.classComment}"> | |
| 128 | + <${subSimpleClassName}Form ref="${subClassNameVar}FormRef" :${subJoinColumn_strikeCase}="formData.id" /> | |
| 129 | + </TabPane> | |
| 130 | + #end | |
| 131 | + </Tabs> | |
| 132 | +#end | |
| 133 | + <template #footer> | |
| 134 | + <Button @click="submitForm" type="primary" :loading="formLoading">确 定</Button> | |
| 135 | + <Button @click="dialogVisible = false">取 消</Button> | |
| 136 | + </template> | |
| 137 | + </Dialog> | |
| 138 | +</template> | |
| 139 | +<script setup lang="ts"> | |
| 140 | +import { Form, FormItem, Input, Button, Select, SelectOption, DatePicker, Textarea, Checkbox, CheckboxGroup, Radio, RadioGroup, Tabs, TabPane, TreeSelect } from 'ant-design-vue' | |
| 141 | +import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict' | |
| 142 | +import { ${simpleClassName}Api, ${simpleClassName}VO } from '@/api/${table.moduleName}/${table.businessName}' | |
| 143 | +## 特殊:树表专属逻辑 | |
| 144 | +#if ( $table.templateType == 2 ) | |
| 145 | +import { defaultProps, handleTree } from '@/utils/tree' | |
| 146 | +#end | |
| 147 | +## 特殊:主子表专属逻辑 | |
| 148 | +#if ( $table.templateType == 10 || $table.templateType == 12 ) | |
| 149 | +#foreach ($subSimpleClassName in $subSimpleClassNames) | |
| 150 | +import ${subSimpleClassName}Form from './components/${subSimpleClassName}Form.vue' | |
| 151 | +#end | |
| 152 | +#end | |
| 153 | + | |
| 154 | +/** ${table.classComment} 表单 */ | |
| 155 | +defineOptions({ name: '${simpleClassName}Form' }) | |
| 156 | + | |
| 157 | +const { t } = useI18n() // 国际化 | |
| 158 | +const message = useMessage() // 消息弹窗 | |
| 159 | + | |
| 160 | +const dialogVisible = ref(false) // 弹窗的是否展示 | |
| 161 | +const dialogTitle = ref('') // 弹窗的标题 | |
| 162 | +const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 163 | +const formType = ref('') // 表单的类型:create - 新增;update - 修改 | |
| 164 | +const formData = ref({ | |
| 165 | +#foreach ($column in $columns) | |
| 166 | + #if ($column.createOperation || $column.updateOperation) | |
| 167 | + #if ($column.htmlType == "checkbox") | |
| 168 | + $column.javaField: [], | |
| 169 | + #else | |
| 170 | + $column.javaField: undefined, | |
| 171 | + #end | |
| 172 | + #end | |
| 173 | +#end | |
| 174 | +}) | |
| 175 | +const formRules = reactive({ | |
| 176 | +#foreach ($column in $columns) | |
| 177 | + #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 | |
| 178 | + #set($comment=$column.columnComment) | |
| 179 | + $column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == 'select')'change'#else'blur'#end }], | |
| 180 | + #end | |
| 181 | +#end | |
| 182 | +}) | |
| 183 | +const formRef = ref() // 表单 Ref | |
| 184 | +## 特殊:树表专属逻辑 | |
| 185 | +#if ( $table.templateType == 2 ) | |
| 186 | +const ${classNameVar}Tree = ref([]) // 树形结构 | |
| 187 | +#end | |
| 188 | +## 特殊:主子表专属逻辑 | |
| 189 | +#if ( $table.templateType == 10 || $table.templateType == 12 ) | |
| 190 | +#if ( $subTables && $subTables.size() > 0 ) | |
| 191 | + | |
| 192 | +/** 子表的表单 */ | |
| 193 | +const subTabsName = ref('$subClassNameVars.get(0)') | |
| 194 | +#foreach ($subClassNameVar in $subClassNameVars) | |
| 195 | +const ${subClassNameVar}FormRef = ref() | |
| 196 | +#end | |
| 197 | +#end | |
| 198 | +#end | |
| 199 | + | |
| 200 | +/** 打开弹窗 */ | |
| 201 | +const open = async (type: string, id?: number) => { | |
| 202 | + dialogVisible.value = true | |
| 203 | + dialogTitle.value = t('action.' + type) | |
| 204 | + formType.value = type | |
| 205 | + resetForm() | |
| 206 | + // 修改时,设置数据 | |
| 207 | + if (id) { | |
| 208 | + formLoading.value = true | |
| 209 | + try { | |
| 210 | + formData.value = await ${simpleClassName}Api.get${simpleClassName}(id) | |
| 211 | + } finally { | |
| 212 | + formLoading.value = false | |
| 213 | + } | |
| 214 | + } | |
| 215 | +## 特殊:树表专属逻辑 | |
| 216 | +#if ( $table.templateType == 2 ) | |
| 217 | + await get${simpleClassName}Tree() | |
| 218 | +#end | |
| 219 | +} | |
| 220 | +defineExpose({ open }) // 提供 open 方法,用于打开弹窗 | |
| 221 | + | |
| 222 | +/** 提交表单 */ | |
| 223 | +const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 | |
| 224 | +const submitForm = async () => { | |
| 225 | + // 校验表单 | |
| 226 | + await formRef.value.validate() | |
| 227 | +## 特殊:主子表专属逻辑 | |
| 228 | +#if ( $table.templateType == 10 || $table.templateType == 12 ) | |
| 229 | +#if ( $subTables && $subTables.size() > 0 ) | |
| 230 | + // 校验子表单 | |
| 231 | + #foreach ($subTable in $subTables) | |
| 232 | + #set ($index = $foreach.count - 1) | |
| 233 | + #set ($subClassNameVar = $subClassNameVars.get($index)) | |
| 234 | + try { | |
| 235 | + await ${subClassNameVar}FormRef.value.validate() | |
| 236 | + } catch (e) { | |
| 237 | + subTabsName.value = '${subClassNameVar}' | |
| 238 | + return | |
| 239 | + } | |
| 240 | + #end | |
| 241 | +#end | |
| 242 | +#end | |
| 243 | + // 提交请求 | |
| 244 | + formLoading.value = true | |
| 245 | + try { | |
| 246 | + const data = formData.value as unknown as ${simpleClassName}VO | |
| 247 | +## 特殊:主子表专属逻辑 | |
| 248 | +#if ( $table.templateType == 10 || $table.templateType == 12 ) | |
| 249 | +#if ( $subTables && $subTables.size() > 0 ) | |
| 250 | + // 拼接子表的数据 | |
| 251 | + #foreach ($subTable in $subTables) | |
| 252 | + #set ($index = $foreach.count - 1) | |
| 253 | + #set ($subClassNameVar = $subClassNameVars.get($index)) | |
| 254 | + data.${subClassNameVar}#if ( $subTable.subJoinMany)s#end = ${subClassNameVar}FormRef.value.getData() | |
| 255 | + #end | |
| 256 | +#end | |
| 257 | +#end | |
| 258 | + if (formType.value === 'create') { | |
| 259 | + await ${simpleClassName}Api.create${simpleClassName}(data) | |
| 260 | + message.success(t('common.createSuccess')) | |
| 261 | + } else { | |
| 262 | + await ${simpleClassName}Api.update${simpleClassName}(data) | |
| 263 | + message.success(t('common.updateSuccess')) | |
| 264 | + } | |
| 265 | + dialogVisible.value = false | |
| 266 | + // 发送操作成功的事件 | |
| 267 | + emit('success') | |
| 268 | + } finally { | |
| 269 | + formLoading.value = false | |
| 270 | + } | |
| 271 | +} | |
| 272 | + | |
| 273 | +/** 重置表单 */ | |
| 274 | +const resetForm = () => { | |
| 275 | + formData.value = { | |
| 276 | +#foreach ($column in $columns) | |
| 277 | + #if ($column.createOperation || $column.updateOperation) | |
| 278 | + #if ($column.htmlType == "checkbox") | |
| 279 | + $column.javaField: [], | |
| 280 | + #else | |
| 281 | + $column.javaField: undefined, | |
| 282 | + #end | |
| 283 | + #end | |
| 284 | +#end | |
| 285 | + } | |
| 286 | + formRef.value?.resetFields() | |
| 287 | +} | |
| 288 | +## 特殊:树表专属逻辑 | |
| 289 | +#if ( $table.templateType == 2 ) | |
| 290 | + | |
| 291 | +/** 获得${table.classComment}树 */ | |
| 292 | +const get${simpleClassName}Tree = async () => { | |
| 293 | + ${classNameVar}Tree.value = [] | |
| 294 | + const data = await ${simpleClassName}Api.get${simpleClassName}List() | |
| 295 | + const root = { id: 0, name: '顶级${table.classComment}', children: [] } | |
| 296 | + root.children = handleTree(data, 'id', '${treeParentColumn.javaField}') | |
| 297 | + ${classNameVar}Tree.value.push(root) | |
| 298 | +} | |
| 299 | +#end | |
| 300 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/general/views/index.vue.vm
0 → 100644
| 1 | +<template> | |
| 2 | + <ContentWrap> | |
| 3 | + <!-- 搜索工作栏 --> | |
| 4 | + <Form | |
| 5 | + class="-mb-15px" | |
| 6 | + :model="queryParams" | |
| 7 | + ref="queryFormRef" | |
| 8 | + layout="inline" | |
| 9 | + label-col="68px" | |
| 10 | + > | |
| 11 | + #foreach($column in $columns) | |
| 12 | + #if ($column.listOperation) | |
| 13 | + #set ($dictType = $column.dictType) | |
| 14 | + #set ($javaField = $column.javaField) | |
| 15 | + #set ($javaType = $column.javaType) | |
| 16 | + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 17 | + #set ($comment = $column.columnComment) | |
| 18 | + #set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法 | |
| 19 | + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short") | |
| 20 | + #set ($dictMethod = "getIntDictOptions") | |
| 21 | + #elseif ($javaType == "String") | |
| 22 | + #set ($dictMethod = "getStrDictOptions") | |
| 23 | + #elseif ($javaType == "Boolean") | |
| 24 | + #set ($dictMethod = "getBoolDictOptions") | |
| 25 | + #end | |
| 26 | + #if ($column.htmlType == "input") | |
| 27 | + <FormItem label="${comment}" name="${javaField}"> | |
| 28 | + <Input | |
| 29 | + v-model:value="queryParams.${javaField}" | |
| 30 | + placeholder="请输入${comment}" | |
| 31 | + allowClear | |
| 32 | + @pressEnter="handleQuery" | |
| 33 | + class="!w-240px" | |
| 34 | + /> | |
| 35 | + </FormItem> | |
| 36 | + #elseif ($column.htmlType == "select" || $column.htmlType == "radio") | |
| 37 | + <FormItem label="${comment}" name="${javaField}"> | |
| 38 | + <Select | |
| 39 | + v-model:value="queryParams.${javaField}" | |
| 40 | + placeholder="请选择${comment}" | |
| 41 | + allowClear | |
| 42 | + class="!w-240px" | |
| 43 | + > | |
| 44 | + #if ("" != $dictType)## 设置了 dictType 数据字典的情况 | |
| 45 | + <SelectOption | |
| 46 | + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())" | |
| 47 | + :key="dict.value" | |
| 48 | + :label="dict.label" | |
| 49 | + :value="dict.value" | |
| 50 | + /> | |
| 51 | + #else## 未设置 dictType 数据字典的情况 | |
| 52 | + <SelectOption label="请选择字典生成" value="" /> | |
| 53 | + #end | |
| 54 | + </Select> | |
| 55 | + </FormItem> | |
| 56 | + #elseif($column.htmlType == "datetime") | |
| 57 | + #if ($column.listOperationCondition != "BETWEEN")## 非范围 | |
| 58 | + <FormItem label="${comment}" name="${javaField}"> | |
| 59 | + <DatePicker | |
| 60 | + v-model:value="queryParams.${javaField}" | |
| 61 | + valueFormat="YYYY-MM-DD" | |
| 62 | + placeholder="选择${comment}" | |
| 63 | + allowClear | |
| 64 | + class="!w-240px" | |
| 65 | + /> | |
| 66 | + </FormItem> | |
| 67 | + #else## 范围 | |
| 68 | + <FormItem label="${comment}" name="${javaField}"> | |
| 69 | + <RangePicker | |
| 70 | + v-model:value="queryParams.${javaField}" | |
| 71 | + v-bind="getRangePickerDefaultProps()" | |
| 72 | + class="!w-220px" | |
| 73 | + /> | |
| 74 | + </FormItem> | |
| 75 | + #end | |
| 76 | + #end | |
| 77 | + #end | |
| 78 | + #end | |
| 79 | + <FormItem> | |
| 80 | + <Button @click="handleQuery"><Icon icon="ep:search" class="mr-5px" /> 搜索</Button> | |
| 81 | + <Button @click="resetQuery"><Icon icon="ep:refresh" class="mr-5px" /> 重置</Button> | |
| 82 | + <Button | |
| 83 | + type="primary" | |
| 84 | + ghost | |
| 85 | + @click="openForm('create')" | |
| 86 | + v-hasPermi="['${permissionPrefix}:create']" | |
| 87 | + > | |
| 88 | + <Icon icon="ep:plus" class="mr-5px" /> 新增 | |
| 89 | + </Button> | |
| 90 | + <Button | |
| 91 | + type="success" | |
| 92 | + ghost | |
| 93 | + @click="handleExport" | |
| 94 | + :loading="exportLoading" | |
| 95 | + v-hasPermi="['${permissionPrefix}:export']" | |
| 96 | + > | |
| 97 | + <Icon icon="ep:download" class="mr-5px" /> 导出 | |
| 98 | + </Button> | |
| 99 | +## 特殊:树表专属逻辑 | |
| 100 | +#if ( $table.templateType == 2 ) | |
| 101 | + <Button type="danger" ghost @click="toggleExpandAll"> | |
| 102 | + <Icon icon="ep:sort" class="mr-5px" /> 展开/折叠 | |
| 103 | + </Button> | |
| 104 | +#end | |
| 105 | + </FormItem> | |
| 106 | + </Form> | |
| 107 | + </ContentWrap> | |
| 108 | + | |
| 109 | + <!-- 列表 --> | |
| 110 | + <ContentWrap> | |
| 111 | +## 特殊:主子表专属逻辑 | |
| 112 | +#if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 ) | |
| 113 | + <Table | |
| 114 | + :loading="loading" | |
| 115 | + :dataSource="list" | |
| 116 | + :bordered="true" | |
| 117 | + :rowClassName="() => 'editable-row'" | |
| 118 | + @change="handleCurrentChange" | |
| 119 | + > | |
| 120 | +## 特殊:树表专属逻辑 | |
| 121 | +#elseif ( $table.templateType == 2 ) | |
| 122 | + <Table | |
| 123 | + :loading="loading" | |
| 124 | + :dataSource="list" | |
| 125 | + :bordered="true" | |
| 126 | + rowKey="id" | |
| 127 | + :expandAllRows="isExpandAll" | |
| 128 | + v-if="refreshTable" | |
| 129 | + > | |
| 130 | +#else | |
| 131 | + <Table :loading="loading" :dataSource="list" :bordered="true"> | |
| 132 | +#end | |
| 133 | +## 特殊:主子表专属逻辑 | |
| 134 | +#if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 ) | |
| 135 | + <!-- 子表的列表 --> | |
| 136 | + <template #expandedRowRender="{ record }"> | |
| 137 | + <Tabs defaultActiveKey="$subClassNameVars.get(0)"> | |
| 138 | + #foreach ($subTable in $subTables) | |
| 139 | + #set ($index = $foreach.count - 1) | |
| 140 | + #set ($subClassNameVar = $subClassNameVars.get($index)) | |
| 141 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | |
| 142 | + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index)) | |
| 143 | + <TabPane key="$subClassNameVar" tab="${subTable.classComment}"> | |
| 144 | + <${subSimpleClassName}List :${subJoinColumn_strikeCase}="record.id" /> | |
| 145 | + </TabPane> | |
| 146 | + #end | |
| 147 | + </Tabs> | |
| 148 | + </template> | |
| 149 | +#end | |
| 150 | + #foreach($column in $columns) | |
| 151 | + #if ($column.listOperationResult) | |
| 152 | + #set ($dictType=$column.dictType) | |
| 153 | + #set ($javaField = $column.javaField) | |
| 154 | + #set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 155 | + #set ($comment=$column.columnComment) | |
| 156 | + #if ($column.javaType == "LocalDateTime")## 时间类型 | |
| 157 | + <Column | |
| 158 | + title="${comment}" | |
| 159 | + align="center" | |
| 160 | + dataIndex="${javaField}" | |
| 161 | + :customRender="({ text }) => dateFormatter(text)" | |
| 162 | + width="180px" | |
| 163 | + /> | |
| 164 | + #elseif($column.dictType && "" != $column.dictType)## 数据字典 | |
| 165 | + <Column title="${comment}" align="center" dataIndex="${javaField}"> | |
| 166 | + <template #default="{ text, record }"> | |
| 167 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="record.${column.javaField}" /> | |
| 168 | + </template> | |
| 169 | + </Column> | |
| 170 | + #else | |
| 171 | + <Column title="${comment}" align="center" dataIndex="${javaField}" /> | |
| 172 | + #end | |
| 173 | + #end | |
| 174 | + #end | |
| 175 | + <Column title="操作" align="center" key="action" :width="120"> | |
| 176 | + <template #default="{ record }"> | |
| 177 | + <Button | |
| 178 | + type="link" | |
| 179 | + @click="openForm('update', record.id)" | |
| 180 | + v-hasPermi="['${permissionPrefix}:update']" | |
| 181 | + > | |
| 182 | + 编辑 | |
| 183 | + </Button> | |
| 184 | + <Button | |
| 185 | + type="link" | |
| 186 | + danger | |
| 187 | + @click="handleDelete(record.id)" | |
| 188 | + v-hasPermi="['${permissionPrefix}:delete']" | |
| 189 | + > | |
| 190 | + 删除 | |
| 191 | + </Button> | |
| 192 | + </template> | |
| 193 | + </Column> | |
| 194 | + </Table> | |
| 195 | + <!-- 分页 --> | |
| 196 | + <Pagination | |
| 197 | + :total="total" | |
| 198 | + v-model:current="queryParams.pageNo" | |
| 199 | + v-model:pageSize="queryParams.pageSize" | |
| 200 | + @change="getList" | |
| 201 | + /> | |
| 202 | + </ContentWrap> | |
| 203 | + | |
| 204 | + <!-- 表单弹窗:添加/修改 --> | |
| 205 | + <${simpleClassName}Form ref="formRef" @success="getList" /> | |
| 206 | +## 特殊:主子表专属逻辑 | |
| 207 | +#if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 ) | |
| 208 | + <!-- 子表的列表 --> | |
| 209 | + <ContentWrap> | |
| 210 | + <Tabs defaultActiveKey="$subClassNameVars.get(0)"> | |
| 211 | + #foreach ($subTable in $subTables) | |
| 212 | + #set ($index = $foreach.count - 1) | |
| 213 | + #set ($subClassNameVar = $subClassNameVars.get($index)) | |
| 214 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | |
| 215 | + #set ($subJoinColumn_strikeCase = $subJoinColumn_strikeCases.get($index)) | |
| 216 | + <TabPane key="$subClassNameVar" tab="${subTable.classComment}"> | |
| 217 | + <${subSimpleClassName}List :${subJoinColumn_strikeCase}="currentRow.id" /> | |
| 218 | + </TabPane> | |
| 219 | + #end | |
| 220 | + </Tabs> | |
| 221 | + </ContentWrap> | |
| 222 | +#end | |
| 223 | +</template> | |
| 224 | + | |
| 225 | +<script setup lang="ts"> | |
| 226 | +import { Form, FormItem, Input, Button, Table, Column, Select, SelectOption, DatePicker, RangePicker, Tabs, TabPane } from 'ant-design-vue' | |
| 227 | +import dayjs from 'dayjs' | |
| 228 | +import { getRangePickerDefaultProps } from '@vben/utils' | |
| 229 | +import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict' | |
| 230 | +import { dateFormatter } from '@/utils/formatTime' | |
| 231 | +## 特殊:树表专属逻辑 | |
| 232 | +#if ( $table.templateType == 2 ) | |
| 233 | +import { handleTree } from '@/utils/tree' | |
| 234 | +#end | |
| 235 | +import download from '@/utils/download' | |
| 236 | +import { ${simpleClassName}Api, ${simpleClassName}VO } from '@/api/${table.moduleName}/${table.businessName}' | |
| 237 | +import ${simpleClassName}Form from './${simpleClassName}Form.vue' | |
| 238 | +## 特殊:主子表专属逻辑 | |
| 239 | +#if ( $table.templateType != 10 ) | |
| 240 | +#foreach ($subSimpleClassName in $subSimpleClassNames) | |
| 241 | +import ${subSimpleClassName}List from './components/${subSimpleClassName}List.vue' | |
| 242 | +#end | |
| 243 | +#end | |
| 244 | + | |
| 245 | +/** ${table.classComment} 列表 */ | |
| 246 | +defineOptions({ name: '${table.className}' }) | |
| 247 | + | |
| 248 | +const message = useMessage() // 消息弹窗 | |
| 249 | +const { t } = useI18n() // 国际化 | |
| 250 | + | |
| 251 | +const loading = ref(true) // 列表的加载中 | |
| 252 | +const list = ref<${simpleClassName}VO[]>([]) // 列表的数据 | |
| 253 | +## 特殊:树表专属逻辑(树不需要分页接口) | |
| 254 | +#if ( $table.templateType != 2 ) | |
| 255 | +const total = ref(0) // 列表的总页数 | |
| 256 | +#end | |
| 257 | +const queryParams = reactive({ | |
| 258 | +## 特殊:树表专属逻辑(树不需要分页接口) | |
| 259 | +#if ( $table.templateType != 2 ) | |
| 260 | + pageNo: 1, | |
| 261 | + pageSize: 10, | |
| 262 | +#end | |
| 263 | + #foreach ($column in $columns) | |
| 264 | + #if ($column.listOperation) | |
| 265 | + #if ($column.listOperationCondition != 'BETWEEN') | |
| 266 | + $column.javaField: undefined, | |
| 267 | + #end | |
| 268 | + #if ($column.htmlType == "datetime" || $column.listOperationCondition == "BETWEEN") | |
| 269 | + $column.javaField: [], | |
| 270 | + #end | |
| 271 | + #end | |
| 272 | + #end | |
| 273 | +}) | |
| 274 | +const queryFormRef = ref() // 搜索的表单 | |
| 275 | +const exportLoading = ref(false) // 导出的加载中 | |
| 276 | + | |
| 277 | +/** 查询列表 */ | |
| 278 | +const getList = async () => { | |
| 279 | + loading.value = true | |
| 280 | + try { | |
| 281 | +## 特殊:树表专属逻辑(树不需要分页接口) | |
| 282 | + #if ( $table.templateType == 2 ) | |
| 283 | + const data = await ${simpleClassName}Api.get${simpleClassName}List(queryParams) | |
| 284 | + list.value = handleTree(data, 'id', '${treeParentColumn.javaField}') | |
| 285 | + #else | |
| 286 | + const data = await ${simpleClassName}Api.get${simpleClassName}Page(queryParams) | |
| 287 | + list.value = data.list | |
| 288 | + total.value = data.total | |
| 289 | + #end | |
| 290 | + } finally { | |
| 291 | + loading.value = false | |
| 292 | + } | |
| 293 | +} | |
| 294 | + | |
| 295 | +/** 搜索按钮操作 */ | |
| 296 | +const handleQuery = () => { | |
| 297 | + queryParams.pageNo = 1 | |
| 298 | + getList() | |
| 299 | +} | |
| 300 | + | |
| 301 | +/** 重置按钮操作 */ | |
| 302 | +const resetQuery = () => { | |
| 303 | + queryFormRef.value.resetFields() | |
| 304 | + handleQuery() | |
| 305 | +} | |
| 306 | + | |
| 307 | +/** 添加/修改操作 */ | |
| 308 | +const formRef = ref() | |
| 309 | +const openForm = (type: string, id?: number) => { | |
| 310 | + formRef.value.open(type, id) | |
| 311 | +} | |
| 312 | + | |
| 313 | +/** 删除按钮操作 */ | |
| 314 | +const handleDelete = async (id: number) => { | |
| 315 | + try { | |
| 316 | + // 删除的二次确认 | |
| 317 | + await message.delConfirm() | |
| 318 | + // 发起删除 | |
| 319 | + await ${simpleClassName}Api.delete${simpleClassName}(id) | |
| 320 | + message.success(t('common.delSuccess')) | |
| 321 | + // 刷新列表 | |
| 322 | + await getList() | |
| 323 | + } catch {} | |
| 324 | +} | |
| 325 | + | |
| 326 | +/** 导出按钮操作 */ | |
| 327 | +const handleExport = async () => { | |
| 328 | + try { | |
| 329 | + // 导出的二次确认 | |
| 330 | + await message.exportConfirm() | |
| 331 | + // 发起导出 | |
| 332 | + exportLoading.value = true | |
| 333 | + const data = await ${simpleClassName}Api.export${simpleClassName}(queryParams) | |
| 334 | + download.excel(data, '${table.classComment}.xls') | |
| 335 | + } catch { | |
| 336 | + } finally { | |
| 337 | + exportLoading.value = false | |
| 338 | + } | |
| 339 | +} | |
| 340 | +## 特殊:主子表专属逻辑 | |
| 341 | +#if ( $table.templateType == 11 ) | |
| 342 | + | |
| 343 | +/** 选中行操作 */ | |
| 344 | +const currentRow = ref({}) // 选中行 | |
| 345 | +const handleCurrentChange = (row) => { | |
| 346 | + currentRow.value = row | |
| 347 | +} | |
| 348 | +#end | |
| 349 | +## 特殊:树表专属逻辑 | |
| 350 | +#if ( $table.templateType == 2 ) | |
| 351 | + | |
| 352 | +/** 展开/折叠操作 */ | |
| 353 | +const isExpandAll = ref(true) // 是否展开,默认全部展开 | |
| 354 | +const refreshTable = ref(true) // 重新渲染表格状态 | |
| 355 | +const toggleExpandAll = async () => { | |
| 356 | + refreshTable.value = false | |
| 357 | + isExpandAll.value = !isExpandAll.value | |
| 358 | + await nextTick() | |
| 359 | + refreshTable.value = true | |
| 360 | +} | |
| 361 | +#end | |
| 362 | + | |
| 363 | +/** 初始化 **/ | |
| 364 | +onMounted(() => { | |
| 365 | + getList() | |
| 366 | +}) | |
| 367 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/general/views/modules/form_sub_erp.vue.vm
0 → 100644
| 1 | +#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组 | |
| 2 | +#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex)) | |
| 3 | +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 | |
| 4 | +<template> | |
| 5 | + <Dialog :title="dialogTitle" v-model="dialogVisible"> | |
| 6 | + <Form | |
| 7 | + ref="formRef" | |
| 8 | + :model="formData" | |
| 9 | + :rules="formRules" | |
| 10 | + label-col="{ span: 6 }" | |
| 11 | + :loading="formLoading" | |
| 12 | + > | |
| 13 | +#foreach($column in $subColumns) | |
| 14 | + #if ($column.createOperation || $column.updateOperation) | |
| 15 | + #set ($dictType = $column.dictType) | |
| 16 | + #set ($javaField = $column.javaField) | |
| 17 | + #set ($javaType = $column.javaType) | |
| 18 | + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 19 | + #set ($comment = $column.columnComment) | |
| 20 | + #set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法 | |
| 21 | + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short") | |
| 22 | + #set ($dictMethod = "getIntDictOptions") | |
| 23 | + #elseif ($javaType == "String") | |
| 24 | + #set ($dictMethod = "getStrDictOptions") | |
| 25 | + #elseif ($javaType == "Boolean") | |
| 26 | + #set ($dictMethod = "getBoolDictOptions") | |
| 27 | + #end | |
| 28 | + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | |
| 29 | + #elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 | |
| 30 | + <FormItem label="${comment}" name="${javaField}"> | |
| 31 | + <Input v-model:value="formData.${javaField}" placeholder="请输入${comment}" /> | |
| 32 | + </FormItem> | |
| 33 | + #elseif($column.htmlType == "imageUpload")## 图片上传 | |
| 34 | + <FormItem label="${comment}" name="${javaField}"> | |
| 35 | + <UploadImg v-model:value="formData.${javaField}" /> | |
| 36 | + </FormItem> | |
| 37 | + #elseif($column.htmlType == "fileUpload")## 文件上传 | |
| 38 | + <FormItem label="${comment}" name="${javaField}"> | |
| 39 | + <UploadFile v-model:value="formData.${javaField}" /> | |
| 40 | + </FormItem> | |
| 41 | + #elseif($column.htmlType == "editor")## 文本编辑器 | |
| 42 | + <FormItem label="${comment}" name="${javaField}"> | |
| 43 | + <Editor v-model:value="formData.${javaField}" height="150px" /> | |
| 44 | + </FormItem> | |
| 45 | + #elseif($column.htmlType == "select")## 下拉框 | |
| 46 | + <FormItem label="${comment}" name="${javaField}"> | |
| 47 | + <Select v-model:value="formData.${javaField}" placeholder="请选择${comment}"> | |
| 48 | + #if ("" != $dictType)## 有数据字典 | |
| 49 | + <SelectOption | |
| 50 | + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())" | |
| 51 | + :key="dict.value" | |
| 52 | + :label="dict.label" | |
| 53 | + :value="dict.value" | |
| 54 | + /> | |
| 55 | + #else##没数据字典 | |
| 56 | + <SelectOption label="请选择字典生成" value="" /> | |
| 57 | + #end | |
| 58 | + </Select> | |
| 59 | + </FormItem> | |
| 60 | + #elseif($column.htmlType == "checkbox")## 多选框 | |
| 61 | + <FormItem label="${comment}" name="${javaField}"> | |
| 62 | + <CheckboxGroup v-model:value="formData.${javaField}"> | |
| 63 | + #if ("" != $dictType)## 有数据字典 | |
| 64 | + <Checkbox | |
| 65 | + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())" | |
| 66 | + :key="dict.value" | |
| 67 | + :label="dict.label" | |
| 68 | + :value="dict.value" | |
| 69 | + /> | |
| 70 | + #else##没数据字典 | |
| 71 | + <Checkbox label="请选择字典生成" /> | |
| 72 | + #end | |
| 73 | + </CheckboxGroup> | |
| 74 | + </FormItem> | |
| 75 | + #elseif($column.htmlType == "radio")## 单选框 | |
| 76 | + <FormItem label="${comment}" name="${javaField}"> | |
| 77 | + <RadioGroup v-model:value="formData.${javaField}"> | |
| 78 | + #if ("" != $dictType)## 有数据字典 | |
| 79 | + <Radio | |
| 80 | + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())" | |
| 81 | + :key="dict.value" | |
| 82 | + :value="dict.value" | |
| 83 | + > | |
| 84 | + {{ dict.label }} | |
| 85 | + </Radio> | |
| 86 | + #else##没数据字典 | |
| 87 | + <Radio value="1">请选择字典生成</Radio> | |
| 88 | + #end | |
| 89 | + </RadioGroup> | |
| 90 | + </FormItem> | |
| 91 | + #elseif($column.htmlType == "datetime")## 时间框 | |
| 92 | + <FormItem label="${comment}" name="${javaField}"> | |
| 93 | + <DatePicker | |
| 94 | + v-model:value="formData.${javaField}" | |
| 95 | + valueFormat="x" | |
| 96 | + placeholder="选择${comment}" | |
| 97 | + /> | |
| 98 | + </FormItem> | |
| 99 | + #elseif($column.htmlType == "textarea")## 文本框 | |
| 100 | + <FormItem label="${comment}" name="${javaField}"> | |
| 101 | + <Textarea v-model:value="formData.${javaField}" placeholder="请输入${comment}" /> | |
| 102 | + </FormItem> | |
| 103 | + #end | |
| 104 | + #end | |
| 105 | +#end | |
| 106 | + </Form> | |
| 107 | + <template #footer> | |
| 108 | + <Button @click="submitForm" type="primary" :loading="formLoading">确 定</Button> | |
| 109 | + <Button @click="dialogVisible = false">取 消</Button> | |
| 110 | + </template> | |
| 111 | + </Dialog> | |
| 112 | +</template> | |
| 113 | +<script setup lang="ts"> | |
| 114 | +import { Form, FormItem, Input, Button, Select, SelectOption, DatePicker, Textarea, Checkbox, CheckboxGroup, Radio, RadioGroup } from 'ant-design-vue' | |
| 115 | +import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict' | |
| 116 | +import { ${simpleClassName}Api } from '@/api/${table.moduleName}/${table.businessName}' | |
| 117 | + | |
| 118 | +const { t } = useI18n() // 国际化 | |
| 119 | +const message = useMessage() // 消息弹窗 | |
| 120 | + | |
| 121 | +const dialogVisible = ref(false) // 弹窗的是否展示 | |
| 122 | +const dialogTitle = ref('') // 弹窗的标题 | |
| 123 | +const formLoading = ref(false) // 表单的加载中:1)修改时的数据加载;2)提交的按钮禁用 | |
| 124 | +const formType = ref('') // 表单的类型:create - 新增;update - 修改 | |
| 125 | +const formData = ref({ | |
| 126 | +#foreach ($column in $subColumns) | |
| 127 | + #if ($column.createOperation || $column.updateOperation) | |
| 128 | + #if ($column.htmlType == "checkbox") | |
| 129 | + $column.javaField: [], | |
| 130 | + #else | |
| 131 | + $column.javaField: undefined, | |
| 132 | + #end | |
| 133 | + #end | |
| 134 | +#end | |
| 135 | +}) | |
| 136 | +const formRules = reactive({ | |
| 137 | +#foreach ($column in $subColumns) | |
| 138 | + #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 | |
| 139 | + #set($comment=$column.columnComment) | |
| 140 | + $column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == 'select')'change'#else'blur'#end }], | |
| 141 | + #end | |
| 142 | +#end | |
| 143 | +}) | |
| 144 | +const formRef = ref() // 表单 Ref | |
| 145 | + | |
| 146 | +/** 打开弹窗 */ | |
| 147 | +const open = async (type: string, id?: number, ${subJoinColumn.javaField}: number) => { | |
| 148 | + dialogVisible.value = true | |
| 149 | + dialogTitle.value = t('action.' + type) | |
| 150 | + formType.value = type | |
| 151 | + resetForm() | |
| 152 | + formData.value.${subJoinColumn.javaField} = ${subJoinColumn.javaField} | |
| 153 | + // 修改时,设置数据 | |
| 154 | + if (id) { | |
| 155 | + formLoading.value = true | |
| 156 | + try { | |
| 157 | + formData.value = await ${simpleClassName}Api.get${subSimpleClassName}(id) | |
| 158 | + } finally { | |
| 159 | + formLoading.value = false | |
| 160 | + } | |
| 161 | + } | |
| 162 | +} | |
| 163 | +defineExpose({ open }) // 提供 open 方法,用于打开弹窗 | |
| 164 | + | |
| 165 | +/** 提交表单 */ | |
| 166 | +const emit = defineEmits(['success']) // 定义 success 事件,用于操作成功后的回调 | |
| 167 | +const submitForm = async () => { | |
| 168 | + // 校验表单 | |
| 169 | + await formRef.value.validate() | |
| 170 | + // 提交请求 | |
| 171 | + formLoading.value = true | |
| 172 | + try { | |
| 173 | + const data = formData.value | |
| 174 | + if (formType.value === 'create') { | |
| 175 | + await ${simpleClassName}Api.create${subSimpleClassName}(data) | |
| 176 | + message.success(t('common.createSuccess')) | |
| 177 | + } else { | |
| 178 | + await ${simpleClassName}Api.update${subSimpleClassName}(data) | |
| 179 | + message.success(t('common.updateSuccess')) | |
| 180 | + } | |
| 181 | + dialogVisible.value = false | |
| 182 | + // 发送操作成功的事件 | |
| 183 | + emit('success') | |
| 184 | + } finally { | |
| 185 | + formLoading.value = false | |
| 186 | + } | |
| 187 | +} | |
| 188 | + | |
| 189 | +/** 重置表单 */ | |
| 190 | +const resetForm = () => { | |
| 191 | + formData.value = { | |
| 192 | +#foreach ($column in $subColumns) | |
| 193 | + #if ($column.createOperation || $column.updateOperation) | |
| 194 | + #if ($column.htmlType == "checkbox") | |
| 195 | + $column.javaField: [], | |
| 196 | + #else | |
| 197 | + $column.javaField: undefined, | |
| 198 | + #end | |
| 199 | + #end | |
| 200 | +#end | |
| 201 | + } | |
| 202 | + formRef.value?.resetFields() | |
| 203 | +} | |
| 204 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/general/views/modules/form_sub_inner.vue.vm
0 → 100644
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/general/views/modules/form_sub_normal.vue.vm
0 → 100644
| 1 | +#set ($subTable = $subTables.get($subIndex))##当前表 | |
| 2 | +#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组 | |
| 3 | +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 | |
| 4 | +#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex)) | |
| 5 | +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 | |
| 6 | +#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | |
| 7 | +<template> | |
| 8 | +#if ( $subTable.subJoinMany )## 情况一:一对多,table + form | |
| 9 | + <Form | |
| 10 | + ref="formRef" | |
| 11 | + :model="formData" | |
| 12 | + :rules="formRules" | |
| 13 | + :loading="formLoading" | |
| 14 | + label-col="{ span: 0 }" | |
| 15 | + > | |
| 16 | + <Table :dataSource="formData" class="-mt-10px"> | |
| 17 | + <Column title="序号" width="100"> | |
| 18 | + <template #customRender="{ index }"> | |
| 19 | + {{ index + 1 }} | |
| 20 | + </template> | |
| 21 | + </Column> | |
| 22 | +#foreach($column in $subColumns) | |
| 23 | + #if ($column.createOperation || $column.updateOperation) | |
| 24 | + #set ($dictType = $column.dictType) | |
| 25 | + #set ($javaField = $column.javaField) | |
| 26 | + #set ($javaType = $column.javaType) | |
| 27 | + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 28 | + #set ($comment = $column.columnComment) | |
| 29 | + #set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法 | |
| 30 | + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short") | |
| 31 | + #set ($dictMethod = "getIntDictOptions") | |
| 32 | + #elseif ($javaType == "String") | |
| 33 | + #set ($dictMethod = "getStrDictOptions") | |
| 34 | + #elseif ($javaType == "Boolean") | |
| 35 | + #set ($dictMethod = "getBoolDictOptions") | |
| 36 | + #end | |
| 37 | + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | |
| 38 | + #elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 | |
| 39 | + <Column title="${comment}" :minWidth="150"> | |
| 40 | + <template #customRender="{ record, index }"> | |
| 41 | + <FormItem :name="[index, '${javaField}']" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 42 | + <Input v-model:value="record.${javaField}" placeholder="请输入${comment}" /> | |
| 43 | + </FormItem> | |
| 44 | + </template> | |
| 45 | + </Column> | |
| 46 | + #elseif($column.htmlType == "imageUpload")## 图片上传 | |
| 47 | + <Column title="${comment}" :minWidth="200"> | |
| 48 | + <template #customRender="{ record, index }"> | |
| 49 | + <FormItem :name="[index, '${javaField}']" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 50 | + <UploadImg v-model:value="record.${javaField}" /> | |
| 51 | + </FormItem> | |
| 52 | + </template> | |
| 53 | + </Column> | |
| 54 | + #elseif($column.htmlType == "fileUpload")## 文件上传 | |
| 55 | + <Column title="${comment}" :minWidth="200"> | |
| 56 | + <template #customRender="{ record, index }"> | |
| 57 | + <FormItem :name="[index, '${javaField}']" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 58 | + <UploadFile v-model:value="record.${javaField}" /> | |
| 59 | + </FormItem> | |
| 60 | + </template> | |
| 61 | + </Column> | |
| 62 | + #elseif($column.htmlType == "editor")## 文本编辑器 | |
| 63 | + <Column title="${comment}" :minWidth="400"> | |
| 64 | + <template #customRender="{ record, index }"> | |
| 65 | + <FormItem :name="[index, '${javaField}']" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 66 | + <Editor v-model:value="record.${javaField}" height="150px" /> | |
| 67 | + </FormItem> | |
| 68 | + </template> | |
| 69 | + </Column> | |
| 70 | + #elseif($column.htmlType == "select")## 下拉框 | |
| 71 | + <Column title="${comment}" :minWidth="150"> | |
| 72 | + <template #customRender="{ record, index }"> | |
| 73 | + <FormItem :name="[index, '${javaField}']" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 74 | + <Select v-model:value="record.${javaField}" placeholder="请选择${comment}"> | |
| 75 | + #if ("" != $dictType)## 有数据字典 | |
| 76 | + <SelectOption | |
| 77 | + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())" | |
| 78 | + :key="dict.value" | |
| 79 | + :label="dict.label" | |
| 80 | + :value="dict.value" | |
| 81 | + /> | |
| 82 | + #else##没数据字典 | |
| 83 | + <SelectOption label="请选择字典生成" value="" /> | |
| 84 | + #end | |
| 85 | + </Select> | |
| 86 | + </FormItem> | |
| 87 | + </template> | |
| 88 | + </Column> | |
| 89 | + #elseif($column.htmlType == "checkbox")## 多选框 | |
| 90 | + <Column title="${comment}" :minWidth="150"> | |
| 91 | + <template #customRender="{ record, index }"> | |
| 92 | + <FormItem :name="[index, '${javaField}']" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 93 | + <CheckboxGroup v-model:value="record.${javaField}"> | |
| 94 | + #if ("" != $dictType)## 有数据字典 | |
| 95 | + <Checkbox | |
| 96 | + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())" | |
| 97 | + :key="dict.value" | |
| 98 | + :label="dict.label" | |
| 99 | + :value="dict.value" | |
| 100 | + /> | |
| 101 | + #else##没数据字典 | |
| 102 | + <Checkbox label="请选择字典生成" /> | |
| 103 | + #end | |
| 104 | + </CheckboxGroup> | |
| 105 | + </FormItem> | |
| 106 | + </template> | |
| 107 | + </Column> | |
| 108 | + #elseif($column.htmlType == "radio")## 单选框 | |
| 109 | + <Column title="${comment}" :minWidth="150"> | |
| 110 | + <template #customRender="{ record, index }"> | |
| 111 | + <FormItem :name="[index, '${javaField}']" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 112 | + <RadioGroup v-model:value="record.${javaField}"> | |
| 113 | + #if ("" != $dictType)## 有数据字典 | |
| 114 | + <Radio | |
| 115 | + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())" | |
| 116 | + :key="dict.value" | |
| 117 | + :value="dict.value" | |
| 118 | + > | |
| 119 | + {{ dict.label }} | |
| 120 | + </Radio> | |
| 121 | + #else##没数据字典 | |
| 122 | + <Radio value="1">请选择字典生成</Radio> | |
| 123 | + #end | |
| 124 | + </RadioGroup> | |
| 125 | + </FormItem> | |
| 126 | + </template> | |
| 127 | + </Column> | |
| 128 | + #elseif($column.htmlType == "datetime")## 时间框 | |
| 129 | + <Column title="${comment}" :minWidth="150"> | |
| 130 | + <template #customRender="{ record, index }"> | |
| 131 | + <FormItem :name="[index, '${javaField}']" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 132 | + <DatePicker | |
| 133 | + v-model:value="record.${javaField}" | |
| 134 | + valueFormat="x" | |
| 135 | + placeholder="选择${comment}" | |
| 136 | + /> | |
| 137 | + </FormItem> | |
| 138 | + </template> | |
| 139 | + </Column> | |
| 140 | + #elseif($column.htmlType == "textarea")## 文本框 | |
| 141 | + <Column title="${comment}" :minWidth="200"> | |
| 142 | + <template #customRender="{ record, index }"> | |
| 143 | + <FormItem :name="[index, '${javaField}']" :rules="formRules.${javaField}" class="mb-0px!"> | |
| 144 | + <Textarea v-model:value="record.${javaField}" placeholder="请输入${comment}" /> | |
| 145 | + </FormItem> | |
| 146 | + </template> | |
| 147 | + </Column> | |
| 148 | + #end | |
| 149 | + #end | |
| 150 | +#end | |
| 151 | + <Column align="center" fixed="right" title="操作" width="60"> | |
| 152 | + <template #customRender="{ index }"> | |
| 153 | + <Button @click="handleDelete(index)" type="link">—</Button> | |
| 154 | + </template> | |
| 155 | + </Column> | |
| 156 | + </Table> | |
| 157 | + </Form> | |
| 158 | + <Row justify="center" class="mt-3"> | |
| 159 | + <Button @click="handleAdd" shape="round">+ 添加${subTable.classComment}</Button> | |
| 160 | + </Row> | |
| 161 | +#else## 情况二:一对一,form | |
| 162 | + <Form | |
| 163 | + ref="formRef" | |
| 164 | + :model="formData" | |
| 165 | + :rules="formRules" | |
| 166 | + label-col="{ span: 6 }" | |
| 167 | + :loading="formLoading" | |
| 168 | + > | |
| 169 | +#foreach($column in $subColumns) | |
| 170 | + #if ($column.createOperation || $column.updateOperation) | |
| 171 | + #set ($dictType = $column.dictType) | |
| 172 | + #set ($javaField = $column.javaField) | |
| 173 | + #set ($javaType = $column.javaType) | |
| 174 | + #set ($AttrName = $column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 175 | + #set ($comment = $column.columnComment) | |
| 176 | + #set ($dictMethod = "getDictOptions")## 计算使用哪个 dict 字典方法 | |
| 177 | + #if ($javaType == "Integer" || $javaType == "Long" || $javaType == "Byte" || $javaType == "Short") | |
| 178 | + #set ($dictMethod = "getIntDictOptions") | |
| 179 | + #elseif ($javaType == "String") | |
| 180 | + #set ($dictMethod = "getStrDictOptions") | |
| 181 | + #elseif ($javaType == "Boolean") | |
| 182 | + #set ($dictMethod = "getBoolDictOptions") | |
| 183 | + #end | |
| 184 | + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | |
| 185 | + #elseif ($column.htmlType == "input" && !$column.primaryKey)## 忽略主键,不用在表单里 | |
| 186 | + <FormItem label="${comment}" name="${javaField}"> | |
| 187 | + <Input v-model:value="formData.${javaField}" placeholder="请输入${comment}" /> | |
| 188 | + </FormItem> | |
| 189 | + #elseif($column.htmlType == "imageUpload")## 图片上传 | |
| 190 | + <FormItem label="${comment}" name="${javaField}"> | |
| 191 | + <UploadImg v-model:value="formData.${javaField}" /> | |
| 192 | + </FormItem> | |
| 193 | + #elseif($column.htmlType == "fileUpload")## 文件上传 | |
| 194 | + <FormItem label="${comment}" name="${javaField}"> | |
| 195 | + <UploadFile v-model:value="formData.${javaField}" /> | |
| 196 | + </FormItem> | |
| 197 | + #elseif($column.htmlType == "editor")## 文本编辑器 | |
| 198 | + <FormItem label="${comment}" name="${javaField}"> | |
| 199 | + <Editor v-model:value="formData.${javaField}" height="150px" /> | |
| 200 | + </FormItem> | |
| 201 | + #elseif($column.htmlType == "select")## 下拉框 | |
| 202 | + <FormItem label="${comment}" name="${javaField}"> | |
| 203 | + <Select v-model:value="formData.${javaField}" placeholder="请选择${comment}"> | |
| 204 | + #if ("" != $dictType)## 有数据字典 | |
| 205 | + <SelectOption | |
| 206 | + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())" | |
| 207 | + :key="dict.value" | |
| 208 | + :label="dict.label" | |
| 209 | + :value="dict.value" | |
| 210 | + /> | |
| 211 | + #else##没数据字典 | |
| 212 | + <SelectOption label="请选择字典生成" value="" /> | |
| 213 | + #end | |
| 214 | + </Select> | |
| 215 | + </FormItem> | |
| 216 | + #elseif($column.htmlType == "checkbox")## 多选框 | |
| 217 | + <FormItem label="${comment}" name="${javaField}"> | |
| 218 | + <CheckboxGroup v-model:value="formData.${javaField}"> | |
| 219 | + #if ("" != $dictType)## 有数据字典 | |
| 220 | + <Checkbox | |
| 221 | + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())" | |
| 222 | + :key="dict.value" | |
| 223 | + :label="dict.label" | |
| 224 | + :value="dict.value" | |
| 225 | + /> | |
| 226 | + #else##没数据字典 | |
| 227 | + <Checkbox label="请选择字典生成" /> | |
| 228 | + #end | |
| 229 | + </CheckboxGroup> | |
| 230 | + </FormItem> | |
| 231 | + #elseif($column.htmlType == "radio")## 单选框 | |
| 232 | + <FormItem label="${comment}" name="${javaField}"> | |
| 233 | + <RadioGroup v-model:value="formData.${javaField}"> | |
| 234 | + #if ("" != $dictType)## 有数据字典 | |
| 235 | + <Radio | |
| 236 | + v-for="dict in $dictMethod(DICT_TYPE.$dictType.toUpperCase())" | |
| 237 | + :key="dict.value" | |
| 238 | + :value="dict.value" | |
| 239 | + > | |
| 240 | + {{ dict.label }} | |
| 241 | + </Radio> | |
| 242 | + #else##没数据字典 | |
| 243 | + <Radio value="1">请选择字典生成</Radio> | |
| 244 | + #end | |
| 245 | + </RadioGroup> | |
| 246 | + </FormItem> | |
| 247 | + #elseif($column.htmlType == "datetime")## 时间框 | |
| 248 | + <FormItem label="${comment}" name="${javaField}"> | |
| 249 | + <DatePicker | |
| 250 | + v-model:value="formData.${javaField}" | |
| 251 | + valueFormat="x" | |
| 252 | + placeholder="选择${comment}" | |
| 253 | + /> | |
| 254 | + </FormItem> | |
| 255 | + #elseif($column.htmlType == "textarea")## 文本框 | |
| 256 | + <FormItem label="${comment}" name="${javaField}"> | |
| 257 | + <Textarea v-model:value="formData.${javaField}" placeholder="请输入${comment}" /> | |
| 258 | + </FormItem> | |
| 259 | + #end | |
| 260 | + #end | |
| 261 | +#end | |
| 262 | + </Form> | |
| 263 | +#end | |
| 264 | +</template> | |
| 265 | +<script setup lang="ts"> | |
| 266 | +import { Form, FormItem, Input, Button, Table, Column, Select, SelectOption, DatePicker, Textarea, Checkbox, CheckboxGroup, Radio, RadioGroup, Row } from 'ant-design-vue' | |
| 267 | +import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict' | |
| 268 | +import { ${simpleClassName}Api } from '@/api/${table.moduleName}/${table.businessName}' | |
| 269 | + | |
| 270 | +const props = defineProps<{ | |
| 271 | + ${subJoinColumn.javaField}: undefined // ${subJoinColumn.columnComment}(主表的关联字段) | |
| 272 | +}>() | |
| 273 | +const formLoading = ref(false) // 表单的加载中 | |
| 274 | +const formData = ref([]) | |
| 275 | +const formRules = reactive({ | |
| 276 | +#foreach ($column in $subColumns) | |
| 277 | + #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 | |
| 278 | + #set($comment=$column.columnComment) | |
| 279 | + $column.javaField: [{ required: true, message: '${comment}不能为空', trigger: #if($column.htmlType == 'select')'change'#else'blur'#end }], | |
| 280 | + #end | |
| 281 | +#end | |
| 282 | +}) | |
| 283 | +const formRef = ref() // 表单 Ref | |
| 284 | + | |
| 285 | +/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 286 | +watch( | |
| 287 | + () => props.${subJoinColumn.javaField}, | |
| 288 | + async (val) => { | |
| 289 | + // 1. 重置表单 | |
| 290 | +#if ( $subTable.subJoinMany ) | |
| 291 | + formData.value = [] | |
| 292 | +#else | |
| 293 | + formData.value = { | |
| 294 | + #foreach ($column in $subColumns) | |
| 295 | + #if ($column.createOperation || $column.updateOperation) | |
| 296 | + #if ($column.htmlType == "checkbox") | |
| 297 | + $column.javaField: [], | |
| 298 | + #else | |
| 299 | + $column.javaField: undefined, | |
| 300 | + #end | |
| 301 | + #end | |
| 302 | + #end | |
| 303 | + } | |
| 304 | +#end | |
| 305 | + // 2. val 非空,则加载数据 | |
| 306 | + if (!val) { | |
| 307 | + return; | |
| 308 | + } | |
| 309 | + try { | |
| 310 | + formLoading.value = true | |
| 311 | +#if ( $subTable.subJoinMany ) | |
| 312 | + formData.value = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(val) | |
| 313 | +#else | |
| 314 | + const data = await ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(val) | |
| 315 | + if (!data) { | |
| 316 | + return | |
| 317 | + } | |
| 318 | + formData.value = data | |
| 319 | +#end | |
| 320 | + } finally { | |
| 321 | + formLoading.value = false | |
| 322 | + } | |
| 323 | + }, | |
| 324 | + { immediate: true } | |
| 325 | +) | |
| 326 | +#if ( $subTable.subJoinMany ) | |
| 327 | + | |
| 328 | +/** 新增按钮操作 */ | |
| 329 | +const handleAdd = () => { | |
| 330 | + const row = { | |
| 331 | +#foreach ($column in $subColumns) | |
| 332 | + #if ($column.createOperation || $column.updateOperation) | |
| 333 | + #if ($column.htmlType == "checkbox") | |
| 334 | + $column.javaField: [], | |
| 335 | + #else | |
| 336 | + $column.javaField: undefined, | |
| 337 | + #end | |
| 338 | + #end | |
| 339 | +#end | |
| 340 | + } | |
| 341 | + row.${subJoinColumn.javaField} = props.${subJoinColumn.javaField} | |
| 342 | + formData.value.push(row) | |
| 343 | +} | |
| 344 | + | |
| 345 | +/** 删除按钮操作 */ | |
| 346 | +const handleDelete = (index) => { | |
| 347 | + formData.value.splice(index, 1) | |
| 348 | +} | |
| 349 | +#end | |
| 350 | + | |
| 351 | +/** 表单校验 */ | |
| 352 | +const validate = () => { | |
| 353 | + return formRef.value.validate() | |
| 354 | +} | |
| 355 | + | |
| 356 | +/** 表单值 */ | |
| 357 | +const getData = () => { | |
| 358 | + return formData.value | |
| 359 | +} | |
| 360 | + | |
| 361 | +defineExpose({ validate, getData }) | |
| 362 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/general/views/modules/list_sub_erp.vue.vm
0 → 100644
| 1 | +#set ($subTable = $subTables.get($subIndex))##当前表 | |
| 2 | +#set ($subColumns = $subColumnsList.get($subIndex))##当前字段数组 | |
| 3 | +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 | |
| 4 | +#set ($subSimpleClassName = $subSimpleClassNames.get($subIndex)) | |
| 5 | +#set ($subJoinColumn = $subJoinColumns.get($subIndex))##当前 join 字段 | |
| 6 | +#set ($SubJoinColumnName = $subJoinColumn.javaField.substring(0,1).toUpperCase() + ${subJoinColumn.javaField.substring(1)})##首字母大写 | |
| 7 | +<template> | |
| 8 | + <!-- 列表 --> | |
| 9 | + <ContentWrap> | |
| 10 | +#if ($table.templateType == 11) | |
| 11 | + <Button | |
| 12 | + type="primary" | |
| 13 | + @click="openForm('create')" | |
| 14 | + v-hasPermi="['${permissionPrefix}:create']" | |
| 15 | + > | |
| 16 | + <Icon icon="ep:plus" class="mr-5px" /> 新增 | |
| 17 | + </Button> | |
| 18 | +#end | |
| 19 | + <Table :loading="loading" :dataSource="list" :rowKey="(record) => record.id" :bordered="true"> | |
| 20 | + #foreach($column in $subColumns) | |
| 21 | + #if ($column.listOperationResult) | |
| 22 | + #set ($dictType=$column.dictType) | |
| 23 | + #set ($javaField = $column.javaField) | |
| 24 | + #set ($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) | |
| 25 | + #set ($comment=$column.columnComment) | |
| 26 | + #if ( $column.id == $subJoinColumn.id) ## 特殊:忽略主子表的 join 字段,不用填写 | |
| 27 | + #elseif ($column.javaType == "LocalDateTime")## 时间类型 | |
| 28 | + <Column | |
| 29 | + title="${comment}" | |
| 30 | + align="center" | |
| 31 | + dataIndex="${javaField}" | |
| 32 | + :customRender="({ text }) => dateFormatter(text)" | |
| 33 | + width="180px" | |
| 34 | + /> | |
| 35 | + #elseif($column.dictType && "" != $column.dictType)## 数据字典 | |
| 36 | + <Column title="${comment}" align="center" dataIndex="${javaField}"> | |
| 37 | + <template #customRender="{ text }"> | |
| 38 | + <dict-tag :type="DICT_TYPE.$dictType.toUpperCase()" :value="text" /> | |
| 39 | + </template> | |
| 40 | + </Column> | |
| 41 | + #else | |
| 42 | + <Column title="${comment}" align="center" dataIndex="${javaField}" /> | |
| 43 | + #end | |
| 44 | + #end | |
| 45 | + #end | |
| 46 | + #if ($table.templateType == 11) | |
| 47 | + <Column title="操作" align="center"> | |
| 48 | + <template #customRender="{ record }"> | |
| 49 | + <Button | |
| 50 | + type="link" | |
| 51 | + @click="openForm('update', record.id)" | |
| 52 | + v-hasPermi="['${permissionPrefix}:update']" | |
| 53 | + > | |
| 54 | + 编辑 | |
| 55 | + </Button> | |
| 56 | + <Button | |
| 57 | + type="link" | |
| 58 | + danger | |
| 59 | + @click="handleDelete(record.id)" | |
| 60 | + v-hasPermi="['${permissionPrefix}:delete']" | |
| 61 | + > | |
| 62 | + 删除 | |
| 63 | + </Button> | |
| 64 | + </template> | |
| 65 | + </Column> | |
| 66 | + #end | |
| 67 | + </Table> | |
| 68 | + #if ($table.templateType == 11) | |
| 69 | + <!-- 分页 --> | |
| 70 | + <Pagination | |
| 71 | + :total="total" | |
| 72 | + v-model:current="queryParams.pageNo" | |
| 73 | + v-model:pageSize="queryParams.pageSize" | |
| 74 | + @change="handleQuery" | |
| 75 | + /> | |
| 76 | + #end | |
| 77 | + </ContentWrap> | |
| 78 | +#if ($table.templateType == 11) | |
| 79 | + <!-- 表单弹窗:添加/修改 --> | |
| 80 | + <${subSimpleClassName}Form ref="formRef" @success="getList" /> | |
| 81 | +#end | |
| 82 | +</template> | |
| 83 | +<script setup lang="ts"> | |
| 84 | +import { Table, Column, Button, Pagination } from 'ant-design-vue' | |
| 85 | +import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict' | |
| 86 | +import { dateFormatter } from '@/utils/formatTime' | |
| 87 | +import { ${simpleClassName}Api } from '@/api/${table.moduleName}/${table.businessName}' | |
| 88 | +#if ($table.templateType == 11) | |
| 89 | +import ${subSimpleClassName}Form from './${subSimpleClassName}Form.vue' | |
| 90 | +#end | |
| 91 | + | |
| 92 | +const { t } = useI18n() // 国际化 | |
| 93 | +const message = useMessage() // 消息弹窗 | |
| 94 | + | |
| 95 | +const props = defineProps<{ | |
| 96 | + ${subJoinColumn.javaField}?: number // ${subJoinColumn.columnComment}(主表的关联字段) | |
| 97 | +}>() | |
| 98 | +const loading = ref(false) // 列表的加载中 | |
| 99 | +const list = ref([]) // 列表的数据 | |
| 100 | +#if ($table.templateType == 11) | |
| 101 | +const total = ref(0) // 列表的总页数 | |
| 102 | +const queryParams = reactive({ | |
| 103 | + pageNo: 1, | |
| 104 | + pageSize: 10, | |
| 105 | + ${subJoinColumn.javaField}: undefined as unknown | |
| 106 | +}) | |
| 107 | + | |
| 108 | +/** 监听主表的关联字段的变化,加载对应的子表数据 */ | |
| 109 | +watch( | |
| 110 | + () => props.${subJoinColumn.javaField}, | |
| 111 | + (val: number) => { | |
| 112 | + if (!val) { | |
| 113 | + return | |
| 114 | + } | |
| 115 | + queryParams.${subJoinColumn.javaField} = val | |
| 116 | + handleQuery() | |
| 117 | + }, | |
| 118 | + { immediate: true, deep: true } | |
| 119 | +) | |
| 120 | +#end | |
| 121 | + | |
| 122 | +/** 查询列表 */ | |
| 123 | +const getList = async () => { | |
| 124 | + loading.value = true | |
| 125 | + try { | |
| 126 | +#if ($table.templateType == 11) | |
| 127 | + const data = await ${simpleClassName}Api.get${subSimpleClassName}Page(queryParams) | |
| 128 | + list.value = data.list | |
| 129 | + total.value = data.total | |
| 130 | +#else | |
| 131 | + #if ( $subTable.subJoinMany ) | |
| 132 | + list.value = await ${simpleClassName}Api.get${subSimpleClassName}ListBy${SubJoinColumnName}(props.${subJoinColumn.javaField}) | |
| 133 | + #else | |
| 134 | + const data = await ${simpleClassName}Api.get${subSimpleClassName}By${SubJoinColumnName}(props.${subJoinColumn.javaField}) | |
| 135 | + if (!data) { | |
| 136 | + return | |
| 137 | + } | |
| 138 | + list.value.push(data) | |
| 139 | + #end | |
| 140 | +#end | |
| 141 | + } finally { | |
| 142 | + loading.value = false | |
| 143 | + } | |
| 144 | +} | |
| 145 | + | |
| 146 | +/** 搜索按钮操作 */ | |
| 147 | +const handleQuery = () => { | |
| 148 | + queryParams.pageNo = 1 | |
| 149 | + getList() | |
| 150 | +} | |
| 151 | +#if ($table.templateType == 11) | |
| 152 | + | |
| 153 | +/** 添加/修改操作 */ | |
| 154 | +const formRef = ref() | |
| 155 | +const openForm = (type: string, id?: number) => { | |
| 156 | + if (!props.${subJoinColumn.javaField}) { | |
| 157 | + message.error('请选择一个${table.classComment}') | |
| 158 | + return | |
| 159 | + } | |
| 160 | + formRef.value.open(type, id, props.${subJoinColumn.javaField}) | |
| 161 | +} | |
| 162 | + | |
| 163 | +/** 删除按钮操作 */ | |
| 164 | +const handleDelete = async (id: number) => { | |
| 165 | + try { | |
| 166 | + // 删除的二次确认 | |
| 167 | + await message.delConfirm() | |
| 168 | + // 发起删除 | |
| 169 | + await ${simpleClassName}Api.delete${subSimpleClassName}(id) | |
| 170 | + message.success(t('common.delSuccess')) | |
| 171 | + // 刷新列表 | |
| 172 | + await getList() | |
| 173 | + } catch {} | |
| 174 | +} | |
| 175 | +#end | |
| 176 | +#if ($table.templateType != 11) | |
| 177 | + | |
| 178 | +/** 初始化 **/ | |
| 179 | +onMounted(() => { | |
| 180 | + getList() | |
| 181 | +}) | |
| 182 | +#end | |
| 183 | +</script> | ... | ... |
yudao-module-infra/yudao-module-infra-biz/src/main/resources/codegen/vue3_vben5_antd/general/views/modules/list_sub_inner.vue.vm
0 → 100644