knowledge.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. import {
  2. http,
  3. Method
  4. } from '@/utils/request.js';
  5. // 使用storage模块的方法设置登录状态为false
  6. import storage from "@/utils/storage.js";
  7. const request = http.request;
  8. /**
  9. * 获取农技知识列表
  10. * @param params
  11. */
  12. export function getTechList(params) {
  13. return http.request({
  14. url: "uniapp/knowledge/tech",
  15. method: Method.GET,
  16. // needToken: true,
  17. data:params,
  18. });
  19. }
  20. /**
  21. * 获取政策解读列表
  22. * @param params
  23. */
  24. export function getPolicyList(params) {
  25. return http.request({
  26. url: "uniapp/knowledge/policy",
  27. method: Method.GET,
  28. // needToken: true,
  29. data:params,
  30. });
  31. }
  32. /**
  33. * 获取知识文章详情
  34. * @param id 文章ID
  35. */
  36. export function getArticleDetail(id) {
  37. return http.request({
  38. url: `uniapp/knowledge/${id}`,
  39. method: Method.GET,
  40. // needToken: true,
  41. headers: {
  42. 'Accept': 'application/json'
  43. }
  44. });
  45. }
  46. /**
  47. * 获取文章相关图片
  48. * @param articleId 文章ID
  49. */
  50. export function getArticleImages(articleId) {
  51. return http.request({
  52. url: `uniapp/knowledge/images/${articleId}`,
  53. method: Method.GET,
  54. });
  55. }
  56. /**
  57. * 获取轮播图列表
  58. */
  59. export function getCarouselImages() {
  60. return http.request({
  61. url: "uniapp/knowledge/carousel",
  62. method: Method.GET,
  63. });
  64. }
  65. /**
  66. * 创建文章
  67. * @param article 文章数据
  68. */
  69. export function createArticle(article) {
  70. return http.request({
  71. url: "uniapp/knowledge",
  72. method: Method.POST,
  73. // needToken: true,
  74. data: article,
  75. headers: {
  76. 'Content-Type': 'application/json'
  77. }
  78. });
  79. }
  80. /**
  81. * 更新文章
  82. * @param article 文章数据
  83. */
  84. export function updateArticle(article) {
  85. return http.request({
  86. url: "uniapp/knowledge",
  87. method: Method.PUT,
  88. // needToken: true,
  89. data: article,
  90. headers: {
  91. 'Content-Type': 'application/json'
  92. }
  93. });
  94. }
  95. /**
  96. * 上传文件
  97. * @param formData 表单数据
  98. */
  99. export function uploadFile(formData) {
  100. return http.request({
  101. url: "uniapp/file/upload",
  102. method: Method.POST,
  103. needToken: true,
  104. data: formData,
  105. });
  106. }
  107. /**
  108. * 点赞文章
  109. * @param id 文章ID
  110. */
  111. export function likeArticle(id) {
  112. return http.request({
  113. url: `uniapp/knowledge/like/${id}`,
  114. method: Method.POST,
  115. needToken: true,
  116. });
  117. }
  118. /**
  119. * 取消点赞文章
  120. * @param id 文章ID
  121. */
  122. export function unlikeArticle(id) {
  123. return http.request({
  124. url: `uniapp/knowledge/like/${id}`,
  125. method: Method.DELETE,
  126. needToken: true,
  127. });
  128. }
  129. /**
  130. * 收藏文章
  131. * @param id 文章ID
  132. */
  133. export function favoriteArticle(id) {
  134. return http.request({
  135. url: `uniapp/knowledge/favorite/${id}`,
  136. method: Method.POST,
  137. needToken: true,
  138. });
  139. }
  140. /**
  141. * 取消收藏文章
  142. * @param id 文章ID
  143. */
  144. export function unfavoriteArticle(id) {
  145. return http.request({
  146. url: `uniapp/knowledge/favorite/${id}`,
  147. method: Method.DELETE,
  148. needToken: true,
  149. });
  150. }