You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
4.2 KiB

  1. <script setup lang="ts">
  2. import { ListItem } from "./data";
  3. import { ref, PropType, nextTick } from "vue";
  4. const props = defineProps({
  5. noticeItem: {
  6. type: Object as PropType<ListItem>,
  7. default: () => {}
  8. }
  9. });
  10. const titleRef = ref(null);
  11. const titleTooltip = ref(false);
  12. const descriptionRef = ref(null);
  13. const descriptionTooltip = ref(false);
  14. function hoverTitle() {
  15. nextTick(() => {
  16. titleRef.value?.scrollWidth > titleRef.value?.clientWidth
  17. ? (titleTooltip.value = true)
  18. : (titleTooltip.value = false);
  19. });
  20. }
  21. function hoverDescription(event, description) {
  22. // currentWidth 为文本在页面中所占的宽度,创建标签,加入到页面,获取currentWidth ,最后在移除
  23. let tempTag = document.createElement("span");
  24. tempTag.innerText = description;
  25. tempTag.className = "getDescriptionWidth";
  26. document.querySelector("body").appendChild(tempTag);
  27. let currentWidth = (
  28. document.querySelector(".getDescriptionWidth") as HTMLSpanElement
  29. ).offsetWidth;
  30. document.querySelector(".getDescriptionWidth").remove();
  31. // cellWidth为容器的宽度
  32. const cellWidth = event.target.offsetWidth;
  33. // 当文本宽度大于容器宽度两倍时,代表文本显示超过两行
  34. currentWidth > 2 * cellWidth
  35. ? (descriptionTooltip.value = true)
  36. : (descriptionTooltip.value = false);
  37. }
  38. </script>
  39. <template>
  40. <div
  41. class="notice-container border-b-[1px] border-solid border-[#f0f0f0] dark:border-[#303030]"
  42. >
  43. <el-avatar
  44. v-if="props.noticeItem.avatar"
  45. :size="30"
  46. :src="props.noticeItem.avatar"
  47. class="notice-container-avatar"
  48. />
  49. <div class="notice-container-text">
  50. <div class="notice-text-title text-[#000000d9] dark:text-white">
  51. <el-tooltip
  52. popper-class="notice-title-popper"
  53. :disabled="!titleTooltip"
  54. :content="props.noticeItem.title"
  55. placement="top-start"
  56. >
  57. <div
  58. ref="titleRef"
  59. class="notice-title-content"
  60. @mouseover="hoverTitle"
  61. >
  62. {{ props.noticeItem.title }}
  63. </div>
  64. </el-tooltip>
  65. <el-tag
  66. v-if="props.noticeItem?.extra"
  67. :type="props.noticeItem?.status"
  68. size="small"
  69. class="notice-title-extra"
  70. >
  71. {{ props.noticeItem?.extra }}
  72. </el-tag>
  73. </div>
  74. <el-tooltip
  75. popper-class="notice-title-popper"
  76. :disabled="!descriptionTooltip"
  77. :content="props.noticeItem.description"
  78. placement="top-start"
  79. >
  80. <div
  81. ref="descriptionRef"
  82. class="notice-text-description"
  83. @mouseover="hoverDescription($event, props.noticeItem.description)"
  84. >
  85. {{ props.noticeItem.description }}
  86. </div>
  87. </el-tooltip>
  88. <div class="notice-text-datetime text-[#00000073] dark:text-white">
  89. {{ props.noticeItem.datetime }}
  90. </div>
  91. </div>
  92. </div>
  93. </template>
  94. <style>
  95. .notice-title-popper {
  96. max-width: 238px;
  97. }
  98. </style>
  99. <style scoped lang="scss">
  100. .notice-container {
  101. display: flex;
  102. align-items: flex-start;
  103. justify-content: space-between;
  104. padding: 12px 0;
  105. // border-bottom: 1px solid #f0f0f0;
  106. .notice-container-avatar {
  107. margin-right: 16px;
  108. background: #fff;
  109. }
  110. .notice-container-text {
  111. display: flex;
  112. flex-direction: column;
  113. justify-content: space-between;
  114. flex: 1;
  115. .notice-text-title {
  116. display: flex;
  117. margin-bottom: 8px;
  118. font-weight: 400;
  119. font-size: 14px;
  120. line-height: 1.5715;
  121. cursor: pointer;
  122. .notice-title-content {
  123. flex: 1;
  124. width: 200px;
  125. overflow: hidden;
  126. white-space: nowrap;
  127. text-overflow: ellipsis;
  128. }
  129. .notice-title-extra {
  130. float: right;
  131. margin-top: -1.5px;
  132. font-weight: 400;
  133. }
  134. }
  135. .notice-text-description,
  136. .notice-text-datetime {
  137. font-size: 12px;
  138. line-height: 1.5715;
  139. }
  140. .notice-text-description {
  141. display: -webkit-box;
  142. text-overflow: ellipsis;
  143. overflow: hidden;
  144. -webkit-line-clamp: 2;
  145. -webkit-box-orient: vertical;
  146. }
  147. .notice-text-datetime {
  148. margin-top: 4px;
  149. }
  150. }
  151. }
  152. </style>