index.vue 877 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <script lang="ts" setup name="GroupSelector">
  2. import { getGroupByList } from '@/api/system/groupApi'
  3. import { packageTreeData } from '@/utils/tool'
  4. const emit = defineEmits(['update:modelValue'])
  5. interface TreeNode {
  6. label: string
  7. groupId: number
  8. children?: TreeNode[]
  9. }
  10. const state = reactive({
  11. loading: false,
  12. groupId: 0,
  13. dataList: [] as TreeNode[],
  14. })
  15. const getData = async () => {
  16. state.loading = true
  17. const { data } = await getGroupByList()
  18. state.dataList = packageTreeData({
  19. data,
  20. id: 'groupId',
  21. })
  22. }
  23. watch(() => state.groupId, (newValue) => {
  24. emit('update:modelValue', newValue)
  25. })
  26. onMounted(() => {
  27. getData ()
  28. })
  29. </script>
  30. <template>
  31. <el-tree-select
  32. v-model="state.groupId"
  33. :data="state.dataList"
  34. style="width: 100%"
  35. filterable
  36. placeholder="请选择部门"
  37. :render-after-expand="false"
  38. />
  39. </template>