common.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import utils from "../js/utils.js";
  2. /**
  3. * 公共接口
  4. */
  5. module.exports = {
  6. /**
  7. * 上传文件
  8. * @returns {Promise<*>}
  9. */
  10. uploadFile(handler, filePath, data = {}, fileType = 'image') {
  11. uni.uploadFile({
  12. url: fun.SITE + 'api/wx/wxpayApplyImage',
  13. header: {
  14. 'token': uni.getStorageSync('token'),
  15. "Content-Type": "multipart/form-data"
  16. },
  17. fileType: fileType,
  18. filePath: filePath,
  19. formData: data,
  20. name: 'file',
  21. success: (res) => {
  22. if (res.statusCode == 413) {
  23. this.modalDo(true, '图片太大了,请压缩后再重新上传')
  24. return
  25. }
  26. let data = JSON.parse(res.data)
  27. if (data.status == 1) {
  28. let result = data.result
  29. this.ocrResult(type, result, lists)
  30. return
  31. } else {
  32. this.modalDo(true, '识别有误,提交可能影响审核,建议重新上传更清晰的图片')
  33. return
  34. }
  35. },
  36. fail: (res) => {
  37. console.log('fail res', res)
  38. },
  39. complete: (uploadFileRes) => {
  40. this.showPopup = false
  41. },
  42. })
  43. },
  44. }