DataRuleList.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. <template>
  2. <BasicDrawer v-bind="$attrs" @register="registerDrawer" title="数据权限规则" :width="adaptiveWidth">
  3. <BasicTable @register="registerTable">
  4. <template #tableTitle>
  5. <a-button type="primary" @click="handleCreate"> 新增</a-button>
  6. </template>
  7. <template #action="{ record }">
  8. <TableAction :actions="getTableAction(record)" />
  9. </template>
  10. </BasicTable>
  11. </BasicDrawer>
  12. <DataRuleModal @register="registerModal" @success="reload" :permissionId="permissionId" />
  13. </template>
  14. <script lang="ts" setup>
  15. import { ref, unref } from 'vue';
  16. import { BasicDrawer, useDrawerInner } from '/@/components/Drawer';
  17. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  18. import { useModal } from '/@/components/Modal';
  19. import DataRuleModal from './DataRuleModal.vue';
  20. import { dataRuleColumns, dataRuleSearchFormSchema } from './menu.data';
  21. import { dataRuleList, deleteRule } from './menu.api';
  22. import { ColEx } from '/@/components/Form/src/types';
  23. import { useDrawerAdaptiveWidth } from '/@/hooks/jeecg/useAdaptiveWidth';
  24. const permissionId = ref('');
  25. const { adaptiveWidth } = useDrawerAdaptiveWidth();
  26. //权限规则model
  27. const [registerModal, { openModal }] = useModal();
  28. const [registerDrawer] = useDrawerInner(async (data) => {
  29. permissionId.value = data.id;
  30. setProps({ searchInfo: { permissionId: unref(permissionId) } });
  31. reload();
  32. });
  33. // 自适应列配置
  34. const adaptiveColProps: Partial<ColEx> = {
  35. xs: 24, // <576px
  36. sm: 24, // ≥576px
  37. md: 24, // ≥768px
  38. lg: 12, // ≥992px
  39. xl: 8, // ≥1200px
  40. xxl: 8, // ≥1600px
  41. };
  42. const [registerTable, { reload, setProps }] = useTable({
  43. api: dataRuleList,
  44. columns: dataRuleColumns,
  45. size: 'small',
  46. formConfig: {
  47. baseColProps: adaptiveColProps,
  48. labelAlign: 'right',
  49. labelCol: {
  50. offset: 1,
  51. xs: 24,
  52. sm: 24,
  53. md: 24,
  54. lg: 8,
  55. xl: 8,
  56. xxl: 8,
  57. },
  58. wrapperCol: {},
  59. schemas: dataRuleSearchFormSchema,
  60. autoSubmitOnEnter: true,
  61. },
  62. striped: true,
  63. useSearchForm: true,
  64. bordered: true,
  65. showIndexColumn: false,
  66. showTableSetting: false,
  67. canResize: false,
  68. immediate: false,
  69. actionColumn: {
  70. width: 100,
  71. title: '操作',
  72. dataIndex: 'action',
  73. slots: { customRender: 'action' },
  74. fixed: undefined,
  75. },
  76. });
  77. /**
  78. * 新增
  79. */
  80. function handleCreate() {
  81. openModal(true, {
  82. isUpdate: false,
  83. });
  84. }
  85. /**
  86. * 编辑
  87. */
  88. function handleEdit(record) {
  89. openModal(true, {
  90. record,
  91. isUpdate: true,
  92. });
  93. }
  94. /**
  95. * 删除
  96. */
  97. async function handleDelete(record) {
  98. await deleteRule({ id: record.id }, reload);
  99. }
  100. /**
  101. * 操作栏
  102. */
  103. function getTableAction(record) {
  104. return [
  105. {
  106. label: '编辑',
  107. onClick: handleEdit.bind(null, record),
  108. },
  109. {
  110. label: '删除',
  111. popConfirm: {
  112. title: '是否确认删除',
  113. confirm: handleDelete.bind(null, record),
  114. },
  115. },
  116. ];
  117. }
  118. </script>