http.ts 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. };
  34. const result: any = await request.get(api.project, { params });
  35. return result.msg == "success" ? result.data.records : [];
  36. },
  37. // 获取工作日列表 YYYY-MM-DD HH:mm:ss
  38. getWorkDayList: async (startDate: string, endDate: string) => {
  39. // const result: any = await request.get(api.workDayList, {
  40. // data: { dateDay: [startDate, endDate] },
  41. // });
  42. // 用一种不太优雅的方式实现请求效果
  43. const encodedStartDate = encodeURIComponent(startDate);
  44. const encodedEndDate = encodeURIComponent(endDate);
  45. const url = `${api.workDayList}?dateDay%5B0%5D=${encodedStartDate}&dateDay%5B1%5D=${encodedEndDate}`;
  46. const result: any = await request.get(url);
  47. return result.msg == "success" ? result.data : [];
  48. },
  49. // 获取接收人历史
  50. getReceiveUser: async () => {
  51. const params = { userId: userInfo.id };
  52. const result: any = await request.get(api.receiveUser, { params });
  53. return result.msg == "success" ? result.data : [];
  54. },
  55. // 获取周日报详情
  56. getLogDetail: async (reportId: string) => {
  57. const params = { reportId };
  58. const result: any = await request.get(api.logDetail, { params });
  59. return result.msg == "success" ? result.data : {};
  60. },
  61. // 获取周日报评论列表
  62. getReportCommentList: async (reportId: string) => {
  63. const uId = userInfo.id ?? "";
  64. const params = { reportId, uId };
  65. const result: any = await request.get(api.reportCommentList, { params });
  66. return result.msg == "success" ? result.data : [];
  67. },
  68. // 删除周日报评论
  69. deleteReportComment: async (reportCommentId: string) => {
  70. return await request.delete(`${api.deleteComment}`, {
  71. data: [reportCommentId],
  72. });
  73. },
  74. // 添加周日报评论
  75. addReportComment: async (params: any) => {
  76. const commentUserId = userInfo.id ?? "";
  77. return await request.post(api.addComment, { ...params, commentUserId });
  78. },
  79. // 获取近三个月周日报日志列表
  80. getLogList: async (type: "weekly" | "daily") => {
  81. const nearThreeMonth = getNearThreeMonth();
  82. const requests = [
  83. request.get(api.logList, {
  84. params: {
  85. reportType: type,
  86. reportYear: nearThreeMonth[0].reportYear,
  87. reportMonth: nearThreeMonth[0].reportMonth,
  88. userId: userInfo.id ?? "",
  89. },
  90. }),
  91. request.get(api.logList, {
  92. params: {
  93. reportType: type,
  94. reportYear: nearThreeMonth[1].reportYear,
  95. reportMonth: nearThreeMonth[1].reportMonth,
  96. userId: userInfo.id ?? "",
  97. },
  98. }),
  99. request.get(api.logList, {
  100. params: {
  101. reportType: type,
  102. reportYear: nearThreeMonth[2].reportYear,
  103. reportMonth: nearThreeMonth[2].reportMonth,
  104. userId: userInfo.id ?? "",
  105. },
  106. }),
  107. ];
  108. const result: any = await Promise.all(requests);
  109. const allLog = [
  110. ...(result?.[0].data ?? []),
  111. ...(result?.[1].data ?? []),
  112. ...(result?.[2].data ?? []),
  113. ];
  114. return allLog;
  115. },
  116. // 获取当月日志列表
  117. getMonthLogList: async (
  118. type: "weekly" | "daily",
  119. year: string,
  120. month: string
  121. ) => {
  122. const params = {
  123. reportType: type,
  124. reportYear: year,
  125. reportMonth: month,
  126. userId: userInfo.id ?? "",
  127. };
  128. const result: any = await request.get(api.logList, {
  129. params,
  130. });
  131. return result.msg == "success" ? result.data : [];
  132. },
  133. };