Compare commits

...

6 Commits

Author SHA1 Message Date
liyulin
165a93cbc7 fix: excel动态src丢失requestOptions 2023-06-02 10:14:19 +08:00
liyulin
758db9c904 change: excel fetch->xhr 2023-05-29 11:51:06 +08:00
hit757
f7caa3984d
Merge pull request #54 from lbw1998/replace-fetch
将excel读取文件的方法由fetch更改为xhr
2023-05-29 11:33:37 +08:00
luobowen
96dfa82b0b 更改方法名称 2023-05-29 10:41:09 +08:00
luobowen
60767ec3b6 更改excel的fetch请求为xhr 2023-05-25 10:08:07 +08:00
liyulin
b4e14063d9 change: 默认禁用excel右键菜单 2023-05-24 09:54:02 +08:00
14 changed files with 663 additions and 11 deletions

View File

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

View File

@ -19,21 +19,36 @@ const themeColor = [
];
let defaultColWidth = 80;
const weekday = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
export function getData(src, options={}) {
return fetchExcel(getUrl(src), options);
return requestExcel(getUrl(src), options);
}
function fetchExcel(src, options) {
return fetch(src, options).then(res=>{
if(res.status !== 200){
return Promise.reject(res);
function requestExcel(src, options) {
return new Promise(function(resolve, reject) {
const xhr = new XMLHttpRequest();
xhr.open(options.method || 'GET', src, true);
xhr.responseType = options.responseType || 'arraybuffer';
xhr.onload = function() {
if (xhr.status === 200) {
resolve(xhr.response);
} else {
reject(xhr.status);
}
};
xhr.onerror = function() {
reject(xhr.status);
};
xhr.withCredentials = options.withCredentials || false;
if(options.headers) {
Object.keys(options.headers).forEach(function(key) {
xhr.setRequestHeader(key, options.headers[key]);
});
}
return res.arrayBuffer();
xhr.send(options.body);
});
}
export function readExcelData(buffer){
try {
const wb = new Excel.Workbook();

View File

@ -73,6 +73,7 @@ export default defineComponent({
window.xs = xs = new Spreadsheet(rootRef.value, {
mode: 'read',
showToolbar: false,
showContextmenu: props.options.showContextmenu || false,
view: {
height: () => wrapperRef.value && wrapperRef.value.clientHeight || 300,
width: () => wrapperRef.value && wrapperRef.value.clientWidth || 300,
@ -130,7 +131,7 @@ export default defineComponent({
});
watch(() => props.src, () => {
if (props.src) {
getData(props.src).then(renderExcel).catch(e => {
getData(props.src, props.requestOptions).then(renderExcel).catch(e => {
xs.loadData({});
emit('error', e);
});

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

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,q as C,_ as I,w as N,s as n,a as p,b as x,u as t,h as i,g as l,t as v,v as S,f as w,p as m,x as V,y as W,z as A,e as R}from"./index-cfab8763.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 z={loading:g,showLoading:$,hideLoading:q};function E(){return location.href.includes("test")}const F=e=>(W("data-v-6e0b6946"),e=e(),A(),e),j={class:"preview-wrapper"},D={key:0,class:"operate-area"},G=F(()=>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,()=>{z.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",j,[t(E)()?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,z as u};

View File

@ -0,0 +1 @@
import{r as d,q as C,_ as I,w as N,s as n,a as p,b as x,u as t,h as i,g as l,t as v,v as S,f as w,p as m,x as V,y as W,z as A,e as R}from"./index-55f94884.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 z={loading:g,showLoading:$,hideLoading:q};function E(){return location.href.includes("test")}const F=e=>(W("data-v-6e0b6946"),e=e(),A(),e),j={class:"preview-wrapper"},D={key:0,class:"operate-area"},G=F(()=>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,()=>{z.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",j,[t(E)()?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,z as u};

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

File diff suppressed because one or more lines are too long

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