dataease-dm/core/core-frontend/src/api/staticResource.ts

46 lines
1.2 KiB
Java
Raw Normal View History

2023-10-23 22:00:14 +08:00
import request from '@/config/axios'
import { guid } from '@/views/visualized/data/dataset/form/util.js'
import { ElMessage } from 'element-plus-secondary'
const staticResourcePath = '/static-resource/'
export const uploadFile = (fileId: number | string, param) =>
request.post({
url: '/staticResource/upload/' + fileId,
headersType: 'multipart/form-data',
data: param
})
export function beforeUploadCheck(file) {
const isImage = file.type.startsWith('image/')
const isSizeValid = file.size / 1024 / 1024 < 15 // 15MB
if (!isImage) {
ElMessage.error('请上传图片')
return false
}
if (!isSizeValid) {
ElMessage.error('图片大小不能超过15M')
return false
}
return true
}
export function uploadFileResult(file, callback) {
const fileId = guid()
const fileName = file.name
const newFileName = fileId + fileName.substr(fileName.lastIndexOf('.'), fileName.length)
const fileUrl = staticResourcePath + newFileName
const param = new FormData()
param.append('file', file)
2024-02-19 16:14:26 +08:00
return uploadFile(fileId, param).then(() => {
2023-10-23 22:00:14 +08:00
callback(fileUrl)
})
}
export function findResourceAsBase64(params) {
return request.post({
url: '/staticResource/findResourceAsBase64',
data: params
2023-10-23 22:00:14 +08:00
})
}