uploadImg.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <view class="">
  3. <view class="grid grid-square flex-sub margin-top-50" :class="col?'col-'+col:'col-' + count">
  4. <view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="viewImage(index)">
  5. <image :src="imgList[index]" mode="aspectFill"></image>
  6. <view class="cu-tag bg-red" @tap.stop="delImg(index)">
  7. <text class='cuIcon-close' style="font-size: 18rpx;"></text>
  8. </view>
  9. </view>
  10. <view class="border" @click="uploadShopPics" v-if="imgList.length< count">
  11. <text class="cuIcon-add"></text>
  12. </view>
  13. </view>
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. props: {
  19. count: {
  20. type: Number,
  21. default: 4
  22. },
  23. col:String
  24. },
  25. data() {
  26. return {
  27. imgList: []
  28. };
  29. },
  30. methods: {
  31. changeImgList(data){
  32. this.imgList=data
  33. },
  34. async uploadShopPics() {
  35. let resp = await this.$mpi.chooseImage()
  36. let res=await this.$api.uploadFile(resp[0])
  37. this.imgList.push(res.data.data.link)
  38. this.$emit('click',this.imgList)
  39. },
  40. viewImage(index) {
  41. uni.previewImage({
  42. urls: this.imgList,
  43. current: index
  44. });
  45. },
  46. delImg(index) {
  47. let _this = this
  48. uni.showModal({
  49. title: '提示',
  50. content: '确定删除',
  51. success: (res) => {
  52. if (res.confirm) {
  53. _this.imgList.splice(index, 1)
  54. _this.$emit('delImg',this.imgList)
  55. }
  56. }
  57. })
  58. },
  59. }
  60. };
  61. </script>
  62. <style lang="scss" scoped>
  63. .border {
  64. border: 4rpx dashed #e1e1e1;
  65. position: relative;
  66. display: flex;
  67. justify-content: center;
  68. align-items: center;
  69. }
  70. .icon {
  71. width: 50rpx;
  72. height: 50rpx;
  73. position: absolute;
  74. left: 0;
  75. right: 0;
  76. bottom: 0;
  77. top: 0;
  78. margin: auto;
  79. }
  80. </style>