You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.1 KiB

2 years ago
  1. import './index.css'
  2. import avatar from './images/avatar.png'
  3. // 依赖的数据
  4. const state = {
  5. // hot: 热度排序 time: 时间排序
  6. tabs: [
  7. {
  8. id: 1,
  9. name: '热度',
  10. type: 'hot'
  11. },
  12. {
  13. id: 2,
  14. name: '时间',
  15. type: 'time'
  16. }
  17. ],
  18. active: 'hot',
  19. list: [
  20. {
  21. id: 1,
  22. author: '刘德华',
  23. comment: '给我一杯忘情水',
  24. time: new Date('2021-10-10 09:09:00'),
  25. // 1: 点赞 0:无态度 -1:踩
  26. attitude: 1
  27. },
  28. {
  29. id: 2,
  30. author: '周杰伦',
  31. comment: '哎哟,不错哦',
  32. time: new Date('2021-10-11 09:09:00'),
  33. // 1: 点赞 0:无态度 -1:踩
  34. attitude: 0
  35. },
  36. {
  37. id: 3,
  38. author: '五月天',
  39. comment: '不打扰,是我的温柔',
  40. time: new Date('2021-10-11 10:09:00'),
  41. // 1: 点赞 0:无态度 -1:踩
  42. attitude: -1
  43. }
  44. ]
  45. }
  46. // 格式化时间文本
  47. function getTime (time) {
  48. return `${time.getFullYear()}-${time.getMonth() + 1}-${time.getDate()}`
  49. }
  50. function App () {
  51. return (
  52. <div className="App">
  53. <div className="comment-container">
  54. {/* 评论数 */}
  55. <div className="comment-head">
  56. <span>5 评论</span>
  57. </div>
  58. {/* 排序 */}
  59. <div className="tabs-order">
  60. <ul className="sort-container">
  61. {state.tabs.map(item => <li key={item.id} className={item.type === state.active ? 'on' : ''}>{item.name}排序</li>)}
  62. </ul>
  63. </div>
  64. {/* 添加评论 */}
  65. <div className="comment-send">
  66. <div className="user-face">
  67. <img className="user-head" src={avatar} alt="" />
  68. </div>
  69. <div className="textarea-container">
  70. <textarea
  71. cols="80"
  72. rows="5"
  73. placeholder="发条友善的评论"
  74. className="ipt-txt"
  75. />
  76. <button className="comment-submit">发表评论</button>
  77. </div>
  78. <div className="comment-emoji">
  79. <i className="face"></i>
  80. <span className="text">表情</span>
  81. </div>
  82. </div>
  83. {/* 评论列表 */}
  84. <div className="comment-list">
  85. {state.list.map(item => (<div className="list-item" key={item.id}>
  86. <div className="user-face">
  87. <img className="user-head" src={avatar} alt="" />
  88. </div>
  89. <div className="comment">
  90. <div className="user">{item.author}</div>
  91. <p className="text">{item.comment}</p>
  92. <div className="info">
  93. <span className="time">{getTime(item.time)}</span>
  94. <span className={item.attitude === 1 ? 'like liked' : 'like'}>
  95. <i className="icon" />
  96. </span>
  97. <span className={item.attitude === -1 ? 'hate hated' : 'hate'}>
  98. <i className="icon" />
  99. </span>
  100. <span className="reply btn-hover">删除</span>
  101. </div>
  102. </div>
  103. </div>))}
  104. </div>
  105. </div>
  106. </div>
  107. )
  108. }
  109. export default App