common.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import {
  2. mainUrl
  3. } from '@/http/baseUrl.js';
  4. export default {
  5. // 选择图片
  6. chooseImage(Num) {
  7. var list=[]
  8. console.log(Num)
  9. var maxNum=Num
  10. console.log(maxNum)
  11. uni.chooseImage({
  12. count: maxNum,
  13. success: function(e) {
  14. for (let i in e.tempFilePaths) {
  15. if (i >= (maxNum - list.length)) {
  16. break;
  17. }
  18. let fileName = '';
  19. // // #ifdef MP-BAIDU
  20. // fileName = e.tempFilePaths[i].substr(e.tempFilePaths[i].lastIndexOf('/') + 1);
  21. // // #endif
  22. uni.uploadFile({
  23. url:mainUrl+'/api/File',
  24. filePath: e.tempFilePaths[i],
  25. name: 'File',
  26. fileType: 'image',
  27. header:{
  28. "User-Agent":"apifox/1.0.0 (https://www.apifox.cn)"
  29. },
  30. formData: {
  31. File: JSON.stringify(e.tempFilePaths[i]),
  32. // file_name: fileName,
  33. },
  34. success(re) {
  35. let res=JSON.parse(re.data)
  36. if (res.code == 200) {
  37. console.log(res.data.file,2225)
  38. var list=[]
  39. list.push(res.data.file)
  40. console.log(list,899)
  41. } else {
  42. console.log(55)
  43. uni.showModal({
  44. title: '',
  45. content: res.msg,
  46. showCancel: false,
  47. });
  48. }
  49. },
  50. fail(e) {
  51. if (e && e.msg) {
  52. uni.showModal({
  53. title: '错误',
  54. content: e.msg,
  55. showCancel: false,
  56. });
  57. }
  58. },
  59. });
  60. }
  61. },
  62. complete: function(e) {
  63. // 触发事件 tabEvent
  64. return []
  65. }
  66. })
  67. return list
  68. }
  69. }