feat: 【ANTD】新增代码生成批量删除接口示例 demo01
parent
2e0c7e23e9
commit
98e9d9fbfc
|
@ -9,7 +9,7 @@ export namespace Demo01ContactApi {
|
||||||
export interface Demo01Contact {
|
export interface Demo01Contact {
|
||||||
id: number; // 编号
|
id: number; // 编号
|
||||||
name?: string; // 名字
|
name?: string; // 名字
|
||||||
sex?: boolean; // 性别
|
sex?: number; // 性别
|
||||||
birthday?: Dayjs | string; // 出生年
|
birthday?: Dayjs | string; // 出生年
|
||||||
description?: string; // 简介
|
description?: string; // 简介
|
||||||
avatar: string; // 头像
|
avatar: string; // 头像
|
||||||
|
@ -46,6 +46,13 @@ export function deleteDemo01Contact(id: number) {
|
||||||
return requestClient.delete(`/infra/demo01-contact/delete?id=${id}`);
|
return requestClient.delete(`/infra/demo01-contact/delete?id=${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 批量删除示例联系人
|
||||||
|
export function deleteDemo01ContactByIds(ids: number[]) {
|
||||||
|
return requestClient.delete(
|
||||||
|
`/infra/demo01-contact/delete-batch?ids=${ids.join(',')}`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/** 导出示例联系人 */
|
/** 导出示例联系人 */
|
||||||
export function exportDemo01Contact(params: any) {
|
export function exportDemo01Contact(params: any) {
|
||||||
return requestClient.download('/infra/demo01-contact/export-excel', params);
|
return requestClient.download('/infra/demo01-contact/export-excel', params);
|
||||||
|
|
|
@ -103,6 +103,7 @@ export function useGridColumns(
|
||||||
onActionClick?: OnActionClickFn<Demo01ContactApi.Demo01Contact>,
|
onActionClick?: OnActionClickFn<Demo01ContactApi.Demo01Contact>,
|
||||||
): VxeTableGridOptions<Demo01ContactApi.Demo01Contact>['columns'] {
|
): VxeTableGridOptions<Demo01ContactApi.Demo01Contact>['columns'] {
|
||||||
return [
|
return [
|
||||||
|
{ type: 'checkbox', width: 40 },
|
||||||
{
|
{
|
||||||
field: 'id',
|
field: 'id',
|
||||||
title: '编号',
|
title: '编号',
|
||||||
|
@ -150,7 +151,6 @@ export function useGridColumns(
|
||||||
minWidth: 200,
|
minWidth: 200,
|
||||||
align: 'center',
|
align: 'center',
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
// TODO @puhui999:headerAlign 要使用 headerAlign: 'center' 么?看着现在分成了 align 和 headerAlign 两种
|
|
||||||
headerAlign: 'center',
|
headerAlign: 'center',
|
||||||
showOverflow: false,
|
showOverflow: false,
|
||||||
cellRender: {
|
cellRender: {
|
||||||
|
|
|
@ -5,17 +5,18 @@ import type {
|
||||||
} from '#/adapter/vxe-table';
|
} from '#/adapter/vxe-table';
|
||||||
import type { Demo01ContactApi } from '#/api/infra/demo/demo01';
|
import type { Demo01ContactApi } from '#/api/infra/demo/demo01';
|
||||||
|
|
||||||
import { h } from 'vue';
|
import { computed, h, ref } from 'vue';
|
||||||
|
|
||||||
import { Page, useVbenModal } from '@vben/common-ui';
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
import { Download, Plus } from '@vben/icons';
|
import { Download, Plus, Trash2 } from '@vben/icons';
|
||||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||||
|
|
||||||
import { Button, message } from 'ant-design-vue';
|
import { Button, message } from 'ant-design-vue';
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import {
|
import {
|
||||||
deleteDemo01Contact,
|
deleteDemo01Contact,
|
||||||
|
deleteDemo01ContactByIds,
|
||||||
exportDemo01Contact,
|
exportDemo01Contact,
|
||||||
getDemo01ContactPage,
|
getDemo01ContactPage,
|
||||||
} from '#/api/infra/demo/demo01';
|
} from '#/api/infra/demo/demo01';
|
||||||
|
@ -55,7 +56,25 @@ async function onDelete(row: Demo01ContactApi.Demo01Contact) {
|
||||||
await deleteDemo01Contact(row.id as number);
|
await deleteDemo01Contact(row.id as number);
|
||||||
message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
message.success($t('ui.actionMessage.deleteSuccess', [row.id]));
|
||||||
onRefresh();
|
onRefresh();
|
||||||
} catch {
|
} finally {
|
||||||
|
hideLoading();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteIds = ref<number[]>([]); // 待删除示例联系人 ID
|
||||||
|
const showDeleteBatchBtn = computed(() => isEmpty(deleteIds.value));
|
||||||
|
/** 批量删除示例联系人 */
|
||||||
|
async function onDeleteBatch() {
|
||||||
|
const hideLoading = message.loading({
|
||||||
|
content: $t('ui.actionMessage.deleting'),
|
||||||
|
duration: 0,
|
||||||
|
key: 'action_process_msg',
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deleteDemo01ContactByIds(deleteIds.value);
|
||||||
|
message.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
hideLoading();
|
hideLoading();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,6 +132,22 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
search: true,
|
search: true,
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions<Demo01ContactApi.Demo01Contact>,
|
} as VxeTableGridOptions<Demo01ContactApi.Demo01Contact>,
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: ({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: Demo01ContactApi.Demo01Contact[];
|
||||||
|
}) => {
|
||||||
|
deleteIds.value = records.map((item) => item.id);
|
||||||
|
},
|
||||||
|
checkboxChange: ({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: Demo01ContactApi.Demo01Contact[];
|
||||||
|
}) => {
|
||||||
|
deleteIds.value = records.map((item) => item.id);
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -139,6 +174,17 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
>
|
>
|
||||||
{{ $t('ui.actionTitle.export') }}
|
{{ $t('ui.actionTitle.export') }}
|
||||||
</Button>
|
</Button>
|
||||||
|
<Button
|
||||||
|
:icon="h(Trash2)"
|
||||||
|
type="primary"
|
||||||
|
danger
|
||||||
|
class="ml-2"
|
||||||
|
:disabled="showDeleteBatchBtn"
|
||||||
|
@click="onDeleteBatch"
|
||||||
|
v-access:code="['infra:demo01-contact:delete']"
|
||||||
|
>
|
||||||
|
批量删除
|
||||||
|
</Button>
|
||||||
</template>
|
</template>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Page>
|
</Page>
|
||||||
|
|
|
@ -68,6 +68,7 @@ export {
|
||||||
Sun,
|
Sun,
|
||||||
SunMoon,
|
SunMoon,
|
||||||
SwatchBook,
|
SwatchBook,
|
||||||
|
Trash2,
|
||||||
Upload,
|
Upload,
|
||||||
UserRoundPen,
|
UserRoundPen,
|
||||||
X,
|
X,
|
||||||
|
|
Loading…
Reference in New Issue