NoticeList.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. import { Avatar, List } from 'antd';
  2. import React from 'react';
  3. import classNames from 'classnames';
  4. import { NoticeIconData } from './index';
  5. import styles from './NoticeList.less';
  6. export interface NoticeIconTabProps {
  7. count?: number;
  8. name?: string;
  9. showClear?: boolean;
  10. showViewMore?: boolean;
  11. style?: React.CSSProperties;
  12. title: string;
  13. tabKey: string;
  14. data?: NoticeIconData[];
  15. onClick?: (item: NoticeIconData) => void;
  16. onClear?: () => void;
  17. emptyText?: string;
  18. clearText?: string;
  19. viewMoreText?: string;
  20. list: NoticeIconData[];
  21. onViewMore?: (e: any) => void;
  22. }
  23. const NoticeList: React.SFC<NoticeIconTabProps> = ({
  24. data = [],
  25. onClick,
  26. onClear,
  27. title,
  28. onViewMore,
  29. emptyText,
  30. showClear = true,
  31. clearText,
  32. viewMoreText,
  33. showViewMore = false,
  34. }) => {
  35. if (!data || data.length === 0) {
  36. return (
  37. <div className={styles.notFound}>
  38. <img
  39. src="https://gw.alipayobjects.com/zos/rmsportal/sAuJeJzSKbUmHfBQRzmZ.svg"
  40. alt="not found"
  41. />
  42. <div>{emptyText}</div>
  43. </div>
  44. );
  45. }
  46. return (
  47. <div>
  48. <List<NoticeIconData>
  49. className={styles.list}
  50. dataSource={data}
  51. renderItem={(item, i) => {
  52. const itemCls = classNames(styles.item, {
  53. [styles.read]: item.read,
  54. });
  55. // eslint-disable-next-line no-nested-ternary
  56. const leftIcon = item.avatar ? (
  57. typeof item.avatar === 'string' ? (
  58. <Avatar className={styles.avatar} src={item.avatar} />
  59. ) : (
  60. <span className={styles.iconElement}>{item.avatar}</span>
  61. )
  62. ) : null;
  63. return (
  64. <List.Item
  65. className={itemCls}
  66. key={item.key || i}
  67. onClick={() => onClick && onClick(item)}
  68. >
  69. <List.Item.Meta
  70. className={styles.meta}
  71. avatar={leftIcon}
  72. title={
  73. <div className={styles.title}>
  74. {item.title}
  75. <div className={styles.extra}>{item.extra}</div>
  76. </div>
  77. }
  78. description={
  79. <div>
  80. <div className={styles.description}>{item.description}</div>
  81. <div className={styles.datetime}>{item.datetime}</div>
  82. </div>
  83. }
  84. />
  85. </List.Item>
  86. );
  87. }}
  88. />
  89. <div className={styles.bottomBar}>
  90. {showClear ? (
  91. <div onClick={onClear}>
  92. {clearText} {title}
  93. </div>
  94. ) : null}
  95. {showViewMore ? (
  96. <div
  97. onClick={(e) => {
  98. if (onViewMore) {
  99. onViewMore(e);
  100. }
  101. }}
  102. >
  103. {viewMoreText}
  104. </div>
  105. ) : null}
  106. </div>
  107. </div>
  108. );
  109. };
  110. export default NoticeList;