index.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <script setup lang="ts">
  2. import { ref, watch, nextTick, onBeforeUnmount } from "vue";
  3. import { useMenu } from "./utils/hook";
  4. import { transformI18n } from "@/plugins/i18n";
  5. import { PureTableBar } from "@/components/RePureTableBar";
  6. import { useRenderIcon } from "@/components/ReIcon/src/hooks";
  7. import Delete from "~icons/ep/delete";
  8. import EditPen from "~icons/ep/edit-pen";
  9. import Refresh from "~icons/ep/refresh";
  10. import AddFill from "~icons/ri/add-circle-line";
  11. defineOptions({
  12. name: "SystemMenu"
  13. });
  14. const formRef = ref();
  15. const tableRef = ref();
  16. const {
  17. form,
  18. loading,
  19. columns,
  20. dataList,
  21. onSearch,
  22. resetForm,
  23. openDialog,
  24. handleDelete,
  25. handleSelectionChange,
  26. initDragSort,
  27. destroyDragSort
  28. } = useMenu();
  29. function onFullscreen() {
  30. // 重置表格高度
  31. tableRef.value.setAdaptive();
  32. }
  33. watch(
  34. () => dataList.value,
  35. () => {
  36. nextTick(() => {
  37. const el = tableRef.value?.getTableRef()?.$el;
  38. if (el) initDragSort(el);
  39. });
  40. }
  41. );
  42. onBeforeUnmount(() => {
  43. destroyDragSort();
  44. });
  45. </script>
  46. <template>
  47. <div class="main">
  48. <el-form
  49. ref="formRef"
  50. :inline="true"
  51. :model="form"
  52. class="search-form bg-bg_color w-full pl-8 pt-[12px] overflow-auto"
  53. >
  54. <el-form-item label="菜单名称:" prop="title">
  55. <el-input
  56. v-model="form.title"
  57. placeholder="请输入菜单名称"
  58. clearable
  59. class="w-[180px]!"
  60. />
  61. </el-form-item>
  62. <el-form-item>
  63. <el-button
  64. type="primary"
  65. :icon="useRenderIcon('ri/search-line')"
  66. :loading="loading"
  67. @click="onSearch"
  68. >
  69. 搜索
  70. </el-button>
  71. <el-button :icon="useRenderIcon(Refresh)" @click="resetForm(formRef)">
  72. 重置
  73. </el-button>
  74. </el-form-item>
  75. </el-form>
  76. <PureTableBar
  77. title="菜单管理(仅演示,操作后不生效)"
  78. :columns="columns"
  79. :isExpandAll="false"
  80. :tableRef="tableRef?.getTableRef()"
  81. @refresh="onSearch"
  82. @fullscreen="onFullscreen"
  83. >
  84. <template #buttons>
  85. <el-button
  86. type="primary"
  87. :icon="useRenderIcon(AddFill)"
  88. @click="openDialog()"
  89. >
  90. 新增菜单
  91. </el-button>
  92. </template>
  93. <template v-slot="{ size, dynamicColumns }">
  94. <pure-table
  95. ref="tableRef"
  96. adaptive
  97. :adaptiveConfig="{ offsetBottom: 45 }"
  98. align-whole="center"
  99. row-key="id"
  100. showOverflowTooltip
  101. table-layout="auto"
  102. :loading="loading"
  103. :size="size"
  104. :data="dataList"
  105. :columns="dynamicColumns"
  106. :header-cell-style="{
  107. background: 'var(--el-fill-color-light)',
  108. color: 'var(--el-text-color-primary)'
  109. }"
  110. @selection-change="handleSelectionChange"
  111. >
  112. <template #operation="{ row }">
  113. <el-button
  114. class="reset-margin"
  115. link
  116. type="primary"
  117. :size="size"
  118. :icon="useRenderIcon(EditPen)"
  119. @click="openDialog('修改', row)"
  120. >
  121. 修改
  122. </el-button>
  123. <el-button
  124. v-show="row.menuType !== 3"
  125. class="reset-margin"
  126. link
  127. type="primary"
  128. :size="size"
  129. :icon="useRenderIcon(AddFill)"
  130. @click="openDialog('新增', { parentId: row.id } as any)"
  131. >
  132. 新增
  133. </el-button>
  134. <el-popconfirm
  135. :title="`是否确认删除菜单名称为${transformI18n(row.title)}的这条数据${row?.children?.length > 0 ? '。注意下级菜单也会一并删除,请谨慎操作' : ''}`"
  136. @confirm="handleDelete(row)"
  137. >
  138. <template #reference>
  139. <el-button
  140. class="reset-margin"
  141. link
  142. type="primary"
  143. :size="size"
  144. :icon="useRenderIcon(Delete)"
  145. >
  146. 删除
  147. </el-button>
  148. </template>
  149. </el-popconfirm>
  150. </template>
  151. </pure-table>
  152. </template>
  153. </PureTableBar>
  154. </div>
  155. </template>
  156. <style lang="scss" scoped>
  157. :deep(.el-table__inner-wrapper::before) {
  158. height: 0;
  159. }
  160. .main-content {
  161. margin: 24px 24px 0 !important;
  162. }
  163. .search-form {
  164. :deep(.el-form-item) {
  165. margin-bottom: 12px;
  166. }
  167. }
  168. :deep(.sortable-ghost) {
  169. opacity: 0.4;
  170. background: var(--el-color-primary-light-9);
  171. }
  172. :deep(.drag-handle) {
  173. cursor: grab;
  174. user-select: none;
  175. }
  176. :deep(.drag-handle:active) {
  177. cursor: grabbing;
  178. }
  179. </style>