index.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <script lang="ts" setup name="GroupSelector">
  2. import { getGroupView } from '@/api/system/groupApi'
  3. const props = withDefaults(defineProps<{
  4. modelValue: number
  5. }>(), {
  6. modelValue: 0,
  7. })
  8. const emit = defineEmits(['update:modelValue'])
  9. interface TreeNode {
  10. id: number
  11. label: string
  12. groupId: number
  13. children?: TreeNode[]
  14. }
  15. const state = reactive({
  16. loading: false,
  17. groupId: 0,
  18. dataList: [] as TreeNode[],
  19. })
  20. const getData = async () => {
  21. state.loading = true
  22. const { data } = await getGroupView()
  23. state.dataList = data
  24. // 初始化第一个给tree
  25. // emit('update:modelValue', data[0].groupId)
  26. }
  27. const groupId = computed({
  28. get: () => {
  29. return props.modelValue
  30. },
  31. set: (val) => {
  32. emit('update:modelValue', val)
  33. },
  34. })
  35. onMounted(() => {
  36. getData ()
  37. })
  38. const selectProps = {
  39. value: 'groupId',
  40. }
  41. </script>
  42. <template>
  43. <el-tree-select
  44. v-model="groupId"
  45. check-strictly
  46. :props="selectProps"
  47. :data="state.dataList"
  48. style="width: 100%"
  49. filterable
  50. placeholder="请选择部门"
  51. default-expand-all
  52. />
  53. </template>