Group.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <template>
  2. <div class="group" v-for="group in userGroupInfo" :key="group.userGroupId">
  3. <span class="group-name">
  4. {{ group.name }}
  5. </span>
  6. <span class="group-info">
  7. <span style="color: #1777ff">{{ group.total }}</span>
  8. </span>
  9. <div class="user-info" :class="[group.isExpand ? 'expanded' : 'hidden']" ref="userInfoRefs">
  10. <div class="user-info--left">
  11. <el-tag type="primary" v-for="user in group.userList" :key="user.id">
  12. {{ user.realname }}({{ user.staffNo }}){{ user.deptName }}
  13. </el-tag>
  14. </div>
  15. <div class="user-info--right" v-if="group.isHidden">
  16. <span class="user-info--btn" @click="toggleExpand(group)">
  17. {{ group.isExpand ? '收起' : '展开' }}
  18. <el-icon><component :is="group.isExpand ? ArrowUp : ArrowDown" /></el-icon>
  19. </span>
  20. </div>
  21. </div>
  22. </div>
  23. </template>
  24. <script lang="ts" setup>
  25. import { ref, watch } from 'vue';
  26. import type { UserGroupInfo } from '@/types/person-group/type';
  27. import { ArrowUp, ArrowDown } from '@element-plus/icons-vue';
  28. const userInfoRefs = ref<Record<string, HTMLElement>>({});
  29. const userGroupInfo = ref<UserGroupInfo[]>();
  30. const toggleExpand = (group: UserGroupInfo) => {
  31. group.isExpand = !group.isExpand;
  32. };
  33. const props = defineProps<{
  34. userGroupInfo?: UserGroupInfo[];
  35. }>();
  36. watch(
  37. () => props.userGroupInfo,
  38. (newVal) => {
  39. userGroupInfo.value = newVal;
  40. },
  41. );
  42. watch(
  43. () => userInfoRefs.value,
  44. (newRefs) => {
  45. if (newRefs) {
  46. Object.keys(newRefs).forEach((key) => {
  47. const el = newRefs[key];
  48. if (el.offsetHeight >= 86) {
  49. userGroupInfo.value![Number(key)].isHidden = true;
  50. }
  51. });
  52. }
  53. },
  54. );
  55. </script>
  56. <style lang="scss" scoped>
  57. .group {
  58. font-size: 12px;
  59. font-weight: 400;
  60. color: rgba($text-color, 0.88);
  61. }
  62. .group-name {
  63. font-size: 16px;
  64. line-height: 22px;
  65. }
  66. .group-info {
  67. margin-left: 4px;
  68. line-height: 17px;
  69. }
  70. .user-info {
  71. display: flex;
  72. &.hidden {
  73. max-height: 86px;
  74. overflow-y: hidden;
  75. }
  76. &.expanded {
  77. max-height: 100%;
  78. overflow-y: auto;
  79. }
  80. &--left,
  81. &--right {
  82. margin-top: 20px;
  83. }
  84. &--left {
  85. display: flex;
  86. flex-wrap: wrap;
  87. gap: 10px;
  88. flex: 1;
  89. }
  90. &--right {
  91. width: 50px;
  92. }
  93. &--btn {
  94. @include flex-center;
  95. gap: 4px;
  96. cursor: pointer;
  97. }
  98. }
  99. .el-tag {
  100. font-weight: 500;
  101. font-size: 12px;
  102. color: $primary-color;
  103. line-height: 20px;
  104. }
  105. </style>