Skip to content
This repository has been archived by the owner on Mar 28, 2024. It is now read-only.

Commit

Permalink
fix(array unique very slow): fix it
Browse files Browse the repository at this point in the history
  • Loading branch information
tubiaoge committed Aug 26, 2020
1 parent 758d789 commit 20f3cb3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
29 changes: 26 additions & 3 deletions src/controllers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default function luckysheetHandler() {
const _locale = locale();
const locale_drag = _locale.drag;
const locale_info = _locale.info;
let prev
let prev, mousewheelArrayUniqueTimeout;
$("#luckysheet-grid-window-1").mousewheel(function (event, delta) {
let scrollLeft = $("#luckysheet-scrollbar-x").scrollLeft(),
scrollTop = $("#luckysheet-scrollbar-y").scrollTop();
Expand All @@ -123,8 +123,26 @@ export default function luckysheetHandler() {
visibledatacolumn_c = luckysheetFreezen.freezenverticaldata[3];
}

visibledatacolumn_c = ArrayUnique(visibledatacolumn_c);
visibledatarow_c = ArrayUnique(visibledatarow_c);
clearTimeout(mousewheelArrayUniqueTimeout);

if(Store.visibledatacolumn_unique!=null){
visibledatacolumn_c = Store.visibledatacolumn_unique;
}
else{
visibledatacolumn_c = ArrayUnique(visibledatacolumn_c);
Store.visibledatacolumn_unique = visibledatacolumn_c;
}

if(Store.visibledatarow_unique!=null){
visibledatarow_c = Store.visibledatarow_unique;
}
else{
visibledatarow_c = ArrayUnique(visibledatarow_c);
Store.visibledatarow_unique = visibledatarow_c;
}

// visibledatacolumn_c = ArrayUnique(visibledatacolumn_c);
// visibledatarow_c = ArrayUnique(visibledatarow_c);

let col_st = luckysheet_searcharray(visibledatacolumn_c, scrollLeft);
let row_st = luckysheet_searcharray(visibledatarow_c, scrollTop);
Expand Down Expand Up @@ -179,6 +197,11 @@ export default function luckysheetHandler() {

$("#luckysheet-scrollbar-x").scrollLeft(scrollLeft);
}

mousewheelArrayUniqueTimeout = setTimeout(() => {
Store.visibledatacolumn_unique = null;
Store.visibledatarow_unique = null;
}, 200);
});

$("#luckysheet-scrollbar-x").scroll(function(){
Expand Down
3 changes: 3 additions & 0 deletions src/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ const Store = {
measureTextCacheTimeOut:null,

zoomRatio:1,

visibledatacolumn_unique:null,
visibledatarow_unique:null,
}

export default Store;
13 changes: 7 additions & 6 deletions src/utils/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,18 @@ function getByteLen(val) {

//数组去重
function ArrayUnique(dataArr) {
let arr = [];

let result = [];
let obj = {};
if (dataArr.length > 0) {
for (let i = 0; i < dataArr.length; i++) {
if (arr.indexOf(dataArr[i]) == -1) {
arr.push(dataArr[i]);
let item = dataArr[i];
if (!obj[item]) {
result.push(item);
obj[item] = 1;
}
}
}

return arr;
return result
}

//获取字体配置
Expand Down

0 comments on commit 20f3cb3

Please sign in to comment.