index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <BasicTable
  3. ref="tableRef"
  4. @register="registerTable"
  5. rowKey="id"
  6. :pagination="{
  7. pageSize: 10,
  8. defaultPageSize: 10,
  9. showSizeChanger: false,
  10. }"
  11. >
  12. <template #form-custom> custom-slot </template>
  13. <template #action="{ record }">
  14. <TableAction :actions="createActions(record)" stopButtonPropagation />
  15. </template>
  16. </BasicTable>
  17. </template>
  18. <script lang="ts">
  19. import { defineComponent, ref, unref } from 'vue';
  20. import { useModal } from '/@/components/Modal';
  21. import { columns } from './data';
  22. import { getAttachmentList } from '/@/api/sys/general';
  23. import moment from 'moment';
  24. import {
  25. BasicTable,
  26. useTable,
  27. TableAction,
  28. ActionItem,
  29. EditRecordRow,
  30. TableActionType,
  31. } from '/@/components/Table';
  32. export default defineComponent({
  33. name: 'Attachment',
  34. components: { BasicTable, TableAction },
  35. emits: ['select'],
  36. setup(_, { emit }) {
  37. const tableRef = ref<Nullable<TableActionType>>(null);
  38. const [registerTable] = useTable({
  39. columns: columns,
  40. clickToRowSelect: false, // 点击行不勾选
  41. api: getAttachmentList,
  42. useSearchForm: true,
  43. showTableSetting: true,
  44. tableSetting: {
  45. redo: false,
  46. size: false,
  47. },
  48. beforeFetch: beforeFetch,
  49. afterFetch: afterFetch,
  50. actionColumn: {
  51. width: 160,
  52. title: '操作',
  53. dataIndex: 'action',
  54. slots: { customRender: 'action' },
  55. fixed: undefined,
  56. },
  57. maxHeight: 190,
  58. showIndexColumn: false,
  59. bordered: true,
  60. });
  61. const [{ openModal: openPopup }] = useModal();
  62. function getTableAction() {
  63. // 获取组件
  64. const tableAction = unref(tableRef);
  65. if (!tableAction) {
  66. throw new Error('tableAction is null');
  67. }
  68. return tableAction;
  69. }
  70. function beforeFetch(params) {
  71. for (let k in params) {
  72. if (k !== 'page' && k !== 'pageSize' && k !== 'field' && k !== 'order') {
  73. if (params[k] === '') {
  74. delete params[k];
  75. } else {
  76. if (!params.filter) {
  77. params.filter = {};
  78. }
  79. if (params.birthday) {
  80. params.birthday = moment(params.birthday).format('YYYY-MM-DD');
  81. } else {
  82. delete params.birthday;
  83. }
  84. params.filter[k] = params[k];
  85. delete params[k];
  86. }
  87. }
  88. }
  89. params.filter = JSON.stringify(params.filter);
  90. params.offset = params.page;
  91. params.limit = params.pageSize;
  92. delete params.page;
  93. delete params.pageSize;
  94. }
  95. function afterFetch(result) {
  96. console.log(`result`, result);
  97. // tableData.result = result;
  98. }
  99. function handleAdd() {
  100. // 开启弹窗
  101. openPopup(true, { family: [] });
  102. }
  103. function handleSelect(record: EditRecordRow) {
  104. emit('select', record);
  105. }
  106. function createActions(record: EditRecordRow): ActionItem[] {
  107. return [
  108. {
  109. label: '选择',
  110. icon: 'ant-design:edit-outlined',
  111. color: 'warning',
  112. onClick: handleSelect.bind(null, record),
  113. },
  114. ];
  115. }
  116. return {
  117. tableRef,
  118. registerTable,
  119. handleAdd,
  120. handleSelect,
  121. createActions,
  122. getTableAction,
  123. };
  124. },
  125. });
  126. </script>
  127. <style>
  128. .ant-calendar-picker {
  129. width: 100%;
  130. }
  131. /* @media (max-width: 639px) {
  132. .sys-container .vben-basic-table-header__toolbar > * {
  133. padding: 6px !important;
  134. margin-right: 3px;
  135. font-size: 12px !important;
  136. }
  137. .sys-container .vben-basic-table .ant-table-wrapper {
  138. padding: 3px;
  139. }
  140. } */
  141. </style>