upload.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import request from '../utils/request.js'
  2. class uploadImg extends request {
  3. static async uploadCommentImgs(tempFilePaths) {
  4. wx.showLoading({
  5. title: '上传图片中...',
  6. mask: true
  7. });
  8. var uploads = [];
  9. tempFilePaths.forEach((item, i) => {
  10. uploads[i] = request.upload(`${this.BASE_URL}Common/upload`, 'image', item)
  11. }
  12. );
  13. var imgUrls = [];
  14. Promise.all(uploads).then(res => {
  15. //图片上传完成
  16. // resolve(res)
  17. console.log(res)
  18. wx.hideLoading()
  19. res.forEach(function (item) {
  20. imgUrls.push(item.data.url)
  21. })
  22. return imgUrls;
  23. }).catch(err => {
  24. // reject(err)
  25. console.log(err)
  26. wx.hideLoading()
  27. wx.showToast({
  28. title: '上传失败请重试',
  29. icon: 'none'
  30. })
  31. })
  32. }
  33. static async uploadAvatar(tempFilePaths) {
  34. wx.showLoading({
  35. title: '上传图片中...',
  36. mask: true
  37. });
  38. const res = await request.upload(`${this.BASE_URL}Common/upload`, 'image', tempFilePaths)
  39. wx.hideLoading()
  40. return res.data.url
  41. }
  42. }
  43. export default uploadImg