人民医院前端

upload.vue 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <view>
  3. <uni-file-picker :value="imgUrlList" @select="handleSelect" @delete="handleDelete" class="uniFilePicker" limit="9" title="最多选择9张图片"/>
  4. </view>
  5. </template>
  6. <script>
  7. import indexConfig from '@/config/index.config';
  8. export default {
  9. data() {
  10. return {
  11. imgIdList:[],
  12. filePathsList: [],
  13. }
  14. },
  15. props: {
  16. imgUrlList: {
  17. type: Array,
  18. default(){
  19. }
  20. }
  21. },
  22. watch: {
  23. 'imgUrlList': function(){
  24. console.log(this.imgUrlList)
  25. this.imgUrlList.forEach((v,n) => {
  26. this.imgIdList.push(v.id)
  27. this.filePathsList.push({
  28. url: v.url
  29. })
  30. })
  31. }
  32. },
  33. methods: {
  34. handleSelect(res) { // 上传图片
  35. uni.showLoading({title: '加载中'})
  36. res.tempFilePaths.forEach((item) => {
  37. this.uploadImg(item)
  38. })
  39. },
  40. handleDelete(err) {
  41. const num = this.filePathsList.findIndex(v => v.url === err.tempFile.path);
  42. this.filePathsList.splice(num, 1);
  43. this.imgIdList.splice(num, 1)
  44. this.getImgData(this.imgIdList)
  45. },
  46. uploadImg(tempFilePaths){
  47. this.filePathsList.push({
  48. url: tempFilePaths
  49. })
  50. uni.uploadFile({
  51. header: {
  52. Authorization: uni.getStorageSync('Admin-Token')
  53. },
  54. url: indexConfig.baseUrl + "/FaultRepair/UploadFile",
  55. filePath: tempFilePaths,
  56. name: 'file',
  57. success: (res) => {
  58. console.log(11)
  59. uni.hideLoading()
  60. const data = JSON.parse(res.data)
  61. this.imgIdList.push(data.data[0].F_FileId)
  62. this.getImgData(this.imgIdList)
  63. },
  64. fail:(erro) => {
  65. }
  66. })
  67. // console.log(uni.getStorageInfoSync('Admin-Token'))
  68. // this.$http.upload("FaultRepair/UploadFile",{
  69. // filePath: tempFilePaths,
  70. // name: 'file',
  71. // header: {
  72. // Authorization: localStorage.getItem('Admin-Token')
  73. // }
  74. // // formData: {
  75. // // token: localStorage.getItem('Admin-Token')
  76. // // },
  77. // }).then((res)=>{
  78. // if(res.message.toLowerCase()==="成功"){
  79. // uni.hideLoading()
  80. // console.log(this.imgUrlList)
  81. // this.imgIdList.push(res.data[0].F_FileId)
  82. // this.getImgData(this.imgIdList)
  83. // }
  84. // }).catch((e) => {
  85. // console.log(e);
  86. // })
  87. },
  88. getImgData(data){
  89. this.$emit('post-string-data',data)
  90. },
  91. }
  92. }
  93. </script>
  94. <style>
  95. </style>