fix: excel中超链接及公式错误预览bug

This commit is contained in:
liyulin 2023-07-14 10:05:03 +08:00
parent 071e7a796e
commit b0262e1e15
22 changed files with 342 additions and 9 deletions

View File

@ -190,7 +190,7 @@ export default {
| 时间 | 打赏总金额 |
|---------|-------|
| 2023-07 | 0 |
| 2023-07 | 43.84 |
| 2023-06 | 20.01 |
| 2023-05 | 70 |
| 2023-04 | 95 |

View File

@ -1,7 +1,7 @@
{
"name": "@js-preview/excel",
"type" :"module",
"version": "1.2.0",
"version": "1.2.1",
"description": "",
"main": "lib/index.js",
"files": [

View File

@ -1,6 +1,6 @@
{
"name": "@vue-office/excel",
"version": "1.2.0",
"version": "1.2.1",
"description": "",
"main": "lib/index.js",
"files": [

View File

@ -1,7 +1,7 @@
import * as Excel from 'exceljs/dist/exceljs';
import {getUrl} from '../../../utils/url';
import tinycolor from 'tinycolor2';
import _, {cloneDeep} from 'lodash';
import {cloneDeep, get, find} from 'lodash';
import {getDarkColor, getLightColor} from './color';
import dayjs from 'dayjs';
@ -76,6 +76,7 @@ function transferColumns(excelSheet, spreadSheet, options){
function getCellText(cell){
//console.log(cell);
const {numFmt, value, type} = cell;
debugger;
switch (type){
case 2: //数字
return value + '';
@ -100,8 +101,10 @@ function getCellText(cell){
return dayjs(value).format('YYYY-MM-DD');
}
case 5: //超链接
return value.text;
case 6: //公式
return cell.result;
return get(value, 'result.error') || value.result;
case 8: //富文本
return cell.text;
default:
@ -217,7 +220,7 @@ function getStyle(cell){
export function transferExcelToSpreadSheet(workbook, options){
let workbookData = [];
//console.log(workbook, 'workbook')
// console.log(workbook, 'workbook')
workbook.eachSheet((sheet) => {
//console.log(sheet,'sheet');
// 构造x-data-spreadsheet 的 sheet 数据源结构
@ -250,7 +253,7 @@ export function transferExcelToSpreadSheet(workbook, options){
(row._cells || []).forEach((cell, spreadSheetColIndex) =>{
sheetData.rows[spreadSheetRowIndex].cells[spreadSheetColIndex] = {};
let mergeAddress = _.find(mergeAddressData, function(o) { return o.startAddress == cell._address; });
let mergeAddress = find(mergeAddressData, function(o) { return o.startAddress == cell._address; });
if(mergeAddress && cell.master.address != mergeAddress.startAddress) {
return;
}
@ -268,7 +271,7 @@ export function transferExcelToSpreadSheet(workbook, options){
sheetData.rows.len = Math.max(Object.keys(sheetData.rows).length, 100);
workbookData.push(sheetData);
});
//console.log(workbookData, 'workbookData')
// console.log(workbookData, 'workbookData')
return {
workbookData,
workbookSource: workbook,

View File

@ -0,0 +1 @@
import{d as r}from"./docx-fe694a97.js";import{d as x}from"./url-de9b02cf.js";import{d as m,_ as l,r as u,o as h,w as g,a as _,c as v,b as D,e as y,f as w,g as B,u as $}from"./index-afb4c379.js";import{P as O,u as f}from"./PreviewWrapper-0a805bfd.js";import"./_commonjs-dynamic-modules-302442b1.js";const R=m({name:"VueOfficeDocx",props:{src:[String,ArrayBuffer,Blob],requestOptions:{type:Object,default:()=>({})},options:{type:Object,default:()=>({})}},emits:["rendered","error"],setup(e,{emit:o}){const t=u(null);let n=null;function a(){let c=t.value;r.getData(e.src,e.requestOptions).then(async d=>{n=await r.getBlob(d),r.render(n,c,e.options).then(()=>{o("rendered")}).catch(p=>{r.render("",c,e.options),o("error",p)})}).catch(d=>{r.render("",c,e.options),o("error",d)})}h(()=>{e.src&&a()}),g(()=>e.src,()=>{e.src?a():r.render("",t.value,e.options).then(()=>{o("rendered")})});function s(c){x(c||`vue-office-docx-${new Date().getTime()}.docx`,n)}return{rootRef:t,download:s}}}),b={class:"vue-office-docx"},k={class:"vue-office-docx-main",ref:"rootRef"};function V(e,o,t,n,a,s){return _(),v("div",b,[D("div",k,null,512)])}const i=l(R,[["render",V]]);i.install=function(e){e.component(i.name,i)};const E={__name:"DocxDemo",setup(e){function o(){f.hideLoading()}function t(s){console.log("出差",s),f.hideLoading()}const n=location.origin+(location.pathname+"/").replace("//","/")+"static/test-files/test.docx",a=u();return(s,c)=>(_(),y(O,{accept:".docx",placeholder:"请输入docx文件地址","default-src":n},{default:w(d=>[B($(i),{ref_key:"docxRef",ref:a,src:d.src,style:{flex:"1",height:"0"},onRendered:o,onError:t},null,8,["src"])]),_:1}))}},P=l(E,[["__scopeId","data-v-637d9a60"]]);export{P as default};

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-637d9a60]{display:flex;margin:10px;align-items:center}

View File

@ -0,0 +1 @@
import{l as C,r as R,S as B,a as h,g as k,b as $,t as T,c as D}from"./hack-34d5149e.js";import{d as L}from"./url-de9b02cf.js";import{d as q,_ as F,r as m,o as V,n as W,h as j,w as I,a as E,c as M,b as N,i as P,e as A,f as H,j as U,g as z,u as G}from"./index-afb4c379.js";import{P as J,u as O}from"./PreviewWrapper-0a805bfd.js";import"./_commonjs-dynamic-modules-302442b1.js";const K=q({name:"VueOfficeExcel",props:{src:[String,ArrayBuffer,Blob],requestOptions:{type:Object,default:()=>({})},options:{type:Object,default:()=>({minColLength:20})}},emits:["rendered","error"],setup(t,{emit:i}){const n=m(null),s=m(null);let r={_worksheets:[]},a=[],d=1,u=null,e=null,f=null,p=null;function _(c){p=c,$(c).then(l=>{if(!l._worksheets||l._worksheets.length===0)throw new Error("未获取到数据,可能文件格式不正确或文件已损坏");const{workbookData:x,medias:g,workbookSource:o}=T(l,t.options);a=g,r=o,f=null,d=1,D(),e.loadData(x),h(u,a,r._worksheets[d],f),i("rendered")}).catch(l=>{console.warn(l),a=[],r={_worksheets:[]},D(),e.loadData({}),i("error",l)})}const v=C.debounce(R,200).bind(this,s.value),b=new MutationObserver(v),S={attributes:!0,childList:!0,subtree:!0};V(()=>{W(()=>{b.observe(s.value,S),v(s),window.xs=e=new B(s.value,{mode:"read",showToolbar:!1,showContextmenu:t.options.showContextmenu||!1,view:{height:()=>n.value&&n.value.clientHeight||300,width:()=>n.value&&n.value.clientWidth||1200},row:{height:24,len:100},col:{len:26,width:80,indexWidth:60,minWidth:60},autoFocus:!1}).loadData({});let c=e.bottombar.swapFunc;e.bottombar.swapFunc=function(o){c.call(e.bottombar,o),d=o+1,setTimeout(()=>{e.reRender(),h(u,a,r._worksheets[d],f)})};let l=e.sheet.editor.clear;e.sheet.editor.clear=function(...o){l.apply(e.sheet.editor,o),setTimeout(()=>{h(u,a,r._worksheets[d],f)})};let x=e.sheet.editor.setOffset;e.sheet.editor.setOffset=function(...o){x.apply(e.sheet.editor,o),f=o[0],h(u,a,r._worksheets[d],f)},u=s.value.querySelector("canvas").getContext("2d"),t.src&&k(t.src,t.requestOptions).then(_).catch(o=>{e.loadData({}),i("error",o)})})}),j(()=>{b.disconnect(),e=null}),I(()=>t.src,()=>{t.src?k(t.src,t.requestOptions).then(_).catch(c=>{e.loadData({}),i("error",c)}):e.loadData({})});function y(c){L(c||`vue-office-excel-${new Date().getTime()}.xlsx`,p)}return{wrapperRef:n,rootRef:s,download:y}}}),Q={class:"vue-office-excel",ref:"wrapperRef"},X={class:"vue-office-excel-main",ref:"rootRef"};function Y(t,i,n,s,r,a){return E(),M("div",Q,[N("div",X,null,512)],512)}const w=F(K,[["render",Y]]);w.install=function(t){t.component(w.name,w)};const se={__name:"ExcelDemo",setup(t){function i(){O.hideLoading()}function n(a){console.log("出差",a),O.hideLoading()}const s=location.origin+(location.pathname+"/").replace("//","/")+"static/test-files/test.xlsx",r=m();return(a,d)=>{const u=P("loading");return E(),A(J,{accept:".xlsx",placeholder:"请输入xlsx文件地址","default-src":s},{default:H(e=>[U(z(G(w),{ref_key:"docxRef",ref:r,src:e.src,style:{flex:"1",height:"0"},onRendered:i,onError:n},null,8,["src"]),[[u,!0]])]),_:1})}}};export{se as default};

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1 @@
var p=Object.defineProperty;var c=(i,e,t)=>e in i?p(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var r=(i,e,t)=>(c(i,typeof e!="symbol"?e+"":e,t),t);import{d as n}from"./docx-fe694a97.js";import{d as l}from"./url-de9b02cf.js";import{r as h,o as d,a as u,c as w}from"./index-afb4c379.js";import"./_commonjs-dynamic-modules-302442b1.js";class m{constructor(e,t={},s={}){r(this,"container",null);r(this,"wrapper",null);r(this,"wrapperMain",null);r(this,"options",{});r(this,"requestOptions",{});r(this,"fileData",null);this.container=e,this.options=t,this.requestOptions=s,this.createWrapper()}createWrapper(){this.wrapper=document.createElement("div"),this.wrapper.className="vue-office-docx",this.wrapperMain=document.createElement("div"),this.wrapperMain.className="vue-office-docx-main",this.wrapper.appendChild(this.wrapperMain),this.container.appendChild(this.wrapper)}setOptions(e){this.options=e}setRequestOptions(e){this.requestOptions=e}preview(e){return new Promise((t,s)=>{n.getData(e,this.requestOptions).then(async o=>{this.fileData=await n.getBlob(o),n.render(this.fileData,this.wrapperMain,this.options).then(()=>{t()}).catch(a=>{n.render("",this.wrapperMain,this.options),s(a)})}).catch(o=>{n.render("",this.wrapperMain,this.options),s(o)})})}download(e){l(e||`js-preview-docx-${new Date().getTime()}.docx`,this.fileData)}destroy(){this.container.removeChild(this.wrapper),this.container=null,this.wrapper=null,this.wrapperMain=null,this.options=null,this.requestOptions=null}}function f(i,e,t){return new m(i,e,t)}const x={init:f};const q={__name:"JsDocxDemo",setup(i){const e=h(null);return d(()=>{let t=x.init(e.value);t.preview("/vue-office/examples/dist/static/test-files/test.docx").then(s=>{console.log("docx preview done"),setTimeout(()=>{t.preview("/vue-office/examples/dist/static/test-files/test2.docx")},3e3)}).catch(s=>{console.log("err",s)})}),(t,s)=>(u(),w("div",{ref_key:"dom",ref:e},null,512))}};export{q as default};

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}}

View File

@ -0,0 +1 @@
var c=Object.defineProperty;var p=(r,e,t)=>e in r?c(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var s=(r,e,t)=>(p(r,typeof e!="symbol"?e+"":e,t),t);import{S as u,a as n,b as d,t as w,c as l,l as x,r as m,g as f}from"./hack-34d5149e.js";import{d as k}from"./url-de9b02cf.js";/* empty css */import{r as b,o as v,a as S,c as D}from"./index-afb4c379.js";import"./_commonjs-dynamic-modules-302442b1.js";class _{constructor(e,t={},i={}){s(this,"container",null);s(this,"wrapper",null);s(this,"wrapperMain",null);s(this,"options",{});s(this,"requestOptions",{});s(this,"mediasSource",[]);s(this,"workbookDataSource",{_worksheets:[]});s(this,"sheetIndex",1);s(this,"ctx",null);s(this,"xs",null);s(this,"offset",null);s(this,"observer",null);s(this,"fileData",null);this.container=e,this.options={minColLength:20,...t},this.requestOptions=i,this.createWrapper(),this.initSpreadsheet(),this.hack()}createWrapper(){this.wrapper=document.createElement("div"),this.wrapper.className="vue-office-excel",this.wrapperMain=document.createElement("div"),this.wrapperMain.className="vue-office-excel-main",this.wrapper.appendChild(this.wrapperMain),this.container.appendChild(this.wrapper)}initSpreadsheet(){this.xs=new u(this.wrapperMain,{mode:"read",showToolbar:!1,showContextmenu:this.options.showContextmenu||!1,view:{height:()=>this.wrapper&&this.wrapper.clientHeight||300,width:()=>this.wrapper&&this.wrapper.clientWidth||1200},row:{height:24,len:100},col:{len:26,width:80,indexWidth:60,minWidth:60},autoFocus:!1}).loadData({});let e=this,t=this.xs.bottombar.swapFunc;this.xs.bottombar.swapFunc=function(a){t.call(e.xs.bottombar,a),e.sheetIndex=a+1,setTimeout(()=>{e.xs.reRender(),n(e.ctx,e.mediasSource,e.workbookDataSource._worksheets[e.sheetIndex],e.offset)})};let i=this.xs.sheet.editor.clear;this.xs.sheet.editor.clear=function(...a){i.apply(e.xs.sheet.editor,a),setTimeout(()=>{n(e.ctx,e.mediasSource,e.workbookDataSource._worksheets[e.sheetIndex],e.offset)})};let o=this.xs.sheet.editor.setOffset;this.xs.sheet.editor.setOffset=function(...a){o.apply(e.xs.sheet.editor,a),e.offset=a[0],n(e.ctx,e.mediasSource,e.workbookDataSource._worksheets[e.sheetIndex],e.offset)};const h=this.wrapperMain.querySelector("canvas");this.ctx=h.getContext("2d")}renderExcel(e){return this.fileData=e,d(e).then(t=>{if(!t._worksheets||t._worksheets.length===0)throw new Error("未获取到数据,可能文件格式不正确或文件已损坏");const{workbookData:i,medias:o,workbookSource:h}=w(t,this.options);this.mediasSource=o,this.workbookDataSource=h,this.offset=null,this.sheetIndex=1,l(),this.xs.loadData(i),n(this.ctx,this.mediasSource,this.workbookDataSource._worksheets[this.sheetIndex],this.offset)}).catch(t=>(this.mediasSource=[],this.workbookDataSource={_worksheets:[]},l(),this.xs.loadData({}),Promise.reject(t)))}hack(){const e=x.debounce(m,200).bind(this,this.wrapperMain);this.observer=new MutationObserver(e);const t={attributes:!0,childList:!0,subtree:!0};this.observer.observe(this.wrapperMain,t),e(this.wrapperMain)}setOptions(e){this.options=e}setRequestOptions(e){this.requestOptions=e}preview(e){return new Promise((t,i)=>{f(e,this.requestOptions).then(o=>{this.renderExcel(o).then(t)}).catch(o=>{this.xs.loadData({}),i(o)})})}download(e){k(e||`js-preview-excel-${new Date().getTime()}.xlsx`,this.fileData)}destroy(){this.observer.disconnect(),this.container.removeChild(this.wrapper),this.container=null,this.wrapper=null,this.wrapperMain=null,this.ctx=null,this.xs=null,this.observer=null,this.options=null,this.requestOptions=null,this.mediasSource=null,this.workbookDataSource=null}}function E(r,e,t){return new _(r,e,t)}const g={init:E},P={__name:"JsExcelDemo",setup(r){const e=b(null);return v(()=>{window.myExcelPreview=g.init(e.value),window.myExcelPreview.preview("/vue-office/examples/dist/static/test-files/test.xlsx").then(t=>{console.log("excel preview done",window.myExcelPreview)}).catch(t=>{console.log("err",t)})}),(t,i)=>(S(),D("div",{ref_key:"dom",ref:e,style:{height:"calc(100vh - 50px)"}},null,512))}};export{P as default};

View File

@ -0,0 +1 @@
var d=Object.defineProperty;var u=(r,t,e)=>t in r?d(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e;var a=(r,t,e)=>(u(r,typeof t!="symbol"?t+"":t,e),e);import{o as f,w,p as m}from"./omit-eb6ad03a.js";import{l as v,g,d as P}from"./url-de9b02cf.js";/* empty css */import{r as M,o as b,a as k,c as x}from"./index-afb4c379.js";const _=`data:text/javascript;base64,${m}`,C=`data:text/javascript;base64,${w}`;class D{constructor(t,e={},i={}){a(this,"container",null);a(this,"wrapper",null);a(this,"wrapperMain",null);a(this,"options",{});a(this,"requestOptions",{});a(this,"pdfDocument",null);this.container=t,this.options={staticFileUrl:"https://unpkg.com/pdfjs-dist@3.1.81/",...e},this.requestOptions=i,this.createWrapper()}createWrapper(){this.wrapper=document.createElement("div"),this.wrapper.className="vue-office-pdf",this.wrapper.setAttribute("style","text-align: center;overflow-y: auto;"),this.container.appendChild(this.wrapper)}createWrapperMain(){this.wrapperMain=document.createElement("div"),this.wrapperMain.className="vue-office-pdf-wrapper",this.wrapperMain.setAttribute("style","background: gray; padding: 30px 0;position: relative;"),this.wrapper.appendChild(this.wrapperMain)}createCanvas(){const t=document.createElement("canvas");return t.setAttribute("style","width:100%"),this.wrapperMain.appendChild(t),[t,t.getContext("2d")]}installPdfScript(){return v(_).then(()=>{window.pdfjsLib.GlobalWorkerOptions.workerSrc=C})}checkPdfLib(){return window.pdfjsLib?Promise.resolve():this.installPdfScript()}getDocument(t){return window.pdfjsLib.getDocument({url:g(t),cMapUrl:`${this.options.staticFileUrl.endsWith("/")?this.options.staticFileUrl:this.options.staticFileUrl+"/"}cmaps/`,cMapPacked:!0,enableXfa:!0,...f(this.options,["width","staticFileUrl"])}).promise}renderSinglePage(t){return this.pdfDocument.getPage(t).then(e=>{const i=e.getViewport({scale:2}),s=window.devicePixelRatio||1;let[n,l]=this.createCanvas();n.width=Math.floor(i.width*s),n.height=Math.floor(i.height*s);let o=Math.floor(i.width),p=Math.floor(i.height);if(this.options.width){let c=this.options.width/o;o=Math.floor(this.options.width),p=Math.floor(p*c)}if(o>document.documentElement.clientWidth){let c=document.documentElement.clientWidth/o;o=Math.floor(document.documentElement.clientWidth),p=Math.floor(p*c)}n.style.width=o+"px",n.style.height=p+"px";const h=s!==1?[s,0,0,s,0,0]:null;return e.render({canvasContext:l,transform:h,viewport:i}).promise.then(()=>{this.pdfDocument.numPages>t&&this.renderSinglePage(t+1)})})}renderPage(){return this.wrapperMain||this.createWrapperMain(),this.renderSinglePage(1)}clearAllCanvas(){this.wrapperMain&&(this.wrapper.removeChild(this.wrapperMain),this.wrapperMain=null)}setOptions(t){this.options=t}setRequestOptions(t){this.requestOptions=t}preview(t){return new Promise((e,i)=>{if(!t){this.clearAllCanvas(),i(new Error("预览地址不能为空"));return}this.checkPdfLib().then(s=>{this.getDocument(t).then(n=>{this.pdfDocument=n,this.renderPage().then(l=>{e()}).catch(l=>{this.clearAllCanvas(),i(l)})}).catch(n=>{this.clearAllCanvas(),i(n)})}).catch(s=>{this.clearAllCanvas(),i(s)})})}download(t){this.pdfDocument&&this.pdfDocument._transport&&this.pdfDocument._transport.getData().then(e=>{P(t||`js-preview-pdf-${new Date().getTime()}.pdf`,e.buffer)})}destroy(){this.container.removeChild(this.wrapper),this.container=null,this.wrapper=null,this.wrapperMain=null,this.options={},this.requestOptions={},this.pdfDocument=null}}function y(r,t,e){return new D(r,t,e)}const W={init:y},j={__name:"JsPdfDemo",setup(r){const t=M(null);return b(()=>{window.myPdfPreview=W.init(t.value),window.myPdfPreview.preview("/vue-office/examples/dist/static/test-files/test.pdf").then(e=>{console.log("excel preview done",window.myPdfPreview)}).catch(e=>{console.log("err",e)})}),(e,i)=>(k(),x("div",{ref_key:"dom",ref:t,style:{height:"calc(100vh - 50px)"}},null,512))}};export{j as default};

View File

@ -0,0 +1 @@
import{o as L,p as $,w as j}from"./omit-eb6ad03a.js";import{g as S,d as W,l as R}from"./url-de9b02cf.js";import{d as E,_ as F,r as v,o as O,w as U,a as p,c as w,F as B,k as C,l as D,e as V,f as T,g as J,u as N}from"./index-afb4c379.js";import{P as q,u as P}from"./PreviewWrapper-0a805bfd.js";const A=`data:text/javascript;base64,${$}`,G=`data:text/javascript;base64,${j}`,H=E({name:"VueOfficePdf",props:{src:[String,ArrayBuffer,Blob],requestOptions:{type:Object,default:()=>({})},staticFileUrl:{type:String,default:"https://unpkg.com/pdfjs-dist@3.1.81/"},options:{type:Object,default:()=>({})}},emits:["rendered","error"],setup(e,{emit:n}){let o=null,i=null;const c=v([]),r=v(0);function m(){return R(A).then(()=>{window.pdfjsLib.GlobalWorkerOptions.workerSrc=G})}function g(){return window.pdfjsLib?Promise.resolve():m()}function k(){if(!e.src){r.value=0;return}i=window.pdfjsLib.getDocument({url:S(e.src),cMapUrl:`${e.staticFileUrl.endsWith("/")?e.staticFileUrl:e.staticFileUrl+"/"}cmaps/`,cMapPacked:!0,enableXfa:!0,...L(e.options,["width"])}),i.promise.then(t=>{o=t,r.value=o.numPages,x(1)}).catch(t=>{n("error",t)})}function x(t){o.getPage(t).then(a=>{const d=a.getViewport({scale:2}),l=window.devicePixelRatio||1,f=c.value[t-1],y=f.getContext("2d");f.width=Math.floor(d.width*l),f.height=Math.floor(d.height*l);let s=Math.floor(d.width),u=Math.floor(d.height);if(e.options.width){let h=e.options.width/s;s=Math.floor(e.options.width),u=Math.floor(u*h)}if(s>document.documentElement.clientWidth){let h=document.documentElement.clientWidth/s;s=Math.floor(document.documentElement.clientWidth),u=Math.floor(u*h)}f.style.width=s+"px",f.style.height=u+"px";const M=l!==1?[l,0,0,l,0,0]:null;a.render({canvasContext:y,transform:M,viewport:d}).promise.then(()=>{r.value>t?x(t+1):n("rendered")}).catch(h=>{n("error",h)})}).catch(a=>{n("error",a)})}O(()=>{e.src&&g().then(k)}),U(()=>e.src,()=>{g().then(k)});function b(t){o&&o._transport&&o._transport.getData().then(a=>{W(t||`vue-office-pdf-${new Date().getTime()}.pdf`,a.buffer)})}return{rootRef:c,numPages:r,download:b}}}),X={class:"vue-office-pdf",ref:"vue-office-pdf",style:{"text-align":"center","overflow-y":"auto"}},z={key:0,class:"vue-office-pdf-wrapper",style:{background:"gray",padding:"30px 0",position:"relative"}};function I(e,n,o,i,c,r){return p(),w("div",X,[e.numPages?(p(),w("div",z,[(p(!0),w(B,null,C(e.numPages,m=>(p(),w("canvas",{ref_for:!0,ref:"rootRef",key:m,style:{width:"100%"}}))),128))])):D("",!0)],512)}const _=F(H,[["render",I]]);_.install=function(e){e.component(_.name,_)};const te={__name:"PdfDemo",setup(e){function n(){P.hideLoading()}function o(r){console.log("出差",r),P.hideLoading()}const i=location.origin+(location.pathname+"/").replace("//","/")+"static/test-files/test.pdf",c=v();return(r,m)=>(p(),V(q,{accept:".pdf",placeholder:"请输入pdf文件地址","default-src":i},{default:T(g=>[J(N(_),{ref_key:"docxRef",ref:c,src:g.src,style:{flex:"1",height:"0"},options:{},onRendered:n,onError:o},null,8,["src"])]),_:1}))}};export{te as default};

View File

@ -0,0 +1 @@
import{r as d,m as C,_ as I,w as N,p as l,a as p,c as x,u as t,g as i,f as n,q as v,s as S,e as y,l as m,t as V,v as W,x as A,b as R}from"./index-afb4c379.js";function T(e){const s=d("url"),a=d(e),r=d(e),u=d([]);function b(w){let c=new FileReader;return c.onload=o=>{let _=o.target.result;r.value=_},c.readAsArrayBuffer(w),!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:w}=T(s.defaultSrc);return N(u,()=>{E.showLoading()},{immediate:!0}),(c,o)=>{const _=l("a-radio-button"),B=l("a-radio-group"),L=l("a-input"),h=l("a-button"),U=l("upload-outlined"),P=l("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:n(()=>[i(_,{value:"url"},{default:n(()=>[v("远程文件地址")]),_:1}),i(_,{value:"upload"},{default:n(()=>[v("上传本地文件")]),_:1})]),_:1},8,["value"]),t(a)==="url"?(p(),y(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(),y(h,{key:1,type:"primary",style:{"margin-left":"10px"},onClick:o[2]||(o[2]=f=>u.value=t(r))},{default:n(()=>[v(" 预览 ")]),_:1})):m("",!0),t(a)!=="url"?(p(),y(P,{key:2,accept:s.accept,action:"",beforeUpload:t(w),"file-list":[]},{default:n(()=>[i(h,{style:{"margin-left":"10px"}},{default:n(()=>[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};

96
examples/dist/assets/docx-fe694a97.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

99
examples/dist/assets/hack-34d5149e.js vendored Normal file

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

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

File diff suppressed because one or more lines are too long

1
examples/dist/assets/omit-eb6ad03a.js vendored Normal file

File diff suppressed because one or more lines are too long

1
examples/dist/assets/url-de9b02cf.js vendored Normal file
View File

@ -0,0 +1 @@
function i(e){return typeof e=="string"?e:e instanceof Blob?URL.createObjectURL(e):e instanceof ArrayBuffer?URL.createObjectURL(new Blob([e])):e instanceof Response?URL.createObjectURL(e.blob()):e}function l(e){return new Promise((n,t)=>{let o=document.createElement("script");o.src=e,o.onload=function(){n()},o.onerror=function(){t()},document.body.append(o)})}async function c(e,n){n&&(n instanceof ArrayBuffer&&(n=new Blob([n])),r(e,URL.createObjectURL(n)))}function r(e,n){let t=document.createElement("a");t.download=e,t.style.display="none",t.href=n,document.body.appendChild(t),t.click(),document.body.removeChild(t)}export{c as d,i as g,l};

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-893deb04.js"></script>
<script type="module" crossorigin src="/vue-office/examples/dist/assets/index-afb4c379.js"></script>
<link rel="stylesheet" href="/vue-office/examples/dist/assets/index-cc8fb346.css">
</head>
<body>