NoticeList.vue 5.2 KB
Newer Older
C
chen-xt 已提交
1
<template>
无木 已提交
2
  <a-list :class="prefixCls" bordered :pagination="getPagination">
3
    <template v-for="item in getData" :key="item.id">
V
vben 已提交
4 5
      <a-list-item class="list-item">
        <a-list-item-meta>
C
chen-xt 已提交
6 7
          <template #title>
            <div class="title">
8 9
              <a-typography-paragraph
                @click="handleTitleClick(item)"
10
                style="width: 100%; margin-bottom: 0 !important"
11 12 13
                :style="{ cursor: isTitleClickable ? 'pointer' : '' }"
                :delete="!!item.titleDelete"
                :ellipsis="
无木 已提交
14 15 16
                  $props.titleRows && $props.titleRows > 0
                    ? { rows: $props.titleRows, tooltip: !!item.title }
                    : false
17 18 19
                "
                :content="item.title"
              />
C
chen-xt 已提交
20
              <div class="extra" v-if="item.extra">
V
vben 已提交
21
                <a-tag class="tag" :color="item.color">
C
chen-xt 已提交
22
                  {{ item.extra }}
V
vben 已提交
23
                </a-tag>
C
chen-xt 已提交
24 25 26
              </div>
            </div>
          </template>
V
vben 已提交
27

C
chen-xt 已提交
28
          <template #avatar>
V
vben 已提交
29
            <a-avatar v-if="item.avatar" class="avatar" :src="item.avatar" />
C
chen-xt 已提交
30 31
            <span v-else> {{ item.avatar }}</span>
          </template>
V
vben 已提交
32

C
chen-xt 已提交
33 34
          <template #description>
            <div>
35 36
              <div class="description" v-if="item.description">
                <a-typography-paragraph
37
                  style="width: 100%; margin-bottom: 0 !important"
38
                  :ellipsis="
无木 已提交
39 40
                    $props.descRows && $props.descRows > 0
                      ? { rows: $props.descRows, tooltip: !!item.description }
41 42 43 44
                      : false
                  "
                  :content="item.description"
                />
V
vben 已提交
45 46 47 48
              </div>
              <div class="datetime">
                {{ item.datetime }}
              </div>
C
chen-xt 已提交
49 50
            </div>
          </template>
V
vben 已提交
51 52
        </a-list-item-meta>
      </a-list-item>
C
chen-xt 已提交
53
    </template>
V
vben 已提交
54
  </a-list>
C
chen-xt 已提交
55 56
</template>
<script lang="ts">
57
  import { computed, defineComponent, PropType, ref, watch, unref } from 'vue';
C
chen-xt 已提交
58
  import { ListItem } from './data';
V
vben 已提交
59
  import { useDesign } from '/@/hooks/web/useDesign';
60 61
  import { List, Avatar, Tag, Typography } from 'ant-design-vue';
  import { isNumber } from '/@/utils/is';
C
chen-xt 已提交
62
  export default defineComponent({
V
vben 已提交
63 64 65 66 67
    components: {
      [Avatar.name]: Avatar,
      [List.name]: List,
      [List.Item.name]: List.Item,
      AListItemMeta: List.Item.Meta,
68
      ATypographyParagraph: Typography.Paragraph,
V
vben 已提交
69 70
      [Tag.name]: Tag,
    },
C
chen-xt 已提交
71 72
    props: {
      list: {
V
vben 已提交
73
        type: Array as PropType<ListItem[]>,
C
chen-xt 已提交
74 75
        default: () => [],
      },
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
      pageSize: {
        type: [Boolean, Number] as PropType<Boolean | Number>,
        default: 5,
      },
      currentPage: {
        type: Number,
        default: 1,
      },
      titleRows: {
        type: Number,
        default: 1,
      },
      descRows: {
        type: Number,
        default: 2,
      },
      onTitleClick: {
        type: Function as PropType<(Recordable) => void>,
      },
C
chen-xt 已提交
95
    },
96 97
    emits: ['update:currentPage'],
    setup(props, { emit }) {
V
vben 已提交
98
      const { prefixCls } = useDesign('header-notify-list');
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
      const current = ref(props.currentPage || 1);
      const getData = computed(() => {
        const { pageSize, list } = props;
        if (pageSize === false) return [];
        let size = isNumber(pageSize) ? pageSize : 5;
        return list.slice(size * (unref(current) - 1), size * unref(current));
      });
      watch(
        () => props.currentPage,
        (v) => {
          current.value = v;
        }
      );
      const isTitleClickable = computed(() => !!props.onTitleClick);
      const getPagination = computed(() => {
        const { list, pageSize } = props;
        if (pageSize > 0 && list && list.length > pageSize) {
          return {
            total: list.length,
            pageSize,
无木 已提交
119
            //size: 'small',
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
            current: unref(current),
            onChange(page) {
              current.value = page;
              emit('update:currentPage', page);
            },
          };
        } else {
          return false;
        }
      });

      function handleTitleClick(item: ListItem) {
        props.onTitleClick && props.onTitleClick(item);
      }

      return { prefixCls, getPagination, getData, handleTitleClick, isTitleClickable };
V
vben 已提交
136
    },
C
chen-xt 已提交
137 138 139
  });
</script>
<style lang="less" scoped>
V
vben 已提交
140 141 142
  @prefix-cls: ~'@{namespace}-header-notify-list';

  .@{prefix-cls} {
C
chen-xt 已提交
143 144 145 146
    &::-webkit-scrollbar {
      display: none;
    }

无木 已提交
147 148 149 150
    ::v-deep(.ant-pagination-disabled) {
      display: inline-block !important;
    }

V
vben 已提交
151
    &-item {
C
chen-xt 已提交
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
      padding: 6px;
      overflow: hidden;
      cursor: pointer;
      transition: all 0.3s;

      .title {
        margin-bottom: 8px;
        font-weight: normal;

        .extra {
          float: right;
          margin-top: -1.5px;
          margin-right: 0;
          font-weight: normal;

          .tag {
            margin-right: 0;
          }
        }

        .avatar {
          margin-top: 4px;
        }

        .description {
          font-size: 12px;
          line-height: 18px;
        }

        .datetime {
          margin-top: 4px;
          font-size: 12px;
          line-height: 18px;
        }
      }
    }
  }
</style>