index.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. <template>
  2. <div>
  3. <BasicTable @register="registerTable">
  4. <template #toolbar>
  5. <a-button type="primary" @click="handleCreate"> 新增角色 </a-button>
  6. </template>
  7. <template #action="{ record }">
  8. <TableAction
  9. :actions="[
  10. {
  11. icon: 'clarity:note-edit-line',
  12. onClick: handleEdit.bind(null, record),
  13. },
  14. {
  15. icon: 'ant-design:delete-outlined',
  16. color: 'error',
  17. popConfirm: {
  18. title: '是否确认删除',
  19. confirm: handleDelete.bind(null, record),
  20. },
  21. },
  22. ]"
  23. />
  24. </template>
  25. </BasicTable>
  26. <RoleDrawer @register="registerDrawer" @success="handleSuccess" />
  27. </div>
  28. </template>
  29. <script lang="ts">
  30. import { defineComponent } from 'vue';
  31. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  32. import { getRoleListByPage } from '/@/api/demo/system';
  33. import { useDrawer } from '/@/components/Drawer';
  34. import RoleDrawer from './RoleDrawer.vue';
  35. import { columns, searchFormSchema } from './role.data';
  36. export default defineComponent({
  37. name: 'RoleManagement',
  38. components: { BasicTable, RoleDrawer, TableAction },
  39. setup() {
  40. const [registerDrawer, { openDrawer }] = useDrawer();
  41. const [registerTable, { reload }] = useTable({
  42. title: '角色列表',
  43. api: getRoleListByPage,
  44. columns,
  45. formConfig: {
  46. labelWidth: 120,
  47. schemas: searchFormSchema,
  48. },
  49. useSearchForm: true,
  50. showTableSetting: true,
  51. bordered: true,
  52. showIndexColumn: false,
  53. actionColumn: {
  54. width: 80,
  55. title: '操作',
  56. dataIndex: 'action',
  57. slots: { customRender: 'action' },
  58. fixed: undefined,
  59. },
  60. });
  61. function handleCreate() {
  62. openDrawer(true, {
  63. isUpdate: false,
  64. });
  65. }
  66. function handleEdit(record: Recordable) {
  67. openDrawer(true, {
  68. record,
  69. isUpdate: true,
  70. });
  71. }
  72. function handleDelete(record: Recordable) {
  73. console.log(record);
  74. }
  75. function handleSuccess() {
  76. reload();
  77. }
  78. return {
  79. registerTable,
  80. registerDrawer,
  81. handleCreate,
  82. handleEdit,
  83. handleDelete,
  84. handleSuccess,
  85. };
  86. },
  87. });
  88. </script>