fix: excel sheet过多不滚动问题

This commit is contained in:
liyulin 2023-08-28 10:45:19 +08:00
parent 2cd4e0aa16
commit d382b798fc
16 changed files with 330 additions and 3 deletions

View File

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

View File

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

View File

@ -411,6 +411,8 @@ body {
border-right: 1px solid #e8eaed; border-right: 1px solid #e8eaed;
} }
.x-spreadsheet-menu { .x-spreadsheet-menu {
display: flex;
overflow-x: auto;
list-style: none; list-style: none;
margin: 0; margin: 0;
padding: 0; padding: 0;

View File

@ -0,0 +1 @@
import{d as r}from"./docx-30db419d.js";import{d as x}from"./url-de9b02cf.js";import{d as m,_ as l,r as u,o as h,w as v,a as _,c as g,b as D,e as y,f as w,g as B,u as O}from"./index-53845faa.js";import{P as R,u as f}from"./PreviewWrapper-d7219173.js";import"./_commonjs-dynamic-modules-302442b1.js";const $=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()}),v(()=>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,save:s}}}),b={class:"vue-office-docx"},k={class:"vue-office-docx-main",ref:"rootRef"};function V(e,o,t,n,a,s){return _(),g("div",b,[D("div",k,null,512)])}const i=l($,[["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(R,{accept:".docx",placeholder:"请输入docx文件地址","default-src":n},{default:w(d=>[B(O(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 @@
import{l as R,r as B,S as T,a as h,g as k,b as $,t as L,c as D}from"./hack-8a07a03f.js";import{d as q}from"./url-de9b02cf.js";import{d as F,_ as V,r as m,o as W,n as j,h as I,w as M,a as S,c as N,b as P,i as A,e as H,f as U,j as z,g as G,u as J}from"./index-53845faa.js";import{P as K,u as O}from"./PreviewWrapper-d7219173.js";import"./_commonjs-dynamic-modules-302442b1.js";const E={minColLength:20},Q=F({name:"VueOfficeExcel",props:{src:[String,ArrayBuffer,Blob],requestOptions:{type:Object,default:()=>({})},options:{type:Object,default:()=>({...E})}},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,w=null;function _(c){w=c,$(c).then(l=>{if(!l._worksheets||l._worksheets.length===0)throw new Error("未获取到数据,可能文件格式不正确或文件已损坏");const{workbookData:x,medias:g,workbookSource:o}=L(l,{...E,...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&&e.loadData({}),i("error",l)})}const v=R.debounce(B,200).bind(this,s.value),b=new MutationObserver(v),y={attributes:!0,childList:!0,subtree:!0};W(()=>{j(()=>{b.observe(s.value,y),v(s),e=new T(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)})})}),I(()=>{b.disconnect(),e=null}),M(()=>t.src,()=>{t.src?k(t.src,t.requestOptions).then(_).catch(c=>{e.loadData({}),i("error",c)}):e.loadData({})});function C(c){q(c||`vue-office-excel-${new Date().getTime()}.xlsx`,w)}return{wrapperRef:n,rootRef:s,save:C}}}),X={class:"vue-office-excel",ref:"wrapperRef"},Y={class:"vue-office-excel-main",ref:"rootRef"};function Z(t,i,n,s,r,a){return S(),N("div",X,[P("div",Y,null,512)],512)}const p=V(Q,[["render",Z]]);p.install=function(t){t.component(p.name,p)};const re={__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=A("loading");return S(),H(K,{accept:".xlsx",placeholder:"请输入xlsx文件地址","default-src":s},{default:U(e=>[z(G(J(p),{ref_key:"docxRef",ref:r,src:e.src,style:{flex:"1",height:"0"},onRendered:i,onError:n},null,8,["src"]),[[u,!0]])]),_:1})}}};export{re 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-30db419d.js";import{d as l}from"./url-de9b02cf.js";import{r as h,o as d,a as u,c as m}from"./index-53845faa.js";import"./_commonjs-dynamic-modules-302442b1.js";class w{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)})})}save(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 w(i,e,t)}const v={init:f};const q={__name:"JsDocxDemo",setup(i){const e=h(null);return d(()=>{let t=v.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(),m("div",{ref_key:"dom",ref:e},null,512))}};export{q as default};

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-8a07a03f.js";import{d as k}from"./url-de9b02cf.js";/* empty css */import{r as v,o as b,a as S,c as D}from"./index-53845faa.js";import"./_commonjs-dynamic-modules-302442b1.js";const _={minColLength:20};class E{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={..._,...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)})})}save(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 g(r,e,t){return new E(r,e,t)}const O={init:g},T={__name:"JsExcelDemo",setup(r){const e=v(null);return b(()=>{window.myExcelPreview=O.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{T as default};

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,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-53845faa.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-30db419d.js vendored Normal file

File diff suppressed because one or more lines are too long

99
examples/dist/assets/hack-8a07a03f.js vendored Normal file

File diff suppressed because one or more lines are too long

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

File diff suppressed because one or more lines are too long

1
examples/dist/assets/omit-90366a56.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" content="width=device-width, initial-scale=1.0,minimum-scale=1.0, maximum-scale=1.0, user-scalable=no"
/> />
<title>@vue-office演示demo</title> <title>@vue-office演示demo</title>
<script type="module" crossorigin src="/vue-office/examples/dist/assets/index-b9f2cb0f.js"></script> <script type="module" crossorigin src="/vue-office/examples/dist/assets/index-53845faa.js"></script>
<link rel="stylesheet" href="/vue-office/examples/dist/assets/index-cc8fb346.css"> <link rel="stylesheet" href="/vue-office/examples/dist/assets/index-cc8fb346.css">
</head> </head>
<body> <body>