DeptTree.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <div class="head-container">
  3. <el-input v-model="deptName" class="mb-20px" clearable placeholder="请输入岗位名称">
  4. <template #prefix>
  5. <Icon icon="ep:search" />
  6. </template>
  7. </el-input>
  8. </div>
  9. <div class="head-container">
  10. <!-- :props="defaultProps"-->
  11. <el-tree
  12. ref="treeRef"
  13. :data="deptList"
  14. :expand-on-click-node="false"
  15. :filter-node-method="filterNode"
  16. :props="{ label: 'workstationName', value: 'id', children: 'children' }"
  17. default-expand-all
  18. highlight-current
  19. node-key="id"
  20. @node-click="handleNodeClick"
  21. />
  22. </div>
  23. </template>
  24. <script lang="ts" setup>
  25. import { ElTree } from 'element-plus'
  26. // import * as DeptApi from '@/api/system/dept'
  27. import * as MarsDeptApi from '@/api/system/marsdept'
  28. import { defaultProps, handleTree } from '@/utils/tree'
  29. defineOptions({ name: 'SystemUserDeptTree' })
  30. const deptName = ref('')
  31. const deptList = ref<Tree[]>([]) // 树形结构
  32. const treeRef = ref<InstanceType<typeof ElTree>>()
  33. /** 获得部门树 */
  34. const getTree = async () => {
  35. // const res = await DeptApi.getSimpleDeptList()
  36. const res=await MarsDeptApi.listMarsDept({pageNo: 1, pageSize: -1})
  37. console.log(res,'mars岗位')
  38. deptList.value = []
  39. // deptList.value.push(...handleTree(res.list))
  40. deptList.value = handleTree(res.list, 'id', 'parentId', 'children')
  41. }
  42. /** 基于名字过滤 */
  43. const filterNode = (name: string, data: Tree) => {
  44. if (!name) return true
  45. return data.name.includes(name)
  46. }
  47. /** 处理部门被点击 */
  48. const handleNodeClick = async (row: { [key: string]: any }) => {
  49. emits('node-click', row)
  50. }
  51. const emits = defineEmits(['node-click'])
  52. /** 监听deptName */
  53. watch(deptName, (val) => {
  54. treeRef.value!.filter(val)
  55. })
  56. /** 初始化 */
  57. onMounted(async () => {
  58. await getTree()
  59. })
  60. </script>