hooks.tsx 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {LDColumnsType, LDTableButton, modifyDataColumns} from '@components';
  2. import {useTableDeleteEvent, useTableModalEvent} from '@hooks';
  3. import {RoleListData} from '@models';
  4. import {TABLE_CELL_WIDTH} from '@utils';
  5. import {deleteRole} from '@apis';
  6. const tableColumns: LDColumnsType<RoleListData>[] = [
  7. {
  8. title: '角色名称',
  9. dataIndex: 'roleName',
  10. width: TABLE_CELL_WIDTH.normal,
  11. sort: true,
  12. },
  13. {
  14. title: '备注信息',
  15. dataIndex: 'remarks',
  16. width: TABLE_CELL_WIDTH.maximal,
  17. },
  18. ...modifyDataColumns,
  19. ];
  20. export function useColumns(refetch: () => void) {
  21. const [deleteId, onDelete] = useTableDeleteEvent(
  22. deleteRole,
  23. refetch,
  24. {label: '角色'},
  25. );
  26. const [{visible, editId}, {onAdd, onClose, onEdit}] = useTableModalEvent();
  27. const [
  28. {visible: authVisible, editId: authId},
  29. {onClose: onAuthClose, onEdit: onAuthClick},
  30. ] = useTableModalEvent();
  31. const columns: LDColumnsType<RoleListData>[] = [
  32. ...tableColumns,
  33. {
  34. title: '操作',
  35. dataIndex: 'id',
  36. fixed: 'right',
  37. width: TABLE_CELL_WIDTH.huge,
  38. render({id, roleName}) {
  39. const loading = deleteId === String(id);
  40. return (
  41. <>
  42. <LDTableButton
  43. onClick={onEdit(String(id))}
  44. disabled={loading}
  45. >
  46. 修改
  47. </LDTableButton>
  48. <LDTableButton
  49. onClick={onAuthClick(String(id))}
  50. disabled={loading}
  51. >
  52. 菜单权限
  53. </LDTableButton>
  54. <LDTableButton
  55. danger
  56. loading={loading}
  57. onClick={onDelete(String(id), roleName)}
  58. >
  59. 删除
  60. </LDTableButton>
  61. </>
  62. );
  63. },
  64. },
  65. ];
  66. return [
  67. {columns, visible, editId, authVisible, authId},
  68. {onAdd, onClose, onAuthClose},
  69. ] as const;
  70. }