NoticeList.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import React from 'react';
  2. import { Avatar, List } from 'antd';
  3. import classNames from 'classnames';
  4. import styles from './NoticeList.less';
  5. export default function NoticeList({
  6. data = [],
  7. onClick,
  8. onClear,
  9. title,
  10. locale,
  11. emptyText,
  12. emptyImage,
  13. showClear = true,
  14. }) {
  15. if (data.length === 0) {
  16. return (
  17. <div className={styles.notFound}>
  18. {emptyImage ? <img src={emptyImage} alt="not found" /> : null}
  19. <div>{emptyText || locale.emptyText}</div>
  20. </div>
  21. );
  22. }
  23. return (
  24. <div>
  25. <List className={styles.list}>
  26. {data.map((item, i) => {
  27. const itemCls = classNames(styles.item, {
  28. [styles.read]: item.read,
  29. });
  30. // eslint-disable-next-line no-nested-ternary
  31. const leftIcon = item.avatar ? (
  32. typeof item.avatar === 'string' ? (
  33. <Avatar className={styles.avatar} src={item.avatar} />
  34. ) : (
  35. item.avatar
  36. )
  37. ) : null;
  38. return (
  39. <List.Item className={itemCls} key={item.key || i} onClick={() => onClick(item)}>
  40. <List.Item.Meta
  41. className={styles.meta}
  42. avatar={<span className={styles.iconElement}>{leftIcon}</span>}
  43. title={
  44. <div className={styles.title}>
  45. {item.title}
  46. <div className={styles.extra}>{item.extra}</div>
  47. </div>
  48. }
  49. description={
  50. <div>
  51. <div className={styles.description} title={item.description}>
  52. {item.description}
  53. </div>
  54. <div className={styles.datetime}>{item.datetime}</div>
  55. </div>
  56. }
  57. />
  58. </List.Item>
  59. );
  60. })}
  61. </List>
  62. {showClear ? (
  63. <div className={styles.clear} onClick={onClear}>
  64. {locale.clear} {title}
  65. </div>
  66. ) : null}
  67. </div>
  68. );
  69. }