Gxd-vue-file-preview
介绍
vue 文件在线预览展示功能,支持文件(PDF,PNG,JPEG,JPG,GIF,DOC,DOCX,PPT,PPTX,ELXS,ELX)
预览

安装
npm i gxd-file-preview --save --registry https://registry.npm.taobao.org
插件全局引用
import vueFilePreview from 'gxd-file-preview';
Vue.use(vueFilePreview,{
pdf: 'https://cdn.jsdelivr.net/npm/pdfjs-dist@2.0.288/build/pdf.min.js',
worker:'https://cdn.jsdelivr.net/npm/pdfjs-dist@2.0.288/build/pdf.worker.min.js',
});
插件使用
<template>
<div id="app"></div>
</template>
<script>
export default {
name: 'app',
components: {},
data(){
return {}
},
created() {
setTimeout(()=>{
this.$preview({
url:'http://storage.xuetangx.com/public_assets/xuetangx/PDF/PlayerAPI_v1.0.6.pdf',
fid: '12121212'
})
}, 2000);
},
methods:{
}
}
</script>
<style>
</style>
<template>
<div id="app">
<h1>列表展示</h1>
<xd-file-list-preview
:show-close="showClose"
:list="list" @remove="handleRemoveClick"
:is-pagination="isPagination"
></xd-file-list-preview>
<hr>
<h1>文件预览模式</h1>
<a @click="handleClick" style="color: #4285f4">9958ff80d202f91b347b14b5c56f14e811</a>
</div>
</template>
<script>
interface FileItemFormat {
url:string;
name?: string;
fid?: string;
download?: string;
}
export default {
name: 'app',
components: {},
data() {
return {
showClose: true,
isPagination: true,
list: [
{url: 'http://storage.xuetangx.com/public_assets/xuetangx/PDF/PlayerAPI_v1.0.6.pdf'},
{url: 'https://jfb-public-images.oss-cn-qingdao.aliyuncs.com/admin-upload/202111081034429231.png?x-oss-process=style/common'},
{url: 'http://static.e56buy.com/XdgfsqR2INp7uFxTuLQtnMstYLY4K8rr.蛋糕缺少内容.docx', name: 'aaaa'},
{
url: 'http://storage.xuetangx.com/public_assets/xuetangx/PDF/PlayerAPI_v1.0.6.pdf',
name: 'aaaa',
fid: 'aadadads',
download: false ,
},
]
}
},
created() {
},
methods: {
handleRemoveClick(item, done) {
setTimeout(() => {
console.log('handleRemoveClick', item);
done()
}, 2000);
},
handleClick() {
this.$preview({
url: 'http://storage.xuetangx.com/public_assets/xuetangx/PDF/PlayerAPI_v1.0.6.pdf',
fid: 'aadadads',
download: false ,
})
},
}
}
</script>
<style>
</style>
项目开发下载与初始化
git clone git@gitee.com:e56buy/xd-file-preview.git
cd xd-file-preview
npm install
建议通过npm按照,通过如下操作解决 npm 下载速度慢的问题
npm install --save --registry=https://registry.npm.taobao.org
Nginx配置静态资源可以跨域访问(注意访问静态资源需要做跨域处理)
server {
listen 80;
add_header 'Access-Control-Allow-Origin' '*';
location /Roboto/ {
root /home/images;
autoindex on;
}
}
location /img/ {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
expires 30d;
root /Users/chokshen/Desktop/;
error_log off;
access_log /dev/null;
autoindex on;
}
版本日志
1.2.0
1、新增JSON,TXT,JS,HTML,CSS预览功能
2、列表展示功能新增 预览模式时候 左右翻页功能
1.1.18
优化文档显示
1.1.17
修复预览offic系列访问不成功问题