index.vue 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <div class="p-4 device-manager-box">
  3. <BasicTable @register="registerTable" :rowSelection="rowSelection">
  4. <template #tableTitle>
  5. <a-button type="primary" preIcon="ant-design:plus-outlined" @click="handleCreate"> 新增菜单</a-button>
  6. <a-button type="primary" preIcon="ic:round-expand" @click="expandAll">展开全部</a-button>
  7. <a-button type="primary" preIcon="ic:round-compress" @click="collapseAll">折叠全部</a-button>
  8. <a-dropdown v-if="checkedKeys.length > 0">
  9. <template #overlay>
  10. <a-menu>
  11. <a-menu-item key="1" @click="batchHandleDelete">
  12. <Icon icon="ant-design:delete-outlined" />
  13. 删除
  14. </a-menu-item>
  15. </a-menu>
  16. </template>
  17. <a-button
  18. >批量操作
  19. <Icon icon="ant-design:down-outlined" />
  20. </a-button>
  21. </a-dropdown>
  22. </template>
  23. <template #action="{ record }">
  24. <TableAction :actions="getTableAction(record)" :dropDownActions="getDropDownAction(record)" />
  25. </template>
  26. </BasicTable>
  27. <MenuDrawer @register="registerDrawer" @success="handleSuccess" :showFooter="showFooter" />
  28. <DataRuleList @register="registerDrawer1" />
  29. </div>
  30. </template>
  31. <script lang="ts" name="system-menu" setup>
  32. import { nextTick, ref } from 'vue';
  33. import { BasicTable, useTable, TableAction } from '/@/components/Table';
  34. import { useListPage } from '/@/hooks/system/useListPage';
  35. import { useDrawer } from '/@/components/Drawer';
  36. import MenuDrawer from './MenuDrawer.vue';
  37. import DataRuleList from './DataRuleList.vue';
  38. import { columns, searchFormSchema } from '../menuModal/menu.data';
  39. import { list, deleteMenu, batchDeleteMenu } from '../menuModal/menu.api';
  40. const checkedKeys = ref<Array<string | number>>([]);
  41. const showFooter = ref(true);
  42. const [registerDrawer, { openDrawer }] = useDrawer();
  43. const [registerDrawer1, { openDrawer: openDataRule }] = useDrawer();
  44. // 列表页面公共参数、方法
  45. const { prefixCls, tableContext } = useListPage({
  46. tableProps: {
  47. title: '菜单列表',
  48. api: list.bind(null, {kind: 3}),
  49. columns: columns,
  50. size: 'small',
  51. pagination: false,
  52. isTreeTable: true,
  53. striped: true,
  54. useSearchForm: true,
  55. showTableSetting: true,
  56. bordered: true,
  57. showIndexColumn: false,
  58. tableSetting: { fullScreen: true },
  59. formConfig: {
  60. schemas: searchFormSchema,
  61. autoAdvancedCol: 4,
  62. baseColProps: { xs: 24, sm: 12, md: 6, lg: 6, xl: 6, xxl: 6 },
  63. actionColOptions: { xs: 24, sm: 12, md: 6, lg: 6, xl: 6, xxl: 6 },
  64. },
  65. actionColumn: {
  66. width: 120,
  67. },
  68. },
  69. });
  70. //注册table数据
  71. const [registerTable, { reload, expandAll, collapseAll }] = tableContext;
  72. /**
  73. * 选择列配置
  74. */
  75. const rowSelection = {
  76. type: 'checkbox',
  77. columnWidth: 30,
  78. selectedRowKeys: checkedKeys,
  79. onChange: onSelectChange,
  80. };
  81. /**
  82. * 选择事件
  83. */
  84. function onSelectChange(selectedRowKeys: (string | number)[]) {
  85. checkedKeys.value = selectedRowKeys;
  86. }
  87. /**
  88. * 新增
  89. */
  90. function handleCreate() {
  91. showFooter.value = true;
  92. openDrawer(true, {
  93. isUpdate: false,
  94. });
  95. }
  96. /**
  97. * 编辑
  98. */
  99. function handleEdit(record) {
  100. showFooter.value = true;
  101. openDrawer(true, {
  102. record,
  103. isUpdate: true,
  104. });
  105. }
  106. /**
  107. * 详情
  108. */
  109. function handleDetail(record) {
  110. showFooter.value = false;
  111. openDrawer(true, {
  112. record,
  113. isUpdate: true,
  114. });
  115. }
  116. /**
  117. * 添加下级
  118. */
  119. function handleAddSub(record) {
  120. openDrawer(true, {
  121. record: { parentId: record.id, menuType: 1, kind: 3 },
  122. isUpdate: false,
  123. });
  124. }
  125. /**
  126. * 数据权限弹窗
  127. */
  128. function handleDataRule(record) {
  129. openDataRule(true, { id: record.id, kind: 3 });
  130. }
  131. /**
  132. * 删除
  133. */
  134. async function handleDelete(record) {
  135. await deleteMenu({ id: record.id }, reload);
  136. }
  137. /**
  138. * 批量删除事件
  139. */
  140. async function batchHandleDelete() {
  141. await batchDeleteMenu({ ids: checkedKeys.value }, reload);
  142. }
  143. /**
  144. * 成功回调
  145. */
  146. function handleSuccess() {
  147. reload();
  148. }
  149. function onFetchSuccess() {
  150. // 演示默认展开所有表项
  151. nextTick(expandAll);
  152. }
  153. /**
  154. * 操作栏
  155. */
  156. function getTableAction(record) {
  157. return [
  158. {
  159. label: '编辑',
  160. onClick: handleEdit.bind(null, record),
  161. },
  162. ];
  163. }
  164. /**
  165. * 下拉操作栏
  166. */
  167. function getDropDownAction(record) {
  168. return [
  169. // {
  170. // label: '详情',
  171. // onClick: handleDetail.bind(null, record),
  172. // },
  173. {
  174. label: '添加下级',
  175. onClick: handleAddSub.bind(null, record),
  176. },
  177. {
  178. label: '数据规则',
  179. onClick: handleDataRule.bind(null, record),
  180. },
  181. {
  182. label: '删除',
  183. color: 'error',
  184. popConfirm: {
  185. title: '是否确认删除',
  186. confirm: handleDelete.bind(null, record),
  187. },
  188. },
  189. ];
  190. }
  191. </script>