index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. <DeptModal @register="registerModal" @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 { getDeptList } from '/@/api/demo/system';
  33. import { useModal } from '/@/components/Modal';
  34. import DeptModal from './DeptModal.vue';
  35. import { columns, searchFormSchema } from './dept.data';
  36. export default defineComponent({
  37. name: 'DeptManagement',
  38. components: { BasicTable, DeptModal, TableAction },
  39. setup() {
  40. const [registerModal, { openModal }] = useModal();
  41. const [registerTable, { reload }] = useTable({
  42. title: '部门列表',
  43. api: getDeptList,
  44. columns,
  45. formConfig: {
  46. labelWidth: 120,
  47. schemas: searchFormSchema,
  48. },
  49. pagination: false,
  50. striped: false,
  51. useSearchForm: true,
  52. showTableSetting: true,
  53. bordered: true,
  54. showIndexColumn: false,
  55. canResize: false,
  56. actionColumn: {
  57. width: 80,
  58. title: '操作',
  59. dataIndex: 'action',
  60. slots: { customRender: 'action' },
  61. fixed: undefined,
  62. },
  63. });
  64. function handleCreate() {
  65. openModal(true, {
  66. isUpdate: false,
  67. });
  68. }
  69. function handleEdit(record: Recordable) {
  70. openModal(true, {
  71. record,
  72. isUpdate: true,
  73. });
  74. }
  75. function handleDelete(record: Recordable) {
  76. console.log(record);
  77. }
  78. function handleSuccess() {
  79. reload();
  80. }
  81. return {
  82. registerTable,
  83. registerModal,
  84. handleCreate,
  85. handleEdit,
  86. handleDelete,
  87. handleSuccess,
  88. };
  89. },
  90. });
  91. </script>