2020-10-21 21:15:06 +08:00
|
|
|
<template>
|
2021-07-12 22:33:28 +08:00
|
|
|
<a-list :class="prefixCls" bordered :pagination="getPagination">
|
2021-07-12 22:09:02 +08:00
|
|
|
<template v-for="item in getData" :key="item.id">
|
2020-11-23 23:24:13 +08:00
|
|
|
<a-list-item class="list-item">
|
|
|
|
|
<a-list-item-meta>
|
2020-10-21 21:15:06 +08:00
|
|
|
<template #title>
|
|
|
|
|
<div class="title">
|
2021-07-12 22:09:02 +08:00
|
|
|
<a-typography-paragraph
|
|
|
|
|
@click="handleTitleClick(item)"
|
2021-07-12 22:22:33 +08:00
|
|
|
style="width: 100%; margin-bottom: 0 !important"
|
2021-07-12 22:09:02 +08:00
|
|
|
:style="{ cursor: isTitleClickable ? 'pointer' : '' }"
|
|
|
|
|
:delete="!!item.titleDelete"
|
|
|
|
|
:ellipsis="
|
2021-08-13 11:13:29 +08:00
|
|
|
$props.titleRows && $props.titleRows > 0
|
|
|
|
|
? { rows: $props.titleRows, tooltip: !!item.title }
|
|
|
|
|
: false
|
2021-07-12 22:09:02 +08:00
|
|
|
"
|
|
|
|
|
:content="item.title"
|
|
|
|
|
/>
|
2020-10-21 21:15:06 +08:00
|
|
|
<div class="extra" v-if="item.extra">
|
2020-11-23 23:24:13 +08:00
|
|
|
<a-tag class="tag" :color="item.color">
|
2020-10-21 21:15:06 +08:00
|
|
|
{{ item.extra }}
|
2020-11-23 23:24:13 +08:00
|
|
|
</a-tag>
|
2020-10-21 21:15:06 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2020-11-23 23:24:13 +08:00
|
|
|
|
2020-10-21 21:15:06 +08:00
|
|
|
<template #avatar>
|
2020-11-23 23:24:13 +08:00
|
|
|
<a-avatar v-if="item.avatar" class="avatar" :src="item.avatar" />
|
2020-10-21 21:15:06 +08:00
|
|
|
<span v-else> {{ item.avatar }}</span>
|
|
|
|
|
</template>
|
2020-11-23 23:24:13 +08:00
|
|
|
|
2020-10-21 21:15:06 +08:00
|
|
|
<template #description>
|
|
|
|
|
<div>
|
2021-07-12 22:09:02 +08:00
|
|
|
<div class="description" v-if="item.description">
|
|
|
|
|
<a-typography-paragraph
|
2021-07-12 22:22:33 +08:00
|
|
|
style="width: 100%; margin-bottom: 0 !important"
|
2021-07-12 22:09:02 +08:00
|
|
|
:ellipsis="
|
2021-08-13 11:13:29 +08:00
|
|
|
$props.descRows && $props.descRows > 0
|
|
|
|
|
? { rows: $props.descRows, tooltip: !!item.description }
|
2021-07-12 22:09:02 +08:00
|
|
|
: false
|
|
|
|
|
"
|
|
|
|
|
:content="item.description"
|
|
|
|
|
/>
|
2021-01-28 23:28:50 +08:00
|
|
|
</div>
|
|
|
|
|
<div class="datetime">
|
|
|
|
|
{{ item.datetime }}
|
|
|
|
|
</div>
|
2020-10-21 21:15:06 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
2020-11-23 23:24:13 +08:00
|
|
|
</a-list-item-meta>
|
|
|
|
|
</a-list-item>
|
2020-10-21 21:15:06 +08:00
|
|
|
</template>
|
2020-11-23 23:24:13 +08:00
|
|
|
</a-list>
|
2020-10-21 21:15:06 +08:00
|
|
|
</template>
|
|
|
|
|
<script lang="ts">
|
2021-07-12 22:09:02 +08:00
|
|
|
import { computed, defineComponent, PropType, ref, watch, unref } from 'vue';
|
2020-10-21 21:15:06 +08:00
|
|
|
import { ListItem } from './data';
|
2020-12-15 00:13:23 +08:00
|
|
|
import { useDesign } from '/@/hooks/web/useDesign';
|
2021-07-12 22:09:02 +08:00
|
|
|
import { List, Avatar, Tag, Typography } from 'ant-design-vue';
|
|
|
|
|
import { isNumber } from '/@/utils/is';
|
2023-07-06 15:00:38 +08:00
|
|
|
|
2023-10-25 11:55:14 +08:00
|
|
|
// types
|
|
|
|
|
import type { StyleValue } from '/@/utils/types';
|
|
|
|
|
import type { FunctionalComponent } from 'vue';
|
|
|
|
|
import type { ParagraphProps } from 'ant-design-vue/es/typography/Paragraph';
|
|
|
|
|
|
2020-10-21 21:15:06 +08:00
|
|
|
export default defineComponent({
|
2021-01-18 23:37:36 +08:00
|
|
|
components: {
|
|
|
|
|
[Avatar.name]: Avatar,
|
|
|
|
|
[List.name]: List,
|
|
|
|
|
[List.Item.name]: List.Item,
|
|
|
|
|
AListItemMeta: List.Item.Meta,
|
2023-10-25 11:55:14 +08:00
|
|
|
ATypographyParagraph: Typography.Paragraph as FunctionalComponent<
|
|
|
|
|
ParagraphProps & {
|
|
|
|
|
style?: StyleValue;
|
|
|
|
|
}
|
|
|
|
|
>,
|
2021-01-18 23:37:36 +08:00
|
|
|
[Tag.name]: Tag,
|
|
|
|
|
},
|
2020-10-21 21:15:06 +08:00
|
|
|
props: {
|
|
|
|
|
list: {
|
2020-11-26 21:19:39 +08:00
|
|
|
type: Array as PropType<ListItem[]>,
|
2020-10-21 21:15:06 +08:00
|
|
|
default: () => [],
|
|
|
|
|
},
|
2021-07-12 22:09:02 +08:00
|
|
|
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>,
|
|
|
|
|
},
|
2020-10-21 21:15:06 +08:00
|
|
|
},
|
2021-07-12 22:09:02 +08:00
|
|
|
emits: ['update:currentPage'],
|
|
|
|
|
setup(props, { emit }) {
|
2020-12-15 00:13:23 +08:00
|
|
|
const { prefixCls } = useDesign('header-notify-list');
|
2021-07-12 22:09:02 +08:00
|
|
|
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;
|
2021-08-24 22:41:48 +08:00
|
|
|
},
|
2021-07-12 22:09:02 +08:00
|
|
|
);
|
|
|
|
|
const isTitleClickable = computed(() => !!props.onTitleClick);
|
|
|
|
|
const getPagination = computed(() => {
|
|
|
|
|
const { list, pageSize } = props;
|
2023-10-17 09:29:43 +08:00
|
|
|
|
|
|
|
|
// compatible line 104
|
|
|
|
|
// if typeof pageSize is boolean, Number(true) && 5 = 5, Number(false) && 5 = 0
|
|
|
|
|
const size = isNumber(pageSize) ? pageSize : Number(pageSize) && 5;
|
|
|
|
|
|
|
|
|
|
if (size > 0 && list && list.length > size) {
|
2021-07-12 22:09:02 +08:00
|
|
|
return {
|
|
|
|
|
total: list.length,
|
2023-10-17 09:29:43 +08:00
|
|
|
pageSize: size,
|
2021-07-12 22:09:02 +08:00
|
|
|
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 };
|
2020-12-15 00:13:23 +08:00
|
|
|
},
|
2020-10-21 21:15:06 +08:00
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
<style lang="less" scoped>
|
2020-12-15 00:13:23 +08:00
|
|
|
@prefix-cls: ~'@{namespace}-header-notify-list';
|
|
|
|
|
|
|
|
|
|
.@{prefix-cls} {
|
2020-10-21 21:15:06 +08:00
|
|
|
&::-webkit-scrollbar {
|
|
|
|
|
display: none;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-12 22:33:28 +08:00
|
|
|
::v-deep(.ant-pagination-disabled) {
|
|
|
|
|
display: inline-block !important;
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-31 14:03:42 +08:00
|
|
|
.list-item {
|
2020-10-21 21:15:06 +08:00
|
|
|
padding: 6px;
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
transition: all 0.3s;
|
2023-04-04 16:55:34 +08:00
|
|
|
cursor: pointer;
|
2020-10-21 21:15:06 +08:00
|
|
|
|
|
|
|
|
.title {
|
|
|
|
|
margin-bottom: 8px;
|
|
|
|
|
font-weight: normal;
|
|
|
|
|
|
|
|
|
|
.extra {
|
|
|
|
|
margin-top: -1.5px;
|
|
|
|
|
margin-right: 0;
|
2023-04-04 16:55:34 +08:00
|
|
|
float: right;
|
2020-10-21 21:15:06 +08:00
|
|
|
font-weight: normal;
|
|
|
|
|
|
|
|
|
|
.tag {
|
|
|
|
|
margin-right: 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-10-31 14:03:42 +08:00
|
|
|
}
|
2020-10-21 21:15:06 +08:00
|
|
|
|
2023-10-31 14:03:42 +08:00
|
|
|
.avatar {
|
|
|
|
|
margin-top: 4px;
|
|
|
|
|
}
|
2020-10-21 21:15:06 +08:00
|
|
|
|
2023-10-31 14:03:42 +08:00
|
|
|
.description {
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
line-height: 18px;
|
|
|
|
|
}
|
2020-10-21 21:15:06 +08:00
|
|
|
|
2023-10-31 14:03:42 +08:00
|
|
|
.datetime {
|
|
|
|
|
margin-top: 4px;
|
|
|
|
|
font-size: 12px;
|
|
|
|
|
line-height: 18px;
|
2020-10-21 21:15:06 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|