import { asyncTimeout, jsonToForm } from "@/utils"; import { PagingRequest, PagingResult } from "."; import { ADD_MATERIAL, DEL_MATERIAL, MATERIAL_GROUP_LIST, MATERIAL_PAG, UPLOAD_HEADS, } from "./constant"; import axios from "./instance"; type ServiceMaterialGroup = { dictKey: string; dictName: string; id: number; }; type ServiceMaterial = { createTime: string; dictId: 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; }; export type Material = { id: number; name: string; format: string; url: string; size: number; groupId: number; group: string; uploadId?: number; modelId?: number; }; export type MaterialPageProps = PagingRequest< Partial & { groupIds: number[], formats: 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 }); const nm = { ...material, list: material.list.map((item): Material => ({ id: item.id, name: item.fileName, format: item.fileFormat, url: item.fileUrl, size: Number(item.fileSize), groupId: item.dictId, group: item.dictName, uploadId: item.uploadId })) } return nm; }; export const fetchMaterialGroups = async () => { return (await axios.get(MATERIAL_GROUP_LIST)).map( (item) => ({ name: item.dictName, id: item.id, }) ) as MaterialGroup[]; }; 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 }); };