NoticeList.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <template>
  2. <a-list :class="prefixCls" bordered :pagination="getPagination" size="small">
  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%"
  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%"
  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. console.log('refreshData', list);
  99. if (pageSize === false) return [];
  100. let size = isNumber(pageSize) ? pageSize : 5;
  101. return list.slice(size * (unref(current) - 1), size * unref(current));
  102. });
  103. watch(
  104. () => props.currentPage,
  105. (v) => {
  106. current.value = v;
  107. }
  108. );
  109. const isTitleClickable = computed(() => !!props.onTitleClick);
  110. const getPagination = computed(() => {
  111. const { list, pageSize } = props;
  112. if (pageSize > 0 && list && list.length > pageSize) {
  113. return {
  114. total: list.length,
  115. pageSize,
  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. &-item {
  140. padding: 6px;
  141. overflow: hidden;
  142. cursor: pointer;
  143. transition: all 0.3s;
  144. .title {
  145. margin-bottom: 8px;
  146. font-weight: normal;
  147. .extra {
  148. float: right;
  149. margin-top: -1.5px;
  150. margin-right: 0;
  151. font-weight: normal;
  152. .tag {
  153. margin-right: 0;
  154. }
  155. }
  156. .avatar {
  157. margin-top: 4px;
  158. }
  159. .description {
  160. font-size: 12px;
  161. line-height: 18px;
  162. }
  163. .datetime {
  164. margin-top: 4px;
  165. font-size: 12px;
  166. line-height: 18px;
  167. }
  168. }
  169. }
  170. }
  171. </style>