1、安装vue-pdf插件,swiper插件、clipboard

npm install vue-pdf -s
npm install swiper -S
npm install clipborad -S

2、使用,标题头提取的组件,slot占位

<template>
<div class="pagepdf">
<page-title :headerSetting="headerSetting">
<!-- header_left就插槽名,不用默认就用slot -->
<div slot="header_left" class="header_ico">
<img class="goBackIcon" :src="goBackIcon" alt="" />
</div>
<div slot="header_center">pdf</div>
<!-- header_right就插槽名,不用默认就用slot -->
<div slot="header_right" class="header_right copyDom" @click="copy(url)">
复制连接
</div>
</page-title> <div class="tools" v-show="lists.length>0">
<div class="swiper-button-prev mr10">上一页</div>
<div class="page">{{currentId}}/{{pageTotalNum}} </div>
<div class="swiper-button-next mr10">下一页</div>
</div>
<div class="">
<div id="tabApp1" class="swiper-container" style="visibility: hidden;">
<div class="swiper-wrapper" ref="swiperWrapper0">
<div class="swiper-slide" v-for="(item, index) in lists" :class="{ active: currentId == item.id }"
:key="index">
</div>
</div>
</div>
</div>
<div id="tabContain" class="tabContain swiper-container" v-show="lists.length>0">
<div class="swiper-wrapper"> <div class="swiper-slide" v-for="(item, index) in lists" :key="index">
<div>
<pdf :id="'pdfPreview'+index
" :src="pdfSrc" :page="index+1" class="pdf" ref="wrapper1" @progress="loadedRatio = $event"
@num-pages="pageTotalNum=$event" @error="pdfError($event)" @link-clicked="page = $event"> </pdf>
</div>
</div>
</div>
</div>
</div>
</template> <script>
import ClipboardJS from "clipboard";
import "swiper/dist/css/swiper.min.css";
import Swiper from "swiper";
import pdf from "vue-pdf";
export default {
components: {
pdf,
pageTitle: (resolve) => require(["@/components/title"], resolve),
},
data() {
return {
titleName: 'pdf',
url:'https://aaeasy-file.newbanker.cn/pic/testforyuhan/裴士杰的专属报告_2021-11-02_11_17_21.pdf',
vuePdf: null,
numPages: 1, // pdf 文件总页数
pageNum: 1,
pageTotalNum: '',
page: 1,
pageRotate: '',
scale: 100,
// swiper
mySwiper: null, //swiper实例
swiperWidth: 0, //swiper可视宽度
maxTranslate: "", //最大的滑动距离
maxWidth: "",
slide: {
offsetLeft: 0,
clientWidth: 0,
},
slideLeft: 0,
slideWidth: 0,
slideCenter: 0,
nowTlanslate: 0,
pageSwiper: {},
currentId: 1,
lists: [],
isHide: true,
// 头部浮层
headerSetting: {
backgroundColor: "transparent",
},
goBackIcon: require("@/assets/imgs/goback.png"),
pdfSrc:'',
}
},
mounted() {
let that = this;
that.initPdf(that.url);
that.mySwiper = new Swiper("#tabApp1", {
freeMode: true,
freeModeMomentumRatio: 0.5,
slidesPerView: "auto",
resistanceRatio: 0.7,
setWrapperSize: true,
observer: true,
observeParents: true,
loop: true,
on: {
tap: function(swiper) {
// if (this.currentId <= this.pageTotalNum) {
that.swiperWidth = that.$refs.swiperWrapper0.clientWidth;
that.maxTranslate = that.mySwiper.maxTranslate();
that.maxWidth = -that.maxTranslate + that.swiperWidth / 2; if ((that.currentId) == that.lists[this.clickedIndex].id) {
return;
}
that.currentId = that.lists[this.clickedIndex].id;
that.slide = this.slides[this.clickedIndex];
that.slideLeft = that.slide.offsetLeft;
that.slideWidth = that.slide.clientWidth;
that.slideCenter = that.slideLeft + that.slideWidth / 2;
that.mySwiper.setTransition(300);
if (that.slideCenter < that.swiperWidth / 2) {
that.mySwiper.setTranslate(0);
} else if (that.slideCenter > that.maxWidth) {
that.mySwiper.setTranslate(that.maxTranslate);
} else {
var nowTlanslate = that.slideCenter - that.swiperWidth / 2;
that.mySwiper.setTranslate(-nowTlanslate);
}
that.pageSwiper.slideTo(this.clickedIndex, 200, false);
},
},
});
//swiper里边内容
that.pageSwiper = new Swiper("#tabContain", {
autoplay: false,
direction: "horizontal", // 切换选项
resistanceRatio: 0,
paginationClickable: true,
watchSlidesProgress: true,
setWrapperSize: true,
observer: true,
observeParents: true,
loop: true,
navigation: {
nextEl: '.swiper-button-next',
prevEl: '.swiper-button-prev',
},
on: {
slideChangeTransitionEnd: function() {},
slideChange: function() {
that.swiperWidth = that.$refs.swiperWrapper0.clientWidth;
that.maxTranslate = that.mySwiper.maxTranslate();
that.maxWidth = -that.maxTranslate + that.swiperWidth / 2;
that.currentId = this.activeIndex + 1;
that.slide = that.mySwiper.slides[that.currentId];
that.slideLeft = that.slide.offsetLeft;
that.slideWidth = that.slide.clientWidth;
that.slideCenter = that.slideLeft + that.slideWidth / 2;
that.mySwiper.setTransition(300);
if (that.slideCenter < that.swiperWidth / 2) {
that.mySwiper.setTranslate(0);
} else if (that.slideCenter > that.maxWidth) {
that.mySwiper.setTranslate(that.maxTranslate);
} else {
var nowTlanslate = that.slideCenter - that.swiperWidth / 2;
that.mySwiper.setTranslate(-nowTlanslate);
}
},
},
});
},
watch: {
'lists': {
handler(newVal) {
if (newVal) {
this.isHide = false; }
},
deep: true,
},
},
methods: {
initPdf(url) {
this.pdfSrc = pdf.createLoadingTask(url)
this.pdfSrc.then(pdf => {
this.pageTotalNum = pdf.numPages
let arr = [];
if (this.pageTotalNum > 0) {
for (let i = 1; i <= this.pageTotalNum; i++) {
let obj = {}
obj.id = i;
obj.name = 'name' + i;
arr.push(obj)
}
this.lists = arr;
}
})
},
// 页面加载回调函数,其中e为当前页数
pageLoaded(e) {
this.curPageNum = e;
},
// 其他的一些回调函数。
pdfError(error) {
console.error(error);
},
copy(val) {
if (val) {
var clipboard = new ClipboardJS(".copyDom", {
text: (trigger) => {
return val
}
});
clipboard.on("success", e => {
//复制成功
this.$commonJS.toastI('pdf地址复制成功');
console.log(val)
// 释放内存
clipboard.destroy();
});
clipboard.on("error", e => {
// 不支持复制
console.log("该浏览器不支持自动复制");
this.$commonJS.toastI('复制失败');
// 释放内存
clipboard.destroy();
});
}
}, }
}
</script>
<style scoped lang="less">
.mr10,
.page {
width: 1.5rem;
height: .5rem;
background: #409EFF;
border-radius: .05rem;
display: inline-block;
line-height: .5rem;
text-align: center;
position: relative;
color: #fff;
flex: 1;
margin: 0.5rem 0.6rem 0;
&.swiper-button-prev {margin-left:.2rem;}
&.swiper-button-next{margin-right:.2rem;}
} .title {
text-align: center;
margin-bottom: 0.5rem;
} .title {
text-align: center;
margin-bottom: 0.5rem;
} // swiper
.tabContain { .vs {
border: 1px solid #fdd;
margin: 0 0.3rem;
overflow: hidden;
min-height: 2.9rem;
}
} .tab {
overflow: hidden;
position: relative;
margin-left: 0.3rem;
height: 0.7rem; &::after {
position: absolute;
content: "";
left: 0;
bottom: 0;
right: 0;
height: 1px;
background: #e6e6e6;
} #tabApp {
width: 100%;
overflow: hidden; .swiper-slide {
width: auto;
flex-shrink: 0;
font-size: 0.32rem;
font-family: PingFangSC, PingFangSC-Regular;
font-weight: 400;
color: #333333;
line-height: 0.48rem;
padding: 0.1rem 0.15rem; &.active {
font-size: 0.34rem;
font-family: PingFangSC, PingFangSC-Medium;
font-weight: bold;
color: #000000;
} span {
transition: all 0.3s ease;
display: block;
} &:first-child {
padding-left: 0;
}
}
}
} .w100 {
width: 100%;
} .swiper-slide {
.pdf {
width:100%;
}
} .swiper-slide.active {
font-size: 0.34rem;
font-family: PingFangSC, PingFangSC-Medium;
font-weight: bold;
color: #000000;
} .loading {
width: 100%;
height: 100%;
background: rgba(255, 255, 255, 0.1);
top: 0;
left: 0;
position: fixed;
z-index: 100;
} /deep/.pageTitle .pTitle .right {
width: 1.6rem; }
.header_right {
color: #2351ba; }
.tools {
display: flex;
}
.pagepdf {
height: 100vh;
width: 100%;
margin-top:1rem;
}
.header_ico {
width: 0.64rem;
img {
width: 100%;
}
}
</style>

3、title.vue标题头组件

<template>
<div class="pageTitle">
<div class="pTitle" :style="{ background: headerSetting.backgroundColor }">
<div class="left" @click="goBack()">
<!-- 以插槽形式对外开放,支持自定义。默认右边不展示 -->
<slot name="header_left"><</slot>
</div>
<div class="center"><slot name="header_center"></slot></div>
<div class="right">
<!-- 以插槽形式对外开放,支持自定义。默认右边不展示 -->
<slot name="header_right"></slot>
</div>
</div>
</div>
</template>
<script>
export default {
props: {
headerSetting: {
backgroundColor: "transparent", //背景色
default: () => {
return {
backgroundColor: "transparent",
};
},
},
},
methods: {
goBack() {},
},
};
</script>
<style scoped lang="less">
/* // 页面顶部header的样式文件 */ .pageTitle {
z-index: 999;
padding-top: 0;
.pTitle {
position: fixed;
left: 0;
top: 1.1rem;
z-index: 9;
color: rgb(51, 51, 51);
font-size: 0.32rem;
word-break: break-all;
width: 100%;
background: transparent;
height: 0.88rem;
line-height: 0.88rem;
border-bottom: 0.5px solid #ddd;
display: flex;
&.noBorder {
border: none;
} .left {
width: 1.38rem;
height: 0.88rem;
line-height: 0.88rem;
text-align: center;
& > .icon_fanhui3x {
font-size: 0.88rem;
font-weight: 1;
margin-left: -0.2rem;
width: 1.38rem;
display: block;
text-align: center;
}
} .center {
color: #272727;
text-align: center;
flex: 1;
}
/* //单行省略号 */
.ellipsis {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
} .right {
width: 2rem;
height: 0.88rem;
line-height: 0.88rem;
display: flex;
}
}
.blank {
width: 100%;
height: 0.88rem;
}
.disableSelection {
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
-o-user-select: none;
pointer-events: none;
} .doubleLines {
display: block;
height: 0.44rem;
line-height: 0.44rem;
}
}
</style>

pdf地址展示成Swiper轮播方式-复制链接的更多相关文章

  1. Swiper轮播隐藏再显示后不动

    公告用Swiper轮播方式,在某些不需要显示公告的页面进行隐藏,在需要展示公告的页面进行显示时候,公告不能正常轮播,在条件里加入重新设置轮播方法等网上的一些方法仍然不行,最后解决方法: this.my ...

  2. 视频swiper轮播

    关于本次文章的内容,实际上是咪咕阅读详情页中的一个前端需求要做的效果,不过比起原需求,此次案例已经被删减掉许多部分了.音频部分舍弃,调用客户端接口舍弃,并做一些整理.最后留下的是这个精简版的案例.方便 ...

  3. swiper轮播在ie浏览器上遇到的显示问题探索

    前言: 最近项目有一个需求,想要下图效果,鼠标指向头像图片,图片会放大同时上面的轮播会跟着切换: 鼠标移开头像图片,图片变回原来的大小 注:下图是我根据上面需求已经实现的效果,所以截图方便说明 思考: ...

  4. 使用Swiper轮播插件引起的探索

    提到Swiper轮播插件,小伙伴们应该不会感到陌生.以前我主要在移动端上使用,PC端使用较少. 注:这里需要注意的是,在PC端和移动端使用Swiper是不同的 官方给的版本有三个,分别是Swiper2 ...

  5. swiper轮播图(逆向自动切换类似于无限循环)

    swiper插件轮播图,默认的轮播循序是会从右向左,第一张,第二张,第三张,然后肉眼可见是的从第三张从左到右倒回第一张,这样就会有些视觉体验不高, ,不过还是能够用swiper本身的特性更改成无限循环 ...

  6. swiper轮播问题之一:轮播图内容为动态数据生成时轮播图无法自动轮播

    本人在用H5做移动端项目中使用Swiper遇到的两个问题,因此加深了对Swiper的掌握,分享出来对刚开始接触Swiper的童鞋们或多或少会有帮助.        首先,new Swiper的初始化最 ...

  7. Swiper轮播图

    今天咱们来说一下.Swiper轮播图. 超级简单的: 翠花,上代码:   <!DOCTYPE html>   <html lang="en">   < ...

  8. 微信小程序_(组件)swiper轮播图

    微信小程序swiper轮播图组件官方文档 传送门 Learn: swiper组件 一.swiper组件 indicator-dots:是否显示面板指示点[默认值false] autoplay:是否自动 ...

  9. Swiper轮播手动后不动

    最近项目首页轮播图用了Swiper轮播,今天突然发现轮播图动画初始正常但是手动换过之后就不动了,解决方法有两种,具体根据采用的情况为准: 1.autoplayDisableOnInteraction: ...

  10. 一个页面多个bootstrip轮播以及一个页面多个swiper轮播 冲突问题

    Bootstript轮播冲突 解决方法: 使用不同的id <div id="myCarousel1" class="carousel slide"> ...

随机推荐

  1. 【企业流行新数仓】Day02:DWS层(按日分区的宽表)、DWT层(全量累计表)、ADS层、总结

    一.DWS层 1.概括 dwd层的数据,每日轻度聚合,建宽表 表名 粒度 dws_uv_detail_daycount 一个设备是一行 dws_user_action_daycount(只统计今天登录 ...

  2. 网络编程 - OSI七层协议详解

    目录 网络编程基础 软件开发架构 网络编程简介 OSI七层协议简介 OSI协议之物理连接层 OSI协议之数据链路层 网络相关专业名词 OSI之网络层 OSI协议之传输层 传输层之TCP协议/UDP协议 ...

  3. jQuery使用 前端框架Bootstrap

    目录 jQuery查找标签 1.基本选择器 2.组合选择器 3.后代选择器 4.属性选择器 5.基本筛选器 7.筛选器方法 链式操作的本质 操作标签 1.class操作 2.位置操作 3.文本操作 4 ...

  4. CGI、WSGI、uWSGI、ASGI……

    在学习 Python Web 开发时候,可能会遇到诸如 uwsgi.wsgi 等名词,下面通过梳理总结,探究它们之间的关系. CGI CGI(Common Gateway Interface)通用网关 ...

  5. JAVA中的注解可以继承吗?

    前言 注解想必大家都用过,也叫元数据,是一种代码级别的注释,可以对类或者方法等元素做标记说明,比如Spring框架中的@Service,@Component等.那么今天我想问大家的是类被继承了,注解能 ...

  6. STM32外部中断(EXTI)控制LED亮灭的代码

    led.c #include "led.h" void LED_Config(void) { GPIO_InitTypeDef GPIO_InitStruct; RCC_APB2P ...

  7. JavaScript:代码细节和良好编码习惯

    这些细节,与语法无关,仅仅是编写代码时需要注意的最最基本的细节和一些良好编码习惯. 注释代码 注释代码分为单行注释和多行注释,如下所示: 严格区分大小写 JS的代码时严格区分大小写的,变量a和A是不同 ...

  8. ES中的内置对象--jquery如何优化代码,少用$进行查找,减少查找次数的方法

  9. webpack动态配置多静态资源路径,动态配置多上线路径,配置less,多种图片引用方式----"webpack": "^4.41.6",

    1.项目场景是有两个静态资源目录,一个用于开发,一个用于发布,上线多个版本,打包多个版本后,也要部署到同一个服务器的同一个端口下. 根据我自己的摸索,我搞出来了下面的配置,自感觉还蛮好用的 先看我的c ...

  10. DaemonSet方式部署nginx-ingress

    前言 nginx-ingress是k8s官方维护的一个Ingress Controller,具体使用,官方有详细的文档:https://kubernetes.github.io/ingress-ngi ...