uniapp 自定义图片预览组件PicturePreview(Vue3、组合式、ts)

embedded/2024/10/19 19:43:10/

组件

<template><view class="preview-container" :style="{display: show ? 'block' : 'none'}"><view class="f-c-c close" @click="close"><YcSvgIcon name="close" width="15rpx" height="15rpx" color="#ffffff"></YcSvgIcon></view><swiper class="swiper" :indicator-dots="true" :autoplay="false" :interval="5000" :duration="500":circular="true" @change="onSwiperChange" :current="currentIndex" @transition="scale = 1"><swiper-item v-for="(image, index) in images" :key="index"><movable-area scale-area class="movable-area"><movable-view class="movable-view" :scale="true" :scale-min="1" :scale-max="1" :scale-value="scale"@scale="onScale" out-of-bounds><image class="preview-image" :src="image" mode="aspectFit" @click="close" /></movable-view></movable-area></swiper-item></swiper></view>
</template><script setup lang="ts">javascript">import { ref } from 'vue';const images = ref<Array<string>>([]);const currentIndex = ref(0);const show = ref(false);const scale = ref(1);function onSwiperChange(e : any) {scale.value = 1;currentIndex.value = e.detail.current;}const onScale = (e : any) => {scale.value = e.detail.scale;console.log(scale.value);}const close = () => {images.value = [];currentIndex.value = 0;show.value = false;}const previewImage = (imgs : Array<string>, index : number) => {images.value = imgs;currentIndex.value = index;show.value = true;}defineExpose({previewImage,})
</script><style scoped lang="scss">.preview-container {position: fixed;top: 0;left: 0;width: 100vw;height: 100vh;overflow: hidden;z-index: 99;background-color: rgba(0, 0, 0, 0.8);.close {position: absolute;top: 25rpx;right: 25rpx;z-index: 999;}.swiper {width: 100%;height: 100%;.movable-area {width: 100%;height: 100%;.movable-view {width: 100%;height: 100%;}}.preview-image {width: 100%;height: 100%;}}}
</style>

组件使用

<template><view class="photography-page view-container"><YcPicturePreview ref="preview" /></view>
</template><script setup lang="ts">javascript">import { ref, computed } from 'vue';import YcPicturePreview from "@/components/YcPicturePreview/YcPicturePreview.vue";let preview = ref<InstanceType<typeof YcPicturePreview>>();const photos = ref([{id: 1,url: 'https://img2.baidu.com/it/u=1028011339,1319212411&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=313',selected: false,},{id: 2,url: 'https://img0.baidu.com/it/u=1668365367,2821596851&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=684',selected: true,},{id: 3,url: 'https://img0.baidu.com/it/u=1668365367,2821596851&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=684',selected: false,},{id: 4,url: 'https://img0.baidu.com/it/u=1668365367,2821596851&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=684',selected: false,},{id: 5,url: 'https://img0.baidu.com/it/u=1668365367,2821596851&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=684',selected: false,},{id: 6,url: 'https://img0.baidu.com/it/u=1668365367,2821596851&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=684',selected: false,},{id: 7,url: 'https://img0.baidu.com/it/u=1668365367,2821596851&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=684',selected: false,},{id: 8,url: 'https://img0.baidu.com/it/u=1668365367,2821596851&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=684',selected: false,},{id: 9,url: 'https://img0.baidu.com/it/u=1668365367,2821596851&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=684',selected: false,},{id: 10,url: 'https://img0.baidu.com/it/u=1668365367,2821596851&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=684',selected: false,},{id: 11,url: 'https://img0.baidu.com/it/u=1668365367,2821596851&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=684',selected: false,},])const photoUrls = computed(() => {return photos.value.map(item => item.url)})const showBig = (currentIndex : number, list : Array<string>) => {preview.value?.previewImage(list, currentIndex);}
</script><style lang="scss" scoped>// ...
</style>

http://www.ppmy.cn/embedded/93335.html

相关文章

python游戏开发之五子棋游戏制作

五子棋是一种源自中国的传统棋类游戏&#xff0c;起源可以追溯到古代。它是一种两人对弈的游戏&#xff0c;使用棋盘和棋子进行。棋盘通常是一个 1515 的网格&#xff0c;棋子分为黑白两色&#xff0c;双方轮流在棋盘上落子。游戏的目标是通过在棋盘上落子&#xff0c;使自己的…

【GCC】基于延迟梯度的带宽估计:速率控制状态机的理解

这部分是一个难点,决定了目标码率。参考了很多大神的分析,大神都很牛x,分析的都很到位。回顾下之前的学习,发现还是在 基于延迟的排队梯度这块,其根本目的就是本文的预估一个下一步的码率出来。之前的文章都在分析“基于延迟梯度的带宽估计” 的一些原理。接收端在RTCP中增…

Spring Boot 3.0 热部署

idea开发环境下的spring boot 3.0热部署启用非常简单&#xff0c;并没有网上教程讲的需要对idea做一些设置。 只需引入依赖&#xff1a; developmentOnly org.springframework.boot:spring-boot-devtools其他不需要做任何设置。 服务启动中&#xff0c;改了代码或配置后&…

C++ 重要特性探究

shared_from_this 使用分析 场景 类的成员函数需要获取指向自身的shared_ptr的时候类成员函数传递shared_ptr给其他函数或者对象的时候&#xff0c;目的是为了管理对象生命周期使用方法 首先类必须继承 std::enable_shared_from_this<T>必须使用 shared_from_this 获取指…

如何在IDEA上使用JDBC编程【保姆级教程】

目录 前言 什么是JDBC编程 本质 使用JDBC编程的优势 JDBC流程 如何在IEDA上使用JDBC JDBC编程 1.创建并初始化数据源 2.与数据库服务器建立连接 3.创建PreparedStatement对象编写sql语句 4.执行SQL语句并处理结果集 executeUpdate executeQuery 5.释放资源 前言 在…

Flink开发:Java与Scala的抉择——深度剖析与实战考量

Flink开发&#xff1a;Java与Scala的抉择——深度剖析与实战考量 在大数据处理与流计算领域&#xff0c;Apache Flink以其高性能、低延迟和精确的状态管理而著称&#xff0c;成为了众多企业和开发者首选的分布式流处理框架。然而&#xff0c;在选择Flink作为技术栈时&#xff…

git:安装 / 设置环境变量 / 使用

一、下载 https://github.com/git-for-windows/git/releases/download/v2.45.1.windows.1/Git-2.45.1-64-bit.exe 下载成功-双击打开 下一步-Next 二、添加环境变量 1、找到git安装地址 win r cmd 回车 where git 设置环境变量 C:\Program Files\Git\cmd\git.exe 此电…

【网络编程】字节序,IP地址、点分十进制、TCP与UDP的异同

记录学习&#xff0c;思维导图绘制 目录 1、字节序​编辑 2、IP地址 3、点分十进制 4、TCP与UDP的异同 1、字节序 2、IP地址 3、点分十进制 4、TCP与UDP的异同