Commit b76c39fa8da3a80a9e4e8942b19476cdf20c492d
1 parent
6a5d3430
perf: 优化 vue2 代码生成模板,增加批量删除功能
Showing
3 changed files
with
123 additions
and
15 deletions
yudao-module-infra/src/main/resources/codegen/vue/api/api.js.vm
| @@ -27,6 +27,16 @@ export function delete${simpleClassName}(id) { | @@ -27,6 +27,16 @@ export function delete${simpleClassName}(id) { | ||
| 27 | }) | 27 | }) |
| 28 | } | 28 | } |
| 29 | 29 | ||
| 30 | +#if ( $table.templateType != 2 && $deleteBatchEnable) | ||
| 31 | +/** 批量删除${table.classComment} */ | ||
| 32 | +export function delete${simpleClassName}List(ids) { | ||
| 33 | + return request({ | ||
| 34 | + url: `${baseURL}/delete-list?ids=${ids.join(',')}`, | ||
| 35 | + method: 'delete' | ||
| 36 | + }) | ||
| 37 | +} | ||
| 38 | +#end | ||
| 39 | + | ||
| 30 | // 获得${table.classComment} | 40 | // 获得${table.classComment} |
| 31 | export function get${simpleClassName}(id) { | 41 | export function get${simpleClassName}(id) { |
| 32 | return request({ | 42 | return request({ |
| @@ -130,6 +140,15 @@ export function export${simpleClassName}Excel(params) { | @@ -130,6 +140,15 @@ export function export${simpleClassName}Excel(params) { | ||
| 130 | method: 'delete' | 140 | method: 'delete' |
| 131 | }) | 141 | }) |
| 132 | } | 142 | } |
| 143 | + #if ($deleteBatchEnable) | ||
| 144 | + /** 批量删除${subTable.classComment} */ | ||
| 145 | + export function delete${subSimpleClassName}List(ids) { | ||
| 146 | + return request({ | ||
| 147 | + url: `${baseURL}/${subSimpleClassName_strikeCase}/delete-list?ids=${ids.join(',')}`, | ||
| 148 | + method: 'delete' | ||
| 149 | + }) | ||
| 150 | + } | ||
| 151 | + #end | ||
| 133 | // 获得${subTable.classComment} | 152 | // 获得${subTable.classComment} |
| 134 | export function get${subSimpleClassName}(id) { | 153 | export function get${subSimpleClassName}(id) { |
| 135 | return request({ | 154 | return request({ |
yudao-module-infra/src/main/resources/codegen/vue/views/components/list_sub_erp.vue.vm
| @@ -13,10 +13,36 @@ | @@ -13,10 +13,36 @@ | ||
| 13 | <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" | 13 | <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)" |
| 14 | v-hasPermi="['${permissionPrefix}:create']">新增</el-button> | 14 | v-hasPermi="['${permissionPrefix}:create']">新增</el-button> |
| 15 | </el-col> | 15 | </el-col> |
| 16 | + #if ($deleteBatchEnable) | ||
| 17 | + <el-col :span="1.5"> | ||
| 18 | + <el-button | ||
| 19 | + type="danger" | ||
| 20 | + plain | ||
| 21 | + icon="el-icon-delete" | ||
| 22 | + size="mini" | ||
| 23 | + :disabled="isEmpty(checkedIds)" | ||
| 24 | + @click="handleDeleteBatch" | ||
| 25 | + v-hasPermi="['${permissionPrefix}:delete']" | ||
| 26 | + > | ||
| 27 | + 批量删除 | ||
| 28 | + </el-button> | ||
| 29 | + </el-col> | ||
| 30 | + #end | ||
| 16 | </el-row> | 31 | </el-row> |
| 17 | #end | 32 | #end |
| 18 | ## 列表 | 33 | ## 列表 |
| 19 | - <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | 34 | + <el-table |
| 35 | + v-loading="loading" | ||
| 36 | + :data="list" | ||
| 37 | + :stripe="true" | ||
| 38 | + :show-overflow-tooltip="true" | ||
| 39 | + #if ($table.templateType == 11 && $deleteBatchEnable) | ||
| 40 | + @selection-change="handleRowCheckboxChange" | ||
| 41 | + #end | ||
| 42 | + > | ||
| 43 | + #if ($table.templateType == 11 && $deleteBatchEnable) | ||
| 44 | + <el-table-column type="selection" width="55" /> | ||
| 45 | + #end | ||
| 20 | #foreach($column in $subColumns) | 46 | #foreach($column in $subColumns) |
| 21 | #if ($column.listOperationResult) | 47 | #if ($column.listOperationResult) |
| 22 | #set ($dictType=$column.dictType) | 48 | #set ($dictType=$column.dictType) |
| @@ -82,6 +108,9 @@ | @@ -82,6 +108,9 @@ | ||
| 82 | // 列表的数据 | 108 | // 列表的数据 |
| 83 | list: [], | 109 | list: [], |
| 84 | #if ($table.templateType == 11) | 110 | #if ($table.templateType == 11) |
| 111 | + #if ($deleteBatchEnable) | ||
| 112 | + checkedIds: [], | ||
| 113 | + #end | ||
| 85 | // 列表的总页数 | 114 | // 列表的总页数 |
| 86 | total: 0, | 115 | total: 0, |
| 87 | // 查询参数 | 116 | // 查询参数 |
| @@ -135,12 +164,27 @@ | @@ -135,12 +164,27 @@ | ||
| 135 | this.loading = false; | 164 | this.loading = false; |
| 136 | } | 165 | } |
| 137 | }, | 166 | }, |
| 138 | - /** 搜索按钮操作 */ | ||
| 139 | - handleQuery() { | ||
| 140 | - this.queryParams.pageNo = 1; | ||
| 141 | - this.getList(); | ||
| 142 | - }, | 167 | + #if ($table.templateType == 11 && $deleteBatchEnable) |
| 168 | + /** 批量删除${table.classComment} */ | ||
| 169 | + async handleDeleteBatch() { | ||
| 170 | + await this.#[[$modal]]#.confirm('是否确认删除?') | ||
| 171 | + try { | ||
| 172 | + await ${simpleClassName}Api.delete${subSimpleClassName}List(this.checkedIds); | ||
| 173 | + await this.getList(); | ||
| 174 | + this.#[[$modal]]#.msgSuccess("删除成功"); | ||
| 175 | + } catch {} | ||
| 176 | + }, | ||
| 177 | + handleRowCheckboxChange(records) { | ||
| 178 | + this.checkedIds = records.map((item) => item.id); | ||
| 179 | + }, | ||
| 180 | + #end | ||
| 181 | + | ||
| 143 | #if ($table.templateType == 11) | 182 | #if ($table.templateType == 11) |
| 183 | + /** 搜索按钮操作 */ | ||
| 184 | + handleQuery() { | ||
| 185 | + this.queryParams.pageNo = 1; | ||
| 186 | + this.getList(); | ||
| 187 | + }, | ||
| 144 | /** 添加/修改操作 */ | 188 | /** 添加/修改操作 */ |
| 145 | openForm(id) { | 189 | openForm(id) { |
| 146 | if (!this.${subJoinColumn.javaField}) { | 190 | if (!this.${subJoinColumn.javaField}) { |
yudao-module-infra/src/main/resources/codegen/vue/views/index.vue.vm
| @@ -53,26 +53,45 @@ | @@ -53,26 +53,45 @@ | ||
| 53 | <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" | 53 | <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading" |
| 54 | v-hasPermi="['${permissionPrefix}:export']">导出</el-button> | 54 | v-hasPermi="['${permissionPrefix}:export']">导出</el-button> |
| 55 | </el-col> | 55 | </el-col> |
| 56 | - ## 特殊:树表专属逻辑 | ||
| 57 | - #if ( $table.templateType == 2 ) | ||
| 58 | - <el-col :span="1.5"> | ||
| 59 | - <el-button type="danger" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll"> | ||
| 60 | - 展开/折叠 | ||
| 61 | - </el-button> | ||
| 62 | - </el-col> | ||
| 63 | - #end | 56 | + ## 特殊:树表专属逻辑 |
| 57 | + #if ( $table.templateType == 2 ) | ||
| 58 | + <el-col :span="1.5"> | ||
| 59 | + <el-button type="danger" plain icon="el-icon-sort" size="mini" @click="toggleExpandAll"> | ||
| 60 | + 展开/折叠 | ||
| 61 | + </el-button> | ||
| 62 | + </el-col> | ||
| 63 | + #end | ||
| 64 | + #if ($table.templateType != 2 && $deleteBatchEnable) | ||
| 65 | + <el-col :span="1.5"> | ||
| 66 | + <el-button | ||
| 67 | + type="danger" | ||
| 68 | + plain | ||
| 69 | + icon="el-icon-delete" | ||
| 70 | + size="mini" | ||
| 71 | + :disabled="isEmpty(checkedIds)" | ||
| 72 | + @click="handleDeleteBatch" | ||
| 73 | + v-hasPermi="['${permissionPrefix}:delete']" | ||
| 74 | + > | ||
| 75 | + 批量删除 | ||
| 76 | + </el-button> | ||
| 77 | + </el-col> | ||
| 78 | + #end | ||
| 64 | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> | 79 | <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar> |
| 65 | </el-row> | 80 | </el-row> |
| 66 | 81 | ||
| 67 | ## 特殊:主子表专属逻辑 | 82 | ## 特殊:主子表专属逻辑 |
| 68 | #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 ) | 83 | #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 ) |
| 69 | <el-table | 84 | <el-table |
| 85 | + row-key="id" | ||
| 70 | v-loading="loading" | 86 | v-loading="loading" |
| 71 | :data="list" | 87 | :data="list" |
| 72 | :stripe="true" | 88 | :stripe="true" |
| 73 | :highlight-current-row="true" | 89 | :highlight-current-row="true" |
| 74 | :show-overflow-tooltip="true" | 90 | :show-overflow-tooltip="true" |
| 75 | @current-change="handleCurrentChange" | 91 | @current-change="handleCurrentChange" |
| 92 | + #if ($deleteBatchEnable) | ||
| 93 | + @selection-change="handleRowCheckboxChange" | ||
| 94 | + #end | ||
| 76 | > | 95 | > |
| 77 | ## 特殊:树表专属逻辑 | 96 | ## 特殊:树表专属逻辑 |
| 78 | #elseif ( $table.templateType == 2 ) | 97 | #elseif ( $table.templateType == 2 ) |
| @@ -87,7 +106,18 @@ | @@ -87,7 +106,18 @@ | ||
| 87 | :tree-props="{children: 'children', hasChildren: 'hasChildren'}" | 106 | :tree-props="{children: 'children', hasChildren: 'hasChildren'}" |
| 88 | > | 107 | > |
| 89 | #else | 108 | #else |
| 90 | - <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true"> | 109 | + <el-table |
| 110 | + v-loading="loading" | ||
| 111 | + :data="list" | ||
| 112 | + :stripe="true" | ||
| 113 | + :show-overflow-tooltip="true" | ||
| 114 | + #if ($deleteBatchEnable) | ||
| 115 | + @selection-change="handleRowCheckboxChange" | ||
| 116 | + #end | ||
| 117 | + > | ||
| 118 | + #end | ||
| 119 | + #if ($table.templateType != 2 && $deleteBatchEnable) | ||
| 120 | + <el-table-column type="selection" width="55" /> | ||
| 91 | #end | 121 | #end |
| 92 | ## 特殊:主子表专属逻辑 | 122 | ## 特殊:主子表专属逻辑 |
| 93 | #if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 ) | 123 | #if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 ) |
| @@ -229,6 +259,7 @@ export default { | @@ -229,6 +259,7 @@ export default { | ||
| 229 | refreshTable: true, | 259 | refreshTable: true, |
| 230 | // 选中行 | 260 | // 选中行 |
| 231 | currentRow: {}, | 261 | currentRow: {}, |
| 262 | + checkedIds: [], | ||
| 232 | // 查询参数 | 263 | // 查询参数 |
| 233 | queryParams: { | 264 | queryParams: { |
| 234 | ## 特殊:树表专属逻辑(树不需要分页接口) | 265 | ## 特殊:树表专属逻辑(树不需要分页接口) |
| @@ -301,6 +332,20 @@ export default { | @@ -301,6 +332,20 @@ export default { | ||
| 301 | this.#[[$modal]]#.msgSuccess("删除成功"); | 332 | this.#[[$modal]]#.msgSuccess("删除成功"); |
| 302 | } catch {} | 333 | } catch {} |
| 303 | }, | 334 | }, |
| 335 | + #if ($table.templateType != 2 && $deleteBatchEnable) | ||
| 336 | + /** 批量删除${table.classComment} */ | ||
| 337 | + async handleDeleteBatch() { | ||
| 338 | + await this.#[[$modal]]#.confirm('是否确认删除?') | ||
| 339 | + try { | ||
| 340 | + await ${simpleClassName}Api.delete${simpleClassName}List(this.checkedIds); | ||
| 341 | + await this.getList(); | ||
| 342 | + this.#[[$modal]]#.msgSuccess("删除成功"); | ||
| 343 | + } catch {} | ||
| 344 | + }, | ||
| 345 | + handleRowCheckboxChange(records) { | ||
| 346 | + this.checkedIds = records.map((item) => item.id); | ||
| 347 | + }, | ||
| 348 | + #end | ||
| 304 | /** 导出按钮操作 */ | 349 | /** 导出按钮操作 */ |
| 305 | async handleExport() { | 350 | async handleExport() { |
| 306 | await this.#[[$modal]]#.confirm('是否确认导出所有${table.classComment}数据项?'); | 351 | await this.#[[$modal]]#.confirm('是否确认导出所有${table.classComment}数据项?'); |