|
|
|
@ -1,11 +1,20 @@ |
|
|
|
<template> |
|
|
|
<a-list :class="prefixCls"> |
|
|
|
<template v-for="item in list" :key="item.id"> |
|
|
|
<a-list :class="prefixCls" bordered :pagination="getPagination" size="small"> |
|
|
|
<template v-for="item in getData" :key="item.id"> |
|
|
|
<a-list-item class="list-item"> |
|
|
|
<a-list-item-meta> |
|
|
|
<template #title> |
|
|
|
<div class="title"> |
|
|
|
{{ item.title }} |
|
|
|
<a-typography-paragraph |
|
|
|
@click="handleTitleClick(item)" |
|
|
|
style="width: 100%" |
|
|
|
:style="{ cursor: isTitleClickable ? 'pointer' : '' }" |
|
|
|
:delete="!!item.titleDelete" |
|
|
|
:ellipsis=" |
|
|
|
$props.titleRows > 0 ? { rows: $props.titleRows, tooltip: item.title } : false |
|
|
|
" |
|
|
|
:content="item.title" |
|
|
|
/> |
|
|
|
<div class="extra" v-if="item.extra"> |
|
|
|
<a-tag class="tag" :color="item.color"> |
|
|
|
{{ item.extra }} |
|
|
|
@ -21,8 +30,16 @@ |
|
|
|
|
|
|
|
<template #description> |
|
|
|
<div> |
|
|
|
<div class="description"> |
|
|
|
{{ item.description }} |
|
|
|
<div class="description" v-if="item.description"> |
|
|
|
<a-typography-paragraph |
|
|
|
style="width: 100%" |
|
|
|
:ellipsis=" |
|
|
|
$props.descRows > 0 |
|
|
|
? { rows: $props.descRows, tooltip: item.description } |
|
|
|
: false |
|
|
|
" |
|
|
|
:content="item.description" |
|
|
|
/> |
|
|
|
</div> |
|
|
|
<div class="datetime"> |
|
|
|
{{ item.datetime }} |
|
|
|
@ -35,16 +52,18 @@ |
|
|
|
</a-list> |
|
|
|
</template> |
|
|
|
<script lang="ts"> |
|
|
|
import { defineComponent, PropType } from 'vue'; |
|
|
|
import { computed, defineComponent, PropType, ref, watch, unref } from 'vue'; |
|
|
|
import { ListItem } from './data'; |
|
|
|
import { useDesign } from '/@/hooks/web/useDesign'; |
|
|
|
import { List, Avatar, Tag } from 'ant-design-vue'; |
|
|
|
import { List, Avatar, Tag, Typography } from 'ant-design-vue'; |
|
|
|
import { isNumber } from '/@/utils/is'; |
|
|
|
export default defineComponent({ |
|
|
|
components: { |
|
|
|
[Avatar.name]: Avatar, |
|
|
|
[List.name]: List, |
|
|
|
[List.Item.name]: List.Item, |
|
|
|
AListItemMeta: List.Item.Meta, |
|
|
|
ATypographyParagraph: Typography.Paragraph, |
|
|
|
[Tag.name]: Tag, |
|
|
|
}, |
|
|
|
props: { |
|
|
|
@ -52,10 +71,66 @@ |
|
|
|
type: Array as PropType<ListItem[]>, |
|
|
|
default: () => [], |
|
|
|
}, |
|
|
|
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>, |
|
|
|
}, |
|
|
|
}, |
|
|
|
setup() { |
|
|
|
emits: ['update:currentPage'], |
|
|
|
setup(props, { emit }) { |
|
|
|
const { prefixCls } = useDesign('header-notify-list'); |
|
|
|
return { prefixCls }; |
|
|
|
const current = ref(props.currentPage || 1); |
|
|
|
const getData = computed(() => { |
|
|
|
const { pageSize, list } = props; |
|
|
|
console.log('refreshData', list); |
|
|
|
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, |
|
|
|
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 }; |
|
|
|
}, |
|
|
|
}); |
|
|
|
</script> |
|
|
|
|