long
2024-06-26 911e0ed72a790ba054385ffe594262e123948691
提交 | 用户 | age
3ac5f2 1 /**
J 2  * 文件上传封装 - elementUI 用
3  */
4
5 import Axios from '../libs/axios'
6
7 // 文件上传路径
8 const uploadUrl = 'pc/requirement!ajaxAddRequirement'
9
10 export default {
6e089f 11   // 文件上传路径
L 12   uploadUrl,
13   // 文件上传方法
14   uploadFile(content) {
15     var formData = new FormData()
16     formData.append(content.filename, content.file)
17     Axios({
18       method: 'post',
19       headers: { 'Content-Type': 'multipart/form-data' },
20       url: content.action,
21       data: formData
22     }).then((res) => {
23       console.log('文件上传完成', res)
24       content.onSuccess(res.data, content)
25     }).catch((res) => {
26       if (res.response) {
27         content.onError('上传文件失败' + res.response.status + ',' + res.response.data, res)
28       } else if (res.request) {
29         content.onError('上传文件失败,服务器端无响应')
30       } else {
31         content.onError('上传文件失败,请求封装失败')
32       }
33     })
34   }
35 }