2025-09-26 10:59:37 +08:00
|
|
|
|
import createAxios from '@/utils/request'
|
2025-12-15 10:35:34 +08:00
|
|
|
|
import { ElMessage } from 'element-plus'
|
2025-09-26 10:59:37 +08:00
|
|
|
|
const SYSTEM_PREFIX = '/system-boot'
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 上传文件
|
|
|
|
|
|
* @param file
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const uploadFile = (file: any, path: string) => {
|
2026-01-04 09:01:32 +08:00
|
|
|
|
const regex = /\[|\]/g
|
|
|
|
|
|
// 替换规则:[ 换成 (,] 换成 )
|
|
|
|
|
|
|
|
|
|
|
|
const newFile = new File(
|
|
|
|
|
|
[file], // 原文件的二进制内容
|
|
|
|
|
|
file.name.replace(regex, match => (match === '[' ? '(' : ')')), // 新的文件名
|
|
|
|
|
|
{
|
|
|
|
|
|
type: file.type, // 复用原文件的MIME类型
|
|
|
|
|
|
lastModified: file.lastModified // 复用最后修改时间
|
|
|
|
|
|
}
|
|
|
|
|
|
)
|
|
|
|
|
|
|
2025-09-26 10:59:37 +08:00
|
|
|
|
let form = new FormData()
|
2026-01-04 09:01:32 +08:00
|
|
|
|
form.append('file', newFile)
|
2025-09-26 10:59:37 +08:00
|
|
|
|
form.append('path', path)
|
|
|
|
|
|
return createAxios({
|
|
|
|
|
|
url: SYSTEM_PREFIX + '/file/upload',
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
'Content-Type': 'multipart/form-data'
|
|
|
|
|
|
},
|
|
|
|
|
|
data: form
|
2025-12-15 10:35:34 +08:00
|
|
|
|
}).then(res => {
|
|
|
|
|
|
if (res.code == `A0000`) {
|
|
|
|
|
|
ElMessage.success('上传成功!')
|
|
|
|
|
|
return res
|
|
|
|
|
|
}
|
2025-09-26 10:59:37 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 删除文件
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const deleteFile = (filePath: string) => {
|
|
|
|
|
|
let form = new FormData()
|
|
|
|
|
|
form.append('filePath', filePath)
|
|
|
|
|
|
return createAxios({
|
|
|
|
|
|
url: SYSTEM_PREFIX + '/file/delete',
|
|
|
|
|
|
method: 'POST',
|
|
|
|
|
|
data: form
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 下载文件
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const downloadFile = (filePath: any) => {
|
|
|
|
|
|
// let form = new FormData()
|
|
|
|
|
|
// form.append('filePath', filePath)
|
|
|
|
|
|
return createAxios({
|
|
|
|
|
|
url: SYSTEM_PREFIX + '/file/download',
|
|
|
|
|
|
method: 'GET',
|
|
|
|
|
|
params: filePath,
|
|
|
|
|
|
responseType: 'blob'
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取文件的短期url展示
|
|
|
|
|
|
*/
|
2025-12-15 10:35:34 +08:00
|
|
|
|
export const getFileUrl = (params: any) => {
|
2025-09-26 10:59:37 +08:00
|
|
|
|
let form = new FormData()
|
|
|
|
|
|
// form.append('filePath', filePath)
|
|
|
|
|
|
return createAxios({
|
|
|
|
|
|
url: SYSTEM_PREFIX + '/file/getFileUrl',
|
|
|
|
|
|
method: 'get',
|
|
|
|
|
|
params
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 根据获取文件的一个短期url及文件名
|
|
|
|
|
|
*/
|
|
|
|
|
|
export const getFileNameAndFilePath = (query: any) => {
|
|
|
|
|
|
return createAxios({
|
|
|
|
|
|
url: SYSTEM_PREFIX + '/file/getFileVO',
|
|
|
|
|
|
method: 'GET',
|
|
|
|
|
|
params: query
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|