dept.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <PageWrapper>
  3. <div class="search"
  4. ><span class="searchLabel"> 搜索:</span><el-input v-model="searchKey" placeholder="请输入关键字进行搜索" />
  5. </div>
  6. <el-table :data="filterData" row-key="id" :tree-props="treeProps" default-expand-all>
  7. <el-table-column label="组织名称">
  8. <template #default="{ row }">
  9. {{ `${row.deptName} (${row.userCount})` }}
  10. </template>
  11. </el-table-column>
  12. </el-table>
  13. <CreateDrawer
  14. ref="createDrawerRef"
  15. :title="drawerTitle"
  16. :deptList="tableData"
  17. :data-source="currentDept"
  18. :width="450"
  19. @change="reloadTable"
  20. />
  21. </PageWrapper>
  22. </template>
  23. <script lang="ts" setup>
  24. import { computed, onMounted, reactive, ref } from 'vue';
  25. import { PageWrapper } from '@/components/Page';
  26. import { getAllDepartments } from '@/api/auth/dept';
  27. import CreateDrawer from './CreateDrawer.vue';
  28. import type { DeptTree, DeptTreeItem } from '@/types/dept/type';
  29. import { filterTree } from '@/utils/tree';
  30. const tableData = ref<DeptTree[]>([]);
  31. const treeProps = reactive({
  32. checkStrictly: false,
  33. });
  34. const createDrawerRef = ref();
  35. const searchKey = ref('');
  36. const drawerTitle = ref('添加部门');
  37. const currentDept = ref<DeptTreeItem>({
  38. id: null,
  39. deptName: '',
  40. parentId: null,
  41. orderNum: undefined,
  42. createdBy: 0,
  43. updatedBy: 0,
  44. createdAt: '',
  45. updatedAt: '',
  46. isDeleted: 0,
  47. tenantId: 0,
  48. userCount: 0,
  49. });
  50. const loadDataTable = async () => {
  51. const result = await getAllDepartments();
  52. tableData.value = result;
  53. };
  54. const filterData = computed(() => {
  55. if (!searchKey.value) {
  56. return tableData.value;
  57. }
  58. return filterTree({ nodes: tableData.value, value: searchKey.value, key: 'deptName' });
  59. });
  60. function reloadTable() {
  61. loadDataTable();
  62. }
  63. onMounted(() => {
  64. loadDataTable();
  65. });
  66. </script>
  67. <style scoped>
  68. .el-space--horizontal {
  69. align-items: center;
  70. gap: 0px 20px;
  71. }
  72. .el-tooltip__trigger {
  73. width: 16px;
  74. }
  75. .tooltip__password {
  76. color: var(--el-color-primary);
  77. }
  78. .box-item {
  79. position: absolute;
  80. top: 0;
  81. right: 0;
  82. }
  83. .el-space__item:hover {
  84. cursor: pointer;
  85. }
  86. .search {
  87. margin: 20px;
  88. width: 300px;
  89. display: flex;
  90. .searchLabel {
  91. width: 65px;
  92. }
  93. }
  94. </style>