long
2024-06-26 911e0ed72a790ba054385ffe594262e123948691
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('上传文件失败,请求封装失败')
      }
    })
  }
}