feat: 【ele】岗位管理新增批量删除
parent
3d331d7fcc
commit
842404d5b9
|
@ -50,6 +50,11 @@ export function deletePost(id: number) {
|
||||||
return requestClient.delete(`/system/post/delete?id=${id}`);
|
return requestClient.delete(`/system/post/delete?id=${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 批量删除岗位 */
|
||||||
|
export function deletePostList(ids: number[]) {
|
||||||
|
return requestClient.delete(`/system/post/delete-list?ids=${ids.join(',')}`);
|
||||||
|
}
|
||||||
|
|
||||||
/** 导出岗位 */
|
/** 导出岗位 */
|
||||||
export function exportPost(params: any) {
|
export function exportPost(params: any) {
|
||||||
return requestClient.download('/system/post/export', {
|
return requestClient.download('/system/post/export', {
|
||||||
|
|
|
@ -90,6 +90,10 @@ export function useGridColumns<T = SystemPostApi.Post>(
|
||||||
onActionClick: OnActionClickFn<T>,
|
onActionClick: OnActionClickFn<T>,
|
||||||
): VxeTableGridOptions['columns'] {
|
): VxeTableGridOptions['columns'] {
|
||||||
return [
|
return [
|
||||||
|
{
|
||||||
|
type: 'checkbox',
|
||||||
|
width: 40,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
field: 'id',
|
field: 'id',
|
||||||
title: '岗位编号',
|
title: '岗位编号',
|
||||||
|
|
|
@ -5,14 +5,20 @@ import type {
|
||||||
} from '#/adapter/vxe-table';
|
} from '#/adapter/vxe-table';
|
||||||
import type { SystemPostApi } from '#/api/system/post';
|
import type { SystemPostApi } from '#/api/system/post';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { Page, useVbenModal } from '@vben/common-ui';
|
import { Page, useVbenModal } from '@vben/common-ui';
|
||||||
import { Download, Plus } from '@vben/icons';
|
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
|
||||||
|
|
||||||
import { ElButton, ElLoading, ElMessage } from 'element-plus';
|
import { ElLoading, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { ACTION_ICON, TableAction, useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import { deletePost, exportPost, getPostPage } from '#/api/system/post';
|
import {
|
||||||
|
deletePost,
|
||||||
|
deletePostList,
|
||||||
|
exportPost,
|
||||||
|
getPostPage,
|
||||||
|
} from '#/api/system/post';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
import { useGridColumns, useGridFormSchema } from './data';
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
@ -54,13 +60,35 @@ async function onDelete(row: SystemPostApi.Post) {
|
||||||
await deletePost(row.id as number);
|
await deletePost(row.id as number);
|
||||||
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
ElMessage.success($t('ui.actionMessage.deleteSuccess', [row.name]));
|
||||||
onRefresh();
|
onRefresh();
|
||||||
} catch {
|
|
||||||
// 异常处理
|
|
||||||
} finally {
|
} finally {
|
||||||
loadingInstance.close();
|
loadingInstance.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 批量删除岗位 */
|
||||||
|
async function onDeleteBatch() {
|
||||||
|
const loadingInstance = ElLoading.service({
|
||||||
|
text: $t('ui.actionMessage.deleting'),
|
||||||
|
fullscreen: true,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await deletePostList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: SystemPostApi.Post[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id as number);
|
||||||
|
}
|
||||||
|
|
||||||
/** 表格操作按钮的回调函数 */
|
/** 表格操作按钮的回调函数 */
|
||||||
function onActionClick({ code, row }: OnActionClickParams<SystemPostApi.Post>) {
|
function onActionClick({ code, row }: OnActionClickParams<SystemPostApi.Post>) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
|
@ -102,6 +130,10 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
search: true,
|
search: true,
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions<SystemPostApi.Post>,
|
} as VxeTableGridOptions<SystemPostApi.Post>,
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: handleRowCheckboxChange,
|
||||||
|
checkboxChange: handleRowCheckboxChange,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -110,23 +142,32 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
<FormModal @success="onRefresh" />
|
<FormModal @success="onRefresh" />
|
||||||
<Grid table-title="岗位列表">
|
<Grid table-title="岗位列表">
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
<ElButton
|
<TableAction
|
||||||
type="primary"
|
:actions="[
|
||||||
@click="onCreate"
|
{
|
||||||
v-access:code="['system:post:create']"
|
label: $t('ui.actionTitle.create', ['岗位']),
|
||||||
>
|
type: 'primary',
|
||||||
<Plus class="mr-2 size-5" />
|
icon: ACTION_ICON.ADD,
|
||||||
{{ $t('ui.actionTitle.create', ['岗位']) }}
|
auth: ['system:post:create'],
|
||||||
</ElButton>
|
onClick: onCreate,
|
||||||
<ElButton
|
},
|
||||||
type="primary"
|
{
|
||||||
class="ml-2"
|
label: $t('ui.actionTitle.export'),
|
||||||
@click="onExport"
|
type: 'primary',
|
||||||
v-access:code="['system:post:export']"
|
icon: ACTION_ICON.DOWNLOAD,
|
||||||
>
|
auth: ['system:post:export'],
|
||||||
<Download class="mr-2 size-5" />
|
onClick: onExport,
|
||||||
{{ $t('ui.actionTitle.export') }}
|
},
|
||||||
</ElButton>
|
{
|
||||||
|
label: $t('ui.actionTitle.deleteBatch'),
|
||||||
|
type: 'danger',
|
||||||
|
icon: ACTION_ICON.DELETE,
|
||||||
|
disabled: isEmpty(checkedIds),
|
||||||
|
auth: ['system:post:delete'],
|
||||||
|
onClick: onDeleteBatch,
|
||||||
|
},
|
||||||
|
]"
|
||||||
|
/>
|
||||||
</template>
|
</template>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Page>
|
</Page>
|
||||||
|
|
Loading…
Reference in New Issue