en-upload.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <template>
  2. <view class="">
  3. <view class="upload-image">
  4. <image class="wh-110 m-t20 m-r16" :style="[{width},{height}]" src="/static/img/logo.png" mode="aspectFill"
  5. v-for="(item,index) in 3" @click="onPreviewImage(index)">
  6. </image>
  7. <view class="add-image column-c justify-center m-t20" @click="addUpload()" v-if="is_add">
  8. <image class="wh-45" src="/static/img/task-details/Mask oup.png" mode=""></image>
  9. <text class="size-24 text-color-666">{{text}}</text>
  10. </view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. text: {
  18. type: String,
  19. default: '图片'
  20. },
  21. is_add: {
  22. type: Boolean,
  23. default: true
  24. },
  25. width: {
  26. type: String,
  27. default: '110rpx'
  28. },
  29. height: {
  30. type: String,
  31. default: '110rpx'
  32. },
  33. fileList: {
  34. type: Array,
  35. default: () => []
  36. }
  37. },
  38. data() {
  39. return {
  40. fileData: []
  41. }
  42. },
  43. methods: {
  44. addUpload() {
  45. uni.chooseImage({
  46. count: 6,
  47. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  48. success: function(res) {
  49. const tempFilePaths = res.tempFilePaths
  50. console.log(tempFilePaths)
  51. // tempFilePaths.forEach(item => {
  52. // uni.uploadFile({
  53. // url: 'https://www.example.com/upload', //仅为示例,非真实的接口地址
  54. // filePath: tempFilePaths[0],
  55. // name: 'file',
  56. // formData: {
  57. // 'user': 'test'
  58. // },
  59. // success: (uploadFileRes) => {
  60. // console.log(uploadFileRes.data);
  61. // }
  62. // })
  63. // })
  64. }
  65. });
  66. },
  67. onPreviewImage(index) {
  68. uni.previewImage({
  69. urls: this.fileList,
  70. current: index
  71. });
  72. }
  73. }
  74. }
  75. </script>
  76. <style lang="scss" scoped>
  77. .upload-image {
  78. display: flex;
  79. flex-wrap: wrap;
  80. }
  81. .add-image {
  82. width: 110rpx;
  83. height: 110rpx;
  84. border-radius: 10rpx;
  85. background: #F4F4F4;
  86. }
  87. </style>