NoticeList.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import { defineComponent } from 'vue';
  2. import { List, Avatar, Tag } from 'ant-design-vue';
  3. import { NoticeListItem } from './data';
  4. import './index.less';
  5. const prefixCls = 'notice-popover';
  6. export default defineComponent({
  7. name: 'NoticeList',
  8. props: {
  9. list: {
  10. type: Array,
  11. default: () => [],
  12. },
  13. },
  14. setup(props) {
  15. // 头像渲染
  16. function renderAvatar(avatar: string) {
  17. return avatar ? <Avatar class="avatar" src={avatar} /> : <span>{avatar}</span>;
  18. }
  19. // 描述渲染
  20. function renderDescription(description: string, datetime: string) {
  21. return (
  22. <div>
  23. <div class="description">{description}</div>
  24. <div class="datetime">{datetime}</div>
  25. </div>
  26. );
  27. }
  28. // 标题渲染
  29. function renderTitle(title: string, extra?: string, color?: string) {
  30. return (
  31. <div class="title">
  32. {title}
  33. {extra && (
  34. <div class="extra">
  35. <Tag class="tag" color={color}>
  36. {() => extra}
  37. </Tag>
  38. </div>
  39. )}
  40. </div>
  41. );
  42. }
  43. return () => {
  44. const { list } = props;
  45. return (
  46. <List dataSource={list} class={`${prefixCls}__list`}>
  47. {() => {
  48. return list.map((item: NoticeListItem) => {
  49. const { id, avatar, title, description, datetime, extra, read, color } = item;
  50. return (
  51. <List.Item key={id} class={`${prefixCls}__list-item ${read ? 'read' : ''}`}>
  52. {() => (
  53. <List.Item.Meta
  54. class="meta"
  55. avatar={renderAvatar(avatar)}
  56. title={renderTitle(title, extra, color)}
  57. description={renderDescription(description, datetime)}
  58. />
  59. )}
  60. </List.Item>
  61. );
  62. });
  63. }}
  64. </List>
  65. );
  66. };
  67. },
  68. });