c-form-image-upload.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <view class="content">
  3. <view class="img-rpeview" v-for="(img, index) in imgs" @click="preview(index, imgs)">
  4. <image :src="img" mode="aspectFill"></image>
  5. <view class="close-tab" @click.stop="remove(index)">
  6. <u-icon name="close" color="#FD8701" size="24rpx"></u-icon>
  7. </view>
  8. </view>
  9. <view class="img-add" @click="choiceImg" v-if="imgs.length < 3">
  10. <u-icon name="plus" color="#d7d7d7" size="62rpx"></u-icon>
  11. <text>{{imgs.length == 0 ? '图片上传' : '图片补充'}}</text>
  12. </view>
  13. <w-compress ref='wCompress' />
  14. </view>
  15. </template>
  16. <script>
  17. export default {
  18. name:"c-form-image-upload",
  19. data() {
  20. return {
  21. imgs: [],
  22. };
  23. },
  24. props: {
  25. count: {
  26. type: Number,
  27. default: 3
  28. },
  29. value: {
  30. type: Array,
  31. default() {
  32. return []
  33. }
  34. }
  35. },
  36. computed:{
  37. },
  38. watch: {
  39. value(val){
  40. this.imgs = val
  41. }
  42. },
  43. mounted() {
  44. this.imgs = this.value
  45. },
  46. methods: {
  47. choiceImg() {
  48. let that = this;
  49. that.$tools.chooseImage(this.count - this.imgs.length).then(res => {
  50. this.$refs.wCompress.start(res).then(res => {
  51. this.$tools.uploadImageAll(res).then(res => {
  52. this.imgs = this.imgs.concat(res)
  53. this.$emit('input', this.imgs);
  54. })
  55. })
  56. });
  57. },
  58. remove(index) {
  59. this.imgs.splice(index, 1)
  60. this.$emit('input', this.imgs);
  61. },
  62. preview(index, urls) {
  63. this.$tools.previewImage(urls, index)
  64. }
  65. },
  66. }
  67. </script>
  68. <style lang="scss" scoped>
  69. .content{
  70. padding-top: 0rpx;
  71. display: flex;
  72. flex-wrap: wrap;
  73. .img-rpeview{
  74. position: relative;
  75. width: 144rpx;
  76. height: 144rpx;
  77. image{
  78. width: 100%;
  79. height: 100%;
  80. }
  81. margin-right: 20rpx;
  82. .close-tab{
  83. position: absolute;
  84. right: -15rpx;
  85. top: -15rpx;
  86. display: flex;
  87. align-items: center;
  88. justify-content: center;
  89. padding: 10rpx;
  90. width: 15rpx;
  91. height: 15rpx;
  92. border-radius: 50%;
  93. color: #FD8701;
  94. z-index: 2;
  95. border: 1px solid #FD8701;
  96. box-sizing: content-box;
  97. background-color: #fff;
  98. }
  99. }
  100. .img-add{
  101. display: flex;
  102. align-items: center;
  103. justify-content: center;
  104. flex-direction: column;
  105. width: 144rpx;
  106. height: 144rpx;
  107. background-color: #fff;
  108. box-shadow: 0 0 14px 1px #eaeaea;
  109. font-size: 19rpx;
  110. text{
  111. margin-top: 12rpx;
  112. color: #cfcfcf;
  113. }
  114. }
  115. }
  116. </style>