当前位置: 首页 > news >正文

uniapp 微信小程序 判断数据返回的是jpg还是pdf,以及pdf预览

<template>
<view class="approval-notice"><block v-for="(imgItem, idx) in drivingLicense" :key="idx">//如果是非图片,那就走pdf预览<view class="pdf-item" v-if="Object.keys(thumbnail).includes(getFileType(imgItem))" @click="handlePreview(idx,drivingLicense)"><image src="../static/pdf-icon.png" mode="aspectFill"></image><text class="text">{{getFileName(imgItem)}}</text></view>//如果是图片,那就走图片预览<view class="img-item" v-else @click="handlePreview(idx,drivingLicense)"><image :src="imgItem" mode="aspectFill"></image><text class="text">{{getFileName(imgItem)}}</text></view></block>
</view>
</template>
data() {return {//数据返回的文件列表(↓↓包含以下格式↓↓)drivingLicense:['https://www.baidu.com/5cf22168b26b0_20230720114248A003.jpg','https://www.baidu.com/5cf22168b26b0_20230720114278A003.jpg'],fileTypeLimit:['png', 'jpg', 'jpeg', 'pdf'],//仅支持这些格式thumbnail:{pdf: '',apk: '',mp4: ''}}}
methods: {//获取文件后缀名getFileType(fileName, isUserType = false) {if (!isUserType) {return fileName.split('.').pop().toLowerCase()} else {return fileName.split('/').pop().toLowerCase()}},//获取文件名getFileName(url){return url.split('/').pop();},//预览handlePreview(index,list){const fileType = this.getFileType(list[index])//如果是不支持的文件类型或者是需要代替的缩略图的类型,则新标签页打开显示if (Object.keys(this.thumbnail).includes(fileType) || !this.fileTypeLimit.includes(fileType)) {uni.navigateTo({//跳转到pdf.vue页面url:"/packageProjectList/pdf/pdf?url="+list[index]})}else{//图片预览已经在其他文章中有例子this.$common.previewImage(index,list)}},
}

pdf.vue

<template><view><web-view :src="webViewSrc"></web-view></view>
</template><script>export default {data() {return {webViewSrc:''}},onLoad(option) {this.webViewSrc = option.url;},methods: {}}
</script><style></style>
http://www.lryc.cn/news/113669.html

相关文章:

  • SpringBoot 的事务及使用
  • Android中的ABI
  • Python爬虫在用户行为模型构建中的应用与挑战
  • LangChain与大模型的学习
  • C语言标准定义的32个关键字
  • PE半透明屏是怎么制造的?工艺、材料、应用
  • linux文本三剑客---grep,sed,awk
  • leaflet-uniapp 缩放地图的同时 显示当前缩放层级
  • [Securinets CTF Quals 2023] Admin Service,ret2libc,One is enough
  • 计算机组成原理-笔记-第二章
  • mysql大量数据导入记要
  • 极狐GitLab 全新「价值流仪表盘」使用指南
  • 通过logrotate实现nginx容器内日志按天存储
  • 广东珠海电子行业导入MES系统需要注意什么
  • 小红书2023/08/06Java后端笔试 AK
  • 3、有序数组的平方
  • 用于自然语言处理 (NLP) 的 MLOps
  • C#抽象静态方法
  • 小研究 - Mysql快速全同步复制技术的设计和应用(一)
  • HTML <samp> 标签
  • C之(8)linux动态库编译框架
  • Zabbix网络拓扑配置
  • 2.4G芯片XL2408开发板,SOP16封装,芯片集成1T 8051内核单片机
  • iPhone苹果手机地震预警功能怎么开启?
  • Storm学习之使用官方Docker镜像快速搭建Storm运行环境
  • 【GTest学习】
  • [JAVAee]网络通信基础
  • 【HDFS】BlockManager#checkRedundancy方法详解
  • c++ 拷贝构造
  • MISRA 2012学习笔记(1)-Directives