feat: 【ele】角色管理新增批量删除
parent
879cad366f
commit
3d331d7fcc
|
@ -50,6 +50,11 @@ export function deleteRole(id: number) {
|
||||||
return requestClient.delete(`/system/role/delete?id=${id}`);
|
return requestClient.delete(`/system/role/delete?id=${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 批量删除角色 */
|
||||||
|
export function deleteRoleList(ids: number[]) {
|
||||||
|
return requestClient.delete(`/system/role/delete-list?ids=${ids.join(',')}`);
|
||||||
|
}
|
||||||
|
|
||||||
/** 导出角色 */
|
/** 导出角色 */
|
||||||
export function exportRole(params: any) {
|
export function exportRole(params: any) {
|
||||||
return requestClient.download('/system/role/export-excel', {
|
return requestClient.download('/system/role/export-excel', {
|
||||||
|
|
|
@ -193,6 +193,10 @@ export function useGridColumns<T = SystemRoleApi.Role>(
|
||||||
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,21 @@ import type {
|
||||||
} from '#/adapter/vxe-table';
|
} from '#/adapter/vxe-table';
|
||||||
import type { SystemRoleApi } from '#/api/system/role';
|
import type { SystemRoleApi } from '#/api/system/role';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
import { DocAlert, Page, useVbenModal } from '@vben/common-ui';
|
||||||
import { Download, Plus } from '@vben/icons';
|
import { Download, Plus } from '@vben/icons';
|
||||||
import { downloadFileFromBlobPart } from '@vben/utils';
|
import { downloadFileFromBlobPart, isEmpty } from '@vben/utils';
|
||||||
|
|
||||||
import { ElButton, ElLoading, ElMessage } from 'element-plus';
|
import { ElButton, ElLoading, ElMessage } from 'element-plus';
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
import { deleteRole, exportRole, getRolePage } from '#/api/system/role';
|
import {
|
||||||
|
deleteRole,
|
||||||
|
deleteRoleList,
|
||||||
|
exportRole,
|
||||||
|
getRolePage,
|
||||||
|
} from '#/api/system/role';
|
||||||
import { $t } from '#/locales';
|
import { $t } from '#/locales';
|
||||||
|
|
||||||
import { useGridColumns, useGridFormSchema } from './data';
|
import { useGridColumns, useGridFormSchema } from './data';
|
||||||
|
@ -67,13 +74,35 @@ async function onDelete(row: SystemRoleApi.Role) {
|
||||||
await deleteRole(row.id as number);
|
await deleteRole(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 deleteRoleList(checkedIds.value);
|
||||||
|
ElMessage.success($t('ui.actionMessage.deleteSuccess'));
|
||||||
|
onRefresh();
|
||||||
|
} finally {
|
||||||
|
loadingInstance.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const checkedIds = ref<number[]>([]);
|
||||||
|
function handleRowCheckboxChange({
|
||||||
|
records,
|
||||||
|
}: {
|
||||||
|
records: SystemRoleApi.Role[];
|
||||||
|
}) {
|
||||||
|
checkedIds.value = records.map((item) => item.id as number);
|
||||||
|
}
|
||||||
|
|
||||||
/** 分配角色的数据权限 */
|
/** 分配角色的数据权限 */
|
||||||
function onAssignDataPermission(row: SystemRoleApi.Role) {
|
function onAssignDataPermission(row: SystemRoleApi.Role) {
|
||||||
assignDataPermissionFormApi.setData(row).open();
|
assignDataPermissionFormApi.setData(row).open();
|
||||||
|
@ -133,6 +162,10 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
search: true,
|
search: true,
|
||||||
},
|
},
|
||||||
} as VxeTableGridOptions<SystemRoleApi.Role>,
|
} as VxeTableGridOptions<SystemRoleApi.Role>,
|
||||||
|
gridEvents: {
|
||||||
|
checkboxAll: handleRowCheckboxChange,
|
||||||
|
checkboxChange: handleRowCheckboxChange,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -168,6 +201,16 @@ const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
<Download class="mr-2 size-5" />
|
<Download class="mr-2 size-5" />
|
||||||
{{ $t('ui.actionTitle.export') }}
|
{{ $t('ui.actionTitle.export') }}
|
||||||
</ElButton>
|
</ElButton>
|
||||||
|
<ElButton
|
||||||
|
type="danger"
|
||||||
|
class="ml-2"
|
||||||
|
@click="onDeleteBatch"
|
||||||
|
v-access:code="['system:role:delete']"
|
||||||
|
:disabled="isEmpty(checkedIds)"
|
||||||
|
>
|
||||||
|
<i class="fa-solid fa-trash-can mr-2"></i>
|
||||||
|
{{ $t('ui.actionTitle.deleteBatch') }}
|
||||||
|
</ElButton>
|
||||||
</template>
|
</template>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Page>
|
</Page>
|
||||||
|
|
Loading…
Reference in New Issue