Commit 6dee926253c86790aa0ea88b2b27a981a7d49794

Authored by puhui999
1 parent 9295d610

feat:【INFRA 基础设施】新增 vben5-antd-schema 模板代码生成时,可生成批量删除

yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/api/api.ts.vm
... ... @@ -89,6 +89,13 @@ export function delete${simpleClassName}(id: number) {
89 89 return requestClient.delete(`${baseURL}/delete?id=${id}`);
90 90 }
91 91  
  92 +#if ( $table.templateType != 2 && $table.deleteBatch)
  93 +// 批量删除${table.classComment}
  94 +export function delete${simpleClassName}ByIds(ids: number[]) {
  95 + return requestClient.delete(`${baseURL}/delete-batch?ids=${ids.join(',')}`)
  96 +}
  97 +#end
  98 +
92 99 /** 导出${table.classComment} */
93 100 export function export${simpleClassName}(params: any) {
94 101 return requestClient.download('${baseURL}/export-excel', params);
... ...
yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/data.ts.vm
... ... @@ -193,6 +193,9 @@ export function useGridColumns(
193 193 onActionClick?: OnActionClickFn<${simpleClassName}Api.${simpleClassName}>,
194 194 ): VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>['columns'] {
195 195 return [
  196 +#if ($table.templateType != 2 && $table.deleteBatch)
  197 + { type: 'checkbox', width: 40 },
  198 +#end
196 199 #if ($table.templateType == 12) ## 内嵌情况
197 200 { type: 'expand', width: 80, slots: { content: 'expand_content' } },
198 201 #end
... ...
yudao-module-infra/src/main/resources/codegen/vue3_vben5_antd/schema/views/index.vue.vm
... ... @@ -4,7 +4,7 @@ import type { ${simpleClassName}Api } from &#39;#/api/${table.moduleName}/${table.bu
4 4  
5 5 import { Page, useVbenModal } from '@vben/common-ui';
6 6 import { Button, message,Tabs } from 'ant-design-vue';
7   -import { Download, Plus } from '@vben/icons';
  7 +import { Download, Plus, Trash2 } from '@vben/icons';
8 8 import Form from './modules/form.vue';
9 9  
10 10 ## 特殊:主子表专属逻辑
... ... @@ -16,15 +16,15 @@ import Form from &#39;./modules/form.vue&#39;;
16 16 #end
17 17 #end
18 18  
19   -import { ref, h } from 'vue';
  19 +import { ref, h, computed } from 'vue';
20 20 import { $t } from '#/locales';
21 21 import { useVbenVxeGrid } from '#/adapter/vxe-table';
22 22 #if (${table.templateType} == 2)## 树表接口
23 23 import { get${simpleClassName}List, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
24 24 #else## 标准表接口
25   -import { get${simpleClassName}Page, delete${simpleClassName}, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
  25 +import { get${simpleClassName}Page, delete${simpleClassName},delete${simpleClassName}ByIds, export${simpleClassName} } from '#/api/${table.moduleName}/${table.businessName}';
26 26 #end
27   -import { downloadFileFromBlobPart } from '@vben/utils';
  27 +import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
28 28  
29 29 import { useGridColumns, useGridFormSchema } from './data';
30 30  
... ... @@ -87,11 +87,31 @@ async function onDelete(row: ${simpleClassName}Api.${simpleClassName}) {
87 87 await delete${simpleClassName}(row.id as number);
88 88 message.success( $t('ui.actionMessage.deleteSuccess', [row.id]) );
89 89 onRefresh();
90   - } catch {
  90 + } finally {
91 91 hideLoading();
92 92 }
93 93 }
94 94  
  95 +#if ($table.templateType != 2 && $table.deleteBatch)
  96 +const deleteIds = ref<number[]>([]) // 待删除${table.classComment} ID
  97 +const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value));
  98 +/** 批量删除${table.classComment} */
  99 +async function onDeleteBatch() {
  100 + const hideLoading = message.loading({
  101 + content: $t('ui.actionMessage.deleting'),
  102 + duration: 0,
  103 + key: 'action_process_msg',
  104 + });
  105 + try {
  106 + await delete${simpleClassName}ByIds(deleteIds.value);
  107 + message.success( $t('ui.actionMessage.deleteSuccess') );
  108 + onRefresh();
  109 + } finally {
  110 + hideLoading();
  111 + }
  112 +}
  113 +#end
  114 +
95 115 /** 导出表格 */
96 116 async function onExport() {
97 117 const data = await export${simpleClassName}(await gridApi.formApi.getValues());
... ... @@ -177,11 +197,21 @@ const [Grid, gridApi] = useVbenVxeGrid({
177 197 search: true,
178 198 },
179 199 } as VxeTableGridOptions<${simpleClassName}Api.${simpleClassName}>,
180   -#if (${table.templateType} == 11)
  200 +#if (${table.templateType} == 11 || $table.deleteBatch)
181 201 gridEvents:{
  202 + #if(${table.templateType} == 11)
182 203 cellClick: ({ row }: { row: ${simpleClassName}Api.${simpleClassName}}) => {
183 204 select${simpleClassName}.value = row;
184 205 },
  206 + #end
  207 + #if($table.deleteBatch)
  208 + checkboxAll: ({records,}: { records: ${simpleClassName}Api.${simpleClassName}[];}) => {
  209 + deleteIds.value = records.map((item) => item.id);
  210 + },
  211 + checkboxChange: ({records,}: { records: ${simpleClassName}Api.${simpleClassName}[];}) => {
  212 + deleteIds.value = records.map((item) => item.id);
  213 + },
  214 + #end
185 215 }
186 216 #end
187 217 });
... ... @@ -229,6 +259,19 @@ const [Grid, gridApi] = useVbenVxeGrid({
229 259 >
230 260 {{ $t('ui.actionTitle.export') }}
231 261 </Button>
  262 +#if ($table.templateType != 2 && $table.deleteBatch)
  263 + <Button
  264 + :icon="h(Trash2)"
  265 + type="primary"
  266 + danger
  267 + class="ml-2"
  268 + :disabled="showDeleteBatchBtn"
  269 + @click="onDeleteBatch"
  270 + v-access:code="['${table.moduleName}:${simpleClassName_strikeCase}:delete']"
  271 + >
  272 + 批量删除
  273 + </Button>
  274 +#end
232 275 </template>
233 276 </Grid>
234 277  
... ...