NoticeList.vue 5.2 KB

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