index.vue 2.5 KB

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