file.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { baseUrl, tenantId, apiPath } from '@/utils/config'
  2. // const uploadApi = {
  3. // file: '/menduner/system/file/upload',
  4. // img: '/infra/file/upload'
  5. // }
  6. // 文件上传
  7. export const uploadFile = (file, path) => {
  8. uni.showLoading({
  9. title: '上传中'
  10. })
  11. return new Promise((resolve, reject) => {
  12. uni.uploadFile({
  13. url: baseUrl + apiPath + '/menduner/system/file/upload',
  14. filePath: file,
  15. formData: {
  16. path
  17. },
  18. name: 'file',
  19. header: {
  20. Accept: '*/*',
  21. 'tenant-id': tenantId,
  22. 'Authorization': 'Bearer ' + uni.getStorageSync('token'),
  23. 'Accept-Language': 'zh_CN',
  24. 'terminal': 'mp-weixin'
  25. },
  26. success: (uploadFileRes) => {
  27. let result = JSON.parse(uploadFileRes.data)
  28. if (result.error === 1) {
  29. uni.showToast({
  30. icon: 'none',
  31. title: result.msg
  32. })
  33. } else {
  34. return resolve(result)
  35. }
  36. },
  37. fail: (error) => {
  38. console.log('上传失败:', error)
  39. return resolve(false)
  40. },
  41. complete: () => {
  42. uni.hideLoading()
  43. }
  44. })
  45. })
  46. }