需求:h5和小程序预览图片需要有当前第几张标识

1.小程序直接使用api:uni.previewImage

2.h5使用轮播图写一个组件

javascript 复制代码
<template>
    <view class="custom-image-preview" v-if="visible">
      <view class="overlay"></view>
      <swiper class="swiper" :current="currentIndex" @change="onSwiperChange">
        <swiper-item v-for="(image, index) in images" :key="index" @click="closePreview">
          <image style="width: 100%;height: 100%;" :src="image" mode="aspectFit" class="preview-image" :show-menu-by-longpress="true"></image>
        </swiper-item>
      </swiper>
      <view class="index-indicator">
        {{ currentIndex + 1 }} / {{ images.length }}
      </view>
    </view>
  </template>
  
  <script>
  export default {
    props: {
      images: {
        type: Array,
        required: true,
      },
      current: {
        type: Number,
        default: 0,
      },
    },
    data() {
      return {
        visible: false,
        currentIndex: 0,
      };
    },
    methods: {
      openPreview() {
        this.currentIndex = this.current;
        this.visible = true;
      },
      closePreview() {
        this.visible = false;
        this.$emit('close');
      },
      onSwiperChange(e) {
        this.currentIndex = e.detail.current;
      },
    },
    mounted() {
      this.openPreview();
    },
  };
  </script>
  
  <style scoped>
  .custom-image-preview {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
  }
  
  .overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
  }
  
  .swiper {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
  }
  
  .preview-image {
    width: 100%;
    height: 100%;
    object-fit: contain;
  }
  
  .index-indicator {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    color: #fff;
    font-size: 24px;
    background: rgba(0, 0, 0, 0.5);
    padding: 8px 16px;
    border-radius: 16px;
  }
  </style>
相关推荐
量化分析码农1 分钟前
【Python量化多因子实战 04】因子暴露不是 alpha:市值与行业中性化实战
前端·后端
不可能片场34 分钟前
Electron 发布 正文写入的三条通道与读回口径
前端·electron
jerrywus44 分钟前
让 AI 帮你部署 Vercel,报错了也不用手动搬日志
前端·agent·mcp
补码缩写1 小时前
11 行 Python 拆 PNG 块,解压后的字节数能手算
前端
coding漫漫长路1 小时前
PNG压缩先看图是哪一类,先无损再量化多半白做
前端
用户257680763211 小时前
搜「洗牙」为什么搜不到「洁治」
前端
费曼学习法1 小时前
Agent 死循环的根因不在模型:错误分类、退避、熔断、快照四层实现
前端
修炼的dance1 小时前
同一张PNG换五种压法,体积差在颜色数上
前端
Lank_M1 小时前
PNG 有损压缩省下的体积,大头不在 deflate
前端
用户老李1 小时前
相机模型与标定自学教程 02:外参 \[R | t] 与完整投影链路
前端