OrgName.vue 807 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <script setup lang="ts">
  2. import { type Dept, getById } from '@/api/modules/system/dept'
  3. const props = withDefaults(
  4. defineProps<{
  5. id: string
  6. showLabel?: boolean
  7. }>(),
  8. {
  9. showLabel: true
  10. }
  11. )
  12. const dept = ref<Dept>()
  13. onMounted(async () => {
  14. if (!props.id) {
  15. throw new Error('id is required')
  16. }
  17. const res = await getById(props.id)
  18. if (res.success) {
  19. dept.value = res.data
  20. }
  21. })
  22. </script>
  23. <template>
  24. <div class="flex-items-center">
  25. <van-image class="h-6 w-6" round fit="cover">
  26. <template v-slot:loading>
  27. <van-icon name="cluster" />
  28. </template>
  29. </van-image>
  30. <span class="org-name" v-show="showLabel">
  31. {{ dept?.name }}
  32. </span>
  33. </div>
  34. </template>
  35. <style scoped lang="less">
  36. .van-image + .org-name {
  37. margin-left: 8px;
  38. }
  39. </style>