From 60767ec3b6d8bd046d657f423cba846732301f13 Mon Sep 17 00:00:00 2001 From: luobowen Date: Thu, 25 May 2023 10:08:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9excel=E7=9A=84fetch=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E4=B8=BAxhr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/packages/excel/src/excel.js | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/core/packages/excel/src/excel.js b/core/packages/excel/src/excel.js index 5315bc0..6a16d13 100644 --- a/core/packages/excel/src/excel.js +++ b/core/packages/excel/src/excel.js @@ -21,16 +21,30 @@ 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); - } - return res.arrayBuffer(); - }); +function request(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.send(options.body); + }); +} + +function requestExcel(src, options) { + return request(src, options); }