vue-vben-admin/src/layouts/default/header/components/notify/NoticeList.vue

204 lines
5.6 KiB
Vue
Raw Normal View History

2020-10-21 21:15:06 +08:00
<template>
<a-list :class="prefixCls" bordered :pagination="getPagination">
<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">
<a-typography-paragraph
@click="handleTitleClick(item)"
style="width: 100%; margin-bottom: 0 !important"
: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
"
: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>
<div class="description" v-if="item.description">
<a-typography-paragraph
style="width: 100%; margin-bottom: 0 !important"
:ellipsis="
2021-08-13 11:13:29 +08:00
$props.descRows && $props.descRows > 0
? { rows: $props.descRows, tooltip: !!item.description }
: 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">
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';
import { List, Avatar, Tag, Typography } from 'ant-design-vue';
import { isNumber } from '/@/utils/is';
// 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,
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: () => [],
},
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
},
emits: ['update:currentPage'],
setup(props, { emit }) {
2020-12-15 00:13:23 +08:00
const { prefixCls } = useDesign('header-notify-list');
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
},
);
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) {
return {
total: list.length,
2023-10-17 09:29:43 +08:00
pageSize: size,
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;
}
::v-deep(.ant-pagination-disabled) {
display: inline-block !important;
}
.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;
}
}
}
2020-10-21 21:15:06 +08:00
.avatar {
margin-top: 4px;
}
2020-10-21 21:15:06 +08:00
.description {
font-size: 12px;
line-height: 18px;
}
2020-10-21 21:15:06 +08:00
.datetime {
margin-top: 4px;
font-size: 12px;
line-height: 18px;
2020-10-21 21:15:06 +08:00
}
}
}
</style>