post.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * 文章接口
  3. * @see https://api.halo.run/content-api.html#tag/post-controller
  4. */
  5. import HttpHandler from '@/common/http/request.js'
  6. export default {
  7. /**
  8. * 获取文章列表
  9. * @param {Object} params 参数
  10. */
  11. getPostList: (params) => {
  12. return HttpHandler.Get(`/apis/api.content.halo.run/v1alpha1/posts`, params)
  13. },
  14. /**
  15. * 根据名称获取文章
  16. * @param {String} name 分类名称
  17. */
  18. getPostByName: (name) => {
  19. return HttpHandler.Get(`/apis/api.content.halo.run/v1alpha1/posts/${name}`, {})
  20. },
  21. /**
  22. * 评论文章
  23. * @param {Object} data 数据
  24. * {
  25. * "allowNotification": true,
  26. * "author": "string",
  27. * "authorUrl": "string",
  28. * "content": "string",
  29. * "email": "string",
  30. * "parentId": 0,
  31. * "postId": 0
  32. * }
  33. */
  34. postCommentPost: (data) => {
  35. return HttpHandler.Post(`/api/content/posts/comments`, data)
  36. },
  37. /**
  38. * 搜索文章
  39. * @param {Object} data 数据
  40. */
  41. getPostListByKeyword: (data) => {
  42. return HttpHandler.Post(`/api/content/posts/search`, data)
  43. },
  44. /**
  45. * 根据分类获取文章
  46. * @param {Object} params 参数
  47. */
  48. getPostDetailBySlug: (params) => {
  49. return HttpHandler.Get(`/api/content/posts/slug`, params)
  50. },
  51. /**
  52. * 根据文章id获取文章
  53. * @param {Object} params 参数
  54. */
  55. getPostDetailByPostId: (postId, params) => {
  56. return HttpHandler.Get(`/api/content/posts/${postId}`, params)
  57. },
  58. /**
  59. * 给文章点赞
  60. * @param {Object} postId 文章id
  61. */
  62. postLikePost: (postId) => {
  63. return HttpHandler.Post(`/api/content/posts/${postId}/likes`)
  64. },
  65. /**
  66. * 根据当前文章id获取前一篇文章
  67. * @param {Object} postId 文章id
  68. */
  69. getPrevByCurrentPostId: (postId) => {
  70. return HttpHandler.Get(`/api/content/posts/${postId}/prev`)
  71. },
  72. /**
  73. * 根据当前文章id获取下一篇文章
  74. * @param {Object} postId 文章id
  75. */
  76. getNextByCurrentPostId: (postId) => {
  77. return HttpHandler.Get(`/api/content/posts/${postId}/next`)
  78. },
  79. }