NoticeList.vue 5.1 KB

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