Commit b76c39fa8da3a80a9e4e8942b19476cdf20c492d

Authored by puhui999
1 parent 6a5d3430

perf: 优化 vue2 代码生成模板,增加批量删除功能

yudao-module-infra/src/main/resources/codegen/vue/api/api.js.vm
... ... @@ -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 40 // 获得${table.classComment}
31 41 export function get${simpleClassName}(id) {
32 42 return request({
... ... @@ -130,6 +140,15 @@ export function export${simpleClassName}Excel(params) {
130 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 152 // 获得${subTable.classComment}
134 153 export function get${subSimpleClassName}(id) {
135 154 return request({
... ...
yudao-module-infra/src/main/resources/codegen/vue/views/components/list_sub_erp.vue.vm
... ... @@ -13,10 +13,36 @@
13 13 <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="openForm(undefined)"
14 14 v-hasPermi="['${permissionPrefix}:create']">新增</el-button>
15 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 31 </el-row>
17 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 46 #foreach($column in $subColumns)
21 47 #if ($column.listOperationResult)
22 48 #set ($dictType=$column.dictType)
... ... @@ -82,6 +108,9 @@
82 108 // 列表的数据
83 109 list: [],
84 110 #if ($table.templateType == 11)
  111 + #if ($deleteBatchEnable)
  112 + checkedIds: [],
  113 + #end
85 114 // 列表的总页数
86 115 total: 0,
87 116 // 查询参数
... ... @@ -135,12 +164,27 @@
135 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 182 #if ($table.templateType == 11)
  183 + /** 搜索按钮操作 */
  184 + handleQuery() {
  185 + this.queryParams.pageNo = 1;
  186 + this.getList();
  187 + },
144 188 /** 添加/修改操作 */
145 189 openForm(id) {
146 190 if (!this.${subJoinColumn.javaField}) {
... ...
yudao-module-infra/src/main/resources/codegen/vue/views/index.vue.vm
... ... @@ -53,26 +53,45 @@
53 53 <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport" :loading="exportLoading"
54 54 v-hasPermi="['${permissionPrefix}:export']">导出</el-button>
55 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 79 <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
65 80 </el-row>
66 81  
67 82 ## 特殊:主子表专属逻辑
68 83 #if ( $table.templateType == 11 && $subTables && $subTables.size() > 0 )
69 84 <el-table
  85 + row-key="id"
70 86 v-loading="loading"
71 87 :data="list"
72 88 :stripe="true"
73 89 :highlight-current-row="true"
74 90 :show-overflow-tooltip="true"
75 91 @current-change="handleCurrentChange"
  92 + #if ($deleteBatchEnable)
  93 + @selection-change="handleRowCheckboxChange"
  94 + #end
76 95 >
77 96 ## 特殊:树表专属逻辑
78 97 #elseif ( $table.templateType == 2 )
... ... @@ -87,7 +106,18 @@
87 106 :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
88 107 >
89 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 121 #end
92 122 ## 特殊:主子表专属逻辑
93 123 #if ( $table.templateType == 12 && $subTables && $subTables.size() > 0 )
... ... @@ -229,6 +259,7 @@ export default {
229 259 refreshTable: true,
230 260 // 选中行
231 261 currentRow: {},
  262 + checkedIds: [],
232 263 // 查询参数
233 264 queryParams: {
234 265 ## 特殊:树表专属逻辑(树不需要分页接口)
... ... @@ -301,6 +332,20 @@ export default {
301 332 this.#[[$modal]]#.msgSuccess("删除成功");
302 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 350 async handleExport() {
306 351 await this.#[[$modal]]#.confirm('是否确认导出所有${table.classComment}数据项?');
... ...