upload.js 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import {
  2. ACCESS_TOKEN,
  3. USER_NAME,
  4. USER_INFO
  5. } from "@/common/util/constants" // 拉取登录token,userName,userInfo
  6. import http from '@/common/service/http.js'
  7. function uploaditem(item) {
  8. let token = uni.getStorageSync(ACCESS_TOKEN)
  9. return new Promise((resolve, reject) => {
  10. const path = item
  11. uni.uploadFile({
  12. // url: http.apiHosp + 'ibps/platform/v3/file/upload/mobile', //仅为示例,非真实的接口地址
  13. url: http.apiHosp + '/ibps/platform/v3/file/upload', //仅为示例,非真实的接口地址
  14. filePath: path,
  15. name: 'file',
  16. formData: {
  17. 'ext': '.jpg'
  18. },
  19. header: {
  20. 'X-Authorization-access_token': token,
  21. 'X-Authorization-systemid': ''
  22. },
  23. success: (uploadFileRes) => {
  24. let data = JSON.parse(uploadFileRes.data)
  25. let obj = {
  26. id: data.data.id,
  27. name: data.data.fileName + '.' + data.data.ext,
  28. ext: data.data.ext,
  29. uuid: data.data.id
  30. }
  31. resolve(obj)
  32. }
  33. })
  34. })
  35. }
  36. function selectUpload(file) {
  37. return new Promise((resolve, reject) => {
  38. let list = []
  39. //读取文件大小
  40. var fileSize = file.size;
  41. if (fileSize > 1048576) {
  42. that.$message({
  43. type: 'error',
  44. showClose: true,
  45. duration: 3000,
  46. message: '文件大于1M!'
  47. });
  48. return
  49. }
  50. let that = this
  51. let eList = []
  52. file.tempFilePaths.forEach(item => {
  53. eList.push(uploaditem(item))
  54. })
  55. Promise.all(eList).then((res3) => {
  56. resolve(res3)
  57. })
  58. })
  59. }
  60. function getFilesList(ids, that = this) {
  61. return new Promise((resolve, reject) => {
  62. let lists = ids.split(",")
  63. let params = {}
  64. params.ids = lists
  65. that.$http.post("/ibps/platform/v3/file/attachment/transfer", params).then(res => {
  66. if (res.data.state == 200) {
  67. const data = res.data.data
  68. let list = []
  69. lists.forEach(item => {
  70. let obj = {
  71. id: item,
  72. name: data[item].fileName + '.' + data[item].ext,
  73. ext: data[item].ext,
  74. uuid: item
  75. }
  76. list.push(obj)
  77. })
  78. resolve(list)
  79. }
  80. })
  81. })
  82. }
  83. export default {
  84. getFilesList,
  85. selectUpload
  86. }