action-table.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <script setup lang="ts">
  2. import { ref, onMounted } from "vue";
  3. import { useColumns } from "../columns";
  4. import { handleTree } from "@pureadmin/utils";
  5. import { httpList, httpStatus, httpDelete } from "/@/api/system/menuOperator";
  6. import { TableProBar } from "/@/components/ReTable";
  7. import { useRenderIcon } from "/@/components/ReIcon/src/hooks";
  8. import { useNav } from "/@/layout/hooks/nav";
  9. import { responseHandle } from "/@/utils/responseHandle";
  10. import { useUserStoreHook } from "/@/store/modules/user";
  11. const { logout } = useNav();
  12. const { columns } = useColumns();
  13. const dataList = ref([]);
  14. const powers = ref([]);
  15. const loading = ref(true);
  16. const tableRef = ref();
  17. const emit = defineEmits(["edit", "create", "view"]);
  18. //更新状态
  19. const handleStatus = async row => {
  20. const { id, status } = row;
  21. const { code, message } = await httpStatus({
  22. id,
  23. status: status + "" === "1" ? "0" : "1"
  24. });
  25. responseHandle({
  26. code,
  27. message,
  28. logout,
  29. handler: () => onSearch()
  30. });
  31. };
  32. //删除
  33. const handleDelete = async row => {
  34. const { id } = row;
  35. const { code, message } = await httpDelete({
  36. id
  37. });
  38. responseHandle({
  39. code,
  40. message,
  41. logout,
  42. handler: () => onSearch()
  43. });
  44. };
  45. //勾选
  46. function handleSelectionChange(val) {
  47. console.log("handleSelectionChange", val);
  48. }
  49. //列表展示
  50. async function onSearch() {
  51. loading.value = true;
  52. const { code, data, message } = await httpList({});
  53. responseHandle({
  54. code,
  55. message,
  56. logout,
  57. handler: () => {
  58. dataList.value = handleTree(data ?? []);
  59. }
  60. });
  61. loading.value = false;
  62. }
  63. //编辑
  64. function editItem(item, id: string, type: "create" | "edit" | "view") {
  65. emit(type, item, id, type);
  66. }
  67. onMounted(() => {
  68. powers.value = useUserStoreHook().getMenuActions("menuOperator");
  69. });
  70. defineExpose({
  71. onSearch
  72. });
  73. </script>
  74. <template>
  75. <div class="main flex" style="width: 100%">
  76. <TableProBar
  77. title="菜单列表"
  78. :loading="loading"
  79. :tableRef="tableRef?.getTableRef()"
  80. :dataList="dataList"
  81. @refresh="onSearch"
  82. >
  83. <template #buttons>
  84. <el-button
  85. v-if="powers.some(i => i == '002')"
  86. type="primary"
  87. size="small"
  88. :icon="useRenderIcon('add')"
  89. @click="editItem(null, '', 'create')"
  90. >
  91. 新增
  92. </el-button>
  93. </template>
  94. <template v-slot="{ size, checkList }">
  95. <PureTable
  96. ref="tableRef"
  97. border
  98. align="left"
  99. row-key="id"
  100. table-layout="auto"
  101. :size="size"
  102. :data="dataList"
  103. :columns="columns"
  104. :checkList="checkList"
  105. :tree-props="{ hasChildren: 'hasChildren', children: 'child' }"
  106. :header-cell-style="{ background: '#fafafa', color: '#606266' }"
  107. @selection-change="handleSelectionChange"
  108. >
  109. <template #operation="{ row }">
  110. <el-button
  111. class="reset-margin"
  112. link
  113. v-if="powers.some(i => i == '007')"
  114. type="primary"
  115. :size="size"
  116. @click="editItem(row, row.id, 'view')"
  117. :icon="useRenderIcon('eye-view')"
  118. />
  119. <el-button
  120. class="reset-margin"
  121. link
  122. type="primary"
  123. :size="size"
  124. v-if="powers.some(i => i == '005')"
  125. @click="editItem(row, row.id, 'edit')"
  126. :icon="useRenderIcon('edits')"
  127. />
  128. <el-popconfirm
  129. :title="row.status === '1' ? '改为禁用?' : '改为启用?'"
  130. v-if="
  131. (powers.some(i => i == '004') && row.status + '' === '1') ||
  132. (powers.some(i => i == '003') && row.status + '' === '0')
  133. "
  134. @confirm="handleStatus(row)"
  135. >
  136. <template #reference>
  137. <el-button
  138. class="reset-margin"
  139. link
  140. type="primary"
  141. :size="size"
  142. :icon="
  143. useRenderIcon(
  144. row.status === '1'
  145. ? 'close-circle-line'
  146. : 'checkbox-circle-line'
  147. )
  148. "
  149. /> </template
  150. ></el-popconfirm>
  151. <el-popconfirm
  152. title="是否确认删除?"
  153. v-if="powers.some(i => i == '006')"
  154. @confirm="handleDelete(row)"
  155. >
  156. <template #reference>
  157. <el-button
  158. class="reset-margin"
  159. link
  160. type="primary"
  161. :size="size"
  162. :icon="useRenderIcon('delete')"
  163. />
  164. </template>
  165. </el-popconfirm>
  166. <el-button
  167. v-if="row.menu_type + '' === '1' && powers.some(i => i == '002')"
  168. class="reset-margin"
  169. link
  170. type="primary"
  171. :size="size"
  172. @click="editItem(null, row.id, 'create')"
  173. :icon="useRenderIcon('add')"
  174. />
  175. </template>
  176. </PureTable>
  177. </template>
  178. </TableProBar>
  179. </div>
  180. </template>