From ab2d8b7b5467200e12c8d4c1ece014ebfc6ee7cc Mon Sep 17 00:00:00 2001 From: renxxing <74659302+renxxing@users.noreply.github.com> Date: Wed, 25 Nov 2020 16:40:37 +0800 Subject: [PATCH] fix(fix #209): highlight highlight follow --- src/controllers/handler.js | 9 +- src/controllers/select.js | 358 +++++++++++++++++++++--------------- src/controllers/server.js | 36 +++- src/controllers/sheetBar.js | 2 - src/global/refresh.js | 11 +- src/index.html | 9 +- src/store/index.js | 4 +- 7 files changed, 261 insertions(+), 168 deletions(-) diff --git a/src/controllers/handler.js b/src/controllers/handler.js index 2af6e34ec..5d4904a1f 100644 --- a/src/controllers/handler.js +++ b/src/controllers/handler.js @@ -76,8 +76,6 @@ export default function luckysheetHandler() { if(isMobile){ mobileinit(); } - - if (!Date.now) Date.now = function() { return new Date().getTime(); }; //requestAnimationFrame method @@ -3263,7 +3261,6 @@ export default function luckysheetHandler() { }); //表格mouseup $(document).on("mouseup.luckysheetEvent",function (event) { - if(luckysheetConfigsetting && luckysheetConfigsetting.hook && luckysheetConfigsetting.hook.sheetMouseup){ let mouse = mouseposition(event.pageX, event.pageY); let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft(); @@ -3661,14 +3658,14 @@ export default function luckysheetHandler() { jfrefreshgrid_rhcw(Store.flowdata.length, null); } - + //改变列宽 if (Store.luckysheet_cols_change_size) { Store.luckysheet_cols_change_size = false; $("#luckysheet-change-size-line").hide(); $("#luckysheet-cols-change-size").css("opacity", 0); $("#luckysheet-sheettable, #luckysheet-cols-h-c, .luckysheet-cols-h-cells, .luckysheet-cols-h-cells canvas").css("cursor", "default"); - + let mouse = mouseposition(event.pageX, event.pageY); let scrollLeft = $("#luckysheet-cols-h-c").scrollLeft(); let x = mouse[0] + scrollLeft; @@ -3681,9 +3678,9 @@ export default function luckysheetHandler() { col = col_location[1], col_pre = col_location[0], col_index = col_location[2]; - let size = (x + 3) - Store.luckysheet_cols_change_size_start[0]; + let firstcolumnlen = Store.defaultcollen; if (Store.config["columnlen"] != null && Store.config["columnlen"][Store.luckysheet_cols_change_size_start[1]] != null) { firstcolumnlen = Store.config["columnlen"][Store.luckysheet_cols_change_size_start[1]]; diff --git a/src/controllers/select.js b/src/controllers/select.js index a4c1b01cc..1ff029f03 100644 --- a/src/controllers/select.js +++ b/src/controllers/select.js @@ -10,61 +10,61 @@ import locale from '../locale/locale'; //公式函数 选区实体框 function seletedHighlistByindex(id, r1, r2, c1, c2) { - let row = Store.visibledatarow[r2], + let row = Store.visibledatarow[r2], row_pre = r1 - 1 == -1 ? 0 : Store.visibledatarow[r1 - 1]; - let col = Store.visibledatacolumn[c2], + let col = Store.visibledatacolumn[c2], col_pre = c1 - 1 == -1 ? 0 : Store.visibledatacolumn[c1 - 1]; - $('#' + id).css({ - "left": col_pre, - "width": col - col_pre - 1, - "top": row_pre, - "height": row - row_pre - 1 + $('#' + id).css({ + "left": col_pre, + "width": col - col_pre - 1, + "top": row_pre, + "height": row - row_pre - 1 }); } //Set selection highlight -function selectHightlightShow(isRestore=false) { +function selectHightlightShow(isRestore = false) { $("#luckysheet-cell-selected-boxs").show(); $("#luckysheet-cell-selected-boxs #luckysheet-cell-selected").siblings(".luckysheet-cell-selected").remove(); - if(Store.luckysheet_select_save.length > 0){ - for(let i = 0; i < Store.luckysheet_select_save.length; i++){ - let r1 = Store.luckysheet_select_save[i].row[0], - r2 = Store.luckysheet_select_save[i].row[1]; - let c1 = Store.luckysheet_select_save[i].column[0], + if (Store.luckysheet_select_save.length > 0) { + for (let i = 0; i < Store.luckysheet_select_save.length; i++) { + let r1 = Store.luckysheet_select_save[i].row[0], + r2 = Store.luckysheet_select_save[i].row[1]; + let c1 = Store.luckysheet_select_save[i].column[0], c2 = Store.luckysheet_select_save[i].column[1]; - + let rf, cf; - if(Store.luckysheet_select_save[i].row_focus == null){ + if (Store.luckysheet_select_save[i].row_focus == null) { rf = r1; } - else{ - rf = Store.luckysheet_select_save[i].row_focus; + else { + rf = Store.luckysheet_select_save[i].row_focus; } - if(Store.luckysheet_select_save[i].column_focus == null){ + if (Store.luckysheet_select_save[i].column_focus == null) { cf = c1; } - else{ + else { cf = Store.luckysheet_select_save[i].column_focus; } - let row = Store.visibledatarow[r2], + let row = Store.visibledatarow[r2], row_pre = r1 - 1 == -1 ? 0 : Store.visibledatarow[r1 - 1]; - let col = Store.visibledatacolumn[c2], + let col = Store.visibledatacolumn[c2], col_pre = c1 - 1 == -1 ? 0 : Store.visibledatacolumn[c1 - 1]; - let row_f = Store.visibledatarow[rf], + let row_f = Store.visibledatarow[rf], row_pre_f = rf - 1 == -1 ? 0 : Store.visibledatarow[rf - 1]; - let col_f = Store.visibledatacolumn[cf], + let col_f = Store.visibledatacolumn[cf], col_pre_f = cf - 1 == -1 ? 0 : Store.visibledatacolumn[cf - 1]; let margeset = menuButton.mergeborer(Store.flowdata, rf, cf); - if(!!margeset){ + if (!!margeset) { row_f = margeset.row[1]; row_pre_f = margeset.row[0]; - + col_f = margeset.column[1]; col_pre_f = margeset.column[0]; } @@ -85,81 +85,81 @@ function selectHightlightShow(isRestore=false) { Store.luckysheet_select_save[i]["top_move"] = row_pre; Store.luckysheet_select_save[i]["height_move"] = row - row_pre - 1; - if(i == 0){ - if(Store.luckysheet_select_save.length == 1){ - if(browser.mobilecheck()){//移动端 - $("#luckysheet-cell-selected-boxs #luckysheet-cell-selected").css({ - "left": Store.luckysheet_select_save[i]["left_move"], - "width": Store.luckysheet_select_save[i]["width_move"], - "top": Store.luckysheet_select_save[i]["top_move"], - "height": Store.luckysheet_select_save[i]["height_move"], - "display": "block", - "border": "1px solid #0188fb" + if (i == 0) { + if (Store.luckysheet_select_save.length == 1) { + if (browser.mobilecheck()) {//移动端 + $("#luckysheet-cell-selected-boxs #luckysheet-cell-selected").css({ + "left": Store.luckysheet_select_save[i]["left_move"], + "width": Store.luckysheet_select_save[i]["width_move"], + "top": Store.luckysheet_select_save[i]["top_move"], + "height": Store.luckysheet_select_save[i]["height_move"], + "display": "block", + "border": "1px solid #0188fb" }) - .find(".luckysheet-cs-draghandle") - .css("display", "block") - .end() - .find(".luckysheet-cs-fillhandle") - .css("display", "none") - .end() - .find(".luckysheet-cs-touchhandle") - .css("display", "block"); + .find(".luckysheet-cs-draghandle") + .css("display", "block") + .end() + .find(".luckysheet-cs-fillhandle") + .css("display", "none") + .end() + .find(".luckysheet-cs-touchhandle") + .css("display", "block"); } - else{ - $("#luckysheet-cell-selected-boxs #luckysheet-cell-selected").css({ - "left": Store.luckysheet_select_save[i]["left_move"], - "width": Store.luckysheet_select_save[i]["width_move"], - "top": Store.luckysheet_select_save[i]["top_move"], - "height": Store.luckysheet_select_save[i]["height_move"], - "display": "block", - "border": "1px solid #0188fb" + else { + $("#luckysheet-cell-selected-boxs #luckysheet-cell-selected").css({ + "left": Store.luckysheet_select_save[i]["left_move"], + "width": Store.luckysheet_select_save[i]["width_move"], + "top": Store.luckysheet_select_save[i]["top_move"], + "height": Store.luckysheet_select_save[i]["height_move"], + "display": "block", + "border": "1px solid #0188fb" }) + .find(".luckysheet-cs-draghandle") + .css("display", "block") + .end() + .find(".luckysheet-cs-fillhandle") + .css("display", "block") + .end() + .find(".luckysheet-cs-touchhandle") + .css("display", "none"); + } + } + else { + $("#luckysheet-cell-selected-boxs #luckysheet-cell-selected").css({ + "left": Store.luckysheet_select_save[i]["left_move"], + "width": Store.luckysheet_select_save[i]["width_move"], + "top": Store.luckysheet_select_save[i]["top_move"], + "height": Store.luckysheet_select_save[i]["height_move"], + "display": "block", + "border": "1px solid rgba(1, 136, 251, 0.15)" + }) .find(".luckysheet-cs-draghandle") - .css("display", "block") + .css("display", "none") .end() .find(".luckysheet-cs-fillhandle") - .css("display", "block") - .end() - .find(".luckysheet-cs-touchhandle") .css("display", "none"); - } - } - else{ - $("#luckysheet-cell-selected-boxs #luckysheet-cell-selected").css({ - "left": Store.luckysheet_select_save[i]["left_move"], - "width": Store.luckysheet_select_save[i]["width_move"], - "top": Store.luckysheet_select_save[i]["top_move"], - "height": Store.luckysheet_select_save[i]["height_move"], - "display": "block", - "border": "1px solid rgba(1, 136, 251, 0.15)" - }) - .find(".luckysheet-cs-draghandle") - .css("display", "none") - .end() - .find(".luckysheet-cs-fillhandle") - .css("display", "none"); } } - else{ - $("#luckysheet-cell-selected-boxs").append('
'); + else { + $("#luckysheet-cell-selected-boxs").append(''); } - if(i == Store.luckysheet_select_save.length - 1){ + if (i == Store.luckysheet_select_save.length - 1) { //focus 取选区数组最后一个 - $("#luckysheet-cell-selected-focus").css({ - "left": Store.luckysheet_select_save[i]["left"], - "width": Store.luckysheet_select_save[i]["width"], - "top": Store.luckysheet_select_save[i]["top"], - "height": Store.luckysheet_select_save[i]["height"], - "display": "block" + $("#luckysheet-cell-selected-focus").css({ + "left": Store.luckysheet_select_save[i]["left"], + "width": Store.luckysheet_select_save[i]["width"], + "top": Store.luckysheet_select_save[i]["top"], + "height": Store.luckysheet_select_save[i]["height"], + "display": "block" }); //行列数 luckysheet_count_show( - Store.luckysheet_select_save[i]["left_move"], - Store.luckysheet_select_save[i]["top_move"], - Store.luckysheet_select_save[i]["width_move"], - Store.luckysheet_select_save[i]["height_move"], - [r1, r2], + Store.luckysheet_select_save[i]["left_move"], + Store.luckysheet_select_save[i]["top_move"], + Store.luckysheet_select_save[i]["width_move"], + Store.luckysheet_select_save[i]["height_move"], + [r1, r2], [c1, c2] ); //左上角选择区域框 @@ -170,13 +170,13 @@ function selectHightlightShow(isRestore=false) { } //行列标题栏 - selectTitlesShow(Store.luckysheet_select_save,isRestore); + selectTitlesShow(Store.luckysheet_select_save, isRestore); //左上角范围显示 selectHelpboxFill(); - + //动态数组显示 - if(Store.luckysheet_select_save.length == 1 && Store.luckysheet_select_save[0].row[0] == Store.luckysheet_select_save[0].row[1] && Store.luckysheet_select_save[0].column[0] == Store.luckysheet_select_save[0].column[1]){ + if (Store.luckysheet_select_save.length == 1 && Store.luckysheet_select_save[0].row[0] == Store.luckysheet_select_save[0].row[1] && Store.luckysheet_select_save[0].column[0] == Store.luckysheet_select_save[0].column[1]) { dynamicArrayHightShow(Store.luckysheet_select_save[0].row[0], Store.luckysheet_select_save[0].column[0]); } } @@ -185,19 +185,19 @@ function selectHightlightShow(isRestore=false) { } //选区标题栏 -function selectTitlesShow(rangeArr,isRestore=false) { +function selectTitlesShow(rangeArr, isRestore = false) { let s = $.extend(true, [], rangeArr); let rowTitleMap = {}, columnTitleMap = {}; - for(let i = 0; i < s.length; i++){ + for (let i = 0; i < s.length; i++) { let r1 = s[i]["row"][0], r2 = s[i]["row"][1], c1 = s[i]["column"][0], c2 = s[i]["column"][1]; - + // if(isRestore){ // let margeset = menuButton.mergeborer(Store.flowdata, r1, c1); // if(!!margeset){ // r1 = margeset.row[2]; // r2 = margeset.row[3]; - + // c1 = margeset.column[2]; // c2 = margeset.column[3]; // } @@ -212,29 +212,30 @@ function selectTitlesShow(rangeArr,isRestore=false) { $("#luckysheet-rows-h-selected").empty(); let rowTitleRange = selectTitlesRange(rowTitleMap); - for(let i = 0; i < rowTitleRange.length; i++){ + for (let i = 0; i < rowTitleRange.length; i++) { let r1 = rowTitleRange[i][0], r2 = rowTitleRange[i][rowTitleRange[i].length - 1]; let row = rowLocationByIndex(r2)[1], row_pre = rowLocationByIndex(r1)[0]; - - $("#luckysheet-rows-h-selected").append(''); + + $("#luckysheet-rows-h-selected").append(''); } //列标题 $("#luckysheet-cols-h-selected").empty(); let columnTitleRange = selectTitlesRange(columnTitleMap); - for(let j = 0; j < columnTitleRange.length; j++){ + for (let j = 0; j < columnTitleRange.length; j++) { let c1 = columnTitleRange[j][0], c2 = columnTitleRange[j][columnTitleRange[j].length - 1]; let col = colLocationByIndex(c2)[1], col_pre = colLocationByIndex(c1)[0]; - - $("#luckysheet-cols-h-selected").append(''); + + $("#luckysheet-cols-h-selected").append(''); + } } function selectTitlesMap(rangeMap, range1, range2) { let map = $.extend(true, {}, rangeMap); - - for(let i = range1; i <= range2; i++){ - if(i in map){ + + for (let i = range1; i <= range2; i++) { + if (i in map) { continue; } @@ -245,51 +246,51 @@ function selectTitlesMap(rangeMap, range1, range2) { } function selectTitlesRange(map) { let mapArr = []; - - for(let i in map){ + + for (let i in map) { mapArr.push(i); } - mapArr.sort(function(a, b){ return a - b; }); + mapArr.sort(function (a, b) { return a - b; }); let rangeArr = []; let item = []; - if(mapArr.length > 1){ - for(let j = 1; j < mapArr.length; j++){ - if(mapArr[j] - mapArr[j - 1] == 1){ + if (mapArr.length > 1) { + for (let j = 1; j < mapArr.length; j++) { + if (mapArr[j] - mapArr[j - 1] == 1) { item.push(mapArr[j - 1]); - - if(j == mapArr.length - 1){ + + if (j == mapArr.length - 1) { item.push(mapArr[j]); rangeArr.push(item); } } - else{ - if(j == 1){ - if(j == mapArr.length - 1){ + else { + if (j == 1) { + if (j == mapArr.length - 1) { item.push(mapArr[j - 1]); rangeArr.push(item); rangeArr.push([mapArr[j]]); } - else{ - rangeArr.push(mapArr[0]); + else { + rangeArr.push(mapArr[0]); } } - else if(j == mapArr.length - 1){ + else if (j == mapArr.length - 1) { item.push(mapArr[j - 1]); rangeArr.push(item); rangeArr.push([mapArr[j]]); } - else{ + else { item.push(mapArr[j - 1]); rangeArr.push(item); - item = []; + item = []; } } } } - else{ + else { rangeArr.push([mapArr[0]]); } @@ -298,26 +299,26 @@ function selectTitlesRange(map) { //选区是否重叠 function selectIsOverlap(range) { - if(range == null){ + if (range == null) { range = Store.luckysheet_select_save; } let overlap = false; let map = {}; - for(let s = 0; s < range.length; s++){ - let str_r = range[s].row[0], + for (let s = 0; s < range.length; s++) { + let str_r = range[s].row[0], end_r = range[s].row[1]; - let str_c = range[s].column[0], + let str_c = range[s].column[0], end_c = range[s].column[1]; - for(let r = str_r; r <= end_r; r++){ - for(let c = str_c; c <= end_c; c++){ - if((r + "_" + c) in map){ + for (let r = str_r; r <= end_r; r++) { + for (let c = str_c; c <= end_c; c++) { + if ((r + "_" + c) in map) { overlap = true; break; } - else{ + else { map[r + "_" + c] = 0; } } @@ -326,32 +327,92 @@ function selectIsOverlap(range) { return overlap; } +// 协同提示框 +function collaborativeEditBox(val1,val2) { + let all_data = luckysheet.getLuckysheetfile(); //获取整个表格数据 + let all_width = [];//当前操作页的所有列距离左边的距离 + let all_height = [];//当前操作页的所有列距离顶部的距离 + all_data.forEach((value1) => { + if(value1.index == Store.currentSheetIndex) { + all_width = value1.visibledatacolumn + all_height = value1.visibledatarow + } + }) + Store.cooperativeEdit.changeCollaborationSize.forEach(value => { + if (value.i == Store.currentSheetIndex) { + if(val1 !== null) { + for(let k in val1) { + if(value.v.column[0] <= k && k <= value.v.column[1]) { + Store.luckysheet_cols_change_size_start[1] = k - 0 + break + } + } + } + if(val2 !== null) { + for(let k in val2) { + if(value.v.row[0] <= k && k <= value.v.row[1]) { + Store.luckysheet_rows_change_size_start[1] = k - 0 + break + } + } + } + let flag1 = value.v.column[0] <= Store.luckysheet_cols_change_size_start[1] && Store.luckysheet_cols_change_size_start[1] <= value.v.column[1] + if(flag1) { + if(Store.luckysheet_cols_change_size_start[1] == 0) { + let change_width = all_width[0] - 1 + $("#luckysheet-multipleRange-show-" + value.id).css({"width":change_width}) + } else { + let count1 = value.v.column[0]; + let count2 = value.v.column[1]; + let change_width1 = all_width[count2] - all_width[count1 - 1] - (count2 - count1 + 1) + $("#luckysheet-multipleRange-show-" + value.id).css({"width":change_width1}) + } + } + let change_width2 = all_width[value.v.column[0] - 1] - 1 + $("#luckysheet-multipleRange-show-" + value.id).css({"left":change_width2 + 'px'}) + let flag2 = value.v.row[0] <= Store.luckysheet_rows_change_size_start[1] && Store.luckysheet_rows_change_size_start[1] <= value.v.row[1] + if(flag2) { + if(Store.luckysheet_rows_change_size_start[1] == 0) { + let change_height = all_height[0] - 1 + $("#luckysheet-multipleRange-show-" + value.id).css({"height":change_height}) + } else { + let count1 = value.v.row[0]; + let count2 = value.v.row[1]; + let change_height1 = all_height[count2] - all_height[count1 - 1] - (count2 - count1 + 1) + $("#luckysheet-multipleRange-show-" + value.id).css({"height":change_height1}) + } + } + let change_height2 = all_height[value.v.row[0] - 1] - 1 + $("#luckysheet-multipleRange-show-" + value.id).css({"top":change_height2 + 'px'}) + } + }) +} //复制选区虚线框 function selectionCopyShow(range) { $("#luckysheet-selection-copy").empty(); - if(range == null){ + if (range == null) { range = Store.luckysheet_selection_range; } - if(range.length > 0){ - for(let s = 0; s < range.length; s++){ + if (range.length > 0) { + for (let s = 0; s < range.length; s++) { let r1 = range[s].row[0], r2 = range[s].row[1]; let c1 = range[s].column[0], c2 = range[s].column[1]; - let row = Store.visibledatarow[r2], + let row = Store.visibledatarow[r2], row_pre = r1 - 1 == -1 ? 0 : Store.visibledatarow[r1 - 1]; - let col = Store.visibledatacolumn[c2], + let col = Store.visibledatacolumn[c2], col_pre = c1 - 1 == -1 ? 0 : Store.visibledatacolumn[c1 - 1]; - let copyDomHtml = '