jazz
2023-12-08 bf4dca5344dee1a84b75d9993f4dfc59de3f3ee9
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
/**
 * 文件上传封装 - elementUI 用
 */
 
import Axios from '../libs/axios'
 
// 文件上传路径
const uploadUrl = 'pc/requirement!ajaxAddRequirement'
 
export default {
    // 文件上传路径
    uploadUrl,
    // 文件上传方法
    uploadFile (content) {
        var formData = new FormData()
        formData.append(content.filename, content.file)
        Axios({
            method: 'post',
            headers: { 'Content-Type': 'multipart/form-data' },
            url: content.action,
            data: formData
        }).then((res)=>{
            console.log('文件上传完成', res)
            content.onSuccess(res.data, content)
        }).catch((res)=>{
            if (res.response) {
                content.onError('上传文件失败' + res.response.status + ',' + res.response.data, res)
            } else if (res.request) {
                content.onError('上传文件失败,服务器端无响应')
            } else {
                content.onError('上传文件失败,请求封装失败')
            }
        })
    }
}