material.ts 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. import { asyncTimeout, jsonToForm } from "@/utils";
  2. import { PagingRequest, PagingResult } from ".";
  3. import {
  4. ADD_MATERIAL,
  5. DEL_MATERIAL,
  6. MATERIAL_GROUP_LIST,
  7. MATERIAL_PAG,
  8. MATERIAL_TA_GROUP_LIST,
  9. SYNC_MATERIAL,
  10. UPLOAD_HEADS,
  11. } from "./constant";
  12. import axios from "./instance";
  13. import { params } from "@/env";
  14. type ServiceMaterialGroup = {
  15. dictKey: string;
  16. dictName: string;
  17. useType: string;
  18. id: number;
  19. dictIconList?: {
  20. iconUrl: string;
  21. }[];
  22. };
  23. type ServiceMaterial = {
  24. createTime: string;
  25. dictId: number;
  26. status: number;
  27. dictName: string;
  28. fileFormat: string;
  29. fileName: string;
  30. fileSize: string;
  31. fileType: string;
  32. fileUrl: string;
  33. id: number;
  34. name: string;
  35. newFileName: string;
  36. typeKey: string;
  37. updateTime: string;
  38. uploadId: number;
  39. };
  40. export type MaterialGroup = {
  41. id: number;
  42. name: string;
  43. useType: string;
  44. icons: string[];
  45. };
  46. export type Material = {
  47. id: number;
  48. name: string;
  49. format: string;
  50. url: string;
  51. size: number;
  52. groupId: number;
  53. status: number;
  54. group: string;
  55. uploadId?: number;
  56. isSystem?: number;
  57. modelId?: number;
  58. };
  59. export type MaterialPageProps = PagingRequest<
  60. Partial<Material> & { groupIds: number[]; formats: string[],
  61. useType?: string }
  62. >;
  63. export const fetchMaterialPage = async (params: MaterialPageProps) => {
  64. const material = await axios.post<PagingResult<ServiceMaterial[]>>(
  65. MATERIAL_PAG,
  66. {
  67. pageNum: params.pageNum,
  68. pageSize: params.pageSize,
  69. name: params.name,
  70. dictIds: params.groupIds,
  71. fileFormats: params.formats,
  72. useType: params.useType
  73. }
  74. );
  75. const nm = {
  76. ...material,
  77. list: material.list.map(
  78. (item): Material => ({
  79. ...item,
  80. id: item.id,
  81. name: item.name,
  82. format: item.fileFormat,
  83. url: item.fileUrl,
  84. size: Number(item.fileSize),
  85. groupId: item.dictId,
  86. status: item.status,
  87. group: item.dictName,
  88. uploadId: item.uploadId,
  89. })
  90. ),
  91. };
  92. return nm;
  93. };
  94. export const fetchMaterialGroups = async (useType?: string) => {
  95. if (useType !== "trace_evidence") {
  96. return (await axios.get<ServiceMaterialGroup[]>(MATERIAL_GROUP_LIST)).map(
  97. (item) => ({
  98. name: item.dictName,
  99. useType: item.useType,
  100. key: item.dictKey,
  101. id: item.id,
  102. icons: item.dictIconList
  103. ? item.dictIconList.map((item) => item.iconUrl)
  104. : [],
  105. })
  106. ) as MaterialGroup[];
  107. } else {
  108. return (
  109. await axios.get<ServiceMaterialGroup[]>(MATERIAL_TA_GROUP_LIST)
  110. ).map((item) => ({
  111. name: item.dictName,
  112. useType: item.useType,
  113. key: item.dictKey,
  114. id: item.id,
  115. icons: item.dictIconList
  116. ? item.dictIconList.map((item) => item.iconUrl)
  117. : [],
  118. })) as MaterialGroup[];
  119. }
  120. };
  121. export const syncMaterialAll = async () => {
  122. await axios.get(SYNC_MATERIAL + params.caseId)
  123. }
  124. export const addMaterial = (file: File) => {
  125. return axios<string>({
  126. method: "POST",
  127. url: ADD_MATERIAL,
  128. data: jsonToForm({ file }),
  129. headers: { ...UPLOAD_HEADS },
  130. });
  131. };
  132. export const delMaterial = (id: Material["id"]) => {
  133. return axios.post(DEL_MATERIAL, { id });
  134. };