All files company.ts

100% Statements 18/18
100% Branches 0/0
100% Functions 9/9
100% Lines 18/18

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121                                                                                                  1x 1x       1x 2x       1x 2x           1x       2x               1x 1x       1x 1x                 1x                   3x           1x 1x       1x 1x          
import { http } from "@/utils/http";
import type { BaseResponse } from "./base";
// ============ 类型定义 ============
/** 公司文件夹 */
export type CompanyFolder = {
  id: string;
  name: string;
  count: number;
  createTime: string;
  description?: string;
  category?: string;
};
 
/** 公司文件 */
export type CompanyFile = {
  id: string;
  fileName: string;
  fileType: string;
  fileSize: string;
  uploadTime: string;
  folderId: string;
  companyName?: string;
  fileCategory: string;
  expireDate?: string;
  description?: string;
};
 
/** API基础响应 */
 
/** 文件夹列表响应 */
export type FoldersResponse = BaseResponse<CompanyFolder[]>;
 
/** 文件列表响应 */
export type FilesResponse = BaseResponse<CompanyFile[]>;
 
/** 上传文件响应 */
export type UploadFileResponse = BaseResponse<{
  uploadedCount: number;
}>;
 
/** 创建/更新文件夹请求 */
export type FolderRequest = {
  name: string;
  description?: string;
  category?: string;
};
 
// ============ API函数 ============
/** 获取文件夹列表 */
export const getCompanyFolders = () => {
  return http.request<FoldersResponse>("get", "/api/company/folders");
};
 
/** 获取文件列表 */
export const getCompanyFiles = (params?: { folderId?: string }) => {
  return http.request<FilesResponse>("get", "/api/company/files", { params });
};
 
/** 创建文件夹 */
export const createCompanyFolder = (data: FolderRequest) => {
  return http.request<BaseResponse<CompanyFolder>>("post", "/api/company/folders", {
    data
  });
};
 
/** 更新文件夹 */
export const updateCompanyFolder = (
  id: string,
  data: Partial<FolderRequest>
) => {
  return http.request<BaseResponse<CompanyFolder>>(
    "put",
    `/api/company/folders/${id}`,
    { data }
  );
};
 
/** 删除文件夹 */
export const deleteCompanyFolder = (id: string) => {
  return http.request<BaseResponse>("delete", `/api/company/folders/${id}`);
};
 
/** 上传公司文件 */
export const uploadCompanyFile = (data: FormData) => {
  return http.request<UploadFileResponse>("post", "/api/company/files/upload", {
    data,
    headers: {
      "Content-Type": "multipart/form-data"
    }
  });
};
 
/** 更新公司文件元信息 */
export const updateCompanyFile = (
  id: string,
  data: {
    companyName: string;
    fileCategory: string;
    expireDate?: string;
    description?: string;
    folderId?: number | null;
  }
) => {
  return http.request<BaseResponse>("put", `/api/company/files/${id}`, {
    data
  });
};
 
/** 删除公司文件 */
export const deleteCompanyFile = (id: string) => {
  return http.request<BaseResponse>("delete", `/api/company/files/${id}`);
};
 
/** 下载公司文件(文件 URL 为 /api/company-files/{fileUrl}) */
export const downloadCompanyFile = (id: string) => {
  return http.request<BaseResponse<{ fileName: string; url: string }>>(
    "get",
    `/api/company/files/${id}/download`
  );
};