Files
portal-mini-front/src/api/file/index.ts
T
2026-10-27 23:26:21 +08:00

35 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import request from '@/utils/request'
import type { PageResult } from '@/types/common'
import type { FileQuery, FileUploadVO, FileVO } from '@/types/file'
// 叠加在 VITE_APP_BASE_API(/api/v1) 之上,经 Vite proxy 剥离 /api/v1 后命中后端 /api/admin/files
const BASE_URL = '/api/admin/files'
export const FileAPI = {
/** 分页查询文件列表 */
query(params: FileQuery) {
return request<PageResult<FileVO>>({ url: BASE_URL, method: 'get', params })
},
/**
* 上传单个文件(multipart/form-data)。
* 实例默认 Content-Type 为 application/json,此处显式置为 undefined,
* 由 axios 在 toJSON 阶段剔除该头,最终交由浏览器自动补全 boundary。
*/
upload(file: File) {
const formData = new FormData()
formData.append('file', file)
return request<FileUploadVO>({
url: `${BASE_URL}/upload`,
method: 'post',
data: formData,
headers: { 'Content-Type': undefined },
})
},
/** 删除文件(同时清理存储内容与元数据) */
delete(id: number) {
return request<{ id: number }>({ url: `${BASE_URL}/${id}`, method: 'delete' })
},
}