index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <script setup lang="ts">
  2. import { useColumns } from "./columns";
  3. import { getDeptList } from "@/api/system";
  4. import { FormInstance } from "element-plus";
  5. import { handleTree } from "@pureadmin/utils";
  6. import { reactive, ref, onMounted } from "vue";
  7. import { TableProBar } from "@/components/ReTable";
  8. import { useRenderIcon } from "@/components/ReIcon/src/hooks";
  9. defineOptions({
  10. name: "Dept"
  11. });
  12. const form = reactive({
  13. user: "",
  14. status: ""
  15. });
  16. const dataList = ref([]);
  17. const loading = ref(true);
  18. const { columns } = useColumns();
  19. const formRef = ref<FormInstance>();
  20. const tableRef = ref();
  21. function handleUpdate(row) {
  22. console.log(row);
  23. }
  24. function handleDelete(row) {
  25. console.log(row);
  26. }
  27. function handleSelectionChange(val) {
  28. console.log("handleSelectionChange", val);
  29. }
  30. async function onSearch() {
  31. loading.value = true;
  32. const { data } = await getDeptList();
  33. dataList.value = handleTree(data as any);
  34. setTimeout(() => {
  35. loading.value = false;
  36. }, 500);
  37. }
  38. const resetForm = (formEl: FormInstance | undefined) => {
  39. if (!formEl) return;
  40. formEl.resetFields();
  41. onSearch();
  42. };
  43. onMounted(() => {
  44. onSearch();
  45. });
  46. </script>
  47. <template>
  48. <div class="main">
  49. <el-form
  50. ref="formRef"
  51. :inline="true"
  52. :model="form"
  53. class="bg-bg_color w-[99/100] pl-8 pt-4"
  54. >
  55. <el-form-item label="部门名称:" prop="user">
  56. <el-input v-model="form.user" placeholder="请输入部门名称" clearable />
  57. </el-form-item>
  58. <el-form-item label="状态:" prop="status">
  59. <el-select v-model="form.status" placeholder="请选择状态" clearable>
  60. <el-option label="开启" value="1" />
  61. <el-option label="关闭" value="0" />
  62. </el-select>
  63. </el-form-item>
  64. <el-form-item>
  65. <el-button
  66. type="primary"
  67. :icon="useRenderIcon('search')"
  68. :loading="loading"
  69. @click="onSearch"
  70. >
  71. 搜索
  72. </el-button>
  73. <el-button :icon="useRenderIcon('refresh')" @click="resetForm(formRef)">
  74. 重置
  75. </el-button>
  76. </el-form-item>
  77. </el-form>
  78. <TableProBar
  79. title="部门列表"
  80. :loading="loading"
  81. :tableRef="tableRef?.getTableRef()"
  82. :dataList="dataList"
  83. @refresh="onSearch"
  84. >
  85. <template #buttons>
  86. <el-button type="primary" :icon="useRenderIcon('add')">
  87. 新增部门
  88. </el-button>
  89. </template>
  90. <template v-slot="{ size, checkList }">
  91. <PureTable
  92. ref="tableRef"
  93. border
  94. align="center"
  95. row-key="id"
  96. table-layout="auto"
  97. default-expand-all
  98. :size="size"
  99. :data="dataList"
  100. :columns="columns"
  101. :checkList="checkList"
  102. :header-cell-style="{
  103. background: 'var(--el-table-row-hover-bg-color)',
  104. color: 'var(--el-text-color-primary)'
  105. }"
  106. @selection-change="handleSelectionChange"
  107. >
  108. <template #operation="{ row }">
  109. <el-button
  110. class="reset-margin"
  111. link
  112. type="primary"
  113. :size="size"
  114. @click="handleUpdate(row)"
  115. :icon="useRenderIcon('edits')"
  116. >
  117. 修改
  118. </el-button>
  119. <el-popconfirm title="是否确认删除?">
  120. <template #reference>
  121. <el-button
  122. class="reset-margin"
  123. link
  124. type="primary"
  125. :size="size"
  126. :icon="useRenderIcon('delete')"
  127. @click="handleDelete(row)"
  128. >
  129. 删除
  130. </el-button>
  131. </template>
  132. </el-popconfirm>
  133. </template>
  134. </PureTable>
  135. </template>
  136. </TableProBar>
  137. </div>
  138. </template>