Commit 6a5d3430362083561551484426ede5965ac2371f
1 parent
c26c4414
perf: 优化 vue3 代码生成模板,增加批量删除功能
Showing
10 changed files
with
184 additions
and
41 deletions
yudao-module-infra/src/main/resources/codegen/vue3/api/api.ts.vm
| 1 | 1 | import request from '@/config/axios' |
| 2 | +import type { Dayjs } from 'dayjs'; | |
| 2 | 3 | #set ($baseURL = "/${table.moduleName}/${simpleClassName_strikeCase}") |
| 3 | 4 | |
| 4 | -// ${table.classComment} VO | |
| 5 | -export interface ${simpleClassName}VO { | |
| 6 | -#foreach ($column in $columns) | |
| 7 | -#if ($column.createOperation || $column.updateOperation) | |
| 8 | -#if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "short" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") | |
| 9 | - ${column.javaField}: number // ${column.columnComment} | |
| 10 | -#elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdate" || ${column.javaType.toLowerCase()} == "localdatetime") | |
| 11 | - ${column.javaField}: Date // ${column.columnComment} | |
| 12 | -#else | |
| 13 | - ${column.javaField}: ${column.javaType.toLowerCase()} // ${column.columnComment} | |
| 14 | -#end | |
| 15 | -#end | |
| 5 | +## 特殊:主子表专属逻辑 | |
| 6 | +#foreach ($subTable in $subTables) | |
| 7 | + #set ($index = $foreach.count - 1) | |
| 8 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | |
| 9 | + #set ($subColumns = $subColumnsList.get($index))##当前字段数组 | |
| 10 | +/** ${subTable.classComment}信息 */ | |
| 11 | +export interface ${subSimpleClassName} { | |
| 12 | + #foreach ($column in $subColumns) | |
| 13 | + #if ($column.createOperation || $column.updateOperation) | |
| 14 | + #if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "short" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") | |
| 15 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: number; // ${column.columnComment} | |
| 16 | + #elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdate" || ${column.javaType.toLowerCase()} == "localdatetime") | |
| 17 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: string | Dayjs; // ${column.columnComment} | |
| 18 | + #else | |
| 19 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: ${column.javaType.toLowerCase()}; // ${column.columnComment} | |
| 20 | + #end | |
| 21 | + #end | |
| 22 | + #end | |
| 23 | +} | |
| 24 | + | |
| 16 | 25 | #end |
| 26 | +/** ${table.classComment}信息 */ | |
| 27 | +export interface ${simpleClassName} { | |
| 28 | + #foreach ($column in $columns) | |
| 29 | + #if ($column.createOperation || $column.updateOperation) | |
| 30 | + #if(${column.javaType.toLowerCase()} == "long" || ${column.javaType.toLowerCase()} == "integer" || ${column.javaType.toLowerCase()} == "short" || ${column.javaType.toLowerCase()} == "double" || ${column.javaType.toLowerCase()} == "bigdecimal") | |
| 31 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: number; // ${column.columnComment} | |
| 32 | + #elseif(${column.javaType.toLowerCase()} == "date" || ${column.javaType.toLowerCase()} == "localdate" || ${column.javaType.toLowerCase()} == "localdatetime") | |
| 33 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: string | Dayjs; // ${column.columnComment} | |
| 34 | + #else | |
| 35 | + ${column.javaField}#if($column.updateOperation && !$column.primaryKey && !$column.nullable)?#end: ${column.javaType.toLowerCase()}; // ${column.columnComment} | |
| 36 | + #end | |
| 37 | + #end | |
| 38 | + #end | |
| 39 | + #if ( $table.templateType == 2 ) | |
| 40 | + children?: ${simpleClassName}[]; | |
| 41 | + #end | |
| 42 | + ## 特殊:主子表专属逻辑 | |
| 43 | + #if ( $table.templateType == 10 || $table.templateType == 12 ) | |
| 44 | + #foreach ($subTable in $subTables) | |
| 45 | + #set ($index = $foreach.count - 1) | |
| 46 | + #set ($subSimpleClassName = $subSimpleClassNames.get($index)) | |
| 47 | + #if ( $subTable.subJoinMany ) | |
| 48 | + ${subSimpleClassName.toLowerCase()}s?: ${subSimpleClassName}[] | |
| 49 | + #else | |
| 50 | + ${subSimpleClassName.toLowerCase()}?: ${subSimpleClassName} | |
| 51 | + #end | |
| 52 | + #end | |
| 53 | + #end | |
| 17 | 54 | } |
| 18 | 55 | |
| 19 | 56 | // ${table.classComment} API |
| ... | ... | @@ -36,12 +73,12 @@ export const ${simpleClassName}Api = { |
| 36 | 73 | }, |
| 37 | 74 | |
| 38 | 75 | // 新增${table.classComment} |
| 39 | - create${simpleClassName}: async (data: ${simpleClassName}VO) => { | |
| 76 | + create${simpleClassName}: async (data: ${simpleClassName}) => { | |
| 40 | 77 | return await request.post({ url: `${baseURL}/create`, data }) |
| 41 | 78 | }, |
| 42 | 79 | |
| 43 | 80 | // 修改${table.classComment} |
| 44 | - update${simpleClassName}: async (data: ${simpleClassName}VO) => { | |
| 81 | + update${simpleClassName}: async (data: ${simpleClassName}) => { | |
| 45 | 82 | return await request.put({ url: `${baseURL}/update`, data }) |
| 46 | 83 | }, |
| 47 | 84 | |
| ... | ... | @@ -50,6 +87,13 @@ export const ${simpleClassName}Api = { |
| 50 | 87 | return await request.delete({ url: `${baseURL}/delete?id=` + id }) |
| 51 | 88 | }, |
| 52 | 89 | |
| 90 | +#if ( $table.templateType != 2 && $deleteBatchEnable) | |
| 91 | + /** 批量删除${table.classComment} */ | |
| 92 | + delete${simpleClassName}List: async (ids: number[]) => { | |
| 93 | + return await request.delete({ url: `${baseURL}/delete-list?ids=${ids.join(',')}` }) | |
| 94 | + }, | |
| 95 | +#end | |
| 96 | + | |
| 53 | 97 | // 导出${table.classComment} Excel |
| 54 | 98 | export${simpleClassName}: async (params) => { |
| 55 | 99 | return await request.download({ url: `${baseURL}/export-excel`, params }) |
| ... | ... | @@ -92,12 +136,12 @@ export const ${simpleClassName}Api = { |
| 92 | 136 | ## 特殊:MASTER_ERP 时,支持单个的新增、修改、删除操作 |
| 93 | 137 | #if ( $table.templateType == 11 ) |
| 94 | 138 | // 新增${subTable.classComment} |
| 95 | - create${subSimpleClassName}: async (data) => { | |
| 139 | + create${subSimpleClassName}: async (data: ${subSimpleClassName}) => { | |
| 96 | 140 | return await request.post({ url: `${baseURL}/${subSimpleClassName_strikeCase}/create`, data }) |
| 97 | 141 | }, |
| 98 | 142 | |
| 99 | 143 | // 修改${subTable.classComment} |
| 100 | - update${subSimpleClassName}: async (data) => { | |
| 144 | + update${subSimpleClassName}: async (data: ${subSimpleClassName}) => { | |
| 101 | 145 | return await request.put({ url: `${baseURL}/${subSimpleClassName_strikeCase}/update`, data }) |
| 102 | 146 | }, |
| 103 | 147 | |
| ... | ... | @@ -106,6 +150,13 @@ export const ${simpleClassName}Api = { |
| 106 | 150 | return await request.delete({ url: `${baseURL}/${subSimpleClassName_strikeCase}/delete?id=` + id }) |
| 107 | 151 | }, |
| 108 | 152 | |
| 153 | + #if ($deleteBatchEnable) | |
| 154 | + /** 批量删除${subTable.classComment} */ | |
| 155 | + delete${subSimpleClassName}List: async (ids: number[]) => { | |
| 156 | + return await request.delete({ url: `${baseURL}/${subSimpleClassName_strikeCase}/delete-list?ids=${ids.join(',')}` }) | |
| 157 | + }, | |
| 158 | + #end | |
| 159 | + | |
| 109 | 160 | // 获得${subTable.classComment} |
| 110 | 161 | get${subSimpleClassName}: async (id: number) => { |
| 111 | 162 | return await request.get({ url: `${baseURL}/${subSimpleClassName_strikeCase}/get?id=` + id }) | ... | ... |
yudao-module-infra/src/main/resources/codegen/vue3/views/components/form_sub_erp.vue.vm
| ... | ... | @@ -113,7 +113,7 @@ |
| 113 | 113 | </template> |
| 114 | 114 | <script setup lang="ts"> |
| 115 | 115 | import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict' |
| 116 | -import { ${simpleClassName}Api } from '@/api/${table.moduleName}/${table.businessName}' | |
| 116 | +import { ${simpleClassName}Api, ${subSimpleClassName} } from '@/api/${table.moduleName}/${table.businessName}' | |
| 117 | 117 | |
| 118 | 118 | const { t } = useI18n() // 国际化 |
| 119 | 119 | const message = useMessage() // 消息弹窗 |
| ... | ... | @@ -144,12 +144,12 @@ const formRules = reactive({ |
| 144 | 144 | const formRef = ref() // 表单 Ref |
| 145 | 145 | |
| 146 | 146 | /** 打开弹窗 */ |
| 147 | -const open = async (type: string, id?: number, ${subJoinColumn.javaField}: number) => { | |
| 147 | +const open = async (type: string, id?: number, ${subJoinColumn.javaField}?: number) => { | |
| 148 | 148 | dialogVisible.value = true |
| 149 | 149 | dialogTitle.value = t('action.' + type) |
| 150 | 150 | formType.value = type |
| 151 | 151 | resetForm() |
| 152 | - formData.value.${subJoinColumn.javaField} = ${subJoinColumn.javaField} | |
| 152 | + formData.value.${subJoinColumn.javaField} = ${subJoinColumn.javaField} as any | |
| 153 | 153 | // 修改时,设置数据 |
| 154 | 154 | if (id) { |
| 155 | 155 | formLoading.value = true |
| ... | ... | @@ -170,7 +170,7 @@ const submitForm = async () => { |
| 170 | 170 | // 提交请求 |
| 171 | 171 | formLoading.value = true |
| 172 | 172 | try { |
| 173 | - const data = formData.value | |
| 173 | + const data = formData.value as unknown as ${subSimpleClassName} | |
| 174 | 174 | if (formType.value === 'create') { |
| 175 | 175 | await ${simpleClassName}Api.create${subSimpleClassName}(data) |
| 176 | 176 | message.success(t('common.createSuccess')) | ... | ... |
yudao-module-infra/src/main/resources/codegen/vue3/views/components/form_sub_normal.vue.vm
| ... | ... | @@ -266,10 +266,10 @@ import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } f |
| 266 | 266 | import { ${simpleClassName}Api } from '@/api/${table.moduleName}/${table.businessName}' |
| 267 | 267 | |
| 268 | 268 | const props = defineProps<{ |
| 269 | - ${subJoinColumn.javaField}: undefined // ${subJoinColumn.columnComment}(主表的关联字段) | |
| 269 | + ${subJoinColumn.javaField}: number // ${subJoinColumn.columnComment}(主表的关联字段) | |
| 270 | 270 | }>() |
| 271 | 271 | const formLoading = ref(false) // 表单的加载中 |
| 272 | -const formData = ref([]) | |
| 272 | +const formData = ref<any#if ( $subTable.subJoinMany )[]#end>(#if ( $subTable.subJoinMany )[]#else{}#end) | |
| 273 | 273 | const formRules = reactive({ |
| 274 | 274 | #foreach ($column in $subColumns) |
| 275 | 275 | #if (($column.createOperation || $column.updateOperation) && !$column.nullable && !${column.primaryKey})## 创建或者更新操作 && 要求非空 && 非主键 |
| ... | ... | @@ -336,7 +336,7 @@ const handleAdd = () => { |
| 336 | 336 | #end |
| 337 | 337 | #end |
| 338 | 338 | } |
| 339 | - row.${subJoinColumn.javaField} = props.${subJoinColumn.javaField} | |
| 339 | + row.${subJoinColumn.javaField} = props.${subJoinColumn.javaField} as any | |
| 340 | 340 | formData.value.push(row) |
| 341 | 341 | } |
| 342 | 342 | ... | ... |
yudao-module-infra/src/main/resources/codegen/vue3/views/components/list_sub_erp.vue.vm
| ... | ... | @@ -16,8 +16,31 @@ |
| 16 | 16 | > |
| 17 | 17 | <Icon icon="ep:plus" class="mr-5px" /> 新增 |
| 18 | 18 | </el-button> |
| 19 | + #if ($deleteBatchEnable) | |
| 20 | + <el-button | |
| 21 | + type="danger" | |
| 22 | + plain | |
| 23 | + :disabled="isEmpty(checkedIds)" | |
| 24 | + @click="handleDeleteBatch" | |
| 25 | + v-hasPermi="['${permissionPrefix}:delete']" | |
| 26 | + > | |
| 27 | + <Icon icon="ep:delete" class="mr-5px" /> 批量删除 | |
| 28 | + </el-button> | |
| 29 | + #end | |
| 19 | 30 | #end |
| 20 | - <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 31 | + <el-table | |
| 32 | + row-key="id" | |
| 33 | + v-loading="loading" | |
| 34 | + :data="list" | |
| 35 | + :stripe="true" | |
| 36 | + :show-overflow-tooltip="true" | |
| 37 | + #if ($table.templateType == 11 && $deleteBatchEnable) | |
| 38 | + @selection-change="handleRowCheckboxChange" | |
| 39 | + #end | |
| 40 | + > | |
| 41 | + #if ($table.templateType == 11 && $deleteBatchEnable) | |
| 42 | + <el-table-column type="selection" width="55" /> | |
| 43 | + #end | |
| 21 | 44 | #foreach($column in $subColumns) |
| 22 | 45 | #if ($column.listOperationResult) |
| 23 | 46 | #set ($dictType=$column.dictType) |
| ... | ... | @@ -85,14 +108,18 @@ |
| 85 | 108 | <script setup lang="ts"> |
| 86 | 109 | import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict' |
| 87 | 110 | import { dateFormatter } from '@/utils/formatTime' |
| 88 | -import { ${simpleClassName}Api } from '@/api/${table.moduleName}/${table.businessName}' | |
| 111 | +#if ($deleteBatchEnable) | |
| 112 | +import { isEmpty } from '@/utils/is' | |
| 113 | +#end | |
| 114 | +import { ${simpleClassName}Api, ${subSimpleClassName} } from '@/api/${table.moduleName}/${table.businessName}' | |
| 89 | 115 | #if ($table.templateType == 11) |
| 90 | 116 | import ${subSimpleClassName}Form from './${subSimpleClassName}Form.vue' |
| 91 | 117 | #end |
| 92 | 118 | |
| 119 | +#if ($table.templateType == 11) | |
| 93 | 120 | const { t } = useI18n() // 国际化 |
| 94 | 121 | const message = useMessage() // 消息弹窗 |
| 95 | - | |
| 122 | +#end | |
| 96 | 123 | const props = defineProps<{ |
| 97 | 124 | ${subJoinColumn.javaField}?: number // ${subJoinColumn.columnComment}(主表的关联字段) |
| 98 | 125 | }>() |
| ... | ... | @@ -144,12 +171,12 @@ const getList = async () => { |
| 144 | 171 | } |
| 145 | 172 | } |
| 146 | 173 | |
| 174 | +#if ($table.templateType == 11) | |
| 147 | 175 | /** 搜索按钮操作 */ |
| 148 | 176 | const handleQuery = () => { |
| 149 | 177 | queryParams.pageNo = 1 |
| 150 | 178 | getList() |
| 151 | 179 | } |
| 152 | -#if ($table.templateType == 11) | |
| 153 | 180 | |
| 154 | 181 | /** 添加/修改操作 */ |
| 155 | 182 | const formRef = ref() |
| ... | ... | @@ -173,6 +200,24 @@ const handleDelete = async (id: number) => { |
| 173 | 200 | await getList() |
| 174 | 201 | } catch {} |
| 175 | 202 | } |
| 203 | + | |
| 204 | +#if ($table.templateType == 11 && $deleteBatchEnable) | |
| 205 | +/** 批量删除${subTable.classComment} */ | |
| 206 | +const handleDeleteBatch = async () => { | |
| 207 | + try { | |
| 208 | + // 删除的二次确认 | |
| 209 | + await message.delConfirm() | |
| 210 | + await ${simpleClassName}Api.delete${subSimpleClassName}List(checkedIds.value); | |
| 211 | + message.success(t('common.delSuccess')) | |
| 212 | + await getList(); | |
| 213 | + } catch {} | |
| 214 | +} | |
| 215 | + | |
| 216 | +const checkedIds = ref<number[]>([]) | |
| 217 | +const handleRowCheckboxChange = (records: ${subSimpleClassName}[]) => { | |
| 218 | + checkedIds.value = records.map((item) => item.id); | |
| 219 | +} | |
| 220 | +#end | |
| 176 | 221 | #end |
| 177 | 222 | #if ($table.templateType != 11) |
| 178 | 223 | ... | ... |
yudao-module-infra/src/main/resources/codegen/vue3/views/form.vue.vm
| ... | ... | @@ -139,7 +139,7 @@ |
| 139 | 139 | </template> |
| 140 | 140 | <script setup lang="ts"> |
| 141 | 141 | import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict' |
| 142 | -import { ${simpleClassName}Api, ${simpleClassName}VO } from '@/api/${table.moduleName}/${table.businessName}' | |
| 142 | +import { ${simpleClassName}Api, ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}' | |
| 143 | 143 | ## 特殊:树表专属逻辑 |
| 144 | 144 | #if ( $table.templateType == 2 ) |
| 145 | 145 | import { defaultProps, handleTree } from '@/utils/tree' |
| ... | ... | @@ -243,7 +243,7 @@ const submitForm = async () => { |
| 243 | 243 | // 提交请求 |
| 244 | 244 | formLoading.value = true |
| 245 | 245 | try { |
| 246 | - const data = formData.value as unknown as ${simpleClassName}VO | |
| 246 | + const data = formData.value as unknown as ${simpleClassName} | |
| 247 | 247 | ## 特殊:主子表专属逻辑 |
| 248 | 248 | #if ( $table.templateType == 10 || $table.templateType == 12 ) |
| 249 | 249 | #if ( $subTables && $subTables.size() > 0 ) | ... | ... |
yudao-module-infra/src/main/resources/codegen/vue3/views/index.vue.vm
| ... | ... | @@ -107,6 +107,17 @@ |
| 107 | 107 | <Icon icon="ep:sort" class="mr-5px" /> 展开/折叠 |
| 108 | 108 | </el-button> |
| 109 | 109 | #end |
| 110 | + #if ($table.templateType != 2 && $deleteBatchEnable) | |
| 111 | + <el-button | |
| 112 | + type="danger" | |
| 113 | + plain | |
| 114 | + :disabled="isEmpty(checkedIds)" | |
| 115 | + @click="handleDeleteBatch" | |
| 116 | + v-hasPermi="['${table.moduleName}:${simpleClassName_strikeCase}:delete']" | |
| 117 | + > | |
| 118 | + <Icon icon="ep:delete" class="mr-5px" /> 批量删除 | |
| 119 | + </el-button> | |
| 120 | + #end | |
| 110 | 121 | </el-form-item> |
| 111 | 122 | </el-form> |
| 112 | 123 | </ContentWrap> |
| ... | ... | @@ -116,12 +127,16 @@ |
| 116 | 127 | ## 特殊:主子表专属逻辑 |
| 117 | 128 | #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 ) |
| 118 | 129 | <el-table |
| 130 | + row-key="id" | |
| 119 | 131 | v-loading="loading" |
| 120 | 132 | :data="list" |
| 121 | 133 | :stripe="true" |
| 122 | 134 | :show-overflow-tooltip="true" |
| 123 | 135 | highlight-current-row |
| 124 | 136 | @current-change="handleCurrentChange" |
| 137 | + #if ($deleteBatchEnable) | |
| 138 | + @selection-change="handleRowCheckboxChange" | |
| 139 | + #end | |
| 125 | 140 | > |
| 126 | 141 | ## 特殊:树表专属逻辑 |
| 127 | 142 | #elseif ( $table.templateType == 2 ) |
| ... | ... | @@ -135,7 +150,19 @@ |
| 135 | 150 | v-if="refreshTable" |
| 136 | 151 | > |
| 137 | 152 | #else |
| 138 | - <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | |
| 153 | + <el-table | |
| 154 | + row-key="id" | |
| 155 | + v-loading="loading" | |
| 156 | + :data="list" | |
| 157 | + :stripe="true" | |
| 158 | + :show-overflow-tooltip="true" | |
| 159 | + #if ($deleteBatchEnable) | |
| 160 | + @selection-change="handleRowCheckboxChange" | |
| 161 | + #end | |
| 162 | + > | |
| 163 | +#end | |
| 164 | +#if ($table.templateType != 2 && $deleteBatchEnable) | |
| 165 | + <el-table-column type="selection" width="55" /> | |
| 139 | 166 | #end |
| 140 | 167 | ## 特殊:主子表专属逻辑 |
| 141 | 168 | #if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 ) |
| ... | ... | @@ -234,13 +261,14 @@ |
| 234 | 261 | |
| 235 | 262 | <script setup lang="ts"> |
| 236 | 263 | import { getIntDictOptions, getStrDictOptions, getBoolDictOptions, DICT_TYPE } from '@/utils/dict' |
| 264 | +import { isEmpty } from '@/utils/is' | |
| 237 | 265 | import { dateFormatter } from '@/utils/formatTime' |
| 238 | 266 | ## 特殊:树表专属逻辑 |
| 239 | 267 | #if ( $table.templateType == 2 ) |
| 240 | 268 | import { handleTree } from '@/utils/tree' |
| 241 | 269 | #end |
| 242 | 270 | import download from '@/utils/download' |
| 243 | -import { ${simpleClassName}Api, ${simpleClassName}VO } from '@/api/${table.moduleName}/${table.businessName}' | |
| 271 | +import { ${simpleClassName}Api, ${simpleClassName} } from '@/api/${table.moduleName}/${table.businessName}' | |
| 244 | 272 | import ${simpleClassName}Form from './${simpleClassName}Form.vue' |
| 245 | 273 | ## 特殊:主子表专属逻辑 |
| 246 | 274 | #if ( $table.templateType != 10 ) |
| ... | ... | @@ -256,7 +284,7 @@ const message = useMessage() // 消息弹窗 |
| 256 | 284 | const { t } = useI18n() // 国际化 |
| 257 | 285 | |
| 258 | 286 | const loading = ref(true) // 列表的加载中 |
| 259 | -const list = ref<${simpleClassName}VO[]>([]) // 列表的数据 | |
| 287 | +const list = ref<${simpleClassName}[]>([]) // 列表的数据 | |
| 260 | 288 | ## 特殊:树表专属逻辑(树不需要分页接口) |
| 261 | 289 | #if ( $table.templateType != 2 ) |
| 262 | 290 | const total = ref(0) // 列表的总页数 |
| ... | ... | @@ -330,6 +358,24 @@ const handleDelete = async (id: number) => { |
| 330 | 358 | } catch {} |
| 331 | 359 | } |
| 332 | 360 | |
| 361 | +#if ($table.templateType != 2 && $deleteBatchEnable) | |
| 362 | +/** 批量删除${table.classComment} */ | |
| 363 | +const handleDeleteBatch = async () => { | |
| 364 | + try { | |
| 365 | + // 删除的二次确认 | |
| 366 | + await message.delConfirm() | |
| 367 | + await ${simpleClassName}Api.delete${simpleClassName}List(checkedIds.value); | |
| 368 | + message.success(t('common.delSuccess')) | |
| 369 | + await getList(); | |
| 370 | + } catch {} | |
| 371 | +} | |
| 372 | + | |
| 373 | +const checkedIds = ref<number[]>([]) | |
| 374 | +const handleRowCheckboxChange = (records: ${simpleClassName}[]) => { | |
| 375 | + checkedIds.value = records.map((item) => item.id); | |
| 376 | +} | |
| 377 | +#end | |
| 378 | + | |
| 333 | 379 | /** 导出按钮操作 */ |
| 334 | 380 | const handleExport = async () => { |
| 335 | 381 | try { | ... | ... |
yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/general/views/index.vue.vm
| ... | ... | @@ -30,7 +30,7 @@ import { handleTree,isEmpty } from '@vben/utils' |
| 30 | 30 | import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${simpleClassName_strikeCase}'; |
| 31 | 31 | #else## 标准表接口 |
| 32 | 32 | import { isEmpty } from '@vben/utils'; |
| 33 | -import { get${simpleClassName}Page, delete${simpleClassName},#if ($deleteBatchEnable) delete${simpleClassName}ListByIds,#end export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; | |
| 33 | +import { get${simpleClassName}Page, delete${simpleClassName},#if ($deleteBatchEnable) delete${simpleClassName}List,#end export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; | |
| 34 | 34 | #end |
| 35 | 35 | import { downloadFileFromBlobPart } from '@vben/utils'; |
| 36 | 36 | |
| ... | ... | @@ -157,7 +157,7 @@ async function onDelete(row: ${simpleClassName}Api.${simpleClassName}) { |
| 157 | 157 | hideLoading(); |
| 158 | 158 | } |
| 159 | 159 | } |
| 160 | - | |
| 160 | +// TODO @puhui999: 改成和 schema 模式一样 | |
| 161 | 161 | #if ($table.templateType != 2 && $deleteBatchEnable) |
| 162 | 162 | /** 批量删除${table.classComment} */ |
| 163 | 163 | async function onDeleteBatch() { |
| ... | ... | @@ -167,7 +167,7 @@ async function onDeleteBatch() { |
| 167 | 167 | key: 'action_process_msg', |
| 168 | 168 | }); |
| 169 | 169 | try { |
| 170 | - await delete${simpleClassName}ListByIds(checkedIds.value); | |
| 170 | + await delete${simpleClassName}List(checkedIds.value); | |
| 171 | 171 | message.success( $t('ui.actionMessage.deleteSuccess') ); |
| 172 | 172 | await getList(); |
| 173 | 173 | } finally { | ... | ... |
yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/general/views/modules/list_sub_erp.vue.vm
| ... | ... | @@ -29,7 +29,7 @@ |
| 29 | 29 | #end |
| 30 | 30 | |
| 31 | 31 | #if ($table.templateType == 11) ## erp |
| 32 | - import { delete${subSimpleClassName},#if ($deleteBatchEnable) delete${subSimpleClassName}ListByIds,#end get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}'; | |
| 32 | + import { delete${subSimpleClassName},#if ($deleteBatchEnable) delete${subSimpleClassName}List,#end get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}'; | |
| 33 | 33 | import { isEmpty } from '@vben/utils'; |
| 34 | 34 | #else |
| 35 | 35 | #if ($subTable.subJoinMany) ## 一对多 |
| ... | ... | @@ -91,7 +91,7 @@ async function onDeleteBatch() { |
| 91 | 91 | key: 'action_process_msg', |
| 92 | 92 | }); |
| 93 | 93 | try { |
| 94 | - await delete${subSimpleClassName}ListByIds(checkedIds.value); | |
| 94 | + await delete${subSimpleClassName}List(checkedIds.value); | |
| 95 | 95 | message.success( $t('ui.actionMessage.deleteSuccess') ); |
| 96 | 96 | await getList(); |
| 97 | 97 | } finally { | ... | ... |
yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm
| ... | ... | @@ -21,7 +21,7 @@ import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; |
| 21 | 21 | #if (${table.templateType} == 2)## 树表接口 |
| 22 | 22 | import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; |
| 23 | 23 | #else## 标准表接口 |
| 24 | -import { get${simpleClassName}Page, delete${simpleClassName},#if ($deleteBatchEnable) delete${simpleClassName}ListByIds,#end export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; | |
| 24 | +import { get${simpleClassName}Page, delete${simpleClassName},#if ($deleteBatchEnable) delete${simpleClassName}List,#end export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}'; | |
| 25 | 25 | #end |
| 26 | 26 | import { downloadFileFromBlobPart, isEmpty } from '@vben/utils'; |
| 27 | 27 | |
| ... | ... | @@ -101,7 +101,8 @@ async function handleDeleteBatch() { |
| 101 | 101 | key: 'action_key_msg', |
| 102 | 102 | }); |
| 103 | 103 | try { |
| 104 | - await delete${simpleClassName}ListByIds(checkedIds.value); | |
| 104 | + // TODO @puhui999: 移除所有模板中的 List | |
| 105 | + await delete${simpleClassName}List(checkedIds.value); | |
| 105 | 106 | message.success({ |
| 106 | 107 | content: $t('ui.actionMessage.deleteSuccess'), |
| 107 | 108 | key: 'action_key_msg', | ... | ... |
yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/modules/list_sub_erp.vue.vm
| ... | ... | @@ -19,7 +19,7 @@ import { $t } from '#/locales'; |
| 19 | 19 | import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table'; |
| 20 | 20 | |
| 21 | 21 | #if ($table.templateType == 11) ## erp |
| 22 | -import { delete${subSimpleClassName},#if ($deleteBatchEnable) delete${subSimpleClassName}ListByIds,#end get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}'; | |
| 22 | +import { delete${subSimpleClassName},#if ($deleteBatchEnable) delete${subSimpleClassName}List,#end get${subSimpleClassName}Page } from '#/api/${table.moduleName}/${table.businessName}'; | |
| 23 | 23 | import { use${subSimpleClassName}GridFormSchema, use${subSimpleClassName}GridColumns } from '../data'; |
| 24 | 24 | import { isEmpty } from '@vben/utils'; |
| 25 | 25 | #else |
| ... | ... | @@ -81,7 +81,7 @@ async function handleDeleteBatch() { |
| 81 | 81 | key: 'action_key_msg', |
| 82 | 82 | }); |
| 83 | 83 | try { |
| 84 | - await delete${subSimpleClassName}ListByIds(checkedIds.value); | |
| 84 | + await delete${subSimpleClassName}List(checkedIds.value); | |
| 85 | 85 | message.success({ |
| 86 | 86 | content: $t('ui.actionMessage.deleteSuccess', [row.id]), |
| 87 | 87 | key: 'action_key_msg', | ... | ... |