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.

177 lines
4.4 KiB

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