uploadImg.js 968 B

1234567891011121314151617181920212223242526272829303132333435
  1. // https://blog.csdn.net/WeiflR10/article/details/122978004
  2. import { commonConfig } from '../common/config';
  3. //直接导出这个方法
  4. export function uploadImg(event,fileList) {
  5. return new Promise((resolve,reject)=>{
  6. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  7. let lists = [].concat(event.file)
  8. let fileListLen = fileList.length
  9. lists.map((item) => {
  10. fileList.push({
  11. ...item
  12. })
  13. })
  14. // 这块把uview的改了一下 不用单独封装上传功能
  15. for (let i = 0; i < lists.length; i++) {
  16. uni.uploadFile({
  17. url: commonConfig.uploadFileUrl, // 测试地址
  18. filePath: lists[i].url, // 文件路径
  19. name: 'file',
  20. formData: {
  21. bucket: 'xusfood'
  22. },
  23. success: (res) => {
  24. let resolveData = {
  25. data: res.data,
  26. fileListLen: fileListLen
  27. }
  28. // 成功之后返回resolveData
  29. resolve(resolveData);
  30. fileListLen++
  31. }
  32. });
  33. }
  34. })
  35. }