领峰UI库,封装一些经常使用到的组件,自定义样式,模块化js函数,调用简单快速上手。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

102 lines
2.0 KiB

  1. <template>
  2. <view class="content">
  3. <block v-if="show">
  4. <view class="image-item"
  5. v-for="(item, index) in list" :key="index"
  6. v-if="(index+1) < count"
  7. @click="clickImage(index)">
  8. <image :src="item"></image>
  9. </view>
  10. <view class="image-item image-surplus"
  11. :style="{'background': themeColor}"
  12. v-if="list.length > count">
  13. <text>{{ surplusNum }}</text>
  14. </view>
  15. </block>
  16. </view>
  17. </template>
  18. <script>
  19. export default {
  20. props: {
  21. list: {
  22. type: Array,
  23. default: function(){
  24. return [
  25. "https://picsum.photos/200",
  26. "https://picsum.photos/210",
  27. "https://picsum.photos/220",
  28. "https://picsum.photos/230",
  29. "https://picsum.photos/240"
  30. ]
  31. }
  32. },
  33. themeColor: {
  34. type: String,
  35. default: '#E21196'
  36. }
  37. },
  38. data(){
  39. return {
  40. show: false,
  41. count: 0
  42. }
  43. },
  44. computed: {
  45. surplusNum(){
  46. let num = this.$props.list.length - this.count;
  47. num = Math.floor(num);
  48. num = num > 99 ? '99+' : '+'+ num;
  49. return num;
  50. }
  51. },
  52. mounted(){
  53. let that = this;
  54. let info = uni.createSelectorQuery().in(this).select(".content");
  55. info.boundingClientRect(function(data) {
  56. let count = Math.floor( parseInt(data.width) / 23 - 1 ); // 预留一个位置出来
  57. that.count = count;
  58. that.show = true;
  59. }).exec();
  60. },
  61. methods: {
  62. clickImage(index){
  63. this.$emit('click', index);
  64. }
  65. }
  66. }
  67. </script>
  68. <style lang="scss" scoped="scoped">
  69. .content{
  70. display: flex;
  71. flex-wrap: nowrap;
  72. width: 100% !important;
  73. height: max-content;
  74. margin-top: 20rpx;
  75. padding: 0 !important;
  76. box-sizing: border-box;
  77. .image-item{
  78. width: 60rpx;
  79. height: 60rpx;
  80. border-radius: 50%;
  81. border: 2rpx solid #FFFFFF;
  82. overflow: hidden;
  83. &:nth-child(n+2){
  84. margin-left: -16rpx;
  85. }
  86. image{
  87. width: 100%;
  88. height: 100%;
  89. }
  90. }
  91. .image-surplus{
  92. border: none;
  93. display: flex;
  94. justify-content: center;
  95. align-items: center;
  96. color: #FFFFFF;
  97. font-size: 20rpx;
  98. }
  99. }
  100. </style>