NoticeList.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. <template>
  2. <a-list :class="prefixCls" :pagination="getPagination">
  3. <template v-for="item in getData" :key="item.id">
  4. <a-list-item class="list-item" @click="handleTitleClick(item)" :style="{ cursor: isTitleClickable ? 'pointer' : '' }">
  5. <a-list-item-meta>
  6. <template #title>
  7. <div class="title">
  8. <a-typography-paragraph
  9. style="width: 100%; margin-bottom: 0 !important"
  10. :delete="!!item.titleDelete"
  11. :ellipsis="$props.titleRows && $props.titleRows > 0 ? { rows: $props.titleRows, tooltip: !!item.title } : false"
  12. :content="item.title"
  13. />
  14. <div class="extra" v-if="item.extra">
  15. <a-tag class="tag" :color="item.color">
  16. {{ item.extra }}
  17. </a-tag>
  18. </div>
  19. </div>
  20. </template>
  21. <template #avatar>
  22. <a-avatar v-if="item.avatar" class="avatar" :src="item.avatar" />
  23. <template v-else-if="item.priority">
  24. <a-avatar v-if="item.priority === PriorityTypes.L" class="avatar priority-L" title="一般消息">
  25. <template #icon>
  26. <Icon icon="entypo:info" />
  27. </template>
  28. </a-avatar>
  29. <a-avatar v-if="item.priority === PriorityTypes.M" class="avatar priority-M" title="重要消息">
  30. <template #icon>
  31. <Icon icon="bi:exclamation-lg" />
  32. </template>
  33. </a-avatar>
  34. <a-avatar v-if="item.priority === PriorityTypes.H" class="avatar priority-H" title="紧急消息">
  35. <template #icon>
  36. <Icon icon="ant-design:warning-filled" />
  37. </template>
  38. </a-avatar>
  39. </template>
  40. <span v-else> {{ item.avatar }}</span>
  41. </template>
  42. <template #description>
  43. <div>
  44. <div class="description" v-if="item.description">
  45. <a-typography-paragraph
  46. style="width: 100%; margin-bottom: 0 !important"
  47. :ellipsis="$props.descRows && $props.descRows > 0 ? { rows: $props.descRows, tooltip: !!item.description } : false"
  48. :content="item.description"
  49. />
  50. </div>
  51. <div class="datetime">
  52. <Time :value="item.datetime" :title="item.datetime" />
  53. </div>
  54. </div>
  55. </template>
  56. </a-list-item-meta>
  57. </a-list-item>
  58. </template>
  59. </a-list>
  60. </template>
  61. <script lang="ts">
  62. import { computed, defineComponent, PropType, ref, watch, unref } from 'vue';
  63. import { PriorityTypes, ListItem } from './data';
  64. import { useDesign } from '/@/hooks/web/useDesign';
  65. import { List, Avatar, Tag, Typography } from 'ant-design-vue';
  66. import { Time } from '/@/components/Time';
  67. import { isNumber } from '/@/utils/is';
  68. export default defineComponent({
  69. components: {
  70. [Avatar.name]: Avatar,
  71. [List.name]: List,
  72. [List.Item.name]: List.Item,
  73. AListItemMeta: List.Item.Meta,
  74. ATypographyParagraph: Typography.Paragraph,
  75. [Tag.name]: Tag,
  76. Time,
  77. },
  78. props: {
  79. list: {
  80. type: Array as PropType<ListItem[]>,
  81. default: () => [],
  82. },
  83. pageSize: {
  84. type: [Boolean, Number] as PropType<Boolean | Number>,
  85. default: 5,
  86. },
  87. currentPage: {
  88. type: Number,
  89. default: 1,
  90. },
  91. titleRows: {
  92. type: Number,
  93. default: 1,
  94. },
  95. descRows: {
  96. type: Number,
  97. default: 1,
  98. },
  99. onTitleClick: {
  100. type: Function as PropType<(Recordable) => void>,
  101. },
  102. },
  103. emits: ['update:currentPage'],
  104. setup(props, { emit }) {
  105. const { prefixCls } = useDesign('header-notify-list');
  106. const current = ref(props.currentPage || 1);
  107. const getData = computed(() => {
  108. const { pageSize, list } = props;
  109. if (pageSize === false) return [];
  110. let size = isNumber(pageSize) ? pageSize : 5;
  111. return list.slice(size * (unref(current) - 1), size * unref(current));
  112. });
  113. watch(
  114. () => props.currentPage,
  115. (v) => {
  116. current.value = v;
  117. }
  118. );
  119. const isTitleClickable = computed(() => !!props.onTitleClick);
  120. const getPagination = computed(() => {
  121. const { list, pageSize } = props;
  122. if (pageSize > 0 && list && list.length > pageSize) {
  123. return {
  124. total: list.length,
  125. pageSize,
  126. //size: 'small',
  127. current: unref(current),
  128. onChange(page) {
  129. current.value = page;
  130. emit('update:currentPage', page);
  131. },
  132. };
  133. } else {
  134. return false;
  135. }
  136. });
  137. function handleTitleClick(item: ListItem) {
  138. props.onTitleClick && props.onTitleClick(item);
  139. }
  140. return {
  141. prefixCls,
  142. getPagination,
  143. getData,
  144. handleTitleClick,
  145. isTitleClickable,
  146. PriorityTypes,
  147. };
  148. },
  149. });
  150. </script>
  151. <style lang="less" scoped>
  152. @prefix-cls: ~'@{namespace}-header-notify-list';
  153. .@{prefix-cls} {
  154. width: 340px;
  155. &::-webkit-scrollbar {
  156. display: none;
  157. }
  158. ::v-deep(.ant-pagination-disabled) {
  159. display: inline-block !important;
  160. }
  161. &-item {
  162. padding: 6px;
  163. overflow: hidden;
  164. cursor: pointer;
  165. transition: all 0.3s;
  166. .title {
  167. margin-bottom: 8px;
  168. font-weight: normal;
  169. .extra {
  170. float: right;
  171. margin-top: -1.5px;
  172. margin-right: 0;
  173. font-weight: normal;
  174. .tag {
  175. margin-right: 0;
  176. }
  177. }
  178. .avatar {
  179. margin-top: 4px;
  180. }
  181. .description {
  182. font-size: 12px;
  183. line-height: 18px;
  184. }
  185. .datetime {
  186. margin-top: 4px;
  187. font-size: 12px;
  188. line-height: 18px;
  189. }
  190. }
  191. }
  192. .list-item {
  193. .priority-L,
  194. .priority-M,
  195. .priority-H {
  196. font-size: 12px;
  197. }
  198. .priority-L {
  199. background-color: #7cd1ff;
  200. }
  201. .priority-M {
  202. background-color: #ffa743;
  203. }
  204. .priority-H {
  205. background-color: #f8766c;
  206. }
  207. .description {
  208. font-size: 12px;
  209. line-height: 18px;
  210. }
  211. }
  212. }
  213. </style>