import { asyncTimeout, jsonToForm } from "@/utils"; import { PagingRequest, PagingResult } from "."; import { ADD_MATERIAL, DEL_MATERIAL, MATERIAL_GROUP_LIST, MATERIAL_PAG, MATERIAL_TA_GROUP_LIST, SYNC_MATERIAL, UPLOAD_HEADS, } from "./constant"; import axios from "./instance"; import { params } from "@/env"; type ServiceMaterialGroup = { dictKey: string; dictName: string; useType: string; id: number; dictIconList?: { iconUrl: string; }[]; }; type ServiceMaterial = { createTime: string; dictId: number; status: number; dictName: string; fileFormat: string; fileName: string; fileSize: string; fileType: string; fileUrl: string; id: number; name: string; newFileName: string; typeKey: string; updateTime: string; uploadId: number; }; export type MaterialGroup = { id: number; name: string; useType: string; icons: string[]; }; export type Material = { id: number; name: string; format: string; url: string; size: number; groupId: number; status: number; group: string; uploadId?: number; isSystem?: number; modelId?: number; }; export type MaterialPageProps = PagingRequest< Partial & { groupIds: number[]; formats: string[], useType?: string } >; export const fetchMaterialPage = async (params: MaterialPageProps) => { const material = await axios.post>( MATERIAL_PAG, { pageNum: params.pageNum, pageSize: params.pageSize, name: params.name, dictIds: params.groupIds, fileFormats: params.formats, useType: params.useType } ); const nm = { ...material, list: material.list.map( (item): Material => ({ ...item, id: item.id, name: item.name, format: item.fileFormat, url: item.fileUrl, size: Number(item.fileSize), groupId: item.dictId, status: item.status, group: item.dictName, uploadId: item.uploadId, }) ), }; return nm; }; export const fetchMaterialGroups = async (useType?: string) => { if (useType !== "trace_evidence") { return (await axios.get(MATERIAL_GROUP_LIST)).map( (item) => ({ name: item.dictName, useType: item.useType, key: item.dictKey, id: item.id, icons: item.dictIconList ? item.dictIconList.map((item) => item.iconUrl) : [], }) ) as MaterialGroup[]; } else { return ( await axios.get(MATERIAL_TA_GROUP_LIST) ).map((item) => ({ name: item.dictName, useType: item.useType, key: item.dictKey, id: item.id, icons: item.dictIconList ? item.dictIconList.map((item) => item.iconUrl) : [], })) as MaterialGroup[]; } }; export const syncMaterialAll = async () => { await axios.get(SYNC_MATERIAL + params.caseId) } export const addMaterial = (file: File) => { return axios({ method: "POST", url: ADD_MATERIAL, data: jsonToForm({ file }), headers: { ...UPLOAD_HEADS }, }); }; export const delMaterial = (id: Material["id"]) => { return axios.post(DEL_MATERIAL, { id }); };