fix:pdf最大宽度为屏幕宽度

This commit is contained in:
liyulin 2023-05-06 17:33:13 +08:00
parent f3dc0c23a3
commit d932c1bfba
12 changed files with 341 additions and 7 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@vue-office/pdf",
"version": "1.1.1",
"version": "1.1.2",
"description": "",
"main": "lib/index.js",
"files": [

View File

@ -80,8 +80,13 @@ export default defineComponent({
let domHeight = Math.floor(viewport.height);
if (props.options.width) {
let scale = props.options.width / domWidth;
domWidth = props.options.width;
domHeight = domHeight * scale;
domWidth = Math.floor(props.options.width);
domHeight = Math.floor(domHeight * scale);
}
if(domWidth > document.documentElement.clientWidth){
let scale = document.documentElement.clientWidth / domWidth;
domWidth = Math.floor(document.documentElement.clientWidth);
domHeight = Math.floor(domHeight * scale);
}
canvas.style.width = domWidth + 'px';

View File

@ -9,13 +9,17 @@ function onError(e){
console.log('出差',e);
useLoading.hideLoading();
}
const defaultSrc = location.origin +
(location.pathname + '/').replace('//', '/')
+ 'static/test-files/test.docx';
</script>
<template>
<PreviewWrapper
accept=".docx"
placeholder="请输入docx文件地址"
default-src="https://501351981.github.io/vue-office/examples/dist/static/test-files/test.docx"
:default-src="defaultSrc"
>
<template v-slot="slotProps">
<VueOfficeDocx

View File

@ -11,13 +11,16 @@ function onError(e){
useLoading.hideLoading();
}
const defaultSrc = location.origin +
(location.pathname + '/').replace('//', '/')
+ 'static/test-files/test.xlsx';
</script>
<template>
<PreviewWrapper
accept=".xlsx"
placeholder="请输入xlsx文件地址"
default-src="https://501351981.github.io/vue-office/examples/dist/static/test-files/test.xlsx"
:default-src="defaultSrc"
>
<template v-slot="slotProps">
<VueOfficeExcel

View File

@ -9,13 +9,16 @@ function onError(e){
console.log('出差',e);
useLoading.hideLoading();
}
const defaultSrc = location.origin +
(location.pathname + '/').replace('//', '/')
+ 'static/test-files/test.pdf';
</script>
<template>
<PreviewWrapper
accept=".pdf"
placeholder="请输入pdf文件地址"
default-src="https://501351981.github.io/vue-office/examples/dist/static/test-files/test.pdf"
:default-src="defaultSrc"
>
<template v-slot="slotProps">
<VueOfficePdf

View File

@ -0,0 +1 @@
.vue-office-docx{height:100%;overflow-y:auto}.vue-office-docx .docx-wrapper>section.docx{margin-bottom:5px}@media screen and (max-width: 800px){.vue-office-docx .docx-wrapper{padding:10px}.vue-office-docx .docx-wrapper>section.docx{padding:10px!important;width:100%!important}}.operate-area[data-v-0993b4b1]{display:flex;margin:10px;align-items:center}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
import{r as d,p as C,_ as I,w as N,q as n,a as p,b as x,u as t,h as i,g as l,s as v,t as S,f as w,n as m,v as V,x as W,y as A,e as R}from"./index-17d88db8.js";function T(e){const s=d("url"),a=d(e),r=d(e),u=d([]);function b(y){let c=new FileReader;return c.onload=o=>{let _=o.target.result;r.value=_},c.readAsArrayBuffer(y),!1}return{type:s,inputSrc:a,src:r,fileList:u,beforeUpload:b}}let g=d(!1),k;function $(e){k=C.loading(e,0),g.value=!0}function q(){g.value===!0&&(k(),g.value=!1)}const E={loading:g,showLoading:$,hideLoading:q};function F(){return location.href.includes("test")}const j=e=>(W("data-v-6e0b6946"),e=e(),A(),e),z={class:"preview-wrapper"},D={key:0,class:"operate-area"},G=j(()=>R("div",{class:"preview-wrapper-main"},null,-1)),H={__name:"PreviewWrapper",props:{accept:String,placeholder:String,defaultSrc:String},setup(e){const s=e,{type:a,inputSrc:r,src:u,fileList:b,beforeUpload:y}=T(s.defaultSrc);return N(u,()=>{E.showLoading()},{immediate:!0}),(c,o)=>{const _=n("a-radio-button"),B=n("a-radio-group"),L=n("a-input"),h=n("a-button"),U=n("upload-outlined"),P=n("a-upload");return p(),x("div",z,[t(F)()?m("",!0):(p(),x("div",D,[i(B,{value:t(a),"onUpdate:value":o[0]||(o[0]=f=>S(a)?a.value=f:null),"button-style":"solid"},{default:l(()=>[i(_,{value:"url"},{default:l(()=>[v("远程文件地址")]),_:1}),i(_,{value:"upload"},{default:l(()=>[v("上传本地文件")]),_:1})]),_:1},8,["value"]),t(a)==="url"?(p(),w(L,{key:0,value:t(r),"onUpdate:value":o[1]||(o[1]=f=>S(r)?r.value=f:null),placeholder:s.placeholder,style:{width:"600px","margin-left":"10px"}},null,8,["value","placeholder"])):m("",!0),t(a)==="url"?(p(),w(h,{key:1,type:"primary",style:{"margin-left":"10px"},onClick:o[2]||(o[2]=f=>u.value=t(r))},{default:l(()=>[v(" 预览 ")]),_:1})):m("",!0),t(a)!=="url"?(p(),w(P,{key:2,accept:s.accept,action:"",beforeUpload:t(y),"file-list":[]},{default:l(()=>[i(h,{style:{"margin-left":"10px"}},{default:l(()=>[i(U),v(" 选择文件 ")]),_:1})]),_:1},8,["accept","beforeUpload"])):m("",!0)])),V(c.$slots,"default",{src:t(u)},void 0,!0),G])}}},K=I(H,[["__scopeId","data-v-6e0b6946"]]);export{K as P,E as u};

121
examples/dist/assets/index-17d88db8.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -7,7 +7,7 @@
content="width=device-width, initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/>
<title>@vue-office演示demo</title>
<script type="module" crossorigin src="/vue-office/examples/dist/assets/index-471197f5.js"></script>
<script type="module" crossorigin src="/vue-office/examples/dist/assets/index-17d88db8.js"></script>
<link rel="stylesheet" href="/vue-office/examples/dist/assets/index-cc8fb346.css">
</head>
<body>