dept.vue 2.7 KB

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