wk-image-content.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <view class="wk-image-content">
  3. <view class="image-file">
  4. <view v-for="(file, index) in list" :key="index" class="file-item">
  5. <wk-auth-img
  6. :src="file.url"
  7. :preview="preview"
  8. mode="aspectFit"
  9. class="pic"
  10. @click.native.stop />
  11. <image
  12. v-if="showDelete"
  13. :src="$static('images/icon/delete_fill.png')"
  14. class="icon"
  15. @click.stop="handleDelete(index)" />
  16. </view>
  17. <template v-if="len !== 0">
  18. <view
  19. v-for="i in len"
  20. :key="i | emptyKey"
  21. class="file-item"
  22. style="visibility: hidden" />
  23. </template>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. /**
  29. * 图片模块
  30. * @author yxk
  31. * @property {Array} list 图片列表
  32. * @property {Boolean} showDelete 是否可删除,默认false不可删除
  33. * @event {Function} delete 点击确认删除时触发
  34. */
  35. export default {
  36. name: 'WkImageContent',
  37. filters: {
  38. emptyKey(key) {
  39. return `empty_${key}`
  40. }
  41. },
  42. props: {
  43. list: {
  44. type: Array,
  45. default: () => []
  46. },
  47. showDelete: {
  48. type: Boolean,
  49. default: false
  50. },
  51. preview: {
  52. type: Boolean,
  53. default: true
  54. }
  55. },
  56. data() {
  57. return {}
  58. },
  59. computed: {
  60. len() {
  61. if (this.list.length === 0) return 0
  62. return (4 - (this.list.length % 4))
  63. }
  64. },
  65. methods: {
  66. handleDelete(index) {
  67. this.$emit('delete', index, this.list[index])
  68. },
  69. handleAdd() {
  70. this.$emit('add')
  71. }
  72. }
  73. }
  74. </script>
  75. <style scoped lang="scss">
  76. .wk-image-content {
  77. margin: 10rpx 0;
  78. .image-file {
  79. width: 100%;
  80. display: flex;
  81. align-items: center;
  82. justify-content: space-between;
  83. flex-wrap: wrap;
  84. // @include left;
  85. .file-item {
  86. position: relative;
  87. width: 150rpx;
  88. height: 150rpx;
  89. flex: 1;
  90. background-color: $main-bg;
  91. margin: 10rpx;
  92. @include center;
  93. .pic, wk-auth-img {
  94. width: 100%;
  95. height: 100%;
  96. // display: block;
  97. }
  98. .icon {
  99. position: absolute;
  100. top: -10rpx;
  101. right: -10rpx;
  102. width: 32rpx;
  103. height: 32rpx;
  104. border-radius: 50%;
  105. background-color: white;
  106. }
  107. }
  108. // .add {
  109. // width: 150rpx;
  110. // height: 150rpx;
  111. // color: #ccc;
  112. // font-size: 80rpx;
  113. // line-height: 1;
  114. // border: 1rpx dashed #ccc;
  115. // background-color: unset;
  116. // background-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="36" height="36" viewBox="0 0 52 52"><path fill="%23cccccc" d="M38.5 25H27V14c0-.553-.448-1-1-1s-1 .447-1 1v11H13.5c-.552 0-1 .447-1 1s.448 1 1 1H25v12c0 .553.448 1 1 1s1-.447 1-1V27h11.5c.552 0 1-.447 1-1s-.448-1-1-1z"/></svg>');
  117. // background-position: center;
  118. // background-repeat: no-repeat;
  119. // @include center;
  120. // }
  121. }
  122. }
  123. </style>