页面思路:

入口:
header 入口 =>当前登录用户 查看自己的主页面信息
文章列表/ 文章详情 => 查看其他用作者的用户的主页面信息

内容:
作者信息 : 头像 / 用户名 / 简介
按钮信息:编辑设置 / 关注按钮(关注 / 取消关注)
选项卡: 当前作者 ,喜欢文章
文章列表:当前作者的文章 ,当前用户喜欢的文章

逻辑判断:
根据用户名称=>用户信息 profile =>跟当前登录用户走比较 用户名称是否相同=>区分按钮信息
是否关注 : 如果关注=>取消关注;没关注=>添加关注


作者Profile + 作者文章

mock 数据

  1. const mock = {
  2. profile: {
  3. username: 'lisi',
  4. avatar: 'https://yudafeng.github.io/static/default.png',
  5. bio: 'lisi user info',
  6. email: 'lisi@qq.com',
  7. following: false
  8. },
  9. currentUser: {
  10. username: 'test1',
  11. avatar: 'https://yudafeng.github.io/static/default.png',
  12. bio: 'test1 user info',
  13. email: 'test1@qq.com'
  14. },
  15. article: {
  16. "articles": [
  17. {
  18. "slug": "1371cdf8",
  19. "title": "你好aa",
  20. "description": "html 你好aa",
  21. "body": "html 你好aa",
  22. "createdAt": "2022-01-20T05:28:57.000Z",
  23. "updatedAt": "2022-01-20T05:28:57.000Z",
  24. "userEmail": "lisi@qq.com",
  25. "tags": [
  26. "html",
  27. "tag1"
  28. ],
  29. "author": {
  30. "username": "lisi",
  31. "email": "lisi@qq.com",
  32. "bio": null,
  33. "avatar": null
  34. },
  35. "isFavorite": false,
  36. "favoriteCount": 1
  37. },
  38. {
  39. "slug": "16bade37",
  40. "title": "你好aa",
  41. "description": "html 你好aa",
  42. "body": "html 你好aa",
  43. "createdAt": "2022-01-20T08:17:44.000Z",
  44. "updatedAt": "2022-01-20T08:17:44.000Z",
  45. "userEmail": "lisi@qq.com",
  46. "tags": [
  47. "html",
  48. "tag1"
  49. ],
  50. "author": {
  51. "username": "lisi",
  52. "email": "lisi@qq.com",
  53. "bio": null,
  54. "avatar": null
  55. },
  56. "isFavorite": false,
  57. "favoriteCount": 1
  58. },
  59. {
  60. "slug": "39dad7ae",
  61. "title": "你好1",
  62. "description": "html 你好1",
  63. "body": "html 你好1",
  64. "createdAt": "2022-01-20T05:21:50.000Z",
  65. "updatedAt": "2022-01-20T05:21:50.000Z",
  66. "userEmail": "wangwu@qq.com",
  67. "tags": [
  68. "html",
  69. "tag1"
  70. ],
  71. "author": {
  72. "username": "wangwu",
  73. "email": "wangwu@qq.com",
  74. "bio": null,
  75. "avatar": null
  76. },
  77. "isFavorite": false,
  78. "favoriteCount": 0
  79. },
  80. {
  81. "slug": "43daa00d",
  82. "title": "你好aa",
  83. "description": "html 你好aa",
  84. "body": "html 你好aa",
  85. "createdAt": "2022-01-20T08:17:45.000Z",
  86. "updatedAt": "2022-01-20T08:17:45.000Z",
  87. "userEmail": "lisi@qq.com",
  88. "tags": [
  89. "html",
  90. "tag1"
  91. ],
  92. "author": {
  93. "username": "lisi",
  94. "email": "lisi@qq.com",
  95. "bio": null,
  96. "avatar": null
  97. },
  98. "isFavorite": false,
  99. "favoriteCount": 0
  100. },
  101. {
  102. "slug": "539547df",
  103. "title": "你好aa",
  104. "description": "html 你好aa",
  105. "body": "html 你好aa",
  106. "createdAt": "2022-01-20T08:17:45.000Z",
  107. "updatedAt": "2022-01-20T08:17:45.000Z",
  108. "userEmail": "lisi@qq.com",
  109. "tags": [
  110. "html",
  111. "tag1"
  112. ],
  113. "author": {
  114. "username": "lisi",
  115. "email": "lisi@qq.com",
  116. "bio": null,
  117. "avatar": null
  118. },
  119. "isFavorite": false,
  120. "favoriteCount": 0
  121. },
  122. {
  123. "slug": "78fef5d6",
  124. "title": "你好",
  125. "description": "html 你好",
  126. "body": "html 你好",
  127. "createdAt": "2022-01-19T10:48:42.000Z",
  128. "updatedAt": "2022-01-19T10:48:42.000Z",
  129. "userEmail": "wangwu@qq.com",
  130. "tags": [
  131. "html",
  132. "tag1"
  133. ],
  134. "author": {
  135. "username": "wangwu",
  136. "email": "wangwu@qq.com",
  137. "bio": null,
  138. "avatar": null
  139. },
  140. "isFavorite": false,
  141. "favoriteCount": 0
  142. },
  143. {
  144. "slug": "7df21475",
  145. "title": "你好aa",
  146. "description": "html 你好aa",
  147. "body": "html 你好aa",
  148. "createdAt": "2022-01-20T08:17:41.000Z",
  149. "updatedAt": "2022-01-20T08:17:41.000Z",
  150. "userEmail": "lisi@qq.com",
  151. "tags": [
  152. "html",
  153. "tag1"
  154. ],
  155. "author": {
  156. "username": "lisi",
  157. "email": "lisi@qq.com",
  158. "bio": null,
  159. "avatar": null
  160. },
  161. "isFavorite": false,
  162. "favoriteCount": 0
  163. },
  164. {
  165. "slug": "a78e3634",
  166. "title": "你好aa",
  167. "description": "html 你好aa",
  168. "body": "html 你好aa",
  169. "createdAt": "2022-01-20T08:17:43.000Z",
  170. "updatedAt": "2022-01-20T08:17:43.000Z",
  171. "userEmail": "lisi@qq.com",
  172. "tags": [
  173. "html",
  174. "tag1"
  175. ],
  176. "author": {
  177. "username": "lisi",
  178. "email": "lisi@qq.com",
  179. "bio": null,
  180. "avatar": null
  181. },
  182. "isFavorite": false,
  183. "favoriteCount": 0
  184. },
  185. {
  186. "slug": "aad4ed9a",
  187. "title": "你好aa",
  188. "description": "html 你好aa",
  189. "body": "html 你好aa",
  190. "createdAt": "2022-01-20T08:17:43.000Z",
  191. "updatedAt": "2022-01-20T08:17:43.000Z",
  192. "userEmail": "lisi@qq.com",
  193. "tags": [
  194. "html",
  195. "tag1"
  196. ],
  197. "author": {
  198. "username": "lisi",
  199. "email": "lisi@qq.com",
  200. "bio": null,
  201. "avatar": null
  202. },
  203. "isFavorite": false,
  204. "favoriteCount": 0
  205. },
  206. {
  207. "slug": "c07d7d23",
  208. "title": "你好aa",
  209. "description": "html 你好aa",
  210. "body": "html 你好aa",
  211. "createdAt": "2022-01-20T08:17:42.000Z",
  212. "updatedAt": "2022-01-20T08:17:42.000Z",
  213. "userEmail": "lisi@qq.com",
  214. "tags": [
  215. "html",
  216. "tag1"
  217. ],
  218. "author": {
  219. "username": "lisi",
  220. "email": "lisi@qq.com",
  221. "bio": null,
  222. "avatar": null
  223. },
  224. "isFavorite": false,
  225. "favoriteCount": 0
  226. },
  227. {
  228. "slug": "d2ba3385",
  229. "title": "你好aa",
  230. "description": "html 你好aa",
  231. "body": "html 你好aa",
  232. "createdAt": "2022-01-20T08:17:46.000Z",
  233. "updatedAt": "2022-01-20T08:17:46.000Z",
  234. "userEmail": "lisi@qq.com",
  235. "tags": [
  236. "html",
  237. "tag1"
  238. ],
  239. "author": {
  240. "username": "lisi",
  241. "email": "lisi@qq.com",
  242. "bio": null,
  243. "avatar": null
  244. },
  245. "isFavorite": false,
  246. "favoriteCount": 0
  247. },
  248. {
  249. "slug": "d6a5dce9",
  250. "title": "你好3",
  251. "description": "html 你好3",
  252. "body": "html 你好3",
  253. "createdAt": "2022-01-20T05:26:24.000Z",
  254. "updatedAt": "2022-01-20T05:26:24.000Z",
  255. "userEmail": "wangwu@qq.com",
  256. "tags": [
  257. "html",
  258. "tag1"
  259. ],
  260. "author": {
  261. "username": "wangwu",
  262. "email": "wangwu@qq.com",
  263. "bio": null,
  264. "avatar": null
  265. },
  266. "isFavorite": false,
  267. "favoriteCount": 0
  268. }
  269. ],
  270. "articlesCount": 12
  271. }
  272. }
  1. const ButtonInfo = memo((props) => {
  2. const { isCurrentUser, profile } = props
  3. if (isCurrentUser) {
  4. return (
  5. <Link
  6. to='/setting'
  7. className="btn btn-sm btn-outline-secondary action-btn">
  8. <i className="fa fa-cog"></i>编辑设置
  9. </Link>
  10. )
  11. } else {
  12. return (
  13. <button className='btn btn-sm action-btn' className={profile.following ? 'btn-secondary' : 'btn-outline-secondary'}>
  14. <i className="fa fa-user-plus"></i> {' '}
  15. {profile.following ? '取消关注' : '关注作者'}
  16. </button>
  17. )
  18. }
  19. })
  20. class Profile extends PureComponent {
  21. renderTag=()=>{
  22. return (
  23. <ul className="nav nav-pills outline-active">
  24. <li className='nav-item'>
  25. <Link
  26. className="nav-link active"
  27. to={`/${mock.currentUser.username}/profile`}
  28. >
  29. 我的文章
  30. </Link>
  31. </li>
  32. <li className='nav-item'>
  33. <Link
  34. className="nav-link"
  35. to={`/${mock.currentUser.username}/favorites`}
  36. >
  37. 喜欢文章
  38. </Link>
  39. </li>
  40. </ul>
  41. )
  42. }
  43. render() {
  44. // const {profile,currentUser} = this.props
  45. const { profile, currentUser, article } = mock
  46. // 根据用户名称=>用户信息 profile =>跟当前登录用户走比较 用户名称是否相同=>区分按钮信息
  47. const isCurrentUser = currentUser && profile.username === currentUser.username
  48. return (
  49. <div className='profile-page'>
  50. {/* 用户信息 */}
  51. <div className='user-info'>
  52. <div className='container'>
  53. <div className='row'>
  54. <div className='col-xs-12 col-md-10 offset-md-1'>
  55. {/*基本信息 */}
  56. <img src={profile.avatar || ''} className='user-img' alt={profile.avatar} />
  57. <h4>{profile.username}</h4>
  58. <p>{profile.bio}</p>
  59. {/* 按钮信息 */}
  60. <ButtonInfo isCurrentUser={isCurrentUser} profile={profile} />
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. {/* 文章信息 */}
  66. <div className='container'>
  67. <div className="row">
  68. <div className="col-xs-12 col-md-10 offset-md-1">
  69. {/* 选项卡 */}
  70. <div className='aticles-toggle'>
  71. {
  72. this.renderTag()
  73. }
  74. </div>
  75. {/* 文章列表 */}
  76. <ArticlesList
  77. articles={article.articles}
  78. articlesCount={article.articlesCount}
  79. currentPage={1}
  80. />
  81. </div>
  82. </div>
  83. </div>
  84. </div>
  85. )
  86. }
  87. componentDidMount() {
  88. // 作者信息profile
  89. // 作者自己文章
  90. }
  91. }
  92. export default Profile

作者Profile + 作者喜欢文章

  1. class ProfileFavorite extends Profile {
  2. renderTag=()=>{
  3. return (
  4. <ul className="nav nav-pills outline-active">
  5. <li className='nav-item'>
  6. <Link
  7. className="nav-link"
  8. to={`/${mock.currentUser.username}/profile`}
  9. >
  10. 我的文章
  11. </Link>
  12. </li>
  13. <li className='nav-item'>
  14. <Link
  15. className="nav-link active"
  16. to={`/${mock.currentUser.username}/favorites`}
  17. >
  18. 喜欢文章
  19. </Link>
  20. </li>
  21. </ul>
  22. )
  23. }
  24. componentDidMount() {
  25. // 作者信息profile
  26. // 作者喜欢的文章
  27. }
  28. }
  29. export default ProfileFavorite