ButtonTable.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <div>
  3. <BasicTable @register="registerTable">
  4. <template #toolbar>
  5. <a-button type="primary" @click="handleCreate"> {{ t('新增按钮') }} </a-button>
  6. </template>
  7. <template #action2="{ record }">
  8. <SetPrintTemplate
  9. v-if="record.code.includes(PrintButton.CODE)"
  10. :row="record"
  11. :hasMetaFormId="hasMetaFormId"
  12. >
  13. <Icon icon="ant-design:setting-outlined" style="cursor: pointer" />
  14. </SetPrintTemplate>
  15. </template>
  16. <template #action="{ record }">
  17. <TableAction
  18. :actions="[
  19. {
  20. icon: 'clarity:note-edit-line',
  21. title: t('编辑'),
  22. onClick: handleEdit.bind(null, record),
  23. },
  24. {
  25. icon: 'ant-design:delete-outlined',
  26. color: 'error',
  27. title: t('删除'),
  28. popConfirm: {
  29. title: t('是否确认删除'),
  30. confirm: handleDelete.bind(null, record),
  31. },
  32. },
  33. ]"
  34. />
  35. </template>
  36. </BasicTable>
  37. <MenuButtonModal @register="registerModal" @success="handleSuccess" />
  38. </div>
  39. </template>
  40. <script lang="ts" setup>
  41. import { reactive } from 'vue';
  42. import { BasicTable, useTable, TableAction, BasicColumn } from '/@/components/Table';
  43. import MenuButtonModal from './MenuButtonModal.vue';
  44. import SetPrintTemplate from './SetPrintTemplate.vue';
  45. import { getMenuButtonById } from '/@/api/system/menu';
  46. import { Icon } from '/@/components/Icon';
  47. import { useModal } from '/@/components/Modal';
  48. import { MenuButtonModel } from '/@/api/system/menuButton/model';
  49. import { useI18n } from '/@/hooks/web/useI18n';
  50. import { PrintButton } from '/@/enums/printEnum';
  51. const { t } = useI18n();
  52. const props = defineProps({
  53. menuId: { type: String, default: '' },
  54. hasMetaFormId: { type: Boolean, default: false },
  55. });
  56. const columns: BasicColumn[] = [
  57. {
  58. title: t('按钮名称'),
  59. dataIndex: 'name',
  60. width: 100,
  61. align: 'left',
  62. },
  63. {
  64. title: t('编码'),
  65. dataIndex: 'code',
  66. width: 100,
  67. },
  68. {
  69. title: t('地址'),
  70. dataIndex: 'url',
  71. width: 100,
  72. },
  73. {
  74. title: t('请求方式'),
  75. dataIndex: 'method',
  76. width: 180,
  77. format: (text: string | number) => {
  78. if (text === 0) return 'GET';
  79. else if (text === 1) return 'POST';
  80. else if (text === 2) return 'PUT';
  81. else return 'DELETE';
  82. },
  83. },
  84. {
  85. title: t('设置'),
  86. dataIndex: 'action2',
  87. width: 100,
  88. },
  89. ];
  90. defineEmits(['success', 'register']);
  91. let btnData = reactive<MenuButtonModel[]>([]);
  92. const [registerTable, { getDataSource, setTableData, updateTableDataRecord }] = useTable({
  93. title: t('按钮列表'),
  94. dataSource: btnData,
  95. api: getMenuButtonById,
  96. beforeFetch: (params) => {
  97. //发送请求默认新增 左边树结构所选机构id
  98. return { ...params, id: props.menuId };
  99. },
  100. columns,
  101. pagination: false,
  102. striped: false,
  103. useSearchForm: false,
  104. showTableSetting: true,
  105. bordered: true,
  106. showIndexColumn: false,
  107. canResize: false,
  108. actionColumn: {
  109. width: 80,
  110. title: t('操作'),
  111. dataIndex: 'action',
  112. slots: { customRender: 'action' },
  113. fixed: undefined,
  114. },
  115. });
  116. const [registerModal, { openModal }] = useModal();
  117. function handleCreate() {
  118. openModal(true, {
  119. isUpdate: false,
  120. });
  121. }
  122. function handleEdit(record: Recordable) {
  123. openModal(true, {
  124. record,
  125. isUpdate: true,
  126. });
  127. }
  128. function handleSuccess({ isUpdate, record }) {
  129. if (isUpdate) {
  130. updateTableDataRecord(record.key, record);
  131. } else {
  132. const dataSource = getDataSource();
  133. dataSource.push(record);
  134. setTableData(dataSource);
  135. }
  136. }
  137. function handleDelete(record: Recordable) {
  138. const dataSource = getDataSource();
  139. setTableData(dataSource.filter((x) => x.key !== record.key));
  140. }
  141. </script>