index.vue 2.8 KB

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