mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2026-09-13 16:34:53 +00:00
Optimize LuckyExcel xlsx preview conversion with Web Worker (#766)
* Optimize LuckyExcel conversion with worker * Fallback LuckyExcel worker errors to main thread
This commit is contained in:
54
server/src/main/resources/static/xlsx/luckyexcel-worker.js
Normal file
54
server/src/main/resources/static/xlsx/luckyexcel-worker.js
Normal file
@@ -0,0 +1,54 @@
|
||||
// LuckyExcel's bundled getBinaryContent reads window.XMLHttpRequest.
|
||||
// Web Worker exposes XMLHttpRequest on self, so provide a minimal window alias
|
||||
// before loading the UMD bundle.
|
||||
self.window = self;
|
||||
|
||||
importScripts('./luckyexcel.umd.js');
|
||||
|
||||
self.console.log = function () {};
|
||||
|
||||
self.onmessage = function (event) {
|
||||
var data = event.data || {};
|
||||
var url = data.url;
|
||||
var name = data.name;
|
||||
|
||||
if (!url) {
|
||||
self.postMessage({
|
||||
type: 'error',
|
||||
message: '文件URL为空'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
LuckyExcel.transformExcelToLuckyByUrl(
|
||||
url,
|
||||
name,
|
||||
function (exportJson, luckysheetfile) {
|
||||
if (!exportJson || !exportJson.sheets || exportJson.sheets.length === 0) {
|
||||
self.postMessage({
|
||||
type: 'error',
|
||||
message: '读取excel文件内容失败!'
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
self.postMessage({
|
||||
type: 'success',
|
||||
exportJson: exportJson
|
||||
});
|
||||
},
|
||||
function (error) {
|
||||
self.postMessage({
|
||||
type: 'error',
|
||||
message: error && error.message ? error.message : String(error)
|
||||
});
|
||||
}
|
||||
);
|
||||
} catch (error) {
|
||||
self.postMessage({
|
||||
type: 'error',
|
||||
message: error && error.message ? error.message : String(error)
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -3938,7 +3938,7 @@ var LuckySheet = /** @class */function (_super) {
|
||||
_this.sheetList = allFileOption.sheetList;
|
||||
_this.imageList = allFileOption.imageList;
|
||||
_this.hide = allFileOption.hide;
|
||||
console.log(allFileOption, 'allFileOption');
|
||||
// console.log(allFileOption, 'allFileOption');
|
||||
_this.dataVerificationSelectCount = allFileOption.dataVerificationSelectCount;
|
||||
//Output
|
||||
_this.name = sheetName;
|
||||
|
||||
Reference in New Issue
Block a user