123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- 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<Material> & { groupIds: number[], formats: string[] }
- >;
- export const fetchMaterialPage = async (params: MaterialPageProps) => {
- //
- const material = await axios.post<PagingResult<ServiceMaterial[]>>(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<ServiceMaterialGroup[]>(MATERIAL_GROUP_LIST)).map(
- (item) => ({
- name: item.dictName,
- id: item.id,
- })
- ) as MaterialGroup[];
- };
- export const addMaterial = (file: File) => {
- return axios<string>({
- method: "POST",
- url: ADD_MATERIAL,
- data: jsonToForm({ file }),
- headers: { ...UPLOAD_HEADS },
- });
-
- };
- export const delMaterial = (id: Material["id"]) => {
- return axios.post(DEL_MATERIAL, { id });
- };
|