http.ts 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. import request from "@/utils/request";
  2. import { getUserInfo } from "@/utils/tools";
  3. import { IReport, IReportList } from "./interface";
  4. import { getNearThreeMonth } from "./service";
  5. // 周日报所有的请求接口
  6. const api = {
  7. list: "/adm/report/list", // 周日报列表
  8. submit: "/admin-api/adm/report/add-report-info", // 周日报提交、暂存
  9. project: "/business/project/page", // 项目列表
  10. workDayList: "/admin-api/adm/workday/list", // 获取工作日列表
  11. receiveUser: "/admin-api/adm/report/recent-receive-user", // 获取最近接收人
  12. logDetail: "/admin-api/adm/report/query-detail", // 获取周日报详情
  13. reportCommentList: "/admin-api/adm/reportComment/getList", // 获取周日报评论列表
  14. deleteComment: "/admin-api/adm/reportComment/delete", // 删除周日报评论
  15. addComment: "/admin-api/adm/reportComment/send", // 添加周日报评论
  16. logList: "/admin-api/adm/report/list", // 获取周报日志列表
  17. receiveList: "/admin-api/adm/report/page/me", // 我收到的周日报
  18. };
  19. const userInfo = getUserInfo();
  20. export const http = {
  21. // 请求周日报列表
  22. getReportList: async (params: IReportList) => {
  23. return await request.get(api.list, { params });
  24. },
  25. // 提交、暂存周日报
  26. submitReport: async (params: IReport) => {
  27. return await request.post(api.submit, params);
  28. },
  29. // 项目列表
  30. getProjectList: async () => {
  31. const params = {
  32. pageSize: -1,
  33. userId: userInfo.id ?? "",
  34. xmzList: [1, 4] + "",
  35. };
  36. // 同 不太优雅的方式 (仅可对进行中和已验收的项目进行填报)
  37. // const url = `${api.project}?xmztList%5B0%5D=1&%5B1%5D=4`;
  38. const url = api.project;
  39. const result: any = await request.get(url, { params });
  40. return result.msg == "success" ? result.data.records : [];
  41. },
  42. // 获取工作日列表 YYYY-MM-DD HH:mm:ss
  43. getWorkDayList: async (startDate: string, endDate: string) => {
  44. // const result: any = await request.get(api.workDayList, {
  45. // data: { dateDay: [startDate, endDate] },
  46. // });
  47. // 用一种不太优雅的方式实现请求效果
  48. const encodedStartDate = encodeURIComponent(startDate);
  49. const encodedEndDate = encodeURIComponent(endDate);
  50. const url = `${api.workDayList}?dateDay%5B0%5D=${encodedStartDate}&dateDay%5B1%5D=${encodedEndDate}`;
  51. const result: any = await request.get(url);
  52. return result.msg == "success" ? result.data : [];
  53. },
  54. // 获取接收人历史
  55. getReceiveUser: async () => {
  56. const params = { userId: userInfo.id };
  57. const result: any = await request.get(api.receiveUser, { params });
  58. return result.msg == "success" ? result.data : [];
  59. },
  60. // 获取周日报详情
  61. getLogDetail: async (reportId: string) => {
  62. const params = { reportId };
  63. const result: any = await request.get(api.logDetail, { params });
  64. return result.msg == "success" ? result.data : {};
  65. },
  66. // 获取周日报评论列表
  67. getReportCommentList: async (reportId: string) => {
  68. const uId = userInfo.id ?? "";
  69. const params = { reportId, uId };
  70. const result: any = await request.get(api.reportCommentList, { params });
  71. return result.msg == "success" ? result.data : [];
  72. },
  73. // 删除周日报评论
  74. deleteReportComment: async (reportCommentId: string) => {
  75. return await request.delete(`${api.deleteComment}`, {
  76. data: [reportCommentId],
  77. });
  78. },
  79. // 添加周日报评论
  80. addReportComment: async (params: any) => {
  81. const commentUserId = userInfo.id ?? "";
  82. return await request.post(api.addComment, { ...params, commentUserId });
  83. },
  84. // 获取近三个月周日报日志列表
  85. getLogList: async (type: "weekly" | "daily") => {
  86. const nearThreeMonth = getNearThreeMonth();
  87. const requests = [
  88. request.get(api.logList, {
  89. params: {
  90. reportType: type,
  91. reportYear: nearThreeMonth[0].reportYear,
  92. reportMonth: nearThreeMonth[0].reportMonth,
  93. userId: userInfo.id ?? "",
  94. },
  95. }),
  96. request.get(api.logList, {
  97. params: {
  98. reportType: type,
  99. reportYear: nearThreeMonth[1].reportYear,
  100. reportMonth: nearThreeMonth[1].reportMonth,
  101. userId: userInfo.id ?? "",
  102. },
  103. }),
  104. request.get(api.logList, {
  105. params: {
  106. reportType: type,
  107. reportYear: nearThreeMonth[2].reportYear,
  108. reportMonth: nearThreeMonth[2].reportMonth,
  109. userId: userInfo.id ?? "",
  110. },
  111. }),
  112. ];
  113. const result: any = await Promise.all(requests);
  114. const allLog = [
  115. ...(result?.[0].data ?? []),
  116. ...(result?.[1].data ?? []),
  117. ...(result?.[2].data ?? []),
  118. ];
  119. return allLog;
  120. },
  121. // 获取当月日志列表
  122. getMonthLogList: async (
  123. type: "weekly" | "daily",
  124. year: string,
  125. month: string
  126. ) => {
  127. const params = {
  128. reportType: type,
  129. reportYear: year,
  130. reportMonth: month,
  131. userId: userInfo.id ?? "",
  132. };
  133. const result: any = await request.get(api.logList, {
  134. params,
  135. });
  136. return result.msg == "success" ? result.data : [];
  137. },
  138. // 获取本周日志列表
  139. getWeeklyLogList: async (
  140. type: "weekly" | "daily",
  141. reportYear: string | number,
  142. reportMonth: string | number,
  143. reportWeek: string | number
  144. ) => {
  145. const params = {
  146. reportType: type,
  147. reportYear,
  148. reportMonth,
  149. reportWeek,
  150. userId: userInfo.id ?? "",
  151. };
  152. const result: any = await request.get(api.logList, {
  153. params,
  154. });
  155. return result.msg == "success" ? result.data : [];
  156. },
  157. // 我收到的日志
  158. getMyReceive: async (params: { pageNo: number; pageSize: number }) => {
  159. const result: any = await request.get(api.receiveList, {
  160. params,
  161. });
  162. return result.msg == "success"
  163. ? result.data
  164. : {
  165. list: [],
  166. total: 0,
  167. };
  168. },
  169. };