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

Commit

Permalink
feat(hide column): hide column
Browse files Browse the repository at this point in the history
hide column
  • Loading branch information
wpxp123456 committed Aug 25, 2020
1 parent cb26ede commit 9f05959
Show file tree
Hide file tree
Showing 6 changed files with 215 additions and 98 deletions.
10 changes: 10 additions & 0 deletions src/controllers/constant.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions src/controllers/controlHistory.js
Expand Up @@ -154,6 +154,16 @@ const controlHistory = {
//行高、列宽 刷新
jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
}
else if (ctr.type == "showHidCols") { // 隐藏、显示列 撤销操作
//config
Store.config = ctr.config;
Store.luckysheetfile[getSheetIndex(ctr.sheetIndex)].config = ctr.config;

server.saveParam("cg", ctr.sheetIndex, ctr.config["colhidden"], { "k": "colhidden" });

//行高、列宽 刷新
jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
}
else if (ctr.type == "datachangeAll") {
formula.execFunctionGroup();
jfrefreshgridall(ctr.data[0].length, ctr.data.length, ctr.data, null, ctr.range, "datachangeAll", ctr.ctrlValue);
Expand Down Expand Up @@ -405,6 +415,16 @@ const controlHistory = {
//行高、列宽 刷新
jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
}
else if (ctr.type == "showHidCols") { // 隐藏、显示列 重做操作
//config
Store.config = ctr.curconfig;
Store.luckysheetfile[getSheetIndex(ctr.sheetIndex)].config = ctr.curconfig;

server.saveParam("cg", ctr.sheetIndex, ctr.curconfig["colhidden"], { "k": "colhidden" });

//行高、列宽 刷新
jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
}
else if (ctr.type == "datachangeAll") {
formula.execFunctionGroup();
jfrefreshgridall(ctr.curdata[0].length, ctr.curdata.length, ctr.curdata, null, ctr.currange, "datachangeAll", ctr.ctrlValue);
Expand Down
88 changes: 82 additions & 6 deletions src/controllers/rowColumnOperation.js
Expand Up @@ -1295,9 +1295,7 @@ export function rowColumnOperationInitial(){

for(let s = 0; s < Store.luckysheet_select_save.length; s++){
let r1 = Store.luckysheet_select_save[s].row[0],
r2 = Store.luckysheet_select_save[s].row[1],
c1 = Store.luckysheet_select_save[s].column[0],
c2 = Store.luckysheet_select_save[s].column[1];
r2 = Store.luckysheet_select_save[s].row[1];

for(let r = r1; r <= r2; r++){
cfg["rowhidden"][r] = 0;
Expand Down Expand Up @@ -1336,9 +1334,7 @@ export function rowColumnOperationInitial(){

for(let s = 0; s < Store.luckysheet_select_save.length; s++){
let r1 = Store.luckysheet_select_save[s].row[0],
r2 = Store.luckysheet_select_save[s].row[1],
c1 = Store.luckysheet_select_save[s].column[0],
c2 = Store.luckysheet_select_save[s].column[1];
r2 = Store.luckysheet_select_save[s].row[1];

for(let r = r1; r <= r2; r++){
delete cfg["rowhidden"][r];
Expand Down Expand Up @@ -1367,6 +1363,86 @@ export function rowColumnOperationInitial(){
jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
})

//隐藏、显示列
$("#luckysheet-hidCols").click(function (event) {
$("#luckysheet-rightclick-menu").hide();
luckysheetContainerFocus();

let cfg = $.extend(true, {}, Store.config);
if(cfg["colhidden"] == null){
cfg["colhidden"] = {};
}

for(let s = 0; s < Store.luckysheet_select_save.length; s++){
let c1 = Store.luckysheet_select_save[s].column[0],
c2 = Store.luckysheet_select_save[s].column[1];

for(let c = c1; c <= c2; c++){
cfg["colhidden"][c] = 0;
}
}

//保存撤销
if(Store.clearjfundo){
let redo = {};
redo["type"] = "showHidCols";
redo["sheetIndex"] = Store.currentSheetIndex;
redo["config"] = $.extend(true, {}, Store.config);
redo["curconfig"] = cfg;

Store.jfundo = [];
Store.jfredo.push(redo);
}

//config
Store.config = cfg;
Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].config = Store.config;

server.saveParam("cg", Store.currentSheetIndex, cfg["colhidden"], { "k": "colhidden" });

//行高、列宽 刷新
jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
})
$("#luckysheet-showHidCols").click(function (event) {
$("#luckysheet-rightclick-menu").hide();
luckysheetContainerFocus();

let cfg = $.extend(true, {}, Store.config);
if(cfg["colhidden"] == null){
return;
}

for(let s = 0; s < Store.luckysheet_select_save.length; s++){
let c1 = Store.luckysheet_select_save[s].column[0],
c2 = Store.luckysheet_select_save[s].column[1];

for(let c = c1; c <= c2; c++){
delete cfg["colhidden"][c];
}
}

//保存撤销
if(Store.clearjfundo){
let redo = {};
redo["type"] = "showHidCols";
redo["sheetIndex"] = Store.currentSheetIndex;
redo["config"] = $.extend(true, {}, Store.config);
redo["curconfig"] = cfg;

Store.jfundo = [];
Store.jfredo.push(redo);
}

//config
Store.config = cfg;
Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].config = Store.config;

server.saveParam("cg", Store.currentSheetIndex, cfg["colhidden"], { "k": "colhidden" });

//行高、列宽 刷新
jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
})

//删除单元格(左移、上移)
$("#luckysheet-delCellsMoveLeft").click(function (event) {
$("#luckysheet-rightclick-menu").hide();
Expand Down
164 changes: 86 additions & 78 deletions src/global/draw.js
Expand Up @@ -223,28 +223,33 @@ function luckysheetDrawgridColumnTitle(scrollWidth, drawWidth, offsetLeft) {
// if(end_c > scrollWidth + drawWidth+1){
// break;
// }

if (Store.config["colhidden"] != null && Store.config["colhidden"][c] != null) {

luckysheetTableContent.fillStyle = "#ffffff";
luckysheetTableContent.fillRect(
(start_c + offsetLeft - 1) ,
0,
(end_c - start_c) ,
Store.columeHeaderHeight -1
)
luckysheetTableContent.fillStyle = "#000000";
}
else {
luckysheetTableContent.fillStyle = "#ffffff";
luckysheetTableContent.fillRect(
(start_c + offsetLeft - 1) ,
0,
(end_c - start_c) ,
Store.columeHeaderHeight -1
)
luckysheetTableContent.fillStyle = "#000000";

//列标题栏序列号
luckysheetTableContent.save();//save scale before draw text
luckysheetTableContent.scale(Store.zoomRatio,Store.zoomRatio);
let abc = chatatABC(c);
let textMetrics = getMeasureText(abc, luckysheetTableContent);
//luckysheetTableContent.measureText(abc);
//列标题栏序列号
luckysheetTableContent.save();//save scale before draw text
luckysheetTableContent.scale(Store.zoomRatio,Store.zoomRatio);
let abc = chatatABC(c);
let textMetrics = getMeasureText(abc, luckysheetTableContent);
//luckysheetTableContent.measureText(abc);

let horizonAlignPos = Math.round((start_c + (end_c - start_c) / 2 + offsetLeft) - textMetrics.width / 2);
let verticalAlignPos = Math.round(Store.columeHeaderHeight / 2 );

luckysheetTableContent.fillText(abc, horizonAlignPos/Store.zoomRatio, verticalAlignPos/Store.zoomRatio);
luckysheetTableContent.restore();//restore scale after draw text
let horizonAlignPos = Math.round((start_c + (end_c - start_c) / 2 + offsetLeft) - textMetrics.width / 2);
let verticalAlignPos = Math.round(Store.columeHeaderHeight / 2 );

luckysheetTableContent.fillText(abc, horizonAlignPos/Store.zoomRatio, verticalAlignPos/Store.zoomRatio);
luckysheetTableContent.restore();//restore scale after draw text
}

//列标题栏竖线 vertical
luckysheetTableContent.beginPath();
Expand Down Expand Up @@ -465,6 +470,10 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of
}

let end_r = Store.visibledatarow[r] - scrollHeight;

if (Store.config["rowhidden"] != null && Store.config["rowhidden"][r] != null) {
continue;
}

for (let c = dataset_col_st; c <= dataset_col_ed; c++) {
let start_c;
Expand All @@ -477,78 +486,77 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of

let end_c = Store.visibledatacolumn[c] - scrollWidth;

if (Store.config["rowhidden"] != null && Store.config["rowhidden"][r] != null) {

if (Store.config["colhidden"] != null && Store.config["colhidden"][c] != null) {
continue
}

let firstcolumnlen = Store.defaultcollen;
if (Store.config["columnlen"] != null && Store.config["columnlen"][c] != null) {
firstcolumnlen = Store.config["columnlen"][c];
}
else {
let firstcolumnlen = Store.defaultcollen;
if (Store.config["columnlen"] != null && Store.config["columnlen"][c] != null) {
firstcolumnlen = Store.config["columnlen"][c];
}

if (Store.flowdata[r] != null && Store.flowdata[r][c] != null) {
let value = Store.flowdata[r][c];
if (Store.flowdata[r] != null && Store.flowdata[r][c] != null) {
let value = Store.flowdata[r][c];

if(getObjType(value) == "object" && ("mc" in value)){
borderOffset[r + "_" + c] = {
"start_r": start_r,
"start_c": start_c,
"end_r": end_r,
"end_c": end_c
};
if(getObjType(value) == "object" && ("mc" in value)){
borderOffset[r + "_" + c] = {
"start_r": start_r,
"start_c": start_c,
"end_r": end_r,
"end_c": end_c
};

if("rs" in value["mc"]){
let key = "r"+ r + "c" + c;
if("rs" in value["mc"]){
let key = "r"+ r + "c" + c;
mergeCache[key] = cellupdate.length;
}
else{
let key = "r"+ value["mc"].r + "c" + value["mc"].c;
let margeMain = cellupdate[mergeCache[key]];

if(margeMain == null){
mergeCache[key] = cellupdate.length;
cellupdate.push({
"r": r,
"c": c,
"start_c": start_c,
"start_r": start_r,
"end_r": end_r,
"end_c": end_c,
"firstcolumnlen": firstcolumnlen,
});
}
else{
let key = "r"+ value["mc"].r + "c" + value["mc"].c;
let margeMain = cellupdate[mergeCache[key]];

if(margeMain == null){
mergeCache[key] = cellupdate.length;
cellupdate.push({
"r": r,
"c": c,
"start_c": start_c,
"start_r": start_r,
"end_r": end_r,
"end_c": end_c,
"firstcolumnlen": firstcolumnlen,
});
if(margeMain.c == c){
margeMain.end_r += (end_r - start_r - 1);
}
else{
if(margeMain.c == c){
margeMain.end_r += (end_r - start_r - 1);
}

if(margeMain.r == r){
margeMain.end_c += (end_c - start_c);
margeMain.firstcolumnlen += firstcolumnlen;
}

if(margeMain.r == r){
margeMain.end_c += (end_c - start_c);
margeMain.firstcolumnlen += firstcolumnlen;
}

continue;
}

continue;
}
}

cellupdate.push({
"r": r,
"c": c,
"start_r": start_r,
"start_c": start_c,
"end_r": end_r,
"end_c": end_c,
"firstcolumnlen": firstcolumnlen,
});
borderOffset[r + "_" + c] = {
"start_r": start_r,
"start_c": start_c,
"end_r": end_r,
"end_c": end_c
};
}

cellupdate.push({
"r": r,
"c": c,
"start_r": start_r,
"start_c": start_c,
"end_r": end_r,
"end_c": end_c,
"firstcolumnlen": firstcolumnlen,
});
borderOffset[r + "_" + c] = {
"start_r": start_r,
"start_c": start_c,
"end_r": end_r,
"end_c": end_c
};
}
}

Expand Down

0 comments on commit 9f05959

Please sign in to comment.