• 随手记:uniapp图片展示,剩余的堆叠


    UI效果图:

     

    实现思路:
    循环图片数组,只展示几张宽度就为几张图片+边距的宽度,剩下的图片直接堆叠展示

    点击预览的时候传入当前的下标,如果是点击堆叠的话,下标从堆叠数量开始计算
     

    1. <template>
    2. <!-- 查看图片展示 -->
    3. <view class="image pos-re" :style="imageStyle">
    4. <u-image :width="width" :height="height" :src="formatImgUrl(item)" border-radius="8" :style="imgStyle" class="img" v-for="(item, index) in imagesList" @click="previewImage(0, index,item)"></u-image>
    5. <view class="mask pos-ab" :style="maskStyle" v-if="imagesList.length > 4" @click="previewImage(1, 3)">
    6. <u-icon name="plus" size="28" color="#FFFFFF"></u-icon>
    7. {{imagesList.length+1 - imgNum }}
    8. </view>
    9. </view>
    10. </template>
    11. <script>
    12. export default {
    13. name:"showImage",
    14. props:{
    15. imagesList: {
    16. type: Array,
    17. default: () => {
    18. return []
    19. },
    20. },
    21. width: {
    22. type: [String, Number],
    23. default: 104,
    24. },
    25. height: {
    26. type: [String, Number],
    27. default: 104,
    28. },
    29. // 图片之间的右边距
    30. marginRight: {
    31. type: [String, Number],
    32. default: 10,
    33. },
    34. // 保留照片数
    35. imgNum: {
    36. type: [String, Number],
    37. default: 4,
    38. }
    39. },
    40. data() {
    41. return {
    42. baseFileUrl: process.uniEnv.BASE_FILEURL,
    43. imageStyle: {
    44. 'width': '0rpx',
    45. 'overflow': 'hidden'
    46. },
    47. imgStyle: {
    48. 'margin-right': '0rpx',
    49. },
    50. maskStyle: {
    51. width: '0rpx',
    52. height: '0rpx'
    53. },
    54. }
    55. },
    56. onLoad() {
    57. },
    58. watch: {
    59. imagesList:{
    60. handler(nV,oV){
    61. this.imgStyle.marginRight = this.marginRight + 'rpx';
    62. this.imageStyle.width = (this.width * this.imgNum ) + (this.marginRight * this.imgNum-1) + 'rpx';
    63. this.maskStyle.width = this.width + 'rpx';
    64. this.maskStyle.height = this.height + 'rpx';
    65. this.maskStyle.lineHeight = this.height + 'rpx';
    66. this.maskStyle.right = 0 + 'rpx';
    67. },
    68. immediate: true,
    69. deep: true
    70. }
    71. },
    72. methods: {
    73. formatImgUrl(img) {
    74. if (!img || img == '/static/images/image_noData.png') {
    75. return '/static/images/image_noData.png'
    76. }
    77. let imgs = img.split(',');
    78. return this.baseFileUrl + imgs[0]
    79. },
    80. previewImage(num, index, item) {
    81. let arr = [];
    82. if(this.imagesList.length){
    83. this.imagesList.forEach(item => {
    84. arr.push(this.baseFileUrl + item )
    85. })
    86. }
    87. if(!num) {
    88. uni.previewImage({
    89. current:index,
    90. urls: arr
    91. })
    92. }else{
    93. uni.previewImage({
    94. current: 3,
    95. urls: arr
    96. })
    97. }
    98. }
    99. }
    100. }
    101. </script>
    102. <style lang="scss" scoped>
    103. .image{
    104. display: flex;
    105. .img{
    106. flex-shrink: 0;
    107. }
    108. .mask{
    109. text-align: center;
    110. background: '#1F2533';
    111. border-radius: 8rpx;
    112. opacity: 0.9;
    113. font-size: 28rpx;
    114. color: #FFFFFF;
    115. }
    116. }
    117. </style>

    成品展示:

  • 相关阅读:
    新买的笔记本电脑分区,笔记本分区分错了怎么重新分
    python关闭科学模式
    [第四篇]——Windows Docker 安装
    周期性触发的自定义触发器
    Android 线程同步(一)
    Hadoop 集群相关知识点
    关于中间件技术
    NumPy基础知识
    前端知识点个人实践
    5招教你提升华为手机的续航能力,只需打开这几个设置即可
  • 原文地址:https://blog.csdn.net/weixin_63515766/article/details/139656884