http.ts 5.4 KB

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