diff --git a/src/controllers/constant.js b/src/controllers/constant.js index cc2d881b7..a2cd635db 100644 --- a/src/controllers/constant.js +++ b/src/controllers/constant.js @@ -491,8 +491,11 @@ function sheetconfigHTML(){ `; } -const luckysheetPivotTableHTML = '
数据透视表
编辑范围
选择需要添加到数据透视表的字段 清除
筛选
数值
'; - +const luckysheetPivotTableHTML = function(){ + const _locale = locale(); + const locale_pivotTable = _locale.pivotTable; + return '
数据透视表
编辑范围
选择需要添加到数据透视表的字段 清除
筛选
数值
'; +} function filtermenuHTML() { const _locale = locale(); diff --git a/src/controllers/filter.js b/src/controllers/filter.js index e667cf5b7..cd6cca5b9 100644 --- a/src/controllers/filter.js +++ b/src/controllers/filter.js @@ -2,13 +2,27 @@ import { getSheetIndex } from '../methods/get'; import editor from '../global/editor'; import { isRealNull, isEditMode } from '../global/validate'; import tooltip from '../global/tooltip'; -import { orderbydata } from '../global/sort'; import { rowlenByRange } from '../global/getRowlen'; -import { jfrefreshgrid } from '../global/refresh'; import { selectHightlightShow } from './select'; import { luckysheetMoveEndCell } from './sheetMove'; import server from './server'; +import locale from '../locale/locale'; import Store from '../store'; +import menuButton from './menuButton'; +import conditionformat from './conditionformat'; +import alternateformat from './alternateformat'; +import { + rgbTohex, + showrightclickmenu, +} from '../utils/util'; +import cleargridelement from '../global/cleargridelement'; +import { + jfrefreshgrid, + jfrefreshgrid_rhcw, +} from '../global/refresh'; +import { orderbydata, orderbydata1D } from '../global/sort'; +import json from '../global/json'; +import { update, genarate } from '../global/format'; //筛选配置状态 function labelFilterOptionState($top, optionstate, rowhidden, caljs, notSave, str, edr, cindex, stc, edc) { @@ -263,9 +277,1501 @@ function createFilterOptions(luckysheet_filter_save, filterObj) { file.filter_select = luckysheet_filter_save; } + + +function initialFilterHandler(){ + //filter event handler + let hidefilersubmenu = null; + const _locale = locale(); + const locale_filter = _locale.filter; + const locale_button= _locale.button; + $("#luckysheetfilter").click(createFilter); + + //右键菜单 菜单项hover + let submenuhide = null, rightclickmenu = null; + $(".luckysheet-cols-menu .luckysheet-cols-submenu").hover( + function () { + let $t = $(this), attrid = $t.attr("id"), $attr = $("#" + attrid + "_sub"), $con = $t.parent(); + let winW = $(window).width(), winH = $(window).height(); + let menuW = $con.width(), attrH = $attr.height() + 25, attrW = $attr.width() + 5; + let offset = $t.offset(); + let top = offset.top, left = offset.left + menuW; + + if (left + attrW > winW) { + left = offset.left - attrW; + } + + if (top + attrH > winH) { + top = winH - attrH; + } + + $attr.css({ "top": top, "left": left }).show(); + rightclickmenu = $t; + }, + function () { + let $t = $(this), attrid = $t.attr("id"), $attr = $("#" + attrid + "_sub"); + submenuhide = setTimeout(function () { $attr.hide(); }, 200); + } + ); + + $(".luckysheet-rightgclick-menu-sub").hover( + function () { + rightclickmenu.addClass("luckysheet-cols-menuitem-hover"); + clearTimeout(submenuhide); + }, + function () { + rightclickmenu.removeClass("luckysheet-cols-menuitem-hover"); + $(this).hide(); + } + ); + + $("#luckysheet-filter-menu").mouseover(function () { + clearTimeout(hidefilersubmenu); + + hidefilersubmenu = setTimeout(function () { + $("#luckysheet-filter-submenu").hide(); + }, 500); + }); + + + $("#luckysheet-filter-submenu").mouseover(function () { + clearTimeout(hidefilersubmenu); + }).find(".luckysheet-cols-menuitem").click(function (e) { + $("#luckysheet-filter-selected span").html($(this).find(".luckysheet-cols-menuitem-content").text()).data("value", $(this).data("value")); + $("#luckysheet-filter-menu .luckysheet-filter-selected-input").hide(); + + let $type = $(this).data("type"); + let $value = $(this).attr("data-value"); + + if ($type == "2") { + $("#luckysheet-filter-selected span").data("type", "2"); + $("#luckysheet-filter-menu .luckysheet-filter-selected-input2").show(); + $("#luckysheet-filter-menu .luckysheet-filter-selected-input input").prop("type", "number"); + } + else if ($type == "0") { + $("#luckysheet-filter-selected span").data("type", "0"); + } + else { + $("#luckysheet-filter-selected span").data("type", "1"); + $("#luckysheet-filter-menu .luckysheet-filter-selected-input").eq(0).show(); + + //若是日期 改变input type类型为date + if($value == "dateequal" || $value == "datelessthan" || $value == "datemorethan"){ + $("#luckysheet-filter-menu .luckysheet-filter-selected-input input").prop("type", "date"); + } + else if($value == "morethan" || $value == "moreequalthan" || $value == "lessthan" || $value == "lessequalthan" || $value == "equal" || $value == "noequal"){ + $("#luckysheet-filter-menu .luckysheet-filter-selected-input input").prop("type", "number"); + } + else{ + $("#luckysheet-filter-menu .luckysheet-filter-selected-input input").prop("type", "text"); + } + } + + $("#luckysheet-filter-byvalue").next().slideUp(); + $("#luckysheet-filter-submenu").hide(); + }); + + $("#luckysheet-filter-bycondition, #luckysheet-filter-byvalue").click(function () { + let $t = $(this); + $t.next().slideToggle(200); + + setTimeout(function () { + if ($t.attr("id") == "luckysheet-filter-bycondition" && $("#luckysheet-filter-bycondition").next().is(":visible")) { + if ($("#luckysheet-filter-selected span").text() != locale_filter.filiterInputNone) { + $("#luckysheet-filter-byvalue").next().slideUp(200); + } + } + + if ($t.is($("#luckysheet-filter-bycondition"))) { + if ($("#luckysheet-filter-bycondition").next().is(":hidden") && $("#luckysheet-filter-byvalue").next().is(":hidden")) { + $("#luckysheet-filter-byvalue").next().slideDown(200); + } + } + }, 300); + }); + + $("#luckysheet-filter-selected").click(function () { + let $t = $(this), toffset = $t.offset(), $menu = $("#luckysheet-filter-submenu"); + $menu.hide(); + + let winH = $(window).height(), winW = $(window).width(); + let menuW = $menu.width(), menuH = $menu.height(); + let top = toffset.top, left = toffset.left, mheight = winH - toffset.top - 20; + + if (toffset.left + menuW > winW) { + left = toffset.left - menuW; + } + + if (toffset.top > winH / 2) { + top = winH - toffset.top; + + if (top < 0) { + top = 0; + } + + mheight = toffset.top - 20; + } + + $menu.css({ "top": top, "left": left, "height": mheight }).show(); + clearTimeout(hidefilersubmenu); + }); + + //筛选按钮点击事件 + $("#luckysheet-cell-main").on("click", ".luckysheet-filter-options", function (e) { + let $t = $(e.currentTarget), + toffset = $t.offset(), + $menu = $("#luckysheet-filter-menu"), + winH = $(window).height(), + winW = $(window).width(); + + let st_r = $t.data("str"), + ed_r = $t.data("edr"), + cindex = $t.data("cindex"), + st_c = $t.data("stc"), + ed_c = $t.data("edc"), + rowhidden = $t.data("rowhidden") == "" ? {} : JSON.parse($t.data("rowhidden").replace(/\'/g, '"')); + + $("body .luckysheet-cols-menu").hide(); + $("#luckysheet-filter-menu, #luckysheet-filter-submenu").hide(); + $("#luckysheet-filter-byvalue-input").val(""); + $("#luckysheet-filter-bycondition").next().hide(); + $("#luckysheet-filter-byvalue").next().show(); + + $menu.data("str", st_r); + $menu.data("edr", ed_r); + $menu.data("cindex", cindex); + $menu.data("stc", st_c); + $menu.data("edc", ed_c); + + $("#luckysheet-filter-menu .luckysheet-filter-selected-input").hide().find("input").val(); + $("#luckysheet-filter-selected span").data("type", "0").data("type", null).text(locale_filter.filiterInputNone); + + let byconditiontype = $t.data("byconditiontype"); + $("#luckysheet-filter-selected span").data("value", $t.data("byconditionvalue")).data("type", byconditiontype).text($t.data("byconditiontext")); + + if (byconditiontype == "2") { + let $input = $("#luckysheet-filter-menu .luckysheet-filter-selected-input2").show().find("input"); + $input.eq(0).val($t.data("byconditionvalue1")); + $input.eq(1).val($t.data("byconditionvalue2")); + } + else if (byconditiontype == "1") { + $("#luckysheet-filter-menu .luckysheet-filter-selected-input").eq(0).show().find("input").val($t.data("byconditionvalue1")); + } + + $("#luckysheet-filter-orderby-asc").off("click").on("click", function () { + orderbydatafiler(st_r, st_c, ed_r, ed_c, cindex, true); + }); + + $("#luckysheet-filter-orderby-desc").off("click").on("click", function () { + orderbydatafiler(st_r, st_c, ed_r, ed_c, cindex, false); + }); + + $("#luckysheet-filter-byvalue-select").empty().html('
'+locale_filter.filiterMoreDataTip+'
'); + + let rowhiddenother = {}; //其它筛选列的隐藏行 + $("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").not(this).each(function () { + let $t = $(this), rh = $t.data("rowhidden"); + + if (rh == "") { + return true; + } + + rh = JSON.parse(rh.replace(/\'/g, '"')); + + for (let r in rh) { + rowhiddenother[r] = 0; + } + }); + + let data = Store.flowdata; + + setTimeout(function () { + //日期值 + let dvmap = {}; + let dvmap_uncheck = {}; + + //除日期以外的值 + let vmap = {}; + let vmap_uncheck = {}; + + for (let r = st_r + 1; r <= ed_r; r++) { + if(r in rowhiddenother){ + continue; + } + + if(Store.flowdata[r] == null){ + continue; + } + + let cell = Store.flowdata[r][cindex]; + + if(cell != null && !isRealNull(cell.v) && cell.ct != null && cell.ct.t == "d" ){ //单元格是日期 + let v = update("YYYY-MM-DD", cell.v); + + let y = v.split("-")[0]; + let m = v.split("-")[1]; + let d = v.split("-")[2]; + + if(!(y in dvmap)){ + dvmap[y] = {}; + } + + if(!(m in dvmap[y])){ + dvmap[y][m] = {}; + } + + if(!(d in dvmap[y][m])){ + dvmap[y][m][d] = 0; + } + + dvmap[y][m][d]++; + + if(r in rowhidden){ + dvmap_uncheck[y] = 0; + dvmap_uncheck[m] = 0; + dvmap_uncheck[d] = 0; + } + } + else{ + let v, m; + if(cell == null || isRealNull(cell.v)){ + v = null; + m = null; + } + else{ + v = cell.v; + m = cell.m; + } + + if(!(v in vmap)){ + vmap[v] = {}; + } + + if(!(m in vmap[v])){ + vmap[v][m] = 0; + } + + vmap[v][m]++; + + if(r in rowhidden){ + vmap_uncheck[v + "#$$$#" + m] = 0; + } + } + } + + //遍历数据加到页面 + let item = []; + + if(JSON.stringify(dvmap).length > 2){ + for(let y in dvmap){ + let ysum = 0; + let monthHtml = ''; + + for(let m in dvmap[y]){ + let msum = 0; + let dayHtml = ''; + + for(let d in dvmap[y][m]){ + let dayL = dvmap[y][m][d]; + msum += dayL; + + //月 小于 10 + let mT; + if(Number(m) < 10){ + mT = "0" + Number(m); + } + else{ + mT = m; + } + + //日 小于 10 + let dT; + if(Number(d) < 10){ + dT = "0" + Number(d); + } + else{ + dT = d; + } + + //日是否选中状态 + if((y in dvmap_uncheck) && (m in dvmap_uncheck) && (d in dvmap_uncheck)){ + dayHtml += '
' + + '' + + '' + + '( ' + dayL + ' )' + + '
'; + } + else{ + dayHtml += '
' + + '' + + '' + + '( ' + dayL + ' )' + + '
'; + } + } + + ysum += msum; + + //月 小于 10 + let mT2; + if(Number(m) < 10){ + mT2 = "0" + Number(m); + } + else{ + mT2 = m; + } + + //月是否选中状态 + if((y in dvmap_uncheck) && (m in dvmap_uncheck)){ + monthHtml += '
' + + '
' + + '' + + '' + + '' + + '( ' + msum + ' )' + + '
' + + '
' + dayHtml + '
' + + '
'; + } + else{ + monthHtml += '
' + + '
' + + '' + + '' + + '' + + '( ' + msum + ' )' + + '
' + + '
' + dayHtml + '
' + + '
'; + } + } + + //年是否选中状态 + let yearHtml; + if(y in dvmap_uncheck){ + yearHtml = '
' + + '
' + + '' + + '' + + '' + + '( ' + ysum + ' )' + + '
' + + '
' + monthHtml + '
' + + '
'; + } + else{ + yearHtml = '
' + + '
' + + '' + + '' + + '' + + '( ' + ysum + ' )' + + '
' + + '
' + monthHtml + '
' + + '
'; + } + + item.unshift(yearHtml); + } + } + + if(JSON.stringify(vmap).length > 2){ + let vmapKeys = Object.keys(vmap); + vmapKeys = orderbydata1D(vmapKeys, true); + + for(let i = 0; i < vmapKeys.length; i++){ + let v = vmapKeys[i]; + + for(let x in vmap[v]){ + let text; + if((v + "#$$$#" + x) == "null#$$$#null"){ + text = "(空白)"; + } + else{ + text = x; + } + + //是否选中状态 + let dataHtml; + if((v + "#$$$#" + x) in vmap_uncheck){ + dataHtml = '
' + + '' + + '' + + '( ' + vmap[v][x] + ' )' + + '
'; + } + else{ + dataHtml = '
' + + '' + + '' + + '( ' + vmap[v][x] + ' )' + + '
'; + } + + item.push(dataHtml); + } + } + } + + $("#luckysheet-filter-byvalue-select").html("
" + item.join("") + "
"); + }, 1); + + showrightclickmenu($menu, toffset.left, toffset.top + 20); + + e.stopPropagation(); + return false; + }); + + //按颜色筛选 + $("#luckysheet-filter-orderby-color").hover( + function(){ + //遍历筛选列颜色 + let $menu = $("#luckysheet-filter-menu"); + let st_r = $menu.data("str"), + ed_r = $menu.data("edr"), + cindex = $menu.data("cindex"), + st_c = $menu.data("stc"), + ed_c = $menu.data("edc"); + let bgMap = {}; //单元格颜色 + let fcMap = {}; //字体颜色 + + let af_compute = alternateformat.getComputeMap(); + let cf_compute = conditionformat.getComputeMap(); + + for (let r = st_r + 1; r <= ed_r; r++) { + let cell = Store.flowdata[r][cindex]; + + //单元格颜色 + let bg = menuButton.checkstatus(Store.flowdata, r, cindex , "bg"); + + let checksAF = alternateformat.checksAF(r, cindex, af_compute); + if(checksAF != null){//若单元格有交替颜色 + bg = checksAF[1]; + } + + let checksCF = conditionformat.checksCF(r, cindex, cf_compute); + if(checksCF != null && checksCF["cellColor"] != null){//若单元格有条件格式 + bg = checksCF["cellColor"]; + } + + if(bg.indexOf("rgb") > -1){ + bg = rgbTohex(bg); + } + + if(bg.length == 4){ + bg = bg.substr(0, 1) + bg.substr(1, 1).repeat(2) + bg.substr(2, 1).repeat(2) + bg.substr(3, 1).repeat(2); + } + + //字体颜色 + let fc = menuButton.checkstatus(Store.flowdata, r, cindex , "fc"); + + if(checksAF != null){//若单元格有交替颜色 + fc = checksAF[0]; + } + + if(checksCF != null && checksCF["textColor"] != null){//若单元格有条件格式 + fc = checksCF["textColor"]; + } + + if(fc.indexOf("rgb") > -1){ + fc = rgbTohex(fc); + } + + if(fc.length == 4){ + fc = fc.substr(0, 1) + fc.substr(1, 1).repeat(2) + fc.substr(2, 1).repeat(2) + fc.substr(3, 1).repeat(2); + } + + if(Store.config != null && Store.config["rowhidden"] != null && r in Store.config["rowhidden"]){ + bgMap[bg] = 1; + + if(cell != null && !isRealNull(cell.v)){ + fcMap[fc] = 1; + } + } + else{ + bgMap[bg] = 0; + + if(cell != null && !isRealNull(cell.v)){ + fcMap[fc] = 0; + } + } + } + // + let filterBgColorHtml = ''; + if(JSON.stringify(bgMap).length > 2 && Object.keys(bgMap).length > 1){ + let bgColorItemHtml = ''; + for(let b in bgMap){ + if(bgMap[b] == 0){ + bgColorItemHtml += '
'; + } + else{ + bgColorItemHtml += '
'; + } + } + filterBgColorHtml = '
'+locale_filter.filiterByColorTip+'
' + bgColorItemHtml + '
'; + } + + let filterFcColorHtml = ''; + if(JSON.stringify(fcMap).length > 2 && Object.keys(fcMap).length > 1){ + let fcColorItemHtml = ''; + for(let f in fcMap){ + if(fcMap[f] == 0){ + fcColorItemHtml += '
'; + } + else{ + fcColorItemHtml += '
'; + } + } + filterFcColorHtml = '
'+locale_filter.filiterByTextColorTip+'
' + fcColorItemHtml + '
'; + } + // + let content; + if(filterBgColorHtml == '' && filterFcColorHtml == ''){ + content = '
'+locale_filter.filterContainerOneColorTip+'
'; + } + else{ + content = filterBgColorHtml + filterFcColorHtml + '
'; + } + //颜色筛选子菜单 + $("#luckysheet-filter-orderby-color-submenu").remove(); + $("body").append('
'+content+'
'); + let $t = $("#luckysheet-filter-orderby-color-submenu").end(); + let $con = $(this).parent(); + let winW = $(window).width(), winH = $(window).height(); + let menuW = $con.width(), + myh = $t.height() + 25, + myw = $t.width() + 5; + let offset = $(this).offset(); + let top = offset.top, left = offset.left + menuW; + + if (left + myw > winW) { + left = offset.left - myw; + } + + if (top + myh > winH) { + top = winH - myh; + } + + $("#luckysheet-filter-orderby-color-submenu").css({ "top": top, "left": left }).show(); + }, + function(){ + submenuhide = setTimeout(function () { $("#luckysheet-filter-orderby-color-submenu").hide(); }, 200); + } + ); + + $(document).on("mouseover mouseleave", "#luckysheet-filter-orderby-color-submenu", function(e){ + if (e.type === "mouseover") { + clearTimeout(submenuhide); + } + else { + $(this).hide(); + } + }); + $(document).on("click", "#luckysheet-filter-orderby-color-submenu .item label", function(){ + $(this).siblings("input[type='checkbox']").click(); + }); + $(document).off("click.orderbyColorConfirm").on("click.orderbyColorConfirm", "#luckysheet-filter-orderby-color-submenu #luckysheet-filter-orderby-color-confirm", function(){ + let bg_colorMap = {}; + let fc_colorMap = {}; + + $("#luckysheet-filter-orderby-color-submenu .item").each(function(i, e){ + if($(e).find("input[type='checkbox']").is(":checked")){ + let color = $(this).find("label").attr("title"); + let $id = $(this).closest(".box").attr("id"); + + if($id == "filterBgColor"){ + bg_colorMap[color] = 0; + } + else if($id == "filterFcColor"){ + fc_colorMap[color] = 0; + } + } + }); + + let bg_filter; + if($("#luckysheet-filter-orderby-color-submenu #filterBgColor").length > 0){ + bg_filter = true; + } + else{ + bg_filter = false; + } + + let fc_filter; + if($("#luckysheet-filter-orderby-color-submenu #filterFcColor").length > 0){ + fc_filter = true; + } + else{ + fc_filter = false; + } + + let $menu = $("#luckysheet-filter-menu"); + let st_r = $menu.data("str"), + ed_r = $menu.data("edr"), + cindex = $menu.data("cindex"), + st_c = $menu.data("stc"), + ed_c = $menu.data("edc"); + + let rowhiddenother = {}; //其它筛选列的隐藏行 + $("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").not($("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").eq(cindex - st_c).get(0)).each(function () { + let $t = $(this), rh = $t.data("rowhidden"); + + if (rh == "") { + return true; + } + + rh = JSON.parse(rh); + + for (let r in rh) { + rowhiddenother[r] = 0; + } + }); + + let filterdata = {}; + let rowhidden = {}; + let caljs = {}; + + let af_compute = alternateformat.getComputeMap(); + let cf_compute = conditionformat.getComputeMap(); + + for (let r = st_r + 1; r <= ed_r; r++) { + if(r in rowhiddenother){ + continue; + } + + if(Store.flowdata[r] == null){ + continue; + } + + let cell = Store.flowdata[r][cindex]; + + //单元格颜色 + let bg = menuButton.checkstatus(Store.flowdata, r, cindex , "bg"); + + let checksAF = alternateformat.checksAF(r, cindex, af_compute); + if(checksAF != null){//若单元格有交替颜色 + bg = checksAF[1]; + } + + let checksCF = conditionformat.checksCF(r, cindex, cf_compute); + if(checksCF != null && checksCF["cellColor"] != null){//若单元格有条件格式 + bg = checksCF["cellColor"]; + } + + if(bg.indexOf("rgb") > -1){ + bg = rgbTohex(bg); + } + + if(bg.length == 4){ + bg = bg.substr(0, 1) + bg.substr(1, 1).repeat(2) + bg.substr(2, 1).repeat(2) + bg.substr(3, 1).repeat(2); + } + + //文本颜色 + let fc = menuButton.checkstatus(Store.flowdata, r, cindex , "fc"); + + if(checksAF != null){//若单元格有交替颜色 + fc = checksAF[0]; + } + + if(checksCF != null && checksCF["textColor"] != null){//若单元格有条件格式 + fc = checksCF["textColor"]; + } + + if(fc.indexOf("rgb") > -1){ + fc = rgbTohex(fc); + } + + if(fc.length == 4){ + fc = fc.substr(0, 1) + fc.substr(1, 1).repeat(2) + fc.substr(2, 1).repeat(2) + fc.substr(3, 1).repeat(2); + } + + if(bg_filter && fc_filter){ + if(!(bg in bg_colorMap) && (!(fc in fc_colorMap) || cell == null || isRealNull(cell.v))){ + rowhidden[r] = 0; + } + } + else if(bg_filter){ + if(!(bg in bg_colorMap)){ + rowhidden[r] = 0; + } + } + else if(fc_filter){ + if(!(fc in fc_colorMap) || cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + } + } + + let $top = $("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").eq(cindex - st_c); + + let optionstate = Object.keys(rowhidden).length > 0; + + let rowhiddenall = $.extend(true, rowhiddenother, rowhidden), + rowhidenPre = json.parseJsonParm($top.data("rowhidden")); + + labelFilterOptionState($top, optionstate, rowhidden, caljs, true, st_r, ed_r, cindex, st_c, ed_c); + + let cfg = $.extend(true, {}, Store.config); + cfg["rowhidden"] = rowhiddenall; + + //保存撤销 + if(Store.clearjfundo){ + let redo = {}; + redo["type"] = "datachangeAll_filter"; + redo["sheetIndex"] = Store.currentSheetIndex; + + redo["config"] = $.extend(true, {}, Store.config); + redo["curconfig"] = cfg; + + redo["optionstate"] = optionstate; + redo["optionsindex"] = cindex - st_c; + + redo["rowhidden"] = $.extend(true, {}, rowhidden); + redo["rowhidenPre"] = $.extend(true, {}, rowhidenPre); + + if (caljs != null) { + redo["caljs"] = caljs; + } + + Store.jfundo = []; + Store.jfredo.push(redo); + } + + //config + Store.config = cfg; + Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].config = Store.config; + + server.saveParam("cg", Store.currentSheetIndex, cfg["rowhidden"], { "k": "rowhidden" }); + + //行高、列宽 刷新 + jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); + + $("#luckysheet-filter-menu, #luckysheet-filter-submenu, #luckysheet-filter-orderby-color-submenu").hide(); + cleargridelement(); + }); + + //点击复选框 + $(document).off("click.filterCheckbox1").on("click.filterCheckbox1", "#luckysheet-filter-byvalue-select .textBox",function(){ + if($(this).attr("data-check") == "true"){ + $(this).attr("data-check", "false"); + $(this).find("input[type='checkbox']").removeAttr("checked"); + } + else{ + $(this).attr("data-check", "true"); + $(this).find("input[type='checkbox']").prop("checked", true); + } + }) + $(document).off("click.filterCheckbox2").on("click.filterCheckbox2", "#luckysheet-filter-byvalue-select .year",function(){ + if($(this).attr("data-check") == "true"){ + $(this).attr("data-check", "false"); + $(this).parents(".yearBox").find(".month").attr("data-check", "false"); + $(this).parents(".yearBox").find(".day").attr("data-check", "false"); + $(this).parents(".yearBox").find("input[type='checkbox']").removeAttr("checked"); + } + else{ + $(this).attr("data-check", "true"); + $(this).parents(".yearBox").find(".month").attr("data-check", "true"); + $(this).parents(".yearBox").find(".day").attr("data-check", "true"); + $(this).parents(".yearBox").find("input[type='checkbox']").prop("checked", true); + } + }) + $(document).off("click.filterCheckbox3").on("click.filterCheckbox3", "#luckysheet-filter-byvalue-select .month",function(){ + //月份 对应的 天 + if($(this).attr("data-check") == "true"){ + $(this).attr("data-check", "false"); + $(this).parents(".monthBox").find(".day").attr("data-check", "false"); + $(this).parents(".monthBox").find("input[type='checkbox']").removeAttr("checked"); + } + else{ + $(this).attr("data-check", "true"); + $(this).parents(".monthBox").find(".day").attr("data-check", "true"); + $(this).parents(".monthBox").find("input[type='checkbox']").prop("checked", true); + } + //月份 对应的 年份 + let yearDayAllCheck = true; + let $yearDay = $(this).parents(".yearBox").find(".day"); + $yearDay.each(function(i,e){ + if($(e).attr("data-check") == "true"){ + + } + else{ + yearDayAllCheck = false; + } + }); + if(yearDayAllCheck){ + $(this).parents(".yearBox").find(".year").attr("data-check", "true"); + $(this).parents(".yearBox").find(".year input[type='checkbox']").prop("checked", true); + } + else{ + $(this).parents(".yearBox").find(".year").attr("data-check", "false"); + $(this).parents(".yearBox").find(".year input[type='checkbox']").removeAttr("checked"); + } + }) + $(document).off("click.filterCheckbox4").on("click.filterCheckbox4", "#luckysheet-filter-byvalue-select .day",function(){ + if($(this).attr("data-check") == "true"){ + $(this).attr("data-check", "false"); + $(this).find("input[type='checkbox']").removeAttr("checked"); + } + else{ + $(this).attr("data-check", "true"); + $(this).find("input[type='checkbox']").prop("checked", true); + } + //天 对应的 月份 + let monthDayAllCheck = true; + let $monthDay = $(this).parents(".monthBox").find(".day"); + $monthDay.each(function(i,e){ + if($(e).attr("data-check") == "true"){ + + } + else{ + monthDayAllCheck = false; + } + }); + if(monthDayAllCheck){ + $(this).parents(".monthBox").find(".month").attr("data-check", "true"); + $(this).parents(".monthBox").find(".month input[type='checkbox']").prop("checked", true); + } + else{ + $(this).parents(".monthBox").find(".month").attr("data-check", "false"); + $(this).parents(".monthBox").find(".month input[type='checkbox']").removeAttr("checked"); + } + //天 对应的 年份 + let yearDayAllCheck = true; + let $yearDay = $(this).parents(".yearBox").find(".day"); + $yearDay.each(function(i,e){ + if($(e).attr("data-check") == "true"){ + + } + else{ + yearDayAllCheck = false; + } + }); + if(yearDayAllCheck){ + $(this).parents(".yearBox").find(".year").attr("data-check", "true"); + $(this).parents(".yearBox").find(".year input[type='checkbox']").prop("checked", true); + } + else{ + $(this).parents(".yearBox").find(".year").attr("data-check", "false"); + $(this).parents(".yearBox").find(".year input[type='checkbox']").removeAttr("checked"); + } + }) + + //日期 三级下拉显示 + $(document).off("click.filterYearDropdown").on("click.filterYearDropdown", "#luckysheet-filter-byvalue-select .yearBox .fa-caret-right",function(event){ + let $p = $(this).parents(".luckysheet-mousedown-cancel"); + if($p.hasClass("year")){ + $(this).parents(".yearBox").find(".monthList").slideToggle(); + } + if($p.hasClass("month")){ + $(this).parents(".monthBox").find(".dayList").slideToggle(); + } + + event.stopPropagation(); + }); + + //全选 + $("#luckysheet-filter-byvalue-btn-all").click(function () { + $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']").prop("checked", true); + $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']").parents(".luckysheet-mousedown-cancel").attr("data-check", "true"); + }); + + //清除 + $("#luckysheet-filter-byvalue-btn-clear").click(function () { + $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']").removeAttr("checked"); + $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']").parents(".luckysheet-mousedown-cancel").attr("data-check", "false"); + }); + + //反选 + $("#luckysheet-filter-byvalue-btn-contra").click(function () { + let $input = $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']"); + $input.each(function(i, e){ + if($(e).is(":checked")){ + $(e).removeAttr("checked"); + $(e).parents(".luckysheet-mousedown-cancel").attr("data-check", "false"); + } + else{ + $(e).prop("checked", true); + $(e).parents(".luckysheet-mousedown-cancel").attr("data-check", "true"); + } + }); + //天 对应的 月份 + let $month = $("#luckysheet-filter-byvalue-select .ListBox .monthBox"); + $month.each(function(index, event){ + let monthDayAllCheck = true; + let $monthDay = $(event).find(".day input[type='checkbox']"); + $monthDay.each(function(i,e){ + if($(e).is(":checked")){ + + } + else{ + monthDayAllCheck = false; + } + }); + if(monthDayAllCheck){ + $(event).find(".month input[type='checkbox']").prop("checked", true); + $(event).attr("data-check", "true"); + } + else{ + $(event).find(".month input[type='checkbox']").removeAttr("checked"); + $(event).attr("data-check", "false"); + } + }); + //天 对应的 年份 + let $year = $("#luckysheet-filter-byvalue-select .ListBox .yearBox"); + $year.each(function(index, event){ + let yearDayAllCheck = true; + let $yearDay = $(event).find(".day input[type='checkbox']"); + $yearDay.each(function(i,e){ + if($(e).is(":checked")){ + + } + else{ + yearDayAllCheck = false; + } + }); + if(yearDayAllCheck){ + $(event).find(".year input[type='checkbox']").prop("checked", true); + $(event).attr("data-check", "true"); + } + else{ + $(event).find(".year input[type='checkbox']").removeAttr("checked"); + $(event).attr("data-check", "false"); + } + }); + }); + + //清除筛选 + $("#luckysheet-filter-initial").click(function () { + $("#luckysheet-filter-menu .luckysheet-filter-selected-input").hide().find("input").val(); + $("#luckysheet-filter-selected span").data("type", "0").data("type", null).text(locale_filter.conditionNone); + + $('#luckysheet-filter-selected-sheet' + Store.currentSheetIndex + ', #luckysheet-filter-options-sheet' + Store.currentSheetIndex).remove(); + $("#luckysheet-filter-menu, #luckysheet-filter-submenu").hide(); + + let redo = {}; + redo["type"] = "datachangeAll_filter_clear"; + redo["sheetIndex"] = Store.currentSheetIndex; + + redo["config"] = $.extend(true, {}, Store.config); + Store.config["rowhidden"] = {}; + redo["curconfig"] = $.extend(true, {}, Store.config); + + redo["filter_save"] = $.extend(true, {}, Store.luckysheet_filter_save); + + let optiongroups = []; + $("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").each(function () { + let $t = $(this); + + let optionstate = $t.hasClass("luckysheet-filter-options-active"); + let rowhidden = json.parseJsonParm($t.data("rowhidden")); + let caljs = json.parseJsonParm($t.data("caljs")); + + optiongroups.push({ + "optionstate":optionstate, + "rowhidden": rowhidden, + "caljs":caljs, + "str": $t.data("str"), + "edr": $t.data("edr"), + "cindex": $t.data("cindex"), + "stc": $t.data("stc"), + "edc": $t.data("edc") + }); + }); + redo["optiongroups"] = optiongroups; + + Store.jfundo = []; + Store.jfredo.push(redo); + + //清除筛选发送给后台 + Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].filter = null; + Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].filter_select = null; + + server.saveParam("fsc", Store.currentSheetIndex, null); + + //config + Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].config = Store.config; + + server.saveParam("cg", Store.currentSheetIndex, {}, { "k": "rowhidden" }); + + //行高、列宽 刷新 + jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); + }); + + //按照值进行筛选 + $("#luckysheet-filter-byvalue-input").on('input propertychange', function () { + let v = $(this).val().toString(); + $("#luckysheet-filter-byvalue-select .ListBox .luckysheet-mousedown-cancel").show(); + + if(v != ""){ + $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']").each(function(i, e){ + if($(e).closest(".day").length > 0){ + let day = $(e).siblings("label").text().toString(); + let month = $(e).closest(".monthBox").find(".month label").text().toString(); + let year = $(e).closest(".yearBox").find(".year label").text().toString(); + let itemV = year + "-" + month + "-" + day; + + if(itemV.indexOf(v) == -1){ + $(e).closest(".day").hide(); + + //天 对应的 月份 + let $monthDay = $(e).closest(".dayList").find(".day:visible"); + if($monthDay.length == 0){ + $(e).closest(".monthBox").find(".month").hide(); + } + + //天 对应的 年份 + let $yearDay = $(e).closest(".monthList").find(".day:visible"); + if($yearDay.length == 0){ + $(e).closest(".yearBox").find(".year").hide(); + } + } + } + + if($(e).closest(".textBox").length > 0){ + let itemV = $(e).siblings("label").text().toString(); + + if(itemV.indexOf(v) == -1){ + $(e).parents(".textBox").hide(); + } + } + }); + } + }); + + //筛选取消 + $("#luckysheet-filter-cancel").click(function () { + $("#luckysheet-filter-menu, #luckysheet-filter-submenu").hide(); + }); + + //筛选 确认 + $("#luckysheet-filter-confirm").click(function () { + let $menu = $("#luckysheet-filter-menu"); + let st_r = $menu.data("str"), + ed_r = $menu.data("edr"), + cindex = $menu.data("cindex"), + st_c = $menu.data("stc"), + ed_c = $menu.data("edc"); + + let rowhiddenother = {}; //其它筛选列的隐藏行 + $("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").not($("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").eq(cindex - st_c).get(0)).each(function () { + let $t = $(this), rh = $t.data("rowhidden"); + + if (rh == "") { + return true; + } + + rh = JSON.parse(rh.replace(/\'/g, '"')); + + for (let r in rh) { + rowhiddenother[r] = 0; + } + }); + + let filterdata = {}; + let rowhidden = {}; + let caljs = {}; + + if ($("#luckysheet-filter-bycondition").next().is(":visible") && $("#luckysheet-filter-byvalue").next().is(":hidden") && $("#luckysheet-filter-selected span").data("value") != "null") { + let $t = $("#luckysheet-filter-selected span"); + let type = $t.data("type"), value = $t.data("value"); + + caljs["value"] = value; + caljs["text"] = $t.text(); + + if (type == "0") { + caljs["type"] = "0"; + } + else if (type == "2") { + let $input = $("#luckysheet-filter-menu .luckysheet-filter-selected-input2 input"); + caljs["type"] = "2"; + caljs["value1"] = $input.eq(0).val(); + caljs["value2"] = $input.eq(1).val(); + } + else { + caljs["type"] = "1"; + caljs["value1"] = $("#luckysheet-filter-menu .luckysheet-filter-selected-input").eq(0).find("input").val(); + } + + for (let r = st_r + 1; r <= ed_r; r++) { + if(r in rowhiddenother){ + continue; + } + + if(Store.flowdata[r] == null){ + continue; + } + + let cell = Store.flowdata[r][cindex]; + + if (value == "cellnull") { //单元格为空 + if(cell != null && !isRealNull(cell.v)){ + rowhidden[r] = 0; + } + } + else if (value == "cellnonull") { //单元格有数据 + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + } + else if (value == "textinclude") { //文本包含 + let value1 = caljs["value1"]; + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else{ + if(cell.m.indexOf(value1) == -1){ + rowhidden[r] = 0; + } + } + } + else if (value == "textnotinclude") { //文本不包含 + let value1 = caljs["value1"]; + + if(cell == null || isRealNull(cell.v)){ + + } + else{ + if(cell.m.indexOf(value1) > -1){ + rowhidden[r] = 0; + } + } + } + else if (value == "textstart") { //文本开头为 + let value1 = caljs["value1"], valuelen = value1.length; + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else{ + if(cell.m.substr(0, valuelen) != value1){ + rowhidden[r] = 0; + } + } + } + else if (value == "textend") { //文本结尾为 + let value1 = caljs["value1"], valuelen = value1.length; + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else{ + if(valuelen > cell.m.length || cell.m.substr(cell.m.length - valuelen, valuelen) != value1){ + rowhidden[r] = 0; + } + } + } + else if (value == "textequal") { //文本等于 + let value1 = caljs["value1"]; + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else{ + if(cell.m != value1){ + rowhidden[r] = 0; + } + } + } + else if (value == "dateequal") { //日期等于 + let value1 = genarate(caljs["value1"])[2]; + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else if(cell.ct != null && cell.ct.t == "d"){ + if(parseInt(cell.v) != value1){ + rowhidden[r] = 0; + } + } + else{ + rowhidden[r] = 0; + } + } + else if (value == "datelessthan") { //日期早于 + let value1 = genarate(caljs["value1"])[2]; + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else if(cell.ct != null && cell.ct.t == "d"){ + if(parseInt(cell.v) >= value1){ + rowhidden[r] = 0; + } + } + else{ + rowhidden[r] = 0; + } + } + else if (value == "datemorethan") { //日期晚于 + let value1 = genarate(caljs["value1"])[2]; + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else if(cell.ct != null && cell.ct.t == "d"){ + if(parseInt(cell.v) <= value1){ + rowhidden[r] = 0; + } + } + else{ + rowhidden[r] = 0; + } + } + else if (value == "morethan") { //大于 + let value1 = parseFloat(caljs["value1"]); + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else if(cell.ct != null && cell.ct.t == "n"){ + if(cell.v <= value1){ + rowhidden[r] = 0; + } + } + else{ + rowhidden[r] = 0; + } + } + else if (value == "moreequalthan") { //大于等于 + let value1 = parseFloat(caljs["value1"]); + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else if(cell.ct != null && cell.ct.t == "n"){ + if(cell.v < value1){ + rowhidden[r] = 0; + } + } + else{ + rowhidden[r] = 0; + } + } + else if (value == "lessthan") { //小于 + let value1 = parseFloat(caljs["value1"]); + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else if(cell.ct != null && cell.ct.t == "n"){ + if(cell.v >= value1){ + rowhidden[r] = 0; + } + } + else{ + rowhidden[r] = 0; + } + } + else if (value == "lessequalthan") { //小于等于 + let value1 = parseFloat(caljs["value1"]); + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else if(cell.ct != null && cell.ct.t == "n"){ + if(cell.v > value1){ + rowhidden[r] = 0; + } + } + else{ + rowhidden[r] = 0; + } + } + else if (value == "equal") { //等于 + let value1 = parseFloat(caljs["value1"]); + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else if(cell.ct != null && cell.ct.t == "n"){ + if(cell.v != value1){ + rowhidden[r] = 0; + } + } + else{ + rowhidden[r] = 0; + } + } + else if (value == "noequal") { //不等于 + let value1 = parseFloat(caljs["value1"]); + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else if(cell.ct != null && cell.ct.t == "n"){ + if(cell.v == value1){ + rowhidden[r] = 0; + } + } + else{ + rowhidden[r] = 0; + } + } + else if (value == "include") { //介于 + let value1 = parseFloat(caljs["value1"]), value2 = parseFloat(caljs["value2"]); + + let min, max; + if(value1 < value2){ + min = value1; + max = value2; + } + else{ + max = value1; + min = value2; + } + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else if(cell.ct != null && cell.ct.t == "n"){ + if(cell.v < min || cell.v > max){ + rowhidden[r] = 0; + } + } + else{ + rowhidden[r] = 0; + } + } + else if (value == "noinclude") { //不在其中 + let value1 = parseFloat(caljs["value1"]), value2 = parseFloat(caljs["value2"]); + + let min, max; + if(value1 < value2){ + min = value1; + max = value2; + } + else{ + max = value1; + min = value2; + } + + if(cell == null || isRealNull(cell.v)){ + rowhidden[r] = 0; + } + else if(cell.ct != null && cell.ct.t == "n"){ + if(cell.v >= min && cell.v <= max){ + rowhidden[r] = 0; + } + } + else{ + rowhidden[r] = 0; + } + } + } + } + else { + $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']").each(function(i, e){ + if($(e).is(":visible") && $(e).is(":checked")){ + return true; + } + + if($(e).closest(".day").length > 0){ + let day = $(e).siblings("label").text(); + if(Number(day) < 10){ + day = "0" + Number(day); + } + + let month = $(e).closest(".monthBox").find(".month label").text().replace(locale_filter.filiterMonthText, ""); + if(Number(month) < 10){ + month = "0" + Number(month); + } + + let year = $(e).closest(".yearBox").find(".year label").text().replace(locale_filter.filiterYearText, ""); + + let itemV = locale_filter.filterDateFormatTip +"#$$$#" + year + "-" + month + "-" + day; + + filterdata[itemV] = "1"; + } + + if($(e).closest(".textBox").length > 0){ + let itemV = $(e).closest(".textBox").data("filter"); + + filterdata[itemV] = "1"; + } + }); + + for (let r = st_r + 1; r <= ed_r; r++) { + if(r in rowhiddenother){ + continue; + } + + if(Store.flowdata[r] == null){ + continue; + } + + let cell = Store.flowdata[r][cindex]; + + let value; + if(cell == null || isRealNull(cell.v)){ + value = "null#$$$#null"; + } + else if(cell.ct != null && cell.ct.t == "d"){ + let fmt = update("YYYY-MM-DD", cell.v); + value = locale_filter.filterDateFormatTip +"#$$$#" + fmt; + } + else{ + value = cell.v + "#$$$#" + cell.m; + } + + if(value in filterdata){ + rowhidden[r] = 0; + } + } + } + + let $top = $("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").eq(cindex - st_c); + + let optionstate = $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']:visible:checked").length < $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']:visible").length || $("#luckysheet-filter-byvalue-input").val().length > 0 || ($("#luckysheet-filter-bycondition").next().is(":visible") && $("#luckysheet-filter-byvalue").next().is(":hidden") && $("#luckysheet-filter-selected span").data("value") != "null"); + + let rowhiddenall = $.extend(true, rowhiddenother, rowhidden), + rowhidenPre = json.parseJsonParm($top.data("rowhidden")); + + labelFilterOptionState($top, optionstate, rowhidden, caljs, true, st_r, ed_r, cindex, st_c, ed_c); + + let cfg = $.extend(true, {}, Store.config); + cfg["rowhidden"] = rowhiddenall; + + //保存撤销 + if(Store.clearjfundo){ + let redo = {}; + redo["type"] = "datachangeAll_filter"; + redo["sheetIndex"] = Store.currentSheetIndex; + + redo["config"] = $.extend(true, {}, Store.config); + redo["curconfig"] = cfg; + + redo["optionstate"] = optionstate; + redo["optionsindex"] = cindex - st_c; + + redo["rowhidden"] = $.extend(true, {}, rowhidden); + redo["rowhidenPre"] = $.extend(true, {}, rowhidenPre); + + if (caljs != null) { + redo["caljs"] = caljs; + } + + Store.jfundo = []; + Store.jfredo.push(redo); + } + + //config + Store.config = cfg; + Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].config = Store.config; + + server.saveParam("cg", Store.currentSheetIndex, cfg["rowhidden"], { "k": "rowhidden" }); + + //行高、列宽 刷新 + jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); + + $("#luckysheet-filter-menu, #luckysheet-filter-submenu").hide(); + cleargridelement(); + }); +} + export { labelFilterOptionState, orderbydatafiler, createFilter, - createFilterOptions + createFilterOptions, + initialFilterHandler } \ No newline at end of file diff --git a/src/controllers/formulaBar.js b/src/controllers/formulaBar.js new file mode 100644 index 000000000..364f43ff1 --- /dev/null +++ b/src/controllers/formulaBar.js @@ -0,0 +1,293 @@ +import menuButton from './menuButton'; +import luckysheetupdateCell from './updateCell'; +import { keycode } from './constant'; +import { + luckysheetMoveHighlightCell, +} from './sheetMove'; + +import insertFormula from './insertFormula'; +import { + rowLocation, + colLocation, + mouseposition +} from '../global/location'; +import { isEditMode } from '../global/validate'; +import formula from '../global/formula'; +import tooltip from '../global/tooltip'; +import locale from '../locale/locale'; +import Store from '../store'; + +export function formulaBarInitial(){ + //公式栏处理 + + const _locale = locale(); + const locale_formula= _locale.formula; + + $("#luckysheet-functionbox-cell").focus(function () { + if(isEditMode()){//此模式下禁用公式栏 + return; + } + + if(Store.luckysheet_select_save.length > 0){ + let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]; + + let row_index = last["row_focus"], col_index = last["column_focus"]; + let row = Store.visibledatarow[row_index], + row_pre = row_index - 1 == -1 ? 0 : Store.visibledatarow[row_index - 1]; + let col = Store.visibledatacolumn[col_index], + col_pre = col_index - 1 == -1 ? 0 : Store.visibledatacolumn[col_index - 1]; + + let margeset = menuButton.mergeborer(Store.flowdata, row_index, col_index); + if(!!margeset){ + row = margeset.row[1]; + row_pre = margeset.row[0]; + row_index = margeset.row[2]; + col = margeset.column[1]; + col_pre = margeset.column[0]; + col_index = margeset.column[2]; + } + + luckysheetupdateCell(row, row_pre, row_index, col, col_pre, col_index, Store.flowdata, null, true); + formula.rangeResizeTo = $("#luckysheet-functionbox-cell"); + } + }).keydown(function (event) { + if(isEditMode()){//此模式下禁用公式栏 + return; + } + + let ctrlKey = event.ctrlKey; + let altKey = event.altKey; + let shiftKey = event.shiftKey; + let kcode = event.keyCode; + let $inputbox = $("#luckysheet-input-box"); + + if (kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0) { + if ($("#luckysheet-formula-search-c").is(":visible") && formula.searchFunctionCell != null) { + formula.searchFunctionEnter($("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active")); + } + else { + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + Store.luckysheet_select_save = [{ "row": [Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[0]], "column": [Store.luckysheetCellUpdate[1], Store.luckysheetCellUpdate[1]], "row_focus": Store.luckysheetCellUpdate[0], "column_focus": Store.luckysheetCellUpdate[1] }]; + luckysheetMoveHighlightCell("down", 1, "rangeOfSelect"); + $("#luckysheet-functionbox-cell").blur(); + } + event.preventDefault(); + } + else if (kcode == keycode.ESC && parseInt($inputbox.css("top")) > 0) { + formula.dontupdate(); + luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); + event.preventDefault(); + } + else if (kcode == keycode.F4 && parseInt($inputbox.css("top")) > 0) { + formula.setfreezonFuc(event); + event.preventDefault(); + } + else if (kcode == keycode.UP && parseInt($inputbox.css("top")) > 0) { + if ($("#luckysheet-formula-search-c").is(":visible")) { + let $up = $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active").prev(); + if ($up.length == 0) { + $up = $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item").last(); + } + $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item").removeClass("luckysheet-formula-search-item-active"); + $up.addClass("luckysheet-formula-search-item-active"); + event.preventDefault(); + } + } + else if (kcode == keycode.DOWN && parseInt($inputbox.css("top")) > 0) { + if ($("#luckysheet-formula-search-c").is(":visible")) { + let $up = $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active").next(); + if ($up.length == 0) { + $up = $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item").first(); + } + $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item").removeClass("luckysheet-formula-search-item-active"); + $up.addClass("luckysheet-formula-search-item-active"); + event.preventDefault(); + } + } + else if (kcode == keycode.LEFT && parseInt($inputbox.css("top")) > 0) { + formula.rangeHightlightselected($("#luckysheet-functionbox-cell")); + } + else if (kcode == keycode.RIGHT && parseInt($inputbox.css("top")) > 0) { + formula.rangeHightlightselected($("#luckysheet-functionbox-cell")); + } + else if (!((kcode >= 112 && kcode <= 123) || kcode <= 46 || kcode == 144 || kcode == 108 || event.ctrlKey || event.altKey || (event.shiftKey && (kcode == 37 || kcode == 38 || kcode == 39 || kcode == 40))) || kcode == 8 || kcode == 32 || kcode == 46 || (event.ctrlKey && kcode == 86)) { + formula.functionInputHanddler($("#luckysheet-rich-text-editor"), $("#luckysheet-functionbox-cell"), kcode); + } + }).click(function () { + if(isEditMode()){//此模式下禁用公式栏 + return; + } + + formula.rangeHightlightselected($("#luckysheet-functionbox-cell")); + }); + + //公式栏 取消(X)按钮 + $("#luckysheet-wa-functionbox-cancel").click(function () { + if (!$(this).hasClass("luckysheet-wa-calculate-active")) { + return; + } + //若有参数弹出框,隐藏 + if($("#luckysheet-search-formula-parm").is(":visible")){ + $("#luckysheet-search-formula-parm").hide(); + } + //若有参数选取范围弹出框,隐藏 + if($("#luckysheet-search-formula-parm-select").is(":visible")){ + $("#luckysheet-search-formula-parm-select").hide(); + } + + formula.dontupdate(); + luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); + }); + + //公式栏 确认()按钮 + $("#luckysheet-wa-functionbox-confirm").click(function () { + if (!$(this).hasClass("luckysheet-wa-calculate-active")) { + return; + } + //若有参数弹出框,隐藏 + if($("#luckysheet-search-formula-parm").is(":visible")){ + $("#luckysheet-search-formula-parm").hide(); + } + //若有参数选取范围弹出框,隐藏 + if($("#luckysheet-search-formula-parm-select").is(":visible")){ + $("#luckysheet-search-formula-parm-select").hide(); + } + + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); + }); + + //公式栏 fx按钮 + $("#luckysheet-wa-functionbox-fx").click(function () { + //点击函数查找弹出框 + if(Store.luckysheet_select_save.length == 0){ + if(isEditMode()){ + alert(locale_formula.tipSelectCell); + } + else{ + tooltip.info(locale_formula.tipSelectCell,""); + } + + return; + } + + let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]; + + let row_index = last["row_focus"], col_index = last["column_focus"]; + let row = Store.visibledatarow[row_index], + row_pre = row_index - 1 == -1 ? 0 : Store.visibledatarow[row_index - 1]; + let col = Store.visibledatacolumn[col_index], + col_pre = col_index - 1 == -1 ? 0 : Store.visibledatacolumn[col_index - 1]; + + luckysheetupdateCell(row, row_pre, row_index, col, col_pre, col_index, Store.flowdata); + + let cell = Store.flowdata[row_index][col_index]; + if(cell != null && cell.f != null){ + //单元格有计算 + let functionStr = formula.getfunctionParam(cell.f); + if(functionStr.fn != null){ + //有函数公式 + insertFormula.formulaParmDialog(functionStr.fn, functionStr.param); + } + else{ + //无函数公式 + insertFormula.formulaListDialog(); + } + } + else{ + //单元格无计算 + $("#luckysheet-rich-text-editor").html('='); + $("#luckysheet-functionbox-cell").html($("#luckysheet-rich-text-editor").html()); + insertFormula.formulaListDialog(); + } + + insertFormula.init(); + }); + + //公式选区操作 + $("#luckysheet-formula-functionrange").on("mousedown", ".luckysheet-copy", function (event) { + formula.rangeMove = true; + Store.luckysheet_scroll_status = true; + formula.rangeMoveObj = $(this).parent(); + formula.rangeMoveIndex = $(this).parent().attr("rangeindex"); + + let mouse = mouseposition(event.pageX, event.pageY); + let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft(); + let y = mouse[1] + $("#luckysheet-cell-main").scrollTop(); + $("#luckysheet-formula-functionrange-highlight-" + formula.rangeMoveIndex).find(".luckysheet-selection-copy-hc").css("opacity", 0.13); + + let type = $(this).data("type"); + if (type == "top") { + y += 3; + } + else if (type == "right") { + x -= 3; + } + else if (type == "bottom") { + y -= 3; + } + else if (type == "left") { + x += 3; + } + + let row_index = rowLocation(y)[2]; + let col_index = colLocation(x)[2]; + + formula.rangeMovexy = [row_index, col_index]; + $("#luckysheet-sheettable").css("cursor", "move"); + event.stopPropagation(); + }); + + $("#luckysheet-formula-functionrange").on("mousedown", ".luckysheet-highlight", function (e) { + formula.rangeResize = $(this).data("type");//开始状态resize + formula.rangeResizeIndex = $(this).parent().attr("rangeindex"); + + let mouse = mouseposition(e.pageX, e.pageY), + scrollLeft = $("#luckysheet-cell-main").scrollLeft(), + scrollTop = $("#luckysheet-cell-main").scrollTop(); + let x = mouse[0] + scrollLeft; + let y = mouse[1] + scrollTop; + formula.rangeResizeObj = $(this).parent(); + $("#luckysheet-formula-functionrange-highlight-" + formula.rangeResizeIndex).find(".luckysheet-selection-copy-hc").css("opacity", 0.13); + + if (formula.rangeResize == "lt") { + x += 3; + y += 3; + } + else if (formula.rangeResize == "lb") { + x += 3; + y -= 3; + } + else if (formula.rangeResize == "rt") { + x -= 3; + y += 3; + } + else if (formula.rangeResize == "rb") { + x -= 3; + y -= 3; + } + + let row_location = rowLocation(y), + row = row_location[1], + row_pre = row_location[0], + row_index = row_location[2]; + let col_location = colLocation(x), + col = col_location[1], + col_pre = col_location[0], + col_index = col_location[2]; + + let position = formula.rangeResizeObj.position(); + formula.rangeResizexy = [ + col_pre, + row_pre, + formula.rangeResizeObj.width(), + formula.rangeResizeObj.height(), + position.left + scrollLeft, + position.top + scrollTop, col, row + ]; + formula.rangeResizeWinH = $("#luckysheet-cell-main")[0].scrollHeight; + formula.rangeResizeWinW = $("#luckysheet-cell-main")[0].scrollWidth; + Store.luckysheet_scroll_status = true; + event.stopPropagation(); + }); +} \ No newline at end of file diff --git a/src/controllers/handler.js b/src/controllers/handler.js index 8fc10e2d0..6502a0d9b 100644 --- a/src/controllers/handler.js +++ b/src/controllers/handler.js @@ -12,62 +12,45 @@ import sheetmanage from './sheetmanage'; import server from './server'; import luckysheetupdateCell from './updateCell'; import { luckysheet_searcharray } from './sheetSearch'; -import { modelHTML, sheetselectlistitemHTML, sheetselectlistHTML, keycode } from './constant'; import luckysheetsizeauto from './resize'; import { luckysheetMoveHighlightCell, - luckysheetMoveHighlightCell2, - luckysheetMoveHighlightRange, - luckysheetMoveHighlightRange2 } from './sheetMove'; import { selectHightlightShow, selectIsOverlap, selectionCopyShow, luckysheet_count_show } from './select'; import selection from './selection'; -import searchReplace from './searchReplace'; import controlHistory from './controlHistory'; import splitColumn from './splitColumn'; -import { labelFilterOptionState, orderbydatafiler, createFilter, createFilterOptions } from './filter'; -import insertFormula from './insertFormula'; + import { replaceHtml, getObjType, chatatABC, ArrayUnique, - getByteLen, - rgbTohex, showrightclickmenu, - luckysheetactiveCell, - numFormat, - mouseclickposition, + luckysheetactiveCell, } from '../utils/util'; import { getSheetIndex, getRangetxt } from '../methods/get'; import { rowLocation, - rowLocationByIndex, colLocation, - colLocationByIndex, mouseposition } from '../global/location'; import { rowlenByRange } from '../global/getRowlen'; -import { isRealNull, isRealNum, hasPartMC, isEditMode } from '../global/validate'; +import { isRealNull, hasPartMC, isEditMode } from '../global/validate'; import { countfunc } from '../global/count'; import browser from '../global/browser'; import formula from '../global/formula'; -import { luckysheetextendtable, luckysheetdeletetable } from '../global/extend'; -import cleargridelement from '../global/cleargridelement'; +import { luckysheetextendtable } from '../global/extend'; import luckysheetscrollevent from '../global/scroll'; import { jfrefreshgrid, - jfrefreshgridall, jfrefreshgrid_rhcw, luckysheetrefreshgrid, } from '../global/refresh'; -import { getdatabyselection, getcellvalue, datagridgrowth } from '../global/getdata'; -import { orderbydata, orderbydata1D, sortColumnSeletion } from '../global/sort'; +import { getdatabyselection, datagridgrowth } from '../global/getdata'; import tooltip from '../global/tooltip'; import editor from '../global/editor'; -import { isdatatype } from '../global/datecontroll'; -import json from '../global/json'; -import { update, genarate } from '../global/format'; +import { genarate } from '../global/format'; import method from '../global/method'; import { getBorderInfoCompute } from '../global/border'; import { luckysheetDrawMain } from '../global/draw'; @@ -91,11 +74,7 @@ export default function luckysheetHandler() { const _locale = locale(); const locale_drag = _locale.drag; - const locale_sheetconfig = _locale.sheetconfig; const locale_info = _locale.info; - const locale_filter = _locale.filter; - const locale_button= _locale.button; - const locale_formula= _locale.formula; $("#luckysheet-grid-window-1").mousewheel(function (event, delta) { let scrollLeft = $("#luckysheet-scrollbar-x").scrollLeft(), @@ -2681,10 +2660,10 @@ export default function luckysheetHandler() { e.preventDefault(); }); - //禁止前台编辑(只可 框选单元格、滚动查看表格) - if(!Store.allowEdit){ - return; - } + // //禁止前台编辑(只可 框选单元格、滚动查看表格) + // if(!Store.allowEdit){ + // return; + // } //选区拖动替换 $("#luckysheet-cell-main div.luckysheet-cs-draghandle").mousedown(function (event) { @@ -2934,581 +2913,6 @@ export default function luckysheetHandler() { $("#luckysheet-scrollbar-y").scrollTop(0); }); - //单元格编辑输入 - let luckysheet_shiftkeydown = false; - - $("#luckysheet-input-box").click(function () { - formula.rangeHightlightselected($("#luckysheet-rich-text-editor")); - }).add("#" + Store.container).on("keydown", function (event) { - if ($("#luckysheet-modal-dialog-mask").is(":visible") || $(event.target).hasClass("luckysheet-mousedown-cancel") || $(event.target).hasClass("formulaInputFocus")) { - return; - } - - let ctrlKey = event.ctrlKey; - let altKey = event.altKey; - let shiftKey = event.shiftKey; - let kcode = event.keyCode; - - if ($("#luckysheet-modal-dialog-mask").is(":visible") || $(event.target).hasClass("luckysheet-mousedown-cancel") || $(event.target).hasClass("sp-input") || (parseInt($("#luckysheet-input-box").css("top")) > 0 && $(event.target).closest(".luckysheet-input-box").length > 0 && kcode != keycode.ENTER && kcode != keycode.TAB && kcode != keycode.UP && kcode != keycode.DOWN && kcode != keycode.LEFT && kcode != keycode.RIGHT)) { - let anchor = $(window.getSelection().anchorNode); - - if(anchor.parent().is("#luckysheet-helpbox-cell") || anchor.is("#luckysheet-helpbox-cell")){ - if(kcode == keycode.ENTER){ - let helpboxValue = $("#luckysheet-helpbox-cell").text(); - - if(formula.iscelldata(helpboxValue)){ - let cellrange = formula.getcellrange(helpboxValue); - - Store.luckysheet_select_save = [{ "row": cellrange["row"], "column": cellrange["column"], "row_focus": cellrange["row"][0], "column_focus": cellrange["column"][0] }]; - selectHightlightShow(); - - $("#luckysheet-helpbox-cell").blur(); - - let scrollLeft = $("#luckysheet-cell-main").scrollLeft(), - scrollTop = $("#luckysheet-cell-main").scrollTop(); - let winH = $("#luckysheet-cell-main").height(), - winW = $("#luckysheet-cell-main").width(); - - let row = Store.visibledatarow[cellrange["row"][1]], - row_pre = cellrange["row"][0] - 1 == -1 ? 0 : Store.visibledatarow[cellrange["row"][0] - 1]; - let col = Store.visibledatacolumn[cellrange["column"][1]], - col_pre = cellrange["column"][0] - 1 == -1 ? 0 : Store.visibledatacolumn[cellrange["column"][0] - 1]; - - if (col - scrollLeft - winW + 20 > 0) { - $("#luckysheet-scrollbar-x").scrollLeft(col - winW + 20); - } - else if (col_pre - scrollLeft - 20 < 0) { - $("#luckysheet-scrollbar-x").scrollLeft(col_pre - 20); - } - - if (row - scrollTop - winH + 20 > 0) { - $("#luckysheet-scrollbar-y").scrollTop(row - winH + 20); - } - else if (row_pre - scrollTop - 20 < 0) { - $("#luckysheet-scrollbar-y").scrollTop(row_pre - 20); - } - } - } - } - - return; - } - - let $inputbox = $("#luckysheet-input-box"); - - if (kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0) { - if ($("#luckysheet-formula-search-c").is(":visible") && formula.searchFunctionCell != null) { - formula.searchFunctionEnter($("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active")); - } - else { - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - Store.luckysheet_select_save = [{ - "row": [Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[0]], - "column": [Store.luckysheetCellUpdate[1], Store.luckysheetCellUpdate[1]], - "row_focus": Store.luckysheetCellUpdate[0], - "column_focus": Store.luckysheetCellUpdate[1] - }]; - luckysheetMoveHighlightCell("down", 1, "rangeOfSelect"); - } - - //若有参数弹出框,隐藏 - if($("#luckysheet-search-formula-parm").is(":visible")){ - $("#luckysheet-search-formula-parm").hide(); - } - //若有参数选取范围弹出框,隐藏 - if($("#luckysheet-search-formula-parm-select").is(":visible")){ - $("#luckysheet-search-formula-parm-select").hide(); - } - event.preventDefault(); - } - else if (kcode == keycode.TAB) { - if (parseInt($inputbox.css("top")) > 0) { - return; - } - - luckysheetMoveHighlightCell("right", 1, "rangeOfSelect"); - event.preventDefault(); - } - else if(kcode == keycode.F2){ - if (parseInt($inputbox.css("top")) > 0) { - return; - } - - let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]; - - let row_index = last["row_focus"], col_index = last["column_focus"]; - let row = Store.visibledatarow[row_index], - row_pre = row_index - 1 == -1 ? 0 : Store.visibledatarow[row_index - 1]; - let col = Store.visibledatacolumn[col_index], - col_pre = col_index - 1 == -1 ? 0 : Store.visibledatacolumn[col_index - 1]; - - luckysheetupdateCell(row, row_pre, row_index, col, col_pre, col_index, Store.flowdata); - event.preventDefault(); - } - else if (kcode == keycode.F4 && parseInt($inputbox.css("top")) > 0) { - formula.setfreezonFuc(event); - event.preventDefault(); - } - else if (kcode == keycode.ESC && parseInt($inputbox.css("top")) > 0) { - formula.dontupdate(); - luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); - event.preventDefault(); - } - else if (kcode == keycode.ENTER) { - if($(event.target).hasClass("formulaInputFocus") || $("#luckysheet-conditionformat-dialog").is(":visible")){ - return; - } - else if (String.fromCharCode(kcode) != null && $("#luckysheet-cell-selected").is(":visible")) { - let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]; - - let row_index = last["row_focus"], col_index = last["column_focus"]; - let row = Store.visibledatarow[row_index], - row_pre = row_index - 1 == -1 ? 0 : Store.visibledatarow[row_index - 1]; - let col = Store.visibledatacolumn[col_index], - col_pre = col_index - 1 == -1 ? 0 : Store.visibledatacolumn[col_index - 1]; - - let margeset = menuButton.mergeborer(Store.flowdata, row_index, col_index); - if(!!margeset){ - row = margeset.row[1]; - row_pre = margeset.row[0]; - row_index = margeset.row[2]; - col = margeset.column[1]; - col_pre = margeset.column[0]; - col_index = margeset.column[2]; - } - - luckysheetupdateCell(row, row_pre, row_index, col, col_pre, col_index, Store.flowdata); - event.preventDefault(); - } - } - else { - if (ctrlKey || event.metaKey) { - if (shiftKey) { - if (!luckysheet_shiftkeydown) { - Store.luckysheet_shiftpositon = $.extend(true, {}, Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]); - Store.luckysheet_shiftkeydown = true; - } - - //Ctrl + shift + 方向键 调整选区 - if (kcode == keycode.UP) { - if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { - return; - } - - luckysheetMoveHighlightRange2("up", "rangeOfSelect"); - } - else if (kcode == keycode.DOWN) { - if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { - return; - } - - luckysheetMoveHighlightRange2("down", "rangeOfSelect"); - } - else if (kcode == keycode.LEFT) { - if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { - return; - } - - luckysheetMoveHighlightRange2("left", "rangeOfSelect"); - } - else if (kcode == keycode.RIGHT) { - if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { - return; - } - - luckysheetMoveHighlightRange2("right", "rangeOfSelect"); - } - } - else if (kcode == 66) {//Ctrl + B 加粗 - $("#luckysheet-icon-bold").click(); - } - else if (kcode == 67) {//Ctrl + C 复制 - //复制时存在格式刷状态,取消格式刷 - if(menuButton.luckysheetPaintModelOn){ - menuButton.cancelPaintModel(); - } - - if(Store.luckysheet_select_save.length == 0){ - return; - } - - //复制范围内包含部分合并单元格,提示 - if(Store.config["merge"] != null){ - let has_PartMC = false; - - 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]; - let c1 = Store.luckysheet_select_save[s].column[0], - c2 = Store.luckysheet_select_save[s].column[1]; - - has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); - - if(has_PartMC){ - break; - } - } - - if(has_PartMC){ - if(isEditMode()){ - alert(locale_drag.noMerge); - } - else{ - tooltip.info(locale_drag.noMerge, ""); - } - return; - } - } - - //多重选区 有条件格式时 提示 - let cdformat = Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].luckysheet_conditionformat_save; - if(Store.luckysheet_select_save.length > 1 && cdformat != null && cdformat.length > 0){ - let hasCF = false; - - let cf_compute = conditionformat.getComputeMap(); - - label: - for(let s = 0; s < Store.luckysheet_select_save.length; s++){ - if(hasCF){ - break; - } - - let r1 = Store.luckysheet_select_save[s].row[0], - r2 = Store.luckysheet_select_save[s].row[1]; - let c1 = Store.luckysheet_select_save[s].column[0], - c2 = Store.luckysheet_select_save[s].column[1]; - - for(let r = r1; r <= r2; r++){ - for(let c = c1; c <= c2; c++){ - if(conditionformat.checksCF(r, c, cf_compute) != null){ - hasCF = true; - continue label; - } - } - } - } - - if(hasCF){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - } - - //多重选区 行不一样且列不一样时 提示 - if(Store.luckysheet_select_save.length > 1){ - let isSameRow = true, - str_r = luckysheet_select_save[0].row[0], - end_r = luckysheet_select_save[0].row[1]; - let isSameCol = true, - str_c = luckysheet_select_save[0].column[0], - end_c = luckysheet_select_save[0].column[1]; - - for(let s = 1; s < luckysheet_select_save.length; s++){ - if(luckysheet_select_save[s].row[0] != str_r || luckysheet_select_save[s].row[1] != end_r){ - isSameRow = false; - } - if(luckysheet_select_save[s].column[0] != str_c || luckysheet_select_save[s].column[1] != end_c){ - isSameCol = false; - } - } - - if((!isSameRow && !isSameCol) || selectIsOverlap()){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - } - - selection.copy(event); - - Store.luckysheet_paste_iscut = false; - luckysheetactiveCell(); - - event.stopPropagation(); - return; - } - else if (kcode == 70) {//Ctrl + F 查找 - searchReplace.createDialog(0); - searchReplace.init(); - - $("#luckysheet-search-replace #searchInput input").focus(); - } - else if (kcode == 72) {//Ctrl + H 替换 - searchReplace.createDialog(1); - searchReplace.init(); - - $("#luckysheet-search-replace #searchInput input").focus(); - } - else if (kcode == 73) {//Ctrl + I 斜体 - $("#luckysheet-icon-italic").click(); - } - else if (kcode == 86) {//Ctrl + V 粘贴 - if(isEditMode()){//此模式下禁用粘贴 - return; - } - - if($(event.target).hasClass("formulaInputFocus")){ - return; - } - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noPaste); - } - else{ - tooltip.info(locale_drag.noPaste, ""); - } - return; - } - - selection.isPasteAction = true; - luckysheetactiveCell(); - - event.stopPropagation(); - return; - } - else if (kcode == 88) {//Ctrl + X 剪切 - //复制时存在格式刷状态,取消格式刷 - if(menuButton.luckysheetPaintModelOn){ - menuButton.cancelPaintModel(); - } - - if(Store.luckysheet_select_save.length == 0){ - return; - } - - //复制范围内包含部分合并单元格,提示 - if(Store.config["merge"] != null){ - let has_PartMC = false; - - 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]; - let c1 = Store.luckysheet_select_save[s].column[0], - c2 = Store.luckysheet_select_save[s].column[1]; - - has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); - - if(has_PartMC){ - break; - } - } - - if(has_PartMC){ - if(luckysheetConfigsetting.editMode){ - alert(_locale_drag.noMerge); - } - else{ - tooltip.info(_locale_drag.noMerge, ""); - } - return; - } - } - - //多重选区时 提示 - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - selection.copy(event); - - Store.luckysheet_paste_iscut = true; - luckysheetactiveCell(); - - event.stopPropagation(); - return; - } - else if (kcode == 90) {//Ctrl + Z 撤销 - controlHistory.redo(event); - luckysheetactiveCell(); - event.stopPropagation(); - return; - } - else if (kcode == 89) {//Ctrl + Y 重做 - controlHistory.undo(event); - luckysheetactiveCell(); - event.stopPropagation(); - return; - } - else if (kcode == keycode.UP) {//Ctrl + up 调整单元格 - if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { - return; - } - - luckysheetMoveHighlightCell2("up", "rangeOfSelect"); - } - else if (kcode == keycode.DOWN) {//Ctrl + down 调整单元格 - if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { - return; - } - - luckysheetMoveHighlightCell2("down", "rangeOfSelect"); - } - else if (kcode == keycode.LEFT) {//Ctrl + top 调整单元格 - if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { - return; - } - - luckysheetMoveHighlightCell2("left", "rangeOfSelect"); - } - else if (kcode == keycode.RIGHT) {//Ctrl + right 调整单元格 - if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { - return; - } - - luckysheetMoveHighlightCell2("right", "rangeOfSelect"); - } - else if (String.fromCharCode(kcode).toLocaleUpperCase() == "A") {//Ctrl + A 全选 - $("#luckysheet-left-top").trigger("mousedown"); - $(document).trigger("mouseup"); - } - - event.preventDefault(); - return; - } - else if (shiftKey && (kcode == keycode.UP || kcode == keycode.DOWN || kcode == keycode.LEFT || kcode == keycode.RIGHT || (altKey && (kcode == 53 || kcode == 101)))) { - if (parseInt($inputbox.css("top")) > 0 || $(event.target).hasClass("formulaInputFocus")) { - return; - } - - if (!luckysheet_shiftkeydown) { - Store.luckysheet_shiftpositon = $.extend(true, {}, Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]); - Store.luckysheet_shiftkeydown = true; - } - - //shift + 方向键 调整选区 - if (kcode == keycode.UP) { - if($("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")){ - return; - } - - luckysheetMoveHighlightRange("down", -1, "rangeOfSelect"); - } - else if (kcode == keycode.DOWN) { - if($("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")){ - return; - } - - luckysheetMoveHighlightRange("down", 1, "rangeOfSelect"); - } - else if (kcode == keycode.LEFT) { - if($("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")){ - return; - } - - luckysheetMoveHighlightRange("right", -1, "rangeOfSelect"); - } - else if (kcode == keycode.RIGHT) { - if($("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")){ - return; - } - - luckysheetMoveHighlightRange("right", 1, "rangeOfSelect"); - } - else if (altKey && (kcode == 53 || kcode == 101)) { - //Alt + Shift + 5(删除线) - $("#luckysheet-icon-strikethrough").click(); - } - - event.preventDefault(); - } - else if (kcode == keycode.ESC) { - if(menuButton.luckysheetPaintModelOn){ - menuButton.cancelPaintModel(); - } - else{ - cleargridelement(event); - event.preventDefault(); - } - - selectHightlightShow(); - } - else if (kcode == keycode.DELETE) { - $("#luckysheet-delete-text").click(); - - event.preventDefault(); - } - else if (kcode == keycode.UP) { - if (parseInt($inputbox.css("top")) > 0 || $(event.target).hasClass("formulaInputFocus") || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { - return; - } - - luckysheetMoveHighlightCell("down", -1, "rangeOfSelect"); - event.preventDefault(); - } - else if (kcode == keycode.DOWN) { - if (parseInt($inputbox.css("top")) > 0 || $(event.target).hasClass("formulaInputFocus") || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { - return; - } - - luckysheetMoveHighlightCell("down", 1, "rangeOfSelect"); - event.preventDefault(); - } - else if (kcode == keycode.LEFT) { - if (parseInt($inputbox.css("top")) > 0 || $(event.target).hasClass("formulaInputFocus") || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { - return; - } - - luckysheetMoveHighlightCell("right", -1, "rangeOfSelect"); - event.preventDefault(); - } - else if (kcode == keycode.RIGHT) { - if (parseInt($inputbox.css("top")) > 0 || $(event.target).hasClass("formulaInputFocus") || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { - return; - } - - luckysheetMoveHighlightCell("right", 1, "rangeOfSelect"); - event.preventDefault(); - } - else if (!((kcode >= 112 && kcode <= 123) || kcode <= 46 || kcode == 144 || kcode == 108 || event.ctrlKey || event.altKey || (event.shiftKey && (kcode == 37 || kcode == 38 || kcode == 39 || kcode == 40))) || kcode == 8 || kcode == 32 || kcode == 46 || kcode == 0 || (event.ctrlKey && kcode == 86)) { - if (String.fromCharCode(kcode) != null && $("#luckysheet-cell-selected").is(":visible") && (kcode != keycode.CAPSLOCK && kcode != keycode.WIN && kcode != 18)) { - let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]; - - let row_index = last["row_focus"], col_index = last["column_focus"]; - let row = Store.visibledatarow[row_index], - row_pre = row_index - 1 == -1 ? 0 : Store.visibledatarow[row_index - 1]; - let col = Store.visibledatacolumn[col_index], - col_pre = col_index - 1 == -1 ? 0 : Store.visibledatacolumn[col_index - 1]; - - let margeset = menuButton.mergeborer(Store.flowdata, row_index, col_index); - if(!!margeset){ - row = margeset.row[1]; - row_pre = margeset.row[0]; - row_index = margeset.row[2]; - col = margeset.column[1]; - col_pre = margeset.column[0]; - col_index = margeset.column[2]; - } - - luckysheetupdateCell(row, row_pre, row_index, col, col_pre, col_index, Store.flowdata, true); - if(kcode == 8){ - $("#luckysheet-rich-text-editor").html("
"); - } - formula.functionInputHanddler($("#luckysheet-functionbox-cell"), $("#luckysheet-rich-text-editor"), kcode); - } - } - } - - luckysheetactiveCell(); - - event.stopPropagation(); - }); - //右键菜单 复制按钮 $("#luckysheet-copy-btn, #luckysheet-cols-copy-btn, #luckysheet-paste-btn-title").click(function (event) { $(this).parent().hide(); @@ -3868,44 +3272,6 @@ export default function luckysheetHandler() { luckysheetFreezen.createAssistCanvas(); }); - //右键菜单 菜单项hover - let submenuhide = null, rightclickmenu = null; - $(".luckysheet-cols-menu .luckysheet-cols-submenu").hover( - function () { - let $t = $(this), attrid = $t.attr("id"), $attr = $("#" + attrid + "_sub"), $con = $t.parent(); - let winW = $(window).width(), winH = $(window).height(); - let menuW = $con.width(), attrH = $attr.height() + 25, attrW = $attr.width() + 5; - let offset = $t.offset(); - let top = offset.top, left = offset.left + menuW; - - if (left + attrW > winW) { - left = offset.left - attrW; - } - - if (top + attrH > winH) { - top = winH - attrH; - } - - $attr.css({ "top": top, "left": left }).show(); - rightclickmenu = $t; - }, - function () { - let $t = $(this), attrid = $t.attr("id"), $attr = $("#" + attrid + "_sub"); - submenuhide = setTimeout(function () { $attr.hide(); }, 200); - } - ); - - $(".luckysheet-rightgclick-menu-sub").hover( - function () { - rightclickmenu.addClass("luckysheet-cols-menuitem-hover"); - clearTimeout(submenuhide); - }, - function () { - rightclickmenu.removeClass("luckysheet-cols-menuitem-hover"); - $(this).hide(); - } - ); - $("#luckysheet-rightclick-menu input").on("keydown", function (e) { e.stopPropagation(); }); @@ -3945,284 +3311,6 @@ export default function luckysheetHandler() { } }); - //单元格编辑 keydown (公式 上下左右键移动) - $("#" + Store.container).add("#luckysheet-input-box").keydown(function (event) { - if ($("#luckysheet-modal-dialog-mask").is(":visible") || $(event.target).hasClass("luckysheet-mousedown-cancel") || $(event.target).hasClass("formulaInputFocus")) { - return; - } - - let ctrlKey = event.ctrlKey; - let altKey = event.altKey; - let shiftKey = event.shiftKey; - let kcode = event.keyCode; - - let $inputbox = $("#luckysheet-input-box"); - if (kcode == keycode.ESC && parseInt($("#luckysheet-input-box").css("top")) > 0) { - formula.dontupdate(); - luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); - event.preventDefault(); - } - else if (kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0) { - if ($("#luckysheet-formula-search-c").is(":visible") && formula.searchFunctionCell != null) { - formula.searchFunctionEnter($("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active")); - event.preventDefault(); - } - } - else if(kcode == keycode.TAB && parseInt($inputbox.css("top")) > 0){ - if ($("#luckysheet-formula-search-c").is(":visible") && formula.searchFunctionCell != null) { - formula.searchFunctionEnter($("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active")); - } - else{ - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - luckysheetMoveHighlightCell("right", 1, "rangeOfSelect"); - } - - event.preventDefault(); - } - else if (kcode == keycode.F4 && parseInt($inputbox.css("top")) > 0) { - formula.setfreezonFuc(event); - event.preventDefault(); - } - else if (kcode == keycode.UP && parseInt($inputbox.css("top")) > 0) { - formulaMoveEvent("up", ctrlKey, shiftKey); - } - else if (kcode == keycode.DOWN && parseInt($inputbox.css("top")) > 0) { - formulaMoveEvent("down", ctrlKey, shiftKey); - } - else if (kcode == keycode.LEFT && parseInt($inputbox.css("top")) > 0) { - formulaMoveEvent("left", ctrlKey, shiftKey); - } - else if (kcode == keycode.RIGHT && parseInt($inputbox.css("top")) > 0) { - formulaMoveEvent("right", ctrlKey, shiftKey); - } - else if (!((kcode >= 112 && kcode <= 123) || kcode <= 46 || kcode == 144 || kcode == 108 || event.ctrlKey || event.altKey || (event.shiftKey && (kcode == 37 || kcode == 38 || kcode == 39 || kcode == 40))) || kcode == 8 || kcode == 32 || kcode == 46 || (event.ctrlKey && kcode == 86)) { - formula.functionInputHanddler($("#luckysheet-functionbox-cell"), $("#luckysheet-rich-text-editor"), kcode); - } - }).keyup(function (e) { - let kcode = e.keyCode; - - if (!e.shiftKey && kcode == 16) { - Store.luckysheet_shiftkeydown = false; - Store.luckysheet_shiftpositon = null; - } - - //输入框中文输入后 shift 和 空格 处理 - if(parseInt($("#luckysheet-input-box").css("top")) > 0 && (kcode == 13 || kcode == 16 || kcode == 32)){ - formula.functionInputHanddler($("#luckysheet-functionbox-cell"), $("#luckysheet-rich-text-editor"), kcode); - } - - e.preventDefault(); - }); - - function formulaMoveEvent(dir, ctrlKey, shiftKey){ - if ($("#luckysheet-formula-search-c").is(":visible")) { - let $up = $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active").next(); - if ($up.length == 0) { - $up = $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item").first(); - } - - $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item").removeClass("luckysheet-formula-search-item-active"); - $up.addClass("luckysheet-formula-search-item-active"); - - event.preventDefault(); - } - else{ - if($("#luckysheet-formula-functionrange-select").is(":visible")){ - if(ctrlKey && shiftKey){ - luckysheetMoveHighlightRange2(dir, "rangeOfFormula"); - } - else if(ctrlKey){ - luckysheetMoveHighlightCell2(dir, "rangeOfFormula"); - } - else if(shiftKey){ - let dir_n = dir, step = 1; - if(dir == 'up'){ - dir_n = 'down'; - step = -1; - } - if(dir == 'left'){ - dir_n = 'right'; - step = -1; - } - - luckysheetMoveHighlightRange(dir_n, step, "rangeOfFormula"); - } - else{ - let dir_n = dir, step = 1; - if(dir == 'up'){ - dir_n = 'down'; - step = -1; - } - if(dir == 'left'){ - dir_n = 'right'; - step = -1; - } - - luckysheetMoveHighlightCell(dir_n, step, "rangeOfFormula"); - } - } - else if(formula.israngeseleciton()){ - let anchor = $(window.getSelection().anchorNode); - - if(anchor.parent().next().text() == null || anchor.parent().next().text() == ""){ - let vText = $("#luckysheet-input-box #luckysheet-input-box-index").text(); - let range = formula.getcellrange(vText); - - if(range == null){ - range = formula.getcellrange($("#luckysheet-input-box-index").text()); - } - - let r1 = range["row"][0], r2 = range["row"][1]; - let c1 = range["column"][0], c2 = range["column"][1]; - - let row = Store.visibledatarow[r2], - row_pre = r1 - 1 == -1 ? 0 : Store.visibledatarow[r1 - 1]; - let col = Store.visibledatacolumn[c2], - col_pre = c1 - 1 == -1 ? 0 : Store.visibledatacolumn[c1 - 1]; - - formula.func_selectedrange = { - "left": col_pre, - "width": col - col_pre - 1, - "top": row_pre, - "height": row - row_pre - 1, - "left_move": col_pre, - "width_move": col - col_pre - 1, - "top_move": row_pre, - "height_move": row - row_pre - 1, - "row": [r1, r2], - "column": [c1, c2], - "row_focus": r1, - "column_focus": c1 - }; - - formula.rangeSetValue({ "row": [r1, r2], "column": [c1, c2] }); - - formula.rangestart = true; - formula.rangedrag_column_start = false; - formula.rangedrag_row_start = false; - - if(ctrlKey && shiftKey){ - luckysheetMoveHighlightRange2(dir, "rangeOfFormula"); - } - else if(ctrlKey){ - luckysheetMoveHighlightCell2(dir, "rangeOfFormula"); - } - else if(shiftKey){ - let dir_n = dir, step = 1; - if(dir == 'up'){ - dir_n = 'down'; - step = -1; - } - if(dir == 'left'){ - dir_n = 'right'; - step = -1; - } - - luckysheetMoveHighlightRange(dir_n, step, "rangeOfFormula"); - } - else{ - let dir_n = dir, step = 1; - if(dir == 'up'){ - dir_n = 'down'; - step = -1; - } - if(dir == 'left'){ - dir_n = 'right'; - step = -1; - } - - luckysheetMoveHighlightCell(dir_n, step, "rangeOfFormula"); - } - } - } - else if(!ctrlKey && !shiftKey){ - let anchor = $(window.getSelection().anchorNode); - let anchorOffset = window.getSelection().anchorOffset; - - if(dir == 'up'){ - if(anchor.parent().is("span") && anchor.parent().next().length == 0 && anchorOffset > 0){ - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - luckysheetMoveHighlightCell("down", -1, "rangeOfSelect"); - - event.preventDefault(); - } - else if(anchor.is("#luckysheet-rich-text-editor") && anchor.context.childElementCount == anchorOffset){ - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - luckysheetMoveHighlightCell("down", -1, "rangeOfSelect"); - - event.preventDefault(); - } - else if(anchor.parent().is("#luckysheet-rich-text-editor") && anchor.context.length == anchorOffset){ - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - luckysheetMoveHighlightCell("down", -1, "rangeOfSelect"); - - event.preventDefault(); - } - } - else if(dir == 'down'){ - if(anchor.parent().is("span") && anchor.parent().next().length == 0 && anchorOffset > 0){ - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - luckysheetMoveHighlightCell("down", 1, "rangeOfSelect"); - - event.preventDefault(); - } - else if(anchor.is("#luckysheet-rich-text-editor") && anchor.context.childElementCount == anchorOffset){ - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - luckysheetMoveHighlightCell("down", 1, "rangeOfSelect"); - - event.preventDefault(); - } - else if(anchor.parent().is("#luckysheet-rich-text-editor") && anchor.context.length == anchorOffset){ - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - luckysheetMoveHighlightCell("down", 1, "rangeOfSelect"); - - event.preventDefault(); - } - } - else if(dir == 'left'){ - if(anchor.parent().is("span") && anchor.parent().prev().length == 0 && anchorOffset == 0){ - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - luckysheetMoveHighlightCell("right", -1, "rangeOfSelect"); - - event.preventDefault(); - } - else if(anchor.is("#luckysheet-rich-text-editor") && anchorOffset == 1){ - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - luckysheetMoveHighlightCell("right", -1, "rangeOfSelect"); - - event.preventDefault(); - } - else if(anchor.parent().is("#luckysheet-rich-text-editor") && anchorOffset == 0){ - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - luckysheetMoveHighlightCell("right", -1, "rangeOfSelect"); - - event.preventDefault(); - } - } - else if(dir == 'right'){ - if(anchor.parent().is("span") && anchor.parent().next().length == 0 && anchorOffset > 0){ - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - luckysheetMoveHighlightCell("right", 1, "rangeOfSelect"); - - event.preventDefault(); - } - else if(anchor.is("#luckysheet-rich-text-editor") && anchor.context.childElementCount == anchorOffset){ - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - luckysheetMoveHighlightCell("right", 1, "rangeOfSelect"); - - event.preventDefault(); - } - else if(anchor.parent().is("#luckysheet-rich-text-editor") && anchor.context.length == anchorOffset){ - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - luckysheetMoveHighlightCell("right", 1, "rangeOfSelect"); - - event.preventDefault(); - } - } - } - } - } - //表格左上角点击 全选表格 $("#luckysheet-left-top").mousedown(function (event) { $("#luckysheet-wa-functionbox-confirm").click(); @@ -4237,5286 +3325,64 @@ export default function luckysheetHandler() { event.stopPropagation(); }); - //表格行标题 mouse事件 - $("#luckysheet-rows-h").mousedown(function (event) { - //有批注在编辑时 - luckysheetPostil.removeActivePs(); - - let mouse = mouseposition(event.pageX, event.pageY); - let y = mouse[1] + $("#luckysheet-rows-h").scrollTop(); - - let row_location = rowLocation(y), - row = row_location[1], - row_pre = row_location[0], - row_index = row_location[2]; - let col_index = Store.visibledatacolumn.length - 1, - col = Store.visibledatacolumn[col_index], col_pre = 0; - - $("#luckysheet-rightclick-menu").hide(); - $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); - - //mousedown是右键 - if (event.which == "3") { - let isright = false; - for(let s = 0; s < Store.luckysheet_select_save.length; s++){ - let obj_s = Store.luckysheet_select_save[s]; + //回退 重做 按钮 + $("#luckysheet-icon-undo").click(function (event) { + controlHistory.redo(event); + }); + $("#luckysheet-icon-redo").click(function (event) { + controlHistory.undo(event); + }); - if(obj_s["row"] != null && (row_index >= obj_s["row"][0] && row_index <= obj_s["row"][1]) && (obj_s["column"][0] == 0 && obj_s["column"][1] == Store.flowdata[0].length - 1)){ - isright = true; - break; - } - } + - if(isright){ - return; - } + //模态框拖动 + $(document).on("mousedown", "div.luckysheet-modal-dialog", function (e) { + if (!$(e.target).is(".luckysheet-modal-dialog")) { + return; } - let top = row_pre, height = row - row_pre - 1; - let rowseleted = [row_index, row_index]; - - Store.luckysheet_scroll_status = true; - - //公式相关 - let $input = $("#luckysheet-input-box"); - if (parseInt($input.css("top")) > 0) { - if (formula.rangestart || formula.rangedrag_column_start || formula.rangedrag_row_start || formula.israngeseleciton() || $("#luckysheet-ifFormulaGenerator-multiRange-dialog").is(":visible")) { - //公式选区 - let changeparam = menuButton.mergeMoveMain([0, col_index], rowseleted, {"row_focus": row_index, "column_focus": 0}, top, height, col_pre, col); - if(changeparam != null){ - //columnseleted = changeparam[0]; - rowseleted = changeparam[1]; - top = changeparam[2]; - height = changeparam[3]; - //left = changeparam[4]; - //width = changeparam[5]; - } - - if(event.shiftKey){ - let last = formula.func_selectedrange; - - let top = 0, height = 0, rowseleted = []; - if (last.top > row_pre) { - top = row_pre; - height = last.top + last.height - row_pre; - - if(last.row[1] > last.row_focus){ - last.row[1] = last.row_focus; - } - - rowseleted = [row_index, last.row[1]]; - } - else if (last.top == row_pre) { - top = row_pre; - height = last.top + last.height - row_pre; - rowseleted = [row_index, last.row[0]]; - } - else { - top = last.top; - height = row - last.top - 1; - - if(last.row[0] < last.row_focus){ - last.row[0] = last.row_focus; - } - - rowseleted = [last.row[0], row_index]; - } - - let changeparam = menuButton.mergeMoveMain([0, col_index], rowseleted, {"row_focus": row_index, "column_focus": 0}, top, height, col_pre, col); - if(changeparam != null){ - // columnseleted = changeparam[0]; - rowseleted = changeparam[1]; - top = changeparam[2]; - height = changeparam[3]; - // left = changeparam[4]; - // width = changeparam[5]; - } - - last["row"] = rowseleted; + Store.luckysheet_model_move_state = true; - last["top_move"] = top; - last["height_move"] = height; + Store.luckysheet_model_move_obj = $(e.currentTarget); + let toffset = Store.luckysheet_model_move_obj.offset(); + Store.luckysheet_model_xy = [e.pageX - toffset.left, e.pageY - toffset.top]; + }); - formula.func_selectedrange = last; - } - else if(event.ctrlKey && $("#luckysheet-rich-text-editor").find("span").last().text() != ","){ - //按住ctrl 选择选区时 先处理上一个选区 - let vText = $("#luckysheet-rich-text-editor").text() + ","; - if(vText.length > 0 && vText.substr(0, 1) == "="){ - vText = formula.functionHTMLGenerate(vText); + //模态框关闭 + $(document).on("click", ".luckysheet-modal-dialog-title-close, .luckysheet-model-close-btn", function (e) { + //选择文本颜色和单元格颜色弹出框取消 + if($("#textcolorselect").is(":visible")||$("#cellcolorselect").is(":visible")){ + $("#luckysheet-conditionformat-dialog").show(); + } + $(e.currentTarget).parents(".luckysheet-modal-dialog").hide(); + $("#luckysheet-modal-dialog-mask").hide(); - if (window.getSelection) { // all browsers, except IE before version 9 - let currSelection = window.getSelection(); - formula.functionRangeIndex = [$(currSelection.anchorNode).parent().index(), currSelection.anchorOffset]; - } - else { // Internet Explorer before version 9 - let textRange = document.selection.createRange(); - formula.functionRangeIndex = textRange; - } + //函数查找功能所有弹出框关闭和取消 + if($(this).parents(".luckysheet-modal-dialog").hasClass("luckysheet-search-formula")){ + formula.dontupdate(); + luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); + } + if($(this).parents(".luckysheet-modal-dialog").hasClass("luckysheet-search-formula-parm")){ + formula.dontupdate(); + luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); + } + if($(this).parents(".luckysheet-modal-dialog").hasClass("luckysheet-search-formula-parm-select")){ + formula.dontupdate(); + luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); + } - $("#luckysheet-rich-text-editor").html(vText); + $("#" + Store.container).attr("tabindex", 0).focus(); + }); - formula.canceFunctionrangeSelected(); - formula.createRangeHightlight(); - } - formula.rangestart = false; - formula.rangedrag_column_start = false; - formula.rangedrag_row_start = false; - $("#luckysheet-functionbox-cell").html(vText); - formula.rangeHightlightselected($("#luckysheet-rich-text-editor")); + //左上角返回按钮 + $("#luckysheet_info_detail_title").click(function(){ + window.open(luckysheetConfigsetting.myFolderUrl, "_self"); + }); - //再进行 选区的选择 - formula.israngeseleciton(); - formula.func_selectedrange = { - "left": colLocationByIndex(0)[0], - "width": colLocationByIndex(0)[1] - colLocationByIndex(0)[0] - 1, - "top": top, - "height": height, - "left_move": col_pre, - "width_move": col - col_pre - 1, - "top_move": top, - "height_move": height, - "row": rowseleted, - "column": [0, col_index], - "row_focus": row_index, - "column_focus": 0 - } - } - else{ - formula.func_selectedrange = { - "left": colLocationByIndex(0)[0], - "width": colLocationByIndex(0)[1] - colLocationByIndex(0)[0] - 1, - "top": top, - "height": height, - "left_move": col_pre, - "width_move": col - col_pre - 1, - "top_move": top, - "height_move": height, - "row": rowseleted, - "column": [0, col_index], - "row_focus": row_index, - "column_focus": 0 - } - } - - if(formula.rangestart || formula.rangedrag_column_start || formula.rangedrag_row_start || formula.israngeseleciton()){ - formula.rangeSetValue({ "row": rowseleted, "column": [null, null] }); - } - else if($("#luckysheet-ifFormulaGenerator-multiRange-dialog").is(":visible")){//if公式生成器 - let range = getRangetxt(Store.currentSheetIndex, { "row": rowseleted, "column": [0, col_index] }, Store.currentSheetIndex); - $("#luckysheet-ifFormulaGenerator-multiRange-dialog input").val(range); - } - - formula.rangedrag_row_start = true; - formula.rangestart = false; - formula.rangedrag_column_start = false; - - $("#luckysheet-formula-functionrange-select").css({ - "left": col_pre, - "width": col - col_pre - 1, - "top": top, - "height": height - }).show(); - $("#luckysheet-formula-help-c").hide(); - - luckysheet_count_show(col_pre, top, col - col_pre - 1, height, rowseleted, [0, col_index]); - - setTimeout(function(){ - let currSelection = window.getSelection(); - let anchorOffset = currSelection.anchorNode; - - let $editor; - if($("#luckysheet-search-formula-parm").is(":visible")||$("#luckysheet-search-formula-parm-select").is(":visible")){ - $editor = $("#luckysheet-rich-text-editor"); - formula.rangechangeindex = formula.data_parm_index; - } - else{ - $editor = $(anchorOffset).closest("div"); - } - - let $span = $editor.find("span[rangeindex='" + formula.rangechangeindex + "']"); - - formula.setCaretPosition($span.get(0), 0, $span.html().length); - }, 1); - - return; - } - else { - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - Store.luckysheet_rows_selected_status = true; - } - } - else { - Store.luckysheet_rows_selected_status = true; - } - - if (Store.luckysheet_rows_selected_status) { - if(event.shiftKey){ - //按住shift点击行索引选取范围 - let last = $.extend(true, {}, Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]); //选区最后一个 - - let top = 0, height = 0, rowseleted = []; - if (last.top > row_pre) { - top = row_pre; - height = last.top + last.height - row_pre; - - if(last.row[1] > last.row_focus){ - last.row[1] = last.row_focus; - } - - rowseleted = [row_index, last.row[1]]; - } - else if (last.top == row_pre) { - top = row_pre; - height = last.top + last.height - row_pre; - rowseleted = [row_index, last.row[0]]; - } - else { - top = last.top; - height = row - last.top - 1; - - if(last.row[0] < last.row_focus){ - last.row[0] = last.row_focus; - } - - rowseleted = [last.row[0], row_index]; - } - - last["row"] = rowseleted; - - last["top_move"] = top; - last["height_move"] = height; - - Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1] = last; - } - else if(event.ctrlKey){ - Store.luckysheet_select_save.push({ - "left": colLocationByIndex(0)[0], - "width": colLocationByIndex(0)[1] - colLocationByIndex(0)[0] - 1, - "top": top, - "height": height, - "left_move": col_pre, - "width_move": col - col_pre - 1, - "top_move": top, - "height_move": height, - "row": rowseleted, - "column": [0, col_index], - "row_focus": row_index, - "column_focus": 0 - }); - } - else{ - Store.luckysheet_select_save = []; - Store.luckysheet_select_save.push({ - "left": colLocationByIndex(0)[0], - "width": colLocationByIndex(0)[1] - colLocationByIndex(0)[0] - 1, - "top": top, - "height": height, - "left_move": col_pre, - "width_move": col - col_pre - 1, - "top_move": top, - "height_move": height, - "row": rowseleted, - "column": [0, col_index], - "row_focus": row_index, - "column_focus": 0 - }); - } - - selectHightlightShow(); - - if(server.allowUpdate){ - //允许编辑后的后台更新时 - server.saveParam("mv", Store.currentSheetIndex, Store.luckysheet_select_save); - } - } - - $("#luckysheet-helpbox-cell").text(getRangetxt(Store.currentSheetIndex, Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1])); - - setTimeout(function () { - clearTimeout(Store.countfuncTimeout); - countfunc(); - }, 101); - }).mousemove(function (event) { - if (Store.luckysheet_rows_selected_status || Store.luckysheet_rows_change_size || Store.luckysheet_select_status) { - $("#luckysheet-rows-h-hover").hide(); - return; - } - - let mouse = mouseposition(event.pageX, event.pageY); - let y = mouse[1] + $("#luckysheet-rows-h").scrollTop(); - - let row_location = rowLocation(y), - row = row_location[1], - row_pre = row_location[0], - row_index = row_location[2]; - - $("#luckysheet-rows-h-hover").css({ "top": row_pre, "height": row - row_pre - 1, "display": "block" }); - - if (y < row - 1 && y >= row - 5) { - $("#luckysheet-rows-change-size").css({ "top": row - 3, "opacity": 0 }); - } - else { - $("#luckysheet-rows-change-size").css("opacity", 0); - } - }).mouseleave(function (event) { - $("#luckysheet-rows-h-hover").hide(); - $("#luckysheet-rows-change-size").css("opacity", 0); - }).mouseup(function (event) { - if (event.which == 3) { - if(isEditMode()){ //非编辑模式下禁止右键功能框 - return; - } - - $("#luckysheet-cols-rows-shift").hide(); - Store.luckysheetRightHeadClickIs = "row"; - $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-word").text(locale().rightclick.row); - $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-size").text(locale().rightclick.height); - $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-left").text(locale().rightclick.top); - $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-right").text(locale().rightclick.bottom); - - $("#luckysheet-cols-rows-add").show(); - $("#luckysheet-cols-rows-data").show(); - $("#luckysheet-cols-rows-shift").hide(); - $("#luckysheet-cols-rows-handleincell").hide(); - - showrightclickmenu($("#luckysheet-rightclick-menu"), $(this).offset().left + 46, event.pageY); - Store.luckysheet_cols_menu_status = true; - - //行高默认值 - let cfg = $.extend(true, {}, Store.config); - if(cfg["rowlen"] == null){ - cfg["rowlen"] = {}; - } - - let first_rowlen = cfg["rowlen"][Store.luckysheet_select_save[0].row[0]] == null ? Store.defaultrowlen : cfg["rowlen"][Store.luckysheet_select_save[0].row[0]]; - let isSame = true; - - for(let i = 0; i < Store.luckysheet_select_save.length; i++){ - let s = Store.luckysheet_select_save[i]; - let r1 = s.row[0], r2 = s.row[1]; - - for(let r = r1; r <= r2; r++){ - let rowlen = cfg["rowlen"][r] == null ? Store.defaultrowlen : cfg["rowlen"][r]; - - if(rowlen != first_rowlen){ - isSame = false; - break; - } - } - } - - if(isSame){ - $("#luckysheet-cols-rows-add").find("input[type='number'].rcsize").val(first_rowlen); - } - else{ - $("#luckysheet-cols-rows-add").find("input[type='number'].rcsize").val(""); - } - } - }); - //表格列标题 mouse事件 - $("#luckysheet-cols-h-c").mousedown(function (event) { - //有批注在编辑时 - luckysheetPostil.removeActivePs(); - - let mouse = mouseposition(event.pageX, event.pageY); - let x = mouse[0] + $(this).scrollLeft(); - - let row_index = Store.visibledatarow.length - 1, - row = Store.visibledatarow[row_index], row_pre = 0; - let col_location = colLocation(x), - col = col_location[1], - col_pre = col_location[0], - col_index = col_location[2]; - - Store.orderbyindex = col_index;//排序全局函数 - - $("#luckysheet-rightclick-menu").hide(); - $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); - $("#luckysheet-filter-menu, #luckysheet-filter-submenu").hide(); - - //mousedown是右键 - if (event.which == "3") { - let isright = false; - - for(let s = 0; s < Store.luckysheet_select_save.length; s++){ - let obj_s = Store.luckysheet_select_save[s]; - - if(obj_s["column"] != null && (col_index >= obj_s["column"][0] && col_index <= obj_s["column"][1]) && (obj_s["row"][0] == 0 && obj_s["row"][1] == Store.flowdata.length - 1)){ - isright = true; - break; - } - } - - if(isright){ - return; - } - } - - let left = col_pre, width = col - col_pre - 1; - let columnseleted = [col_index, col_index]; - - Store.luckysheet_scroll_status = true; - - //公式相关 - let $input = $("#luckysheet-input-box"); - if (parseInt($input.css("top")) > 0) { - if (formula.rangestart || formula.rangedrag_column_start || formula.rangedrag_row_start || formula.israngeseleciton() || $("#luckysheet-ifFormulaGenerator-multiRange-dialog").is(":visible")) { - //公式选区 - let changeparam = menuButton.mergeMoveMain(columnseleted, [0, row_index], {"row_focus": 0, "column_focus": col_index}, row_pre, row, left, width); - if(changeparam != null){ - columnseleted = changeparam[0]; - //rowseleted= changeparam[1]; - //top = changeparam[2]; - //height = changeparam[3]; - left = changeparam[4]; - width = changeparam[5]; - } - - if(event.shiftKey){ - let last = formula.func_selectedrange; - - let left = 0, width = 0, columnseleted = []; - if (last.left > col_pre) { - left = col_pre; - width = last.left + last.width - col_pre; - - if(last.column[1] > last.column_focus){ - last.column[1] = last.column_focus; - } - - columnseleted = [col_index, last.column[1]]; - } - else if (last.left == col_pre) { - left = col_pre; - width = last.left + last.width - col_pre; - columnseleted = [col_index, last.column[0]]; - } - else { - left = last.left; - width = col - last.left - 1; - - if(last.column[0] < last.column_focus){ - last.column[0] = last.column_focus; - } - - columnseleted = [last.column[0], col_index]; - } - - let changeparam = menuButton.mergeMoveMain(columnseleted , [0, row_index], {"row_focus": 0, "column_focus": col_index}, row_pre, row, left, width); - if(changeparam != null){ - columnseleted = changeparam[0]; - //rowseleted= changeparam[1]; - //top = changeparam[2]; - //height = changeparam[3]; - left = changeparam[4]; - width = changeparam[5]; - } - - last["column"] = columnseleted; - - last["left_move"] = left; - last["width_move"] = width; - - formula.func_selectedrange = last; - } - else if(event.ctrlKey && $("#luckysheet-rich-text-editor").find("span").last().text() != ","){ - //按住ctrl 选择选区时 先处理上一个选区 - let vText = $("#luckysheet-rich-text-editor").text() + ","; - if(vText.length > 0 && vText.substr(0, 1) == "="){ - vText = formula.functionHTMLGenerate(vText); - - if (window.getSelection) { // all browsers, except IE before version 9 - let currSelection = window.getSelection(); - formula.functionRangeIndex = [$(currSelection.anchorNode).parent().index(), currSelection.anchorOffset]; - } - else { // Internet Explorer before version 9 - let textRange = document.selection.createRange(); - formula.functionRangeIndex = textRange; - } - - $("#luckysheet-rich-text-editor").html(vText); - - formula.canceFunctionrangeSelected(); - formula.createRangeHightlight(); - } - - formula.rangestart = false; - formula.rangedrag_column_start = false; - formula.rangedrag_row_start = false; - - $("#luckysheet-functionbox-cell").html(vText); - formula.rangeHightlightselected($("#luckysheet-rich-text-editor")); - - //再进行 选区的选择 - formula.israngeseleciton(); - formula.func_selectedrange = { - "left": left, - "width": width, - "top": rowLocationByIndex(0)[0], - "height": rowLocationByIndex(0)[1] - rowLocationByIndex(0)[0] - 1, - "left_move": left, - "width_move": width, - "top_move": row_pre, - "height_move": row - row_pre - 1, - "row": [0, row_index], - "column": columnseleted, - "row_focus": 0, - "column_focus": col_index - } - } - else{ - formula.func_selectedrange = { - "left": left, - "width": width, - "top": rowLocationByIndex(0)[0], - "height": rowLocationByIndex(0)[1] - rowLocationByIndex(0)[0] - 1, - "left_move": left, - "width_move": width, - "top_move": row_pre, - "height_move": row - row_pre - 1, - "row": [0, row_index], - "column": columnseleted, - "row_focus": 0, - "column_focus": col_index - } - } - - if(formula.rangestart || formula.rangedrag_column_start || formula.rangedrag_row_start || formula.israngeseleciton()){ - formula.rangeSetValue({ "row": [null, null], "column": columnseleted }); - } - else if($("#luckysheet-ifFormulaGenerator-multiRange-dialog").is(":visible")){//if公式生成器 - let range = getRangetxt(Store.currentSheetIndex, { "row": [0, row_index], "column": columnseleted }, Store.currentSheetIndex); - $("#luckysheet-ifFormulaGenerator-multiRange-dialog input").val(range); - } - - formula.rangedrag_column_start = true; - formula.rangestart = false; - formula.rangedrag_row_start = false; - - $("#luckysheet-formula-functionrange-select").css({ - "left": left, - "width": width, - "top": row_pre, - "height": row - row_pre - 1 - }).show(); - $("#luckysheet-formula-help-c").hide(); - - luckysheet_count_show(left, row_pre, width, row - row_pre - 1, [0, row_index], columnseleted); - - return; - } - else { - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - Store.luckysheet_cols_selected_status = true; - } - } - else { - Store.luckysheet_cols_selected_status = true; - } - - if (Store.luckysheet_cols_selected_status) { - if(event.shiftKey){ - //按住shift点击列索引选取范围 - let last = $.extend(true, {}, Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]); //选区最后一个 - - let left = 0, width = 0, columnseleted = []; - if (last.left > col_pre) { - left = col_pre; - width = last.left + last.width - col_pre; - - if(last.column[1] > last.column_focus){ - last.column[1] = last.column_focus; - } - - columnseleted = [col_index, last.column[1]]; - } - else if (last.left == col_pre) { - left = col_pre; - width = last.left + last.width - col_pre; - columnseleted = [col_index, last.column[0]]; - } - else { - left = last.left; - width = col - last.left - 1; - - if(last.column[0] < last.column_focus){ - last.column[0] = last.column_focus; - } - - columnseleted = [last.column[0], col_index]; - } - - last["column"] = columnseleted; - - last["left_move"] = left; - last["width_move"] = width; - - Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1] = last; - } - else if(event.ctrlKey){ - //选区添加 - Store.luckysheet_select_save.push({ - "left": left, - "width": width, - "top": rowLocationByIndex(0)[0], - "height": rowLocationByIndex(0)[1] - rowLocationByIndex(0)[0] - 1, - "left_move": left, - "width_move": width, - "top_move": row_pre, - "height_move": row - row_pre - 1, - "row": [0, row_index], - "column": columnseleted, - "row_focus": 0, - "column_focus": col_index - }); - } - else{ - Store.luckysheet_select_save = []; - Store.luckysheet_select_save.push({ - "left": left, - "width": width, - "top": rowLocationByIndex(0)[0], - "height": rowLocationByIndex(0)[1] - rowLocationByIndex(0)[0] - 1, - "left_move": left, - "width_move": width, - "top_move": row_pre, - "height_move": row - row_pre - 1, - "row": [0, row_index], - "column": columnseleted, - "row_focus": 0, - "column_focus": col_index - }); - } - - selectHightlightShow(); - - if(server.allowUpdate){ - //允许编辑后的后台更新时 - server.saveParam("mv", Store.currentSheetIndex, Store.luckysheet_select_save); - } - } - - $("#luckysheet-helpbox-cell").text(getRangetxt(Store.currentSheetIndex, Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1])); - - setTimeout(function () { - clearTimeout(Store.countfuncTimeout); - countfunc(); - }, 101); - - if (Store.luckysheet_cols_menu_status) { - $("#luckysheet-rightclick-menu").hide(); - $("#luckysheet-cols-h-hover").hide(); - $("#luckysheet-cols-menu-btn").hide(); - Store.luckysheet_cols_menu_status = false; - } - event.stopPropagation(); - }).mousemove(function (event) { - if (Store.luckysheet_cols_selected_status || Store.luckysheet_select_status) { - $("#luckysheet-cols-h-hover").hide(); - $("#luckysheet-cols-menu-btn").hide(); - return; - } - - if (Store.luckysheet_cols_menu_status || Store.luckysheet_cols_change_size) { - return; - } - - let mouse = mouseposition(event.pageX, event.pageY); - let x = mouse[0] + $("#luckysheet-cols-h-c").scrollLeft(); - - let col_location = colLocation(x), - col = col_location[1], - col_pre = col_location[0], - col_index = col_location[2]; - - $("#luckysheet-cols-h-hover").css({ "left": col_pre, "width": col - col_pre - 1, "display": "block" }); - $("#luckysheet-cols-menu-btn").css({ "left": col - 19, "display": "block" }); - - $("#luckysheet-cols-change-size").css({ "left": col - 5 }); - if (x < col && x >= col - 5) { - $("#luckysheet-cols-change-size").css({ "opacity": 0 }); - $("#luckysheet-cols-menu-btn").hide(); - } - else { - $("#luckysheet-change-size-line").hide(); - $("#luckysheet-cols-change-size").css("opacity", 0); - } - }).mouseleave(function (event) { - if (Store.luckysheet_cols_menu_status || Store.luckysheet_cols_change_size) { - return; - } - - $("#luckysheet-cols-h-hover").hide(); - $("#luckysheet-cols-menu-btn").hide(); - $("#luckysheet-cols-change-size").css("opacity", 0); - }).mouseup(function (event) { - if (event.which == 3) { - if(isEditMode()){ //非编辑模式下禁止右键功能框 - return; - } - - Store.luckysheetRightHeadClickIs = "column"; - $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-word").text(locale().rightclick.column); - $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-size").text(locale().rightclick.width); - $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-left").text(locale().rightclick.left); - $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-right").text(locale().rightclick.right); - - $("#luckysheet-cols-rows-add").show(); - $("#luckysheet-cols-rows-data").show(); - $("#luckysheet-cols-rows-shift").hide(); - $("#luckysheet-cols-rows-handleincell").hide(); - - showrightclickmenu($("#luckysheet-rightclick-menu"), event.pageX, $(this).offset().top + 18); - Store.luckysheet_cols_menu_status = true; - - //列宽默认值 - let cfg = $.extend(true, {}, Store.config); - if(cfg["columlen"] == null){ - cfg["columlen"] = {}; - } - - let first_collen = cfg["columlen"][Store.luckysheet_select_save[0].column[0]] == null ? Store.defaultcollen : cfg["columlen"][Store.luckysheet_select_save[0].column[0]]; - let isSame = true; - - for(let i = 0; i < Store.luckysheet_select_save.length; i++){ - let s = Store.luckysheet_select_save[i]; - let c1 = s.column[0], c2 = s.column[1]; - - for(let c = c1; c <= c2; c++){ - let collen = cfg["columlen"][c] == null ? Store.defaultcollen : cfg["columlen"][c]; - - if(collen != first_collen){ - isSame = false; - break; - } - } - } - - if(isSame){ - $("#luckysheet-cols-rows-add").find("input[type='number'].rcsize").val(first_collen); - } - else{ - $("#luckysheet-cols-rows-add").find("input[type='number'].rcsize").val(""); - } - } - }); - - //表格列标题 改变列宽按钮 - $("#luckysheet-cols-change-size").mousedown(function (event) { - //有批注在编辑时 - luckysheetPostil.removeActivePs(); - - $("#luckysheet-input-box").hide(); - $("#luckysheet-cols-change-size").css({ "opacity": 1 }); - - let mouse = mouseposition(event.pageX, event.pageY); - let scrollLeft = $("#luckysheet-cols-h-c").scrollLeft(); - let scrollTop = $("#luckysheet-cell-main").scrollTop(); - let winH = $("#luckysheet-cell-main").height(); - let x = mouse[0] + scrollLeft; - - let row_index = Store.visibledatarow.length - 1, - row = Store.visibledatarow[row_index], row_pre = 0; - let col_location = colLocation(x), - col = col_location[1], - col_pre = col_location[0], - col_index = col_location[2]; - - Store.luckysheet_cols_change_size = true; - Store.luckysheet_scroll_status = true; - $("#luckysheet-change-size-line").css({ - "height": winH + scrollTop, - "border-width": "0 1px 0 0", - "top": 0, - "left": col - 3, - "width": "1px", - "display": "block", - "cursor": "ew-resize" - }); - $("#luckysheet-sheettable, #luckysheet-cols-h-c, .luckysheet-cols-h-cells, .luckysheet-cols-h-cells canvas").css("cursor", "ew-resize"); - Store.luckysheet_cols_change_size_start = [col_pre, col_index]; - $("#luckysheet-rightclick-menu").hide(); - $("#luckysheet-cols-h-hover").hide(); - $("#luckysheet-cols-menu-btn").hide(); - Store.luckysheet_cols_dbclick_times = 0; - event.stopPropagation(); - }).dblclick(function () { - luckysheetcolsdbclick(); - }) - - function luckysheetcolsdbclick() { - 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; - let winW = $(window).width(); - - let row_index = Store.visibledatarow.length - 1, - row = Store.visibledatarow[row_index], - row_pre = 0; - let col_location = colLocation(x), - col = col_location[1], - col_pre = col_location[0], - col_index = col_location[2]; - Store.luckysheet_cols_change_size_start = [col_pre, col_index]; - let dataflow = $("#luckysheetTableContent").get(0).getContext("2d"); - let cfg = $.extend(true, {}, Store.config); - - let matchColumn = {}; - 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]; - - if (col_index < c1 || col_index > c2) { - if(col_index in matchColumn){//此列已计算过 - continue; - } - - x = -Infinity; - let countret = 0; - let fontsize = 13; - for (let r = 0; r < Store.flowdata.length; r++) { - if (countret >= 15) { - break; - } - - let value = getcellvalue(r, Store.luckysheet_cols_change_size_start[1], Store.flowdata); - let mask = getcellvalue(r, Store.luckysheet_cols_change_size_start[1], Store.flowdata, "m"); - - if(mask != null){ - value = mask; - } - - let cell = Store.flowdata[r][Store.luckysheet_cols_change_size_start[1]]; - if(getObjType(cell) == "object" && ("fs" in cell)){ - if(cell.fs > fontsize){ - fontsize = cell.fs; - } - } - - if (value == null || value.toString().length == 0) { - countret++; - continue; - } - let textMetrics = dataflow.measureText(value).width; - if (textMetrics > x) { - x = textMetrics; - } - } - - let size = x + fontsize * 1.5; - if ((x + 3) < 30) { - size = 30; - } - - if (x >= winW - 100 + scrollLeft) { - size = winW - 100 + scrollLeft; - } - - if (cfg["columlen"] == null) { - cfg["columlen"] = {}; - } - - cfg["columlen"][Store.luckysheet_cols_change_size_start[1]] = Math.ceil(size); - - matchColumn[col_index] = 1; - } - else { - for (let c = c1; c <= c2; c++) { - if(c in matchColumn){//此列已计算过 - continue; - } - - x = -Infinity; - let countret = 0; - let fontsize = 13; - for (let r = 0; r < Store.flowdata.length; r++) { - if (countret >= 15) { - break; - } - let value = getcellvalue(r, c, Store.flowdata); - - let cell = Store.flowdata[r][c]; - if(getObjType(cell) == "object" && ("fs" in cell)){ - if(cell.fs > fontsize){ - fontsize = cell.fs; - } - } - - if (isRealNull(value)) { - countret++; - continue; - } - - let textMetrics = dataflow.measureText(value).width; - if (textMetrics > x) { - x = textMetrics; - } - } - - let size = x + fontsize*1.5;; - if ((x + 3) < 30) { - size = 30; - } - - if (x >= winW - 100 + scrollLeft) { - size = winW - 100 + scrollLeft; - } - - if (cfg["columlen"] == null) { - cfg["columlen"] = {}; - } - cfg["columlen"][c] = Math.ceil(size); - - matchColumn[c] = 1; - } - } - } - - jfrefreshgridall(Store.flowdata[0].length, Store.flowdata.length, Store.flowdata, cfg, Store.luckysheet_select_save, "resizeC", "columlen"); - } - - //表格行标题 改变行高按钮 - $("#luckysheet-rows-change-size").mousedown(function (event) { - //有批注在编辑时 - luckysheetPostil.removeActivePs(); - - $("#luckysheet-input-box").hide(); - $("#luckysheet-rows-change-size").css({ "opacity": 1 }); - - let mouse = mouseposition(event.pageX, event.pageY); - let y = mouse[1] + $("#luckysheet-rows-h").scrollTop(); - - let scrollLeft = $("#luckysheet-cell-main").scrollLeft(); - let winW = $("#luckysheet-cell-main").width(); - - let row_location = rowLocation(y), - row = row_location[1], - row_pre = row_location[0], - row_index = row_location[2]; - - Store.luckysheet_rows_change_size = true; - Store.luckysheet_scroll_status = true; - $("#luckysheet-change-size-line").css({ - "height": "1px", - "border-width": - "0 0px 1px 0", - "top": row - 3, - "left": 0, - "width": scrollLeft + winW, - "display": "block", - "cursor": "ns-resize" - }); - $("#luckysheet-sheettable, #luckysheet-rows-h, #luckysheet-rows-h canvas").css("cursor", "ns-resize"); - Store.luckysheet_rows_change_size_start = [row_pre, row_index]; - $("#luckysheet-rightclick-menu").hide(); - $("#luckysheet-rows-h-hover").hide(); - $("#luckysheet-cols-menu-btn").hide(); - event.stopPropagation(); - }); - - $("#luckysheet-cols-menu-btn").click(function (event) { - let $menu = $("#luckysheet-rightclick-menu"); - let offset = $(this).offset(); - $("#luckysheet-cols-rows-shift").show(); - Store.luckysheetRightHeadClickIs = "column"; - $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-word").text(locale().rightclick.column); - $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-left").text(locale().rightclick.left); - $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-right").text(locale().rightclick.right); - - $("#luckysheet-cols-rows-add").show(); - $("#luckysheet-cols-rows-data").hide(); - $("#luckysheet-cols-rows-shift").show(); - $("#luckysheet-cols-rows-handleincell").hide(); - - showrightclickmenu($menu, offset.left, offset.top + 18); - Store.luckysheet_cols_menu_status = true; - }); - - //菜单栏 排序按钮 - $("#luckysheetorderbyasc, #luckysheetorderbyasc_t").mousedown(function (event) { - cleargridelement(event); - sortColumnSeletion(Store.orderbyindex, true); - selectHightlightShow(); - }); - - $("#luckysheetorderbydesc, #luckysheetorderbydesc_t").click(function (event) { - cleargridelement(event); - sortColumnSeletion(Store.orderbyindex, false); - selectHightlightShow(); - }); - - //右键功能键 - //复制为json格式字符串,首行为标题 - $("#luckysheet-copy-json-head").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - //复制范围内包含部分合并单元格,提示 - if(Store.config["merge"] != null){ - let has_PartMC = false; - - 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]; - let c1 = Store.luckysheet_select_save[s].column[0], - c2 = Store.luckysheet_select_save[s].column[1]; - - has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); - - if(has_PartMC){ - break; - } - } - - if(has_PartMC){ - if(isEditMode()){ - alert(locale_drag.noPartMerge); - } - else{ - tooltip.info(locale_drag.noPartMerge, ""); - } - return; - } - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - let arr = []; - if (getdata.length == 0) { - return; - } - - if (getdata.length == 1) { - let obj = {}; - for (let i = 0; i < getdata[0].length; i++) { - obj[getcellvalue(0, i, getdata)] = ""; - } - arr.push(obj); - } - else { - for (let r = 1; r < getdata.length; r++) { - let obj = {}; - for (let c = 0; c < getdata[0].length; c++) { - if(getcellvalue(0, c, getdata) == undefined){ - obj[""] = getcellvalue(r, c, getdata); - }else{ - obj[getcellvalue(0, c, getdata)] = getcellvalue(r, c, getdata); - } - } - arr.push(obj); - } - } - - selection.copybyformat(event, JSON.stringify(arr)); - }); - - //复制为json格式字符串,无标题,采用ABCD作为标题 - $("#luckysheet-copy-json-nohead").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - //复制范围内包含部分合并单元格,提示 - if(Store.config["merge"] != null){ - let has_PartMC = false; - - 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]; - let c1 = Store.luckysheet_select_save[s].column[0], - c2 = Store.luckysheet_select_save[s].column[1]; - - has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); - - if(has_PartMC){ - break; - } - } - - if(has_PartMC){ - if(isEditMode()){ - alert(locale_drag.noPartMerge); - } - else{ - tooltip.info(locale_drag.noPartMerge, ""); - } - return; - } - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - let arr = []; - if (getdata.length == 0) { - return; - } - let st = Store.luckysheet_select_save[0]["column"][0]; - for (let r = 0; r < getdata.length; r++) { - let obj = {}; - for (let c = 0; c < getdata[0].length; c++) { - obj[chatatABC(c + st)] = getcellvalue(r, c, getdata); - } - arr.push(obj); - } - - selection.copybyformat(event, JSON.stringify(arr)); - }); - - //复制为一维数组 - $("#luckysheet-copy-array1").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - //复制范围内包含部分合并单元格,提示 - if(Store.config["merge"] != null){ - let has_PartMC = false; - - 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]; - let c1 = Store.luckysheet_select_save[s].column[0], - c2 = Store.luckysheet_select_save[s].column[1]; - - has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); - - if(has_PartMC){ - break; - } - } - - if(has_PartMC){ - if(isEditMode()){ - alert(locale_drag.noPartMerge); - } - else{ - tooltip.info(locale_drag.noPartMerge, ""); - } - return; - } - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - let arr = []; - if (getdata.length == 0) { - return; - } - for (let r = 0; r < getdata.length; r++) { - for (let c = 0; c < getdata[0].length; c++) { - arr.push(getcellvalue(r, c, getdata)); - } - } - - selection.copybyformat(event, JSON.stringify(arr)); - }); - - //复制为二维数组 - $("#luckysheet-copy-array2").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - //复制范围内包含部分合并单元格,提示 - if(Store.config["merge"] != null){ - let has_PartMC = false; - - 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]; - let c1 = Store.luckysheet_select_save[s].column[0], - c2 = Store.luckysheet_select_save[s].column[1]; - - has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); - - if(has_PartMC){ - break; - } - } - - if(has_PartMC){ - if(isEditMode()){ - alert(locale_drag.noPartMerge); - } - else{ - tooltip.info(locale_drag.noPartMerge, ""); - } - return; - } - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - let arr = []; - if (getdata.length == 0) { - return; - } - for (let r = 0; r < getdata.length; r++) { - let a = []; - for (let c = 0; c < getdata[0].length; c++) { - a.push(getcellvalue(r, c, getdata)); - } - arr.push(a); - } - - selection.copybyformat(event, JSON.stringify(arr)); - }); - - //复制为多维数组 - $("#luckysheet-copy-arraymore-confirm").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - //复制范围内包含部分合并单元格,提示 - if(Store.config["merge"] != null){ - let has_PartMC = false; - - 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]; - let c1 = Store.luckysheet_select_save[s].column[0], - c2 = Store.luckysheet_select_save[s].column[1]; - - has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); - - if(has_PartMC){ - break; - } - } - - if(has_PartMC){ - if(isEditMode()){ - alert(locale_drag.noPartMerge); - } - else{ - tooltip.info(locale_drag.noPartMerge, ""); - } - return; - } - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - let arr = []; - if (getdata.length == 0) { - return; - } - - for (let r = 0; r < getdata.length; r++) { - for (let c = 0; c < getdata[0].length; c++) { - arr.push(getdata[r][c]); - } - } - - let row = $("#luckysheet-copy-arraymore-row").val(), col = $("#luckysheet-copy-arraymore-col").val(); - - if (row == "" && col == "") { - selection.copybyformat(event, JSON.stringify(arr)); - $("body .luckysheet-cols-menu").hide(); - return; - } - - if (row == "") { - row = 1; - } - else { - row = parseInt(row); - if (row == null) { - row = 1; - } - } - - if (col == "") { - col = 1; - } - else { - col = parseInt(col); - if (col == null) { - col = 1; - } - } - - if(row.toString() == "NaN" || col.toString() == "NaN"){ - if(isEditMode()){ - alert(locale_drag.inputCorrect); - } - else{ - tooltip.info(locale_drag.inputCorrect, ""); - } - return; - } - - if(row < 1 || col < 1){ - if(isEditMode()){ - alert(locale_drag.notLessOne); - } - else{ - tooltip.info(locale_drag.notLessOne, ""); - } - return; - } - - let arrlen = arr.length, i = 0, ret = []; - for (let r = 0; r < row; r++) { - let a = []; - for (let c = 0; c < col; c++) { - a.push(arr[i++]); - if (i >= arrlen) { - selection.copybyformat(event, JSON.stringify(ret)); - $("body .luckysheet-cols-menu").hide(); - return; - } - } - ret.push(a); - } - - selection.copybyformat(event, JSON.stringify(ret)); - }); - - //复制为对角线 - $("#luckysheet-copy-diagonal").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - //复制范围内包含部分合并单元格,提示 - if(Store.config["merge"] != null){ - let has_PartMC = false; - - 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]; - let c1 = Store.luckysheet_select_save[s].column[0], - c2 = Store.luckysheet_select_save[s].column[1]; - - has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); - - if(has_PartMC){ - break; - } - } - - if(has_PartMC){ - if(isEditMode()){ - alert(locale_drag.noPartMerge); - } - else{ - tooltip.info(locale_drag.noPartMerge, ""); - } - return; - } - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - let arr = []; - if (getdata.length == 0) { - return; - } - - let clen = getdata[0].length; - for (let r = 0; r < getdata.length; r++) { - if (r >= clen) { - break; - } - arr.push(getdata[r][r]); - } - - selection.copybyformat(event, JSON.stringify(arr)); - }); - - //复制为反对角线 - $("#luckysheet-copy-antidiagonal").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - //复制范围内包含部分合并单元格,提示 - if(Store.config["merge"] != null){ - let has_PartMC = false; - - 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]; - let c1 = Store.luckysheet_select_save[s].column[0], - c2 = Store.luckysheet_select_save[s].column[1]; - - has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); - - if(has_PartMC){ - break; - } - } - - if(has_PartMC){ - if(isEditMode()){ - alert(locale_drag.noPartMerge); - } - else{ - tooltip.info(locale_drag.noPartMerge, ""); - } - return; - } - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - let arr = []; - if (getdata.length == 0) { - return; - } - - let clen = getdata[0].length; - for (let r = 0; r < getdata.length; r++) { - if (r >= clen) { - break; - } - arr.push(getdata[r][clen - r - 1]); - } - - selection.copybyformat(event, JSON.stringify(arr)); - }); - - //复制为对角偏移n列 - $("#luckysheet-copy-diagonaloffset").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - //复制范围内包含部分合并单元格,提示 - if(Store.config["merge"] != null){ - let has_PartMC = false; - - 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]; - let c1 = Store.luckysheet_select_save[s].column[0], - c2 = Store.luckysheet_select_save[s].column[1]; - - has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); - - if(has_PartMC){ - break; - } - } - - if(has_PartMC){ - if(isEditMode()){ - alert(locale_drag.noPartMerge); - } - else{ - tooltip.info(locale_drag.noPartMerge, ""); - } - return; - } - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - let arr = []; - if (getdata.length == 0) { - return; - } - - let clen = getdata[0].length, - offset = parseInt($("#luckysheet-copy-diagonaloffset-value").val()); - - if(offset.toString() == "NaN"){ - if(isEditMode()){ - alert(locale_drag.inputCorrect); - } - else{ - tooltip.info(locale_drag.inputCorrect, ""); - } - return; - } - - if(offset < 0){ - if(isEditMode()){ - alert(locale_drag.offsetColumnLessZero); - } - else{ - tooltip.info(locale_drag.offsetColumnLessZero, ""); - } - return; - } - - if (offset == null) { - offset = 1; - } - - for (let r = 0; r < getdata.length; r++) { - if (r + offset >= clen) { - break; - } - arr.push(getdata[r][r + offset]); - } - - selection.copybyformat(event, JSON.stringify(arr)); - }); - - //复制为布尔值 - $("#luckysheet-copy-boolvalue").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - //复制范围内包含部分合并单元格,提示 - if(Store.config["merge"] != null){ - let has_PartMC = false; - - 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]; - let c1 = Store.luckysheet_select_save[s].column[0], - c2 = Store.luckysheet_select_save[s].column[1]; - - has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); - - if(has_PartMC){ - break; - } - } - - if(has_PartMC){ - if(isEditMode()){ - alert(locale_drag.noPartMerge); - } - else{ - tooltip.info(locale_drag.noPartMerge, ""); - } - return; - } - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - let arr = []; - if (getdata.length == 0) { - return; - } - for (let r = 0; r < getdata.length; r++) { - let a = []; - for (let c = 0; c < getdata[0].length; c++) { - let bool = false; - - if(getObjType(getdata[r][c]) == "object"){ - let v = getdata[r][c].v; - } - else{ - let v = getdata[r][c]; - } - - if (v == null || v == "") { - bool = false; - } - else { - v = parseInt(v); - if (v == null || v > 0) { - bool = true; - } - else { - bool = false; - } - } - a.push(bool); - } - arr.push(a); - } - - selection.copybyformat(event, JSON.stringify(arr)); - }); - - //矩阵操作选区 翻转 上下 - $("#luckysheet-matrix-turn-up").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - if (getdata.length == 0) { - return; - } - - let arr = []; - for (let r = getdata.length - 1; r >= 0; r--) { - let a = []; - for (let c = 0; c < getdata[0].length; c++) { - let value = ""; - if (getdata[r] != null && getdata[r][c] != null) { - value = getdata[r][c]; - } - a.push(value); - } - arr.push(a); - } - - editor.controlHandler(arr); - }); - - //矩阵操作选区 翻转 左右 - $("#luckysheet-matrix-turn-left").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - if (getdata.length == 0) { - return; - } - - let arr = []; - for (let r = 0; r < getdata.length; r++) { - let a = []; - for (let c = getdata[0].length - 1; c >= 0; c--) { - let value = ""; - if (getdata[r] != null && getdata[r][c] != null) { - value = getdata[r][c]; - } - a.push(value); - } - arr.push(a); - } - - editor.controlHandler(arr); - }); - - //矩阵操作选区 翻转 顺时针 - $("#luckysheet-matrix-turn-cw").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - if (getdata.length == 0) { - return; - } - - let arr = []; - for (let c = 0; c < getdata[0].length; c++) { - let a = []; - for (let r = getdata.length - 1; r >= 0; r--) { - let value = ""; - if (getdata[r] != null && getdata[r][c] != null) { - value = getdata[r][c]; - } - a.push(value); - } - arr.push(a); - } - - editor.controlHandlerD(arr); - }); - - //矩阵操作选区 翻转 逆时针 - $("#luckysheet-matrix-turn-anticw").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - if (getdata.length == 0) { - return; - } - - let arr = []; - for (let c = getdata[0].length - 1; c >= 0; c--) { - let a = []; - for (let r = 0; r < getdata.length; r++) { - let value = ""; - if (getdata[r] != null && getdata[r][c] != null) { - value = getdata[r][c]; - } - a.push(value); - } - arr.push(a); - } - - editor.controlHandlerD(arr); - }); - - //矩阵操作选区 转置 - $("#luckysheet-matrix-turn-trans").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - if (getdata.length == 0) { - return; - } - - let arr = []; - for (let c = 0; c < getdata[0].length; c++) { - let a = []; - for (let r = 0; r < getdata.length; r++) { - let value = ""; - if (getdata[r] != null && getdata[r][c] != null) { - value = getdata[r][c]; - } - a.push(value); - } - arr.push(a); - } - - editor.controlHandlerD(arr); - }); - - let jfnqrt = function (x, p) { - if (x == 0) - return 0; - let x0, x1; - x0 = x; - x1 = ((p - 1) * x0 / p) + (x / (Math.pow(x0, p - 1) * p));//利用迭代法求解 - while (Math.abs(x1 - x0) > 0.000001) { - x0 = x1; - x1 = ((p - 1) * x0 / p) + (x / (Math.pow(x0, p - 1) * p)); - } - return x1; - } - - //矩阵操作选区 矩阵计算 - $("#luckysheet-matrix-cal-confirm").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - if (getdata.length == 0) { - return; - } - - let caltype = $("#luckysheet-matrix-cal-type").val(), - calvalue = parseInt($("#luckysheet-matrix-cal-value").val()); - - if(calvalue.toString() == "NaN"){ - if(isEditMode()){ - alert(locale_drag.inputCorrect); - } - else{ - tooltip.info(locale_drag.inputCorrect, ""); - } - return; - } - - if (calvalue == null) { - calvalue = 2; - } - - let arr = []; - - for (let r = 0; r < getdata.length; r++) { - let a = []; - - for (let c = 0; c < getdata[0].length; c++) { - let value = ""; - if (getdata[r] != null && getdata[r][c] != null) { - value = getdata[r][c]; - if (parseInt(value) != null && getdata[r][c].ct != undefined && getdata[r][c].ct.t == "n") { - if (caltype == "minus") { - value.v = value.v - calvalue; - } - else if (caltype == "multiply") { - value.v = value.v * calvalue; - } - else if (caltype == "divided") { - value.v = numFormat(value.v / calvalue, 4); - } - else if (caltype == "power") { - value.v = Math.pow(value.v, calvalue); - } - else if (caltype == "root") { - if (calvalue == 2) { - value.v = numFormat(Math.sqrt(value.v), 4); - } - else if (calvalue == 3 && Math.cbrt) { - value.v = numFormat(Math.cbrt(value.v), 4); - } - else { - value.v = numFormat(jfnqrt(value.v, calvalue), 4); - } - } - else if (caltype == "log") { - value.v = numFormat(Math.log(value.v) * 10000 / Math.log(Math.abs(calvalue)), 4); - } - else { - value.v = value.v + calvalue; - } - - if(value.v == null){ - value.m = ""; - } - else{ - value.m = value.v.toString(); - } - } - } - a.push(value); - } - arr.push(a); - } - - editor.controlHandler(arr); - }); - - //矩阵操作选区 删除两端0值 按行 - $("#luckysheet-matrix-delezero-row").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - if (getdata.length == 0) { - return; - } - - let arr = []; - let getdatalen = getdata[0].length; - for (let r = 0; r < getdata.length; r++) { - let a = [], stdel = true, eddel = true; - for (let c = 0; c < getdatalen; c++) { - let value = ""; - if (getdata[r] != null && getdata[r][c] != null) { - value = getdata[r][c]; - if ((value.v == "0" || value.v == 0) && stdel) { - continue; - } - else { - stdel = false; - } - } - a.push(value); - } - - let a1 = []; - if (a.length == getdatalen) { - a1 = a; - } - else { - for (let c = a.length - 1; c >= 0; c--) { - let value = ""; - if (a[c] != null) { - value = a[c]; - if ((value.v == "0" || value.v == 0) && eddel) { - continue; - } - else { - eddel = false; - } - } - a1.unshift(value); - } - - let l = getdatalen - a1.length; - for (let c1 = 0; c1 < l; c1++) { - a1.push(""); - } - } - arr.push(a1); - } - - editor.controlHandler(arr); - }); - - //矩阵操作选区 删除两端0值 按列 - $("#luckysheet-matrix-delezero-column").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - if (getdata.length == 0) { - return; - } - - let arr = []; - let getdatalen = getdata.length, collen = getdata[0].length; - for (let c = 0; c < collen; c++) { - let a = [], stdel = true, eddel = true; - for (let r = 0; r < getdatalen; r++) { - let value = ""; - if (getdata[r] != null && getdata[r][c] != null) { - value = getdata[r][c]; - if ((value.v == "0" || value.v == 0) && stdel) { - continue; - } - else { - stdel = false; - } - } - a.push(value); - } - - let a1 = []; - if (a.length == getdatalen) { - a1 = a; - } - else { - for (let r = a.length - 1; r >= 0; r--) { - let value = ""; - if (a[r] != null) { - value = a[r]; - if ((value.v == "0" || value.v == 0) && eddel) { - continue; - } - else { - eddel = false; - } - } - a1.unshift(value); - } - - let l = getdatalen - a1.length; - for (let r1 = 0; r1 < l; r1++) { - a1.push(""); - } - } - arr.push(a1); - } - - let arr1 = []; - for (let c = 0; c < arr[0].length; c++) { - let a = []; - for (let r = 0; r < arr.length; r++) { - let value = ""; - if (arr[r] != null && arr[r][c] != null) { - value = arr[r][c]; - } - a.push(value); - } - arr1.push(a); - } - - editor.controlHandler(arr1); - }); - - //矩阵操作选区 删除重复值 按行 - $("#luckysheet-matrix-delerpt-row").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - if (getdata.length == 0) { - return; - } - - let arr = []; - let getdatalen = getdata[0].length; - for (let r = 0; r < getdata.length; r++) { - let a = [], repeat = {}; - - for (let c = 0; c < getdatalen; c++) { - let value = null; - if (getdata[r] != null && getdata[r][c] != null) { - value = getdata[r][c]; - - if(value.v in repeat){ - repeat[value.v].push(value); - } - else{ - repeat[value.v] = []; - repeat[value.v].push(value); - } - } - } - - for (let c = 0; c < getdatalen; c++) { - let value = null; - if (getdata[r] != null && getdata[r][c] != null) { - value = getdata[r][c]; - - if(repeat[value.v].length == 1){ - a.push(value); - } - } - } - - let l = getdatalen - a.length; - for (let c1 = 0; c1 < l; c1++) { - a.push(null); - } - arr.push(a); - } - - editor.controlHandler(arr); - }); - - //矩阵操作选区 删除重复值 按列 - $("#luckysheet-matrix-delerpt-column").click(function (event) { - $("body .luckysheet-cols-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - return; - } - - let getdata = getdatabyselection(Store.luckysheet_select_save[0]); - if (getdata.length == 0) { - return; - } - - let arr = []; - let getdatalen = getdata.length, collen = getdata[0].length; - for (let c = 0; c < collen; c++) { - let a = [], repeat = {}; - - for (let r = 0; r < getdatalen; r++) { - let value = null; - if (getdata[r] != null && getdata[r][c] != null) { - value = getdata[r][c]; - - if(value.v in repeat){ - repeat[value.v].push(value); - } - else{ - repeat[value.v] = []; - repeat[value.v].push(value); - } - } - } - - for (let r = 0; r < getdatalen; r++) { - let value = null; - if (getdata[r] != null && getdata[r][c] != null) { - value = getdata[r][c]; - - if(repeat[value.v].length == 1){ - a.push(value); - } - } - } - - a1 = a; - let l = getdatalen - a1.length; - for (let r1 = 0; r1 < l; r1++) { - a1.push(null); - } - arr.push(a1); - } - - let arr1 = []; - for (let c = 0; c < arr[0].length; c++) { - let a = []; - for (let r = 0; r < arr.length; r++) { - let value = null; - if (arr[r] != null && arr[r][c] != null) { - value = arr[r][c]; - } - a.push(value); - } - arr1.push(a); - } - - editor.controlHandler(arr1); - }); - - //回退 重做 按钮 - $("#luckysheet-icon-undo").click(function (event) { - controlHistory.redo(event); - }); - $("#luckysheet-icon-redo").click(function (event) { - controlHistory.undo(event); - }); - - //表格底部名称栏区域 相关事件(增、删、改、隐藏显示、颜色等等) - let isInitialSheetConfig = false, luckysheetcurrentSheetitem = null, jfdbclicklagTimeout = null; - function showsheetconfigmenu() { - if (!isInitialSheetConfig) { - isInitialSheetConfig = true; - let locale_toolbar = _locale.toolbar; - $("#luckysheetsheetconfigcolorur").spectrum({ - showPalette: true, - preferredFormat: "hex", - clickoutFiresChange: false, - showInitial: true, - showInput: true, - flat: true, - hideAfterPaletteSelect: false, - showSelectionPalette: true, - maxPaletteSize: 10, - cancelText: _locale.sheetconfig.cancelText, - chooseText: _locale.sheetconfig.chooseText, - togglePaletteMoreText: locale_toolbar.toolMore, - togglePaletteLessText: locale_toolbar.toolLess, - clearText: locale_toolbar.clearText, - noColorSelectedText: locale_toolbar.noColorSelectedText, - palette: [["rgb(0, 0, 0)", "rgb(67, 67, 67)", "rgb(102, 102, 102)", "rgb(204, 204, 204)", "rgb(217, 217, 217)", "rgb(255, 255, 255)"], ["rgb(152, 0, 0)", "rgb(255, 0, 0)", "rgb(255, 153, 0)", "rgb(255, 255, 0)", "rgb(0, 255, 0)", "rgb(0, 255, 255)", "rgb(74, 134, 232)", "rgb(0, 0, 255)", "rgb(153, 0, 255)", "rgb(255, 0, 255)"], ["rgb(230, 184, 175)", "rgb(244, 204, 204)", "rgb(252, 229, 205)", "rgb(255, 242, 204)", "rgb(217, 234, 211)", "rgb(208, 224, 227)", "rgb(201, 218, 248)", "rgb(207, 226, 243)", "rgb(217, 210, 233)", "rgb(234, 209, 220)"], ["rgb(221, 126, 107)", "rgb(234, 153, 153)", "rgb(249, 203, 156)", "rgb(255, 229, 153)", "rgb(182, 215, 168)", "rgb(162, 196, 201)", "rgb(164, 194, 244)", "rgb(159, 197, 232)", "rgb(180, 167, 214)", "rgb(213, 166, 189)"], ["rgb(204, 65, 37)", "rgb(224, 102, 102)", "rgb(246, 178, 107)", "rgb(255, 217, 102)", "rgb(147, 196, 125)", "rgb(118, 165, 175)", "rgb(109, 158, 235)", "rgb(111, 168, 220)", "rgb(142, 124, 195)", "rgb(194, 123, 160)"], ["rgb(166, 28, 0)", "rgb(204, 0, 0)", "rgb(230, 145, 56)", "rgb(241, 194, 50)", "rgb(106, 168, 79)", "rgb(69, 129, 142)", "rgb(60, 120, 216)", "rgb(61, 133, 198)", "rgb(103, 78, 167)", "rgb(166, 77, 121)"], ["rgb(91, 15, 0)", "rgb(102, 0, 0)", "rgb(120, 63, 4)", "rgb(127, 96, 0)", "rgb(39, 78, 19)", "rgb(12, 52, 61)", "rgb(28, 69, 135)", "rgb(7, 55, 99)", "rgb(32, 18, 77)", "rgb(76, 17, 48)"], ["#c1232b", "#27727b", "#fcce10", "#e87c25", "#b5c334", "#fe8463", "#9bca63", "#fad860", "#f3a43b", "#60c0dd", "#d7504b", "#c6e579", "#f4e001", "#f0805a", "#26c0c0", "#c12e34", "#e6b600", "#0098d9", "#2b821d", "#005eaa", "#339ca8", "#cda819", "#32a487", "#3fb1e3", "#6be6c1", "#626c91", "#a0a7e6", "#c4ebad", "#96dee8"]], - change: function (color) { - let $input = $(this); - if (color != null) { - color = color.toHexString(); - } - else { - color = "rgb(0, 0, 0)"; - } - - let oldcolor = null; - if(luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").length>0){ - oldcolor = luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").css("background-color"); - } - - luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").remove(); - luckysheetcurrentSheetitem.append('
'); - let index = getSheetIndex(Store.currentSheetIndex); - Store.luckysheetfile[index].color = color; - server.saveParam("all", Store.currentSheetIndex, color, { "k": "color" }); - - if (Store.clearjfundo) { - let redo = {}; - redo["type"] = "sheetColor"; - redo["sheetIndex"] = Store.currentSheetIndex; - - redo["oldcolor"] = oldcolor; - redo["color"] = color; - - Store.jfundo = []; - Store.jfredo.push(redo); - } - } - }); - - $("#luckysheetsheetconfigcolorreset").click(function () { - let oldcolor = null; - if(luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").length>0){ - oldcolor = luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").css("background-color"); - } - - luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").remove(); - let index = getSheetIndex(Store.currentSheetIndex); - Store.luckysheetfile[index].color = null; - server.saveParam("all", Store.currentSheetIndex, null, { "k": "color" } ); - - if (Store.clearjfundo) { - let redo = {}; - redo["type"] = "sheetColor"; - redo["sheetIndex"] = Store.currentSheetIndex; - - redo["oldcolor"] = oldcolor; - redo["color"] = null; - - Store.jfundo = []; - Store.jfredo.push(redo); - } - }); - } - - let index = getSheetIndex(Store.currentSheetIndex); - if (Store.luckysheetfile[index].color != null && Store.luckysheetfile[index].color.length > 0) { - $("#luckysheetsheetconfigcolorur").spectrum("set", Store.luckysheetfile[index].color); - - } - - $("#luckysheetsheetconfigcolorur").parent().find("span, div, button, input, a").addClass("luckysheet-mousedown-cancel"); - setTimeout(function(){ - mouseclickposition($("#luckysheet-rightclick-sheet-menu"), luckysheetcurrentSheetitem.offset().left + luckysheetcurrentSheetitem.width(), luckysheetcurrentSheetitem.offset().top - 18, "leftbottom"); - },1); - } - - let luckysheetsheetrightclick = function ($t, $cur, e) { - clearTimeout(jfdbclicklagTimeout); - if ($cur.hasClass("luckysheet-sheets-item-name") && $cur.attr("contenteditable") == "true") { - return; - } - if (formula.rangestart || formula.rangedrag_column_start || formula.rangedrag_row_start || formula.israngeseleciton()) { - setTimeout(function () { - formula.setCaretPosition(formula.rangeSetValueTo.get(0), 0, formula.rangeSetValueTo.text().length); - formula.createRangeHightlight(); - $("#luckysheet-input-box-index").find(".luckysheet-input-box-index-sheettxt").remove().end().prepend("" + sheetmanage.getSheetName(formula.rangetosheet) + "!").show(); - $("#luckysheet-input-box-index").css({"left": $("#luckysheet-input-box").css("left"), "top": (parseInt($("#luckysheet-input-box").css("top")) - 20) + "px", "z-index": $("#luckysheet-input-box").css("z-index")}); - }, 1); - } - else { - $("#luckysheet-input-box").removeAttr("style"); - $("#luckysheet-formula-functionrange .luckysheet-formula-functionrange-highlight").remove(); - } - - $("#luckysheet-sheet-area div.luckysheet-sheets-item").removeClass("luckysheet-sheets-item-active"); - $t.addClass("luckysheet-sheets-item-active"); - cleargridelement(e); - sheetmanage.changeSheet($t.data("index")); - - $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); - - if ($cur.hasClass("luckysheet-sheets-item-menu") || $cur.hasClass("fa-sort-desc") || e.which == "3") { - luckysheetcurrentSheetitem = $cur.closest(".luckysheet-sheets-item"); - showsheetconfigmenu(); - } - } - - $("#luckysheet-sheet-area").on("mousedown", "div.luckysheet-sheets-item", function (e) { - if(isEditMode()){ - // alert("非编辑模式下不允许该操作!"); - return; - } - - let $t = $(this), $cur = $(e.target), $item = $cur.closest(".luckysheet-sheets-item"); - - if (e.which == "3") { - luckysheetsheetrightclick($t, $cur, e); - luckysheetcurrentSheetitem = $item; - showsheetconfigmenu(); - return; - } - - if ($item.hasClass("luckysheet-sheets-item-active") && $item.find(".luckysheet-sheets-item-name").attr("contenteditable") == "false") { - jfdbclicklagTimeout = setTimeout(function () { - Store.luckysheet_sheet_move_status = true; - Store.luckysheet_sheet_move_data = {}; - Store.luckysheet_sheet_move_data.widthlist = []; - - $("#luckysheet-sheet-area div.luckysheet-sheets-item:visible").each(function (i) { - if (i == 0) { - Store.luckysheet_sheet_move_data.widthlist.push(parseInt($(this).outerWidth())); - } - else { - Store.luckysheet_sheet_move_data.widthlist.push(parseInt($(this).outerWidth()) + Store.luckysheet_sheet_move_data.widthlist[i - 1]); - } - }); - - Store.luckysheet_sheet_move_data.curindex = $("#luckysheet-sheet-area div.luckysheet-sheets-item").index($item); - let x = e.pageX; - Store.luckysheet_sheet_move_data.curleft = x - $item.offset().left; - Store.luckysheet_sheet_move_data.pageX = x; - Store.luckysheet_sheet_move_data.activeobject = $item; - Store.luckysheet_sheet_move_data.cursorobject = $cur; - let $itemclone = $item.clone().css("visibility", "hidden").attr("id", "luckysheet-sheets-item-clone"); - $item.after($itemclone); - $item.css({ "position": "absolute", "opacity": 0.8, "cursor": "move", "transition": "initial", "z-index": 10 }); - }, 200); - } - }).on("click", "div.luckysheet-sheets-item", function (e) { - if(isEditMode()){ - // alert("非编辑模式下不允许该操作!"); - return; - } - - let $t = $(this), $cur = $(e.target); - luckysheetsheetrightclick($t, $cur, e); - }); - - let luckysheetsheetnameeditor = function ($t) { - $t.attr("contenteditable", "true").addClass("luckysheet-mousedown-cancel").data("oldtxt", $t.text()); - - setTimeout(function () { - if (document.selection) { - let range = document.body.createTextRange(); - range.moveToElementText($t.get(0)); - range.select(); - } else if (window.getSelection) { - let range = document.createRange(); - range.selectNodeContents($t.get(0)); - window.getSelection().removeAllRanges(); - window.getSelection().addRange(range); - } - }, 1); - } - - $("#luckysheet-sheet-area").on("dblclick", "span.luckysheet-sheets-item-name", function (e) { - luckysheetsheetnameeditor($(this)); - }); - - $("#luckysheet-sheet-area").on("blur", "span.luckysheet-sheets-item-name", function (e) { - let $t = $(this); - let txt = $t.text(), oldtxt = $t.data("oldtxt"); - - let index = getSheetIndex(Store.currentSheetIndex); - for (let i = 0; i < Store.luckysheetfile.length; i++) { - if (index != i && Store.luckysheetfile[i].name == txt) { - if(isEditMode()){ - alert(locale_sheetconfig.tipNameRepeat); - } - else{ - tooltip.info("", locale_sheetconfig.tipNameRepeat); - } - $t.text(oldtxt).attr("contenteditable", "false"); - return; - } - } - - let winW = $(window).width(); - - let c_width = 0; - $("#luckysheet-sheet-container-c > div.luckysheet-sheets-item:visible").each(function(){ - c_width += $(this).outerWidth(); - }); - - if (c_width >= winW * 0.7) { - $("#luckysheet-sheet-area .luckysheet-sheets-scroll").css("display", "inline-block"); - $("#luckysheet-sheet-container .docs-sheet-fade-left").show(); - } - - Store.luckysheetfile[index].name = txt; - server.saveParam("all", Store.currentSheetIndex, txt, { "k": "name" }); - - $t.attr("contenteditable", "false").removeClass("luckysheet-mousedown-cancel"); - - if (Store.clearjfundo) { - let redo = {}; - redo["type"] = "sheetName"; - redo["sheetIndex"] = Store.currentSheetIndex; - - redo["oldtxt"] = oldtxt; - redo["txt"] = txt; - - Store.jfundo = []; - Store.jfredo.push(redo); - } - }); - - $("#luckysheet-sheet-area").on("keydown", "span.luckysheet-sheets-item-name", function (e) { - let kcode = e.keyCode; - let $t = $(this); - if (kcode == keycode.ENTER) { - let index = getSheetIndex(Store.currentSheetIndex); - Store.luckysheetfile[index].name = $t.text(); - $t.attr("contenteditable", "false"); - } - }); - - $("#luckysheetsheetconfigrename").click(function () { - luckysheetsheetnameeditor(luckysheetcurrentSheetitem.find("span.luckysheet-sheets-item-name")); - $("#luckysheet-input-box").removeAttr("style"); - $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); - }); - - $("#luckysheetsheetconfigshow").click(function () { - $("#luckysheet-sheets-m").click(); - $("#luckysheet-input-box").removeAttr("style"); - $("#luckysheet-rightclick-sheet-menu").hide(); - }); - - $("#luckysheetsheetconfigmoveleft").click(function () { - if (luckysheetcurrentSheetitem.preval(":visible").length > 0) { - luckysheetcurrentSheetitem.insertBefore(luckysheetcurrentSheetitem.preval(":visible").eq(0)); - sheetmanage.reOrderAllSheet(); - } - $("#luckysheet-input-box").removeAttr("style"); - $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); - }); - - $("#luckysheetsheetconfigmoveright").click(function () { - if (luckysheetcurrentSheetitem.nextAll(":visible").length > 0) { - luckysheetcurrentSheetitem.insertAfter(luckysheetcurrentSheetitem.nextAll(":visible").eq(0)); - sheetmanage.reOrderAllSheet(); - } - $("#luckysheet-input-box").removeAttr("style"); - $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); - }); - - $("#luckysheetsheetconfigdelete").click(function (e) { - $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); - - if($("#luckysheet-sheet-container-c .luckysheet-sheets-item:visible").length <= 1){ - if(isEditMode()){ - alert(locale_sheetconfig.noMoreSheet); - } - else{ - tooltip.info(locale_sheetconfig.noMoreSheet, ""); - } - - return; - } - - let index = getSheetIndex(Store.currentSheetIndex); - - tooltip.confirm(locale_sheetconfig.confirmDelete+"【" + Store.luckysheetfile[index].name + "】?", ""+locale_sheetconfig.redoDelete+"", function () { - sheetmanage.deleteSheet(luckysheetcurrentSheetitem.data("index")); - }, null); - - $("#luckysheet-input-box").removeAttr("style"); - }); - - $("#luckysheetsheetconfigcopy").click(function (e) { - sheetmanage.copySheet(luckysheetcurrentSheetitem.data("index"), e); - $("#luckysheet-input-box").removeAttr("style"); - $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); - }); - - $("#luckysheetsheetconfighide").click(function () { - if ($("#luckysheet-sheet-area div.luckysheet-sheets-item:visible").length == 1) { - if(isEditMode()){ - alert(locale_sheetconfig.noHide); - } - else{ - tooltip.info("", locale_sheetconfig.noHide); - } - return; - } - sheetmanage.setSheetHide(luckysheetcurrentSheetitem.data("index")); - $("#luckysheet-input-box").removeAttr("style"); - $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); - }); - - $("#luckysheet-sheets-add").click(function (e) { - sheetmanage.addNewSheet(e); - sheetmanage.locationSheet(); - $("#luckysheet-input-box").removeAttr("style"); - }); - - let sheetscrollani = null, sheetscrollstart = 0, sheetscrollend = 0, sheetscrollstep = 150; - $("#luckysheet-sheets-leftscroll").click(function () { - let $c = $("#luckysheet-sheet-container-c"); - sheetscrollstart = $c.scrollLeft(); - sheetscrollend = $c.scrollLeft() - sheetscrollstep; - - if (sheetscrollend <= 0) { - $("#luckysheet-sheet-container .docs-sheet-fade-left").hide(); - } - $("#luckysheet-sheet-container .docs-sheet-fade-right").show(); - - clearInterval(sheetscrollani); - sheetscrollani = setInterval(function () { - sheetscrollstart -= 4; - $c.scrollLeft(sheetscrollstart); - if (sheetscrollstart <= sheetscrollend) { - clearInterval(sheetscrollani); - } - }, 1); - }); - - $("#luckysheet-sheets-rightscroll").click(function () { - let $c = $("#luckysheet-sheet-container-c"); - sheetscrollstart = $c.scrollLeft(); - sheetscrollend = $c.scrollLeft() + sheetscrollstep; - - if (sheetscrollstart > 0) { - $("#luckysheet-sheet-container .docs-sheet-fade-right").hide(); - } - $("#luckysheet-sheet-container .docs-sheet-fade-left").show(); - - clearInterval(sheetscrollani); - sheetscrollani = setInterval(function () { - sheetscrollstart += 4; - $c.scrollLeft(sheetscrollstart); - if (sheetscrollstart >= sheetscrollend) { - clearInterval(sheetscrollani); - } - }, 1); - }); - - let initialOpenSheet = true; - $("#luckysheet-sheets-m").click(function (e) { - $("#luckysheet-sheet-list").html(""); - - let item = ""; - for (let i = 0; i < Store.luckysheetfile.length; i++) { - let f = Store.luckysheetfile[i], icon = '', style = ""; - if (f["status"] == 1) { - icon = ''; - } - - if (f["hide"] == 1) { - icon = ''; - style += "color:#BBBBBB;"; - } - - if (f["color"] != null && f["color"].length > 0) { - style += "border-right:4px solid " + f["color"] + ";"; - } - - item += replaceHtml(sheetselectlistitemHTML, { "index": f["index"], "name": f["name"], "icon": icon, "style": style }); - } - - if (initialOpenSheet) { - $("#" + Store.container).append(replaceHtml(sheetselectlistHTML, { "item": item })); - $("#luckysheet-sheet-list").on("click", ".luckysheet-cols-menuitem", function (e) { - if(isEditMode()){ - // tooltip.info("提示", "图表编辑模式下不允许该操作!"); - alert(locale_sheetconfig.chartEditNoOpt); - return; - } - - let $item = $(this), index = $item.data("index"); - - if ($item.data("index") != Store.currentSheetIndex) { - sheetmanage.setSheetShow(index); - sheetmanage.locationSheet(); - } - }); - - initialOpenSheet = false; - } - else { - $("#luckysheet-sheet-list").html(item); - } - - let $t = $("#luckysheet-sheet-list"); - - mouseclickposition($t, $(this).offset().left, $(this).offset().top - 12, "leftbottom"); - $("#luckysheet-input-box").removeAttr("style"); - }); - - //向左增加列,向上增加行 - $("#luckysheet-add-lefttop, #luckysheet-add-lefttop_t").click(function (event) { - $("#luckysheet-rightclick-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - - return; - } - - let $t = $(this), value = $t.parent().find("input").val(); - if (!isRealNum(value)) { - if(isEditMode()){ - alert(locale_info.tipInputNumber); - } - else{ - tooltip.info(locale_info.tipInputNumber, ""); - } - - return; - } - - value = parseInt(value); - - if (value < 1 || value > 100) { - if(isEditMode()){ - alert(locale_info.tipInputNumberLimit); - } - else{ - tooltip.info(locale_info.tipInputNumberLimit, ""); - } - return; - } - - let st_index = Store.luckysheet_select_save[0][Store.luckysheetRightHeadClickIs][0]; - luckysheetextendtable(Store.luckysheetRightHeadClickIs, st_index, value, "lefttop"); - }); - $("#luckysheet-addTopRows").click(function (event) { - $("#luckysheet-rightclick-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - - return; - } - - let $t = $(this), value = $t.parent().find("input").val(); - if (!isRealNum(value)) { - if(isEditMode()){ - alert(locale_info.tipInputNumber); - } - else{ - tooltip.info(locale_info.tipInputNumber, ""); - } - - return; - } - - value = parseInt(value); - - if (value < 1 || value > 100) { - if(isEditMode()){ - alert(llocale_info.tipInputNumberLimit); - } - else{ - tooltip.info(llocale_info.tipInputNumberLimit, ""); - } - return; - } - - let st_index = Store.luckysheet_select_save[0].row[0]; - luckysheetextendtable('row', st_index, value, "lefttop"); - }) - $("#luckysheet-addLeftCols").click(function (event) { - $("#luckysheet-rightclick-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - - return; - } - - let $t = $(this), value = $t.parent().find("input").val(); - if (!isRealNum(value)) { - if(isEditMode()){ - alert(locale_info.tipInputNumber); - } - else{ - tooltip.info(locale_info.tipInputNumber, ""); - } - - return; - } - - value = parseInt(value); - - if (value < 1 || value > 100) { - if(isEditMode()){ - alert(llocale_info.tipInputNumberLimit); - } - else{ - tooltip.info(llocale_info.tipInputNumberLimit, ""); - } - return; - } - - let st_index = Store.luckysheet_select_save[0].column[0]; - luckysheetextendtable('column', st_index, value, "lefttop"); - }) - - //向右增加列,向下增加行 - $("#luckysheet-add-rightbottom, #luckysheet-add-rightbottom_t").click(function (event) { - $("#luckysheet-rightclick-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - - return; - } - - let $t = $(this), value = $t.parent().find("input").val(); - if (!isRealNum(value)) { - if(isEditMode()){ - alert(locale_info.tipInputNumber); - } - else{ - tooltip.info(locale_info.tipInputNumber, ""); - } - - return; - } - - value = parseInt(value); - - if (value < 1 || value > 100) { - if(isEditMode()){ - alert(llocale_info.tipInputNumberLimit); - } - else{ - tooltip.info(llocale_info.tipInputNumberLimit, ""); - } - - return; - } - - let st_index = Store.luckysheet_select_save[0][Store.luckysheetRightHeadClickIs][1]; - luckysheetextendtable(Store.luckysheetRightHeadClickIs, st_index, value, "rightbottom"); - }); - $("#luckysheet-addBottomRows").click(function (event) { - $("#luckysheet-rightclick-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - - return; - } - - let $t = $(this), value = $t.parent().find("input").val(); - if (!isRealNum(value)) { - if(isEditMode()){ - alert(locale_info.tipInputNumber); - } - else{ - tooltip.info(locale_info.tipInputNumber, ""); - } - - return; - } - - value = parseInt(value); - - if (value < 1 || value > 100) { - if(isEditMode()){ - alert(llocale_info.tipInputNumberLimit); - } - else{ - tooltip.info(llocale_info.tipInputNumberLimit, ""); - } - - return; - } - - let st_index = Store.luckysheet_select_save[0].row[1]; - luckysheetextendtable('row', st_index, value, "rightbottom"); - }); - $("#luckysheet-addRightCols").click(function (event) { - $("#luckysheet-rightclick-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - - return; - } - - let $t = $(this), value = $t.parent().find("input").val(); - if (!isRealNum(value)) { - if(isEditMode()){ - alert(locale_info.tipInputNumber); - } - else{ - tooltip.info(locale_info.tipInputNumber, ""); - } - - return; - } - - value = parseInt(value); - - if (value < 1 || value > 100) { - if(isEditMode()){ - alert(llocale_info.tipInputNumberLimit); - } - else{ - tooltip.info(llocale_info.tipInputNumberLimit, ""); - } - - return; - } - - let st_index = Store.luckysheet_select_save[0].column[1]; - luckysheetextendtable('column', st_index, value, "rightbottom"); - }); - - //删除选中行列 - $("#luckysheet-del-selected, #luckysheet-del-selected_t").click(function (event) { - $("#luckysheet-rightclick-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(Store.luckysheetRightHeadClickIs == "row"){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - } - else if(Store.luckysheetRightHeadClickIs == "column"){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - } - return; - } - - let st_index = Store.luckysheet_select_save[0][Store.luckysheetRightHeadClickIs][0], - ed_index = Store.luckysheet_select_save[0][Store.luckysheetRightHeadClickIs][1]; - luckysheetdeletetable(Store.luckysheetRightHeadClickIs, st_index, ed_index); - }); - $("#luckysheet-delRows").click(function (event) { - $("#luckysheet-rightclick-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(Store.luckysheetRightHeadClickIs == "row"){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - } - else if(Store.luckysheetRightHeadClickIs == "column"){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - } - return; - } - - let st_index = Store.luckysheet_select_save[0].row[0], - ed_index = Store.luckysheet_select_save[0].row[1]; - luckysheetdeletetable('row', st_index, ed_index); - }) - $("#luckysheet-delCols").click(function (event) { - $("#luckysheet-rightclick-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 1){ - if(Store.luckysheetRightHeadClickIs == "row"){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - } - else if(Store.luckysheetRightHeadClickIs == "column"){ - if(isEditMode()){ - alert(locale_drag.noMulti); - } - else{ - tooltip.info(locale_drag.noMulti, ""); - } - } - return; - } - - let st_index = Store.luckysheet_select_save[0].column[0], - ed_index = Store.luckysheet_select_save[0].column[1]; - luckysheetdeletetable('column', st_index, ed_index); - }) - - //隐藏、显示行 - $("#luckysheet-hidRows").click(function (event) { - $("#luckysheet-rightclick-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - let cfg = $.extend(true, {}, Store.config); - if(cfg["rowhidden"] == null){ - cfg["rowhidden"] = {}; - } - - 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]; - - for(let r = r1; r <= r2; r++){ - cfg["rowhidden"][r] = 0; - } - } - - //保存撤销 - if(Store.clearjfundo){ - let redo = {}; - redo["type"] = "showHidRows"; - 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["rowhidden"], { "k": "rowhidden" }); - - //行高、列宽 刷新 - jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); - }) - $("#luckysheet-showHidRows").click(function (event) { - $("#luckysheet-rightclick-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - let cfg = $.extend(true, {}, Store.config); - if(cfg["rowhidden"] == null){ - return; - } - - 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]; - - for(let r = r1; r <= r2; r++){ - delete cfg["rowhidden"][r]; - } - } - - //保存撤销 - if(Store.clearjfundo){ - let redo = {}; - redo["type"] = "showHidRows"; - 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["rowhidden"], { "k": "rowhidden" }); - - //行高、列宽 刷新 - jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); - }) - - //清除单元格内容 - $("#luckysheet-delete-text").click(function(){ - $("#luckysheet-rightclick-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - if(Store.luckysheet_select_save.length > 0){ - let d = editor.deepCopyFlowData(Store.flowdata); - - let has_PartMC = false; - - 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]; - let c1 = Store.luckysheet_select_save[s].column[0], - c2 = Store.luckysheet_select_save[s].column[1]; - - if(hasPartMC(Store.config, r1, r2, c1, c2)){ - has_PartMC = true; - break; - } - } - - if(has_PartMC){ - if(isEditMode()){ - alert(locale_drag.noPartMerge); - } - else{ - tooltip.info(locale_drag.noPartMerge, ""); - } - - return; - } - - 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]; - let c1 = Store.luckysheet_select_save[s].column[0], - c2 = Store.luckysheet_select_save[s].column[1]; - - for(let r = r1; r <= r2; r++){ - for(let c = c1; c <= c2; c++){ - if(pivotTable.isPivotRange(r, c)){ - continue; - } - - if(getObjType(d[r][c]) == "object"){ - delete d[r][c]["m"]; - delete d[r][c]["v"]; - - if(d[r][c]["f"] != null){ - delete d[r][c]["f"]; - formula.delFunctionGroup(r, c, Store.currentSheetIndex); - - delete d[r][c]["spl"]; - } - } - else{ - d[r][c] = null; - } - } - } - } - - jfrefreshgrid(d, Store.luckysheet_select_save); - } - }); - - //行高列宽设置 - $("#luckysheet-rows-cols-changesize").click(function(){ - $("#luckysheet-rightclick-menu").hide(); - $("#" + Store.container).attr("tabindex", 0).focus(); - - let size = parseInt($(this).siblings("input[type='number']").val().trim()); - - if(size < 0 || size > 255){ - if(isEditMode()){ - alert(llocale_info.tipRowHeightLimit); - } - else{ - tooltip.info(llocale_info.tipRowHeightLimit, ""); - } - - return; - } - - let cfg = $.extend(true, {}, Store.config); - let type; - - if(Store.luckysheetRightHeadClickIs == "row"){ - type = "resizeR"; - - if(cfg["rowlen"] == null){ - cfg["rowlen"] = {}; - } - - for(let s = 0; s < Store.luckysheet_select_save.length; s++){ - let r1 = Store.luckysheet_select_save[s].row[0]; - let r2 = Store.luckysheet_select_save[s].row[1]; - - for(let r = r1; r <= r2; r++){ - cfg["rowlen"][r] = size; - } - } - } - else if(Store.luckysheetRightHeadClickIs == "column"){ - type = "resizeC"; - - if(cfg["columlen"] == null){ - cfg["columlen"] = {}; - } - - for(let s = 0; s < Store.luckysheet_select_save.length; s++){ - let c1 = Store.luckysheet_select_save[s].column[0]; - let c2 = Store.luckysheet_select_save[s].column[1]; - - for(let c = c1; c <= c2; c++){ - cfg["columlen"][c] = size; - } - } - } - - if (Store.clearjfundo) { - Store.jfundo = []; - Store.jfredo.push({ - "type": "resize", - "ctrlType": type, - "config": $.extend(true, {}, Store.config), - "curconfig": $.extend(true, {}, cfg), - "sheetIndex": Store.currentSheetIndex - }); - } - - //config - Store.config = cfg; - Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].config = Store.config; - - if(Store.luckysheetRightHeadClickIs == "row"){ - server.saveParam("cg", Store.currentSheetIndex, cfg["rowlen"], { "k": "rowlen" }); - jfrefreshgrid_rhcw(Store.flowdata.length, null); - } - else if(Store.luckysheetRightHeadClickIs == "column"){ - server.saveParam("cg", Store.currentSheetIndex, cfg["columlen"], { "k": "columlen" }); - jfrefreshgrid_rhcw(null, Store.flowdata[0].length); - } - }); - - //模态框拖动 - $(document).on("mousedown", "div.luckysheet-modal-dialog", function (e) { - if (!$(e.target).is(".luckysheet-modal-dialog")) { - return; - } - - Store.luckysheet_model_move_state = true; - - Store.luckysheet_model_move_obj = $(e.currentTarget); - let toffset = Store.luckysheet_model_move_obj.offset(); - Store.luckysheet_model_xy = [e.pageX - toffset.left, e.pageY - toffset.top]; - }); - - //模态框关闭 - $(document).on("click", ".luckysheet-modal-dialog-title-close, .luckysheet-model-close-btn", function (e) { - //选择文本颜色和单元格颜色弹出框取消 - if($("#textcolorselect").is(":visible")||$("#cellcolorselect").is(":visible")){ - $("#luckysheet-conditionformat-dialog").show(); - } - $(e.currentTarget).parents(".luckysheet-modal-dialog").hide(); - $("#luckysheet-modal-dialog-mask").hide(); - - //函数查找功能所有弹出框关闭和取消 - if($(this).parents(".luckysheet-modal-dialog").hasClass("luckysheet-search-formula")){ - formula.dontupdate(); - luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); - } - if($(this).parents(".luckysheet-modal-dialog").hasClass("luckysheet-search-formula-parm")){ - formula.dontupdate(); - luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); - } - if($(this).parents(".luckysheet-modal-dialog").hasClass("luckysheet-search-formula-parm-select")){ - formula.dontupdate(); - luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); - } - - $("#" + Store.container).attr("tabindex", 0).focus(); - }); - - //排序事件 - let luckysheet_sort_initial = true; - $("#luckysheetorderby").click(function () { - $("body .luckysheet-cols-menu").hide(); - const locale_sort = _locale.sort; - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_sort.noRangeError); - } - else{ - tooltip.info(locale_sort.noRangeError, ""); - } - return; - } - - let last = Store.luckysheet_select_save[0]; - let r1 = last["row"][0], r2 = last["row"][1]; - let c1 = last["column"][0], c2 = last["column"][1]; - - if (luckysheet_sort_initial) { - luckysheet_sort_initial = false; - - let content = `
${locale_sort.hasTitle}
+ ${locale_sort.addOthers}
`; - - $("body").append(replaceHtml(modelHTML, { "id": "luckysheet-sort-dialog", "addclass": "", "title": _locale.sort.sortTitle, "content": content, "botton": ``})); - - $("#luckysheet-sort-dialog .luckysheet-sort-dialog-additem").click(function () { - let last = Store.luckysheet_select_save[0]; - let r1 = last["row"][0], r2 = last["row"][1]; - let c1 = last["column"][0], c2 = last["column"][1]; - - let option = "", i = $("#luckysheet-sort-dialog table").data("itemcount") + 1; - let t = $("#luckysheet-sort-haveheader").is(':checked'); - - for (let c = c1; c <= c2; c++) { - if (t) { - let v = getcellvalue(r1, c, Store.flowdata, "m"); - - if(v == null){ - v = locale_sort.columnOperation + (c - c1 + 1); - } - - option += ''; - } - else { - option += ''; - } - } - - $("#luckysheet-sort-dialog table").append(` - - ${locale_sort.secondaryTitle} - -
-
-
- - - `); - $("#luckysheet-sort-dialog table").data("itemcount", i); - }); - - $("#luckysheet-sort-haveheader").change(function () { - let last = Store.luckysheet_select_save[0]; - let r1 = last["row"][0], r2 = last["row"][1]; - let c1 = last["column"][0], c2 = last["column"][1]; - - let t = $(this).is(':checked'); - let option = ""; - - for (let c = c1; c <= c2; c++) { - if (t) { - let v = getcellvalue(r1, c, Store.flowdata, "m"); - - if(v == null){ - v = locale_sort.columnOperation + (c - c1 + 1); - } - - option += ''; - } - else { - option += ''; - } - } - - $("#luckysheet-sort-dialog tr select").each(function () { - $(this).html(option); - }); - }); - - //Custom sort - $("#luckysheet-sort-modal-confirm").click(function () { - if(Store.luckysheet_select_save.length > 1){ - if(isEditMode()){ - alert(locale_sort.noRangeError); - } - else{ - tooltip.info(locale_sort.noRangeError, ""); - } - - return; - } - - let d = editor.deepCopyFlowData(Store.flowdata); - - let last = Store.luckysheet_select_save[0]; - let r1 = last["row"][0], r2 = last["row"][1]; - let c1 = last["column"][0], c2 = last["column"][1]; - - //Data has header row - let t = $("#luckysheet-sort-haveheader").is(':checked'); - - let str; - if(t){ - str = r1 + 1; - } - else{ - str = r1; - } - - let hasMc = false; //Whether the sort selection has merged cells - - let data = []; - - for(let r = str; r <= r2; r++){ - let data_row = []; - - for(let c = c1; c <= c2; c++){ - if(d[r][c] != null && d[r][c].mc != null){ - hasMc = true; - break; - } - - data_row.push(d[r][c]); - } - - data.push(data_row); - } - - if(hasMc){ - if(isEditMode()){ - alert(locale_sort.mergeError); - } - else{ - tooltip.info(locale_sort.mergeError, ""); - } - - return; - } - - $($("#luckysheet-sort-dialog table tr").toArray().reverse()).each(function () { - let i = $(this).find("select").val(), - asc = $(this).find('input:radio:checked').val(); - - i -= c1; - - if (asc == "asc") { - asc = true; - } - else { - asc = false; - } - - data = orderbydata([].concat(data), i, asc); - }); - - for(let r = str; r <= r2; r++){ - for(let c = c1; c <= c2; c++){ - d[r][c] = data[r - str][c - c1]; - } - } - - if(Store.config["rowlen"] != null){ - let cfg = $.extend(true, {}, Store.config); - cfg = rowlenByRange(d, str, r2, cfg); - - jfrefreshgrid(d, [{ "row": [str, r2], "column": [c1, c2] }], cfg, null, true); - } - else{ - jfrefreshgrid(d, [{ "row": [str, r2], "column": [c1, c2] }]); - } - - $("#luckysheet-sort-dialog").hide(); - $("#luckysheet-modal-dialog-mask").hide(); - }); - } - - let option = ""; - for (let c = c1; c <= c2; c++) { - option += ''; - } - - $("#luckysheet-sort-dialog select").html(option); - - $("#luckysheet-sort-dialog .luckysheet-sort-dialog-tr").remove(); - - $("#luckysheet-sort-haveheader").prop("checked", false); - $("#luckysheet-sort-dialog input:radio:first").prop("checked", "checked"); - - $("#luckysheet-sort-dialog .luckysheet-modal-dialog-title-text").html(locale_sort.sortRangeTitle+"" + chatatABC(c1) + (r1 + 1) + ""+ locale_sort.sortRangeTitleTo +"" + chatatABC(c2) + (r2 + 1) + ""); - - let $t = $("#luckysheet-sort-dialog"), myh = $t.outerHeight(), myw = $t.outerWidth(); - let winw = $(window).width(), winh = $(window).height(); - let scrollLeft = $(document).scrollLeft(), scrollTop = $(document).scrollTop(); - - $("#luckysheet-sort-dialog-tablec").css("max-height", (winh - myh) / 2); - $("#luckysheet-sort-dialog").css({ "left": (winw + scrollLeft - myw) / 2, "top": (winh + scrollTop - myh) / 2 }).show(); - $("#luckysheet-modal-dialog-mask").show(); - - if (r1 < r2) { - setTimeout(function () { - let flowrowdata1 = Store.flowdata[r1], - flowrowdata2 = Store.flowdata[r1 + 1], - hastitle = false; - - for (let i = c1; i <= c2; i++) { - let isdatatype_r1 = isdatatype(flowrowdata1[i]), - isdatatype_r2 = isdatatype(flowrowdata2[i]); - - if (isdatatype_r1 != isdatatype_r2) { - hastitle = true; - } - } - - if (hastitle) { - $("#luckysheet-sort-haveheader").prop("checked", true).change(); - } - }, 10); - } - }); - - //filter event handler - let hidefilersubmenu = null; - $("#luckysheetfilter").click(createFilter); - - $("#luckysheet-filter-menu").mouseover(function () { - clearTimeout(hidefilersubmenu); - - hidefilersubmenu = setTimeout(function () { - $("#luckysheet-filter-submenu").hide(); - }, 500); - }); - - $("#luckysheet-filter-submenu").mouseover(function () { - clearTimeout(hidefilersubmenu); - }).find(".luckysheet-cols-menuitem").click(function (e) { - $("#luckysheet-filter-selected span").html($(this).find(".luckysheet-cols-menuitem-content").text()).data("value", $(this).data("value")); - $("#luckysheet-filter-menu .luckysheet-filter-selected-input").hide(); - - let $type = $(this).data("type"); - let $value = $(this).attr("data-value"); - - if ($type == "2") { - $("#luckysheet-filter-selected span").data("type", "2"); - $("#luckysheet-filter-menu .luckysheet-filter-selected-input2").show(); - $("#luckysheet-filter-menu .luckysheet-filter-selected-input input").prop("type", "number"); - } - else if ($type == "0") { - $("#luckysheet-filter-selected span").data("type", "0"); - } - else { - $("#luckysheet-filter-selected span").data("type", "1"); - $("#luckysheet-filter-menu .luckysheet-filter-selected-input").eq(0).show(); - - //若是日期 改变input type类型为date - if($value == "dateequal" || $value == "datelessthan" || $value == "datemorethan"){ - $("#luckysheet-filter-menu .luckysheet-filter-selected-input input").prop("type", "date"); - } - else if($value == "morethan" || $value == "moreequalthan" || $value == "lessthan" || $value == "lessequalthan" || $value == "equal" || $value == "noequal"){ - $("#luckysheet-filter-menu .luckysheet-filter-selected-input input").prop("type", "number"); - } - else{ - $("#luckysheet-filter-menu .luckysheet-filter-selected-input input").prop("type", "text"); - } - } - - $("#luckysheet-filter-byvalue").next().slideUp(); - $("#luckysheet-filter-submenu").hide(); - }); - - $("#luckysheet-filter-bycondition, #luckysheet-filter-byvalue").click(function () { - let $t = $(this); - $t.next().slideToggle(200); - - setTimeout(function () { - if ($t.attr("id") == "luckysheet-filter-bycondition" && $("#luckysheet-filter-bycondition").next().is(":visible")) { - if ($("#luckysheet-filter-selected span").text() != locale_filter.filiterInputNone) { - $("#luckysheet-filter-byvalue").next().slideUp(200); - } - } - - if ($t.is($("#luckysheet-filter-bycondition"))) { - if ($("#luckysheet-filter-bycondition").next().is(":hidden") && $("#luckysheet-filter-byvalue").next().is(":hidden")) { - $("#luckysheet-filter-byvalue").next().slideDown(200); - } - } - }, 300); - }); - - $("#luckysheet-filter-selected").click(function () { - let $t = $(this), toffset = $t.offset(), $menu = $("#luckysheet-filter-submenu"); - $menu.hide(); - - let winH = $(window).height(), winW = $(window).width(); - let menuW = $menu.width(), menuH = $menu.height(); - let top = toffset.top, left = toffset.left, mheight = winH - toffset.top - 20; - - if (toffset.left + menuW > winW) { - left = toffset.left - menuW; - } - - if (toffset.top > winH / 2) { - top = winH - toffset.top; - - if (top < 0) { - top = 0; - } - - mheight = toffset.top - 20; - } - - $menu.css({ "top": top, "left": left, "height": mheight }).show(); - clearTimeout(hidefilersubmenu); - }); - - //筛选按钮点击事件 - $("#luckysheet-cell-main").on("click", ".luckysheet-filter-options", function (e) { - let $t = $(e.currentTarget), - toffset = $t.offset(), - $menu = $("#luckysheet-filter-menu"), - winH = $(window).height(), - winW = $(window).width(); - - let st_r = $t.data("str"), - ed_r = $t.data("edr"), - cindex = $t.data("cindex"), - st_c = $t.data("stc"), - ed_c = $t.data("edc"), - rowhidden = $t.data("rowhidden") == "" ? {} : JSON.parse($t.data("rowhidden").replace(/\'/g, '"')); - - $("body .luckysheet-cols-menu").hide(); - $("#luckysheet-filter-menu, #luckysheet-filter-submenu").hide(); - $("#luckysheet-filter-byvalue-input").val(""); - $("#luckysheet-filter-bycondition").next().hide(); - $("#luckysheet-filter-byvalue").next().show(); - - $menu.data("str", st_r); - $menu.data("edr", ed_r); - $menu.data("cindex", cindex); - $menu.data("stc", st_c); - $menu.data("edc", ed_c); - - $("#luckysheet-filter-menu .luckysheet-filter-selected-input").hide().find("input").val(); - $("#luckysheet-filter-selected span").data("type", "0").data("type", null).text(locale_filter.filiterInputNone); - - let byconditiontype = $t.data("byconditiontype"); - $("#luckysheet-filter-selected span").data("value", $t.data("byconditionvalue")).data("type", byconditiontype).text($t.data("byconditiontext")); - - if (byconditiontype == "2") { - let $input = $("#luckysheet-filter-menu .luckysheet-filter-selected-input2").show().find("input"); - $input.eq(0).val($t.data("byconditionvalue1")); - $input.eq(1).val($t.data("byconditionvalue2")); - } - else if (byconditiontype == "1") { - $("#luckysheet-filter-menu .luckysheet-filter-selected-input").eq(0).show().find("input").val($t.data("byconditionvalue1")); - } - - $("#luckysheet-filter-orderby-asc").off("click").on("click", function () { - orderbydatafiler(st_r, st_c, ed_r, ed_c, cindex, true); - }); - - $("#luckysheet-filter-orderby-desc").off("click").on("click", function () { - orderbydatafiler(st_r, st_c, ed_r, ed_c, cindex, false); - }); - - $("#luckysheet-filter-byvalue-select").empty().html('
'+locale_filter.filiterMoreDataTip+'
'); - - let rowhiddenother = {}; //其它筛选列的隐藏行 - $("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").not(this).each(function () { - let $t = $(this), rh = $t.data("rowhidden"); - - if (rh == "") { - return true; - } - - rh = JSON.parse(rh.replace(/\'/g, '"')); - - for (let r in rh) { - rowhiddenother[r] = 0; - } - }); - - let data = Store.flowdata; - - setTimeout(function () { - //日期值 - let dvmap = {}; - let dvmap_uncheck = {}; - - //除日期以外的值 - let vmap = {}; - let vmap_uncheck = {}; - - for (let r = st_r + 1; r <= ed_r; r++) { - if(r in rowhiddenother){ - continue; - } - - if(Store.flowdata[r] == null){ - continue; - } - - let cell = Store.flowdata[r][cindex]; - - if(cell != null && !isRealNull(cell.v) && cell.ct != null && cell.ct.t == "d" ){ //单元格是日期 - let v = update("YYYY-MM-DD", cell.v); - - let y = v.split("-")[0]; - let m = v.split("-")[1]; - let d = v.split("-")[2]; - - if(!(y in dvmap)){ - dvmap[y] = {}; - } - - if(!(m in dvmap[y])){ - dvmap[y][m] = {}; - } - - if(!(d in dvmap[y][m])){ - dvmap[y][m][d] = 0; - } - - dvmap[y][m][d]++; - - if(r in rowhidden){ - dvmap_uncheck[y] = 0; - dvmap_uncheck[m] = 0; - dvmap_uncheck[d] = 0; - } - } - else{ - let v, m; - if(cell == null || isRealNull(cell.v)){ - v = null; - m = null; - } - else{ - v = cell.v; - m = cell.m; - } - - if(!(v in vmap)){ - vmap[v] = {}; - } - - if(!(m in vmap[v])){ - vmap[v][m] = 0; - } - - vmap[v][m]++; - - if(r in rowhidden){ - vmap_uncheck[v + "#$$$#" + m] = 0; - } - } - } - - //遍历数据加到页面 - let item = []; - - if(JSON.stringify(dvmap).length > 2){ - for(let y in dvmap){ - let ysum = 0; - let monthHtml = ''; - - for(let m in dvmap[y]){ - let msum = 0; - let dayHtml = ''; - - for(let d in dvmap[y][m]){ - let dayL = dvmap[y][m][d]; - msum += dayL; - - //月 小于 10 - let mT; - if(Number(m) < 10){ - mT = "0" + Number(m); - } - else{ - mT = m; - } - - //日 小于 10 - let dT; - if(Number(d) < 10){ - dT = "0" + Number(d); - } - else{ - dT = d; - } - - //日是否选中状态 - if((y in dvmap_uncheck) && (m in dvmap_uncheck) && (d in dvmap_uncheck)){ - dayHtml += '
' + - '' + - '' + - '( ' + dayL + ' )' + - '
'; - } - else{ - dayHtml += '
' + - '' + - '' + - '( ' + dayL + ' )' + - '
'; - } - } - - ysum += msum; - - //月 小于 10 - let mT2; - if(Number(m) < 10){ - mT2 = "0" + Number(m); - } - else{ - mT2 = m; - } - - //月是否选中状态 - if((y in dvmap_uncheck) && (m in dvmap_uncheck)){ - monthHtml += '
' + - '
' + - '' + - '' + - '' + - '( ' + msum + ' )' + - '
' + - '
' + dayHtml + '
' + - '
'; - } - else{ - monthHtml += '
' + - '
' + - '' + - '' + - '' + - '( ' + msum + ' )' + - '
' + - '
' + dayHtml + '
' + - '
'; - } - } - - //年是否选中状态 - let yearHtml; - if(y in dvmap_uncheck){ - yearHtml = '
' + - '
' + - '' + - '' + - '' + - '( ' + ysum + ' )' + - '
' + - '
' + monthHtml + '
' + - '
'; - } - else{ - yearHtml = '
' + - '
' + - '' + - '' + - '' + - '( ' + ysum + ' )' + - '
' + - '
' + monthHtml + '
' + - '
'; - } - - item.unshift(yearHtml); - } - } - - if(JSON.stringify(vmap).length > 2){ - let vmapKeys = Object.keys(vmap); - vmapKeys = orderbydata1D(vmapKeys, true); - - for(let i = 0; i < vmapKeys.length; i++){ - let v = vmapKeys[i]; - - for(let x in vmap[v]){ - let text; - if((v + "#$$$#" + x) == "null#$$$#null"){ - text = "(空白)"; - } - else{ - text = x; - } - - //是否选中状态 - let dataHtml; - if((v + "#$$$#" + x) in vmap_uncheck){ - dataHtml = '
' + - '' + - '' + - '( ' + vmap[v][x] + ' )' + - '
'; - } - else{ - dataHtml = '
' + - '' + - '' + - '( ' + vmap[v][x] + ' )' + - '
'; - } - - item.push(dataHtml); - } - } - } - - $("#luckysheet-filter-byvalue-select").html("
" + item.join("") + "
"); - }, 1); - - showrightclickmenu($menu, toffset.left, toffset.top + 20); - - e.stopPropagation(); - return false; - }); - - //按颜色筛选 - $("#luckysheet-filter-orderby-color").hover( - function(){ - //遍历筛选列颜色 - let $menu = $("#luckysheet-filter-menu"); - let st_r = $menu.data("str"), - ed_r = $menu.data("edr"), - cindex = $menu.data("cindex"), - st_c = $menu.data("stc"), - ed_c = $menu.data("edc"); - let bgMap = {}; //单元格颜色 - let fcMap = {}; //字体颜色 - - let af_compute = alternateformat.getComputeMap(); - let cf_compute = conditionformat.getComputeMap(); - - for (let r = st_r + 1; r <= ed_r; r++) { - let cell = Store.flowdata[r][cindex]; - - //单元格颜色 - let bg = menuButton.checkstatus(Store.flowdata, r, cindex , "bg"); - - let checksAF = alternateformat.checksAF(r, cindex, af_compute); - if(checksAF != null){//若单元格有交替颜色 - bg = checksAF[1]; - } - - let checksCF = conditionformat.checksCF(r, cindex, cf_compute); - if(checksCF != null && checksCF["cellColor"] != null){//若单元格有条件格式 - bg = checksCF["cellColor"]; - } - - if(bg.indexOf("rgb") > -1){ - bg = rgbTohex(bg); - } - - if(bg.length == 4){ - bg = bg.substr(0, 1) + bg.substr(1, 1).repeat(2) + bg.substr(2, 1).repeat(2) + bg.substr(3, 1).repeat(2); - } - - //字体颜色 - let fc = menuButton.checkstatus(Store.flowdata, r, cindex , "fc"); - - if(checksAF != null){//若单元格有交替颜色 - fc = checksAF[0]; - } - - if(checksCF != null && checksCF["textColor"] != null){//若单元格有条件格式 - fc = checksCF["textColor"]; - } - - if(fc.indexOf("rgb") > -1){ - fc = rgbTohex(fc); - } - - if(fc.length == 4){ - fc = fc.substr(0, 1) + fc.substr(1, 1).repeat(2) + fc.substr(2, 1).repeat(2) + fc.substr(3, 1).repeat(2); - } - - if(Store.config != null && Store.config["rowhidden"] != null && r in Store.config["rowhidden"]){ - bgMap[bg] = 1; - - if(cell != null && !isRealNull(cell.v)){ - fcMap[fc] = 1; - } - } - else{ - bgMap[bg] = 0; - - if(cell != null && !isRealNull(cell.v)){ - fcMap[fc] = 0; - } - } - } - // - let filterBgColorHtml = ''; - if(JSON.stringify(bgMap).length > 2 && Object.keys(bgMap).length > 1){ - let bgColorItemHtml = ''; - for(let b in bgMap){ - if(bgMap[b] == 0){ - bgColorItemHtml += '
'; - } - else{ - bgColorItemHtml += '
'; - } - } - filterBgColorHtml = '
'+locale_filter.filiterByColorTip+'
' + bgColorItemHtml + '
'; - } - - let filterFcColorHtml = ''; - if(JSON.stringify(fcMap).length > 2 && Object.keys(fcMap).length > 1){ - let fcColorItemHtml = ''; - for(let f in fcMap){ - if(fcMap[f] == 0){ - fcColorItemHtml += '
'; - } - else{ - fcColorItemHtml += '
'; - } - } - filterFcColorHtml = '
'+locale_filter.filiterByTextColorTip+'
' + fcColorItemHtml + '
'; - } - // - let content; - if(filterBgColorHtml == '' && filterFcColorHtml == ''){ - content = '
'+locale_filter.filterContainerOneColorTip+'
'; - } - else{ - content = filterBgColorHtml + filterFcColorHtml + '
'; - } - //颜色筛选子菜单 - $("#luckysheet-filter-orderby-color-submenu").remove(); - $("body").append('
'+content+'
'); - let $t = $("#luckysheet-filter-orderby-color-submenu").end(); - let $con = $(this).parent(); - let winW = $(window).width(), winH = $(window).height(); - let menuW = $con.width(), - myh = $t.height() + 25, - myw = $t.width() + 5; - let offset = $(this).offset(); - let top = offset.top, left = offset.left + menuW; - - if (left + myw > winW) { - left = offset.left - myw; - } - - if (top + myh > winH) { - top = winH - myh; - } - - $("#luckysheet-filter-orderby-color-submenu").css({ "top": top, "left": left }).show(); - }, - function(){ - submenuhide = setTimeout(function () { $("#luckysheet-filter-orderby-color-submenu").hide(); }, 200); - } - ); - - $(document).on("mouseover mouseleave", "#luckysheet-filter-orderby-color-submenu", function(e){ - if (e.type === "mouseover") { - clearTimeout(submenuhide); - } - else { - $(this).hide(); - } - }); - $(document).on("click", "#luckysheet-filter-orderby-color-submenu .item label", function(){ - $(this).siblings("input[type='checkbox']").click(); - }); - $(document).off("click.orderbyColorConfirm").on("click.orderbyColorConfirm", "#luckysheet-filter-orderby-color-submenu #luckysheet-filter-orderby-color-confirm", function(){ - let bg_colorMap = {}; - let fc_colorMap = {}; - - $("#luckysheet-filter-orderby-color-submenu .item").each(function(i, e){ - if($(e).find("input[type='checkbox']").is(":checked")){ - let color = $(this).find("label").attr("title"); - let $id = $(this).closest(".box").attr("id"); - - if($id == "filterBgColor"){ - bg_colorMap[color] = 0; - } - else if($id == "filterFcColor"){ - fc_colorMap[color] = 0; - } - } - }); - - let bg_filter; - if($("#luckysheet-filter-orderby-color-submenu #filterBgColor").length > 0){ - bg_filter = true; - } - else{ - bg_filter = false; - } - - let fc_filter; - if($("#luckysheet-filter-orderby-color-submenu #filterFcColor").length > 0){ - fc_filter = true; - } - else{ - fc_filter = false; - } - - let $menu = $("#luckysheet-filter-menu"); - let st_r = $menu.data("str"), - ed_r = $menu.data("edr"), - cindex = $menu.data("cindex"), - st_c = $menu.data("stc"), - ed_c = $menu.data("edc"); - - let rowhiddenother = {}; //其它筛选列的隐藏行 - $("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").not($("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").eq(cindex - st_c).get(0)).each(function () { - let $t = $(this), rh = $t.data("rowhidden"); - - if (rh == "") { - return true; - } - - rh = JSON.parse(rh); - - for (let r in rh) { - rowhiddenother[r] = 0; - } - }); - - let filterdata = {}; - let rowhidden = {}; - let caljs = {}; - - let af_compute = alternateformat.getComputeMap(); - let cf_compute = conditionformat.getComputeMap(); - - for (let r = st_r + 1; r <= ed_r; r++) { - if(r in rowhiddenother){ - continue; - } - - if(Store.flowdata[r] == null){ - continue; - } - - let cell = Store.flowdata[r][cindex]; - - //单元格颜色 - let bg = menuButton.checkstatus(Store.flowdata, r, cindex , "bg"); - - let checksAF = alternateformat.checksAF(r, cindex, af_compute); - if(checksAF != null){//若单元格有交替颜色 - bg = checksAF[1]; - } - - let checksCF = conditionformat.checksCF(r, cindex, cf_compute); - if(checksCF != null && checksCF["cellColor"] != null){//若单元格有条件格式 - bg = checksCF["cellColor"]; - } - - if(bg.indexOf("rgb") > -1){ - bg = rgbTohex(bg); - } - - if(bg.length == 4){ - bg = bg.substr(0, 1) + bg.substr(1, 1).repeat(2) + bg.substr(2, 1).repeat(2) + bg.substr(3, 1).repeat(2); - } - - //文本颜色 - let fc = menuButton.checkstatus(Store.flowdata, r, cindex , "fc"); - - if(checksAF != null){//若单元格有交替颜色 - fc = checksAF[0]; - } - - if(checksCF != null && checksCF["textColor"] != null){//若单元格有条件格式 - fc = checksCF["textColor"]; - } - - if(fc.indexOf("rgb") > -1){ - fc = rgbTohex(fc); - } - - if(fc.length == 4){ - fc = fc.substr(0, 1) + fc.substr(1, 1).repeat(2) + fc.substr(2, 1).repeat(2) + fc.substr(3, 1).repeat(2); - } - - if(bg_filter && fc_filter){ - if(!(bg in bg_colorMap) && (!(fc in fc_colorMap) || cell == null || isRealNull(cell.v))){ - rowhidden[r] = 0; - } - } - else if(bg_filter){ - if(!(bg in bg_colorMap)){ - rowhidden[r] = 0; - } - } - else if(fc_filter){ - if(!(fc in fc_colorMap) || cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - } - } - - let $top = $("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").eq(cindex - st_c); - - let optionstate = Object.keys(rowhidden).length > 0; - - let rowhiddenall = $.extend(true, rowhiddenother, rowhidden), - rowhidenPre = json.parseJsonParm($top.data("rowhidden")); - - labelFilterOptionState($top, optionstate, rowhidden, caljs, true, st_r, ed_r, cindex, st_c, ed_c); - - let cfg = $.extend(true, {}, Store.config); - cfg["rowhidden"] = rowhiddenall; - - //保存撤销 - if(Store.clearjfundo){ - let redo = {}; - redo["type"] = "datachangeAll_filter"; - redo["sheetIndex"] = Store.currentSheetIndex; - - redo["config"] = $.extend(true, {}, Store.config); - redo["curconfig"] = cfg; - - redo["optionstate"] = optionstate; - redo["optionsindex"] = cindex - st_c; - - redo["rowhidden"] = $.extend(true, {}, rowhidden); - redo["rowhidenPre"] = $.extend(true, {}, rowhidenPre); - - if (caljs != null) { - redo["caljs"] = caljs; - } - - Store.jfundo = []; - Store.jfredo.push(redo); - } - - //config - Store.config = cfg; - Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].config = Store.config; - - server.saveParam("cg", Store.currentSheetIndex, cfg["rowhidden"], { "k": "rowhidden" }); - - //行高、列宽 刷新 - jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); - - $("#luckysheet-filter-menu, #luckysheet-filter-submenu, #luckysheet-filter-orderby-color-submenu").hide(); - cleargridelement(); - }); - - //点击复选框 - $(document).off("click.filterCheckbox1").on("click.filterCheckbox1", "#luckysheet-filter-byvalue-select .textBox",function(){ - if($(this).attr("data-check") == "true"){ - $(this).attr("data-check", "false"); - $(this).find("input[type='checkbox']").removeAttr("checked"); - } - else{ - $(this).attr("data-check", "true"); - $(this).find("input[type='checkbox']").prop("checked", true); - } - }) - $(document).off("click.filterCheckbox2").on("click.filterCheckbox2", "#luckysheet-filter-byvalue-select .year",function(){ - if($(this).attr("data-check") == "true"){ - $(this).attr("data-check", "false"); - $(this).parents(".yearBox").find(".month").attr("data-check", "false"); - $(this).parents(".yearBox").find(".day").attr("data-check", "false"); - $(this).parents(".yearBox").find("input[type='checkbox']").removeAttr("checked"); - } - else{ - $(this).attr("data-check", "true"); - $(this).parents(".yearBox").find(".month").attr("data-check", "true"); - $(this).parents(".yearBox").find(".day").attr("data-check", "true"); - $(this).parents(".yearBox").find("input[type='checkbox']").prop("checked", true); - } - }) - $(document).off("click.filterCheckbox3").on("click.filterCheckbox3", "#luckysheet-filter-byvalue-select .month",function(){ - //月份 对应的 天 - if($(this).attr("data-check") == "true"){ - $(this).attr("data-check", "false"); - $(this).parents(".monthBox").find(".day").attr("data-check", "false"); - $(this).parents(".monthBox").find("input[type='checkbox']").removeAttr("checked"); - } - else{ - $(this).attr("data-check", "true"); - $(this).parents(".monthBox").find(".day").attr("data-check", "true"); - $(this).parents(".monthBox").find("input[type='checkbox']").prop("checked", true); - } - //月份 对应的 年份 - let yearDayAllCheck = true; - let $yearDay = $(this).parents(".yearBox").find(".day"); - $yearDay.each(function(i,e){ - if($(e).attr("data-check") == "true"){ - - } - else{ - yearDayAllCheck = false; - } - }); - if(yearDayAllCheck){ - $(this).parents(".yearBox").find(".year").attr("data-check", "true"); - $(this).parents(".yearBox").find(".year input[type='checkbox']").prop("checked", true); - } - else{ - $(this).parents(".yearBox").find(".year").attr("data-check", "false"); - $(this).parents(".yearBox").find(".year input[type='checkbox']").removeAttr("checked"); - } - }) - $(document).off("click.filterCheckbox4").on("click.filterCheckbox4", "#luckysheet-filter-byvalue-select .day",function(){ - if($(this).attr("data-check") == "true"){ - $(this).attr("data-check", "false"); - $(this).find("input[type='checkbox']").removeAttr("checked"); - } - else{ - $(this).attr("data-check", "true"); - $(this).find("input[type='checkbox']").prop("checked", true); - } - //天 对应的 月份 - let monthDayAllCheck = true; - let $monthDay = $(this).parents(".monthBox").find(".day"); - $monthDay.each(function(i,e){ - if($(e).attr("data-check") == "true"){ - - } - else{ - monthDayAllCheck = false; - } - }); - if(monthDayAllCheck){ - $(this).parents(".monthBox").find(".month").attr("data-check", "true"); - $(this).parents(".monthBox").find(".month input[type='checkbox']").prop("checked", true); - } - else{ - $(this).parents(".monthBox").find(".month").attr("data-check", "false"); - $(this).parents(".monthBox").find(".month input[type='checkbox']").removeAttr("checked"); - } - //天 对应的 年份 - let yearDayAllCheck = true; - let $yearDay = $(this).parents(".yearBox").find(".day"); - $yearDay.each(function(i,e){ - if($(e).attr("data-check") == "true"){ - - } - else{ - yearDayAllCheck = false; - } - }); - if(yearDayAllCheck){ - $(this).parents(".yearBox").find(".year").attr("data-check", "true"); - $(this).parents(".yearBox").find(".year input[type='checkbox']").prop("checked", true); - } - else{ - $(this).parents(".yearBox").find(".year").attr("data-check", "false"); - $(this).parents(".yearBox").find(".year input[type='checkbox']").removeAttr("checked"); - } - }) - - //日期 三级下拉显示 - $(document).off("click.filterYearDropdown").on("click.filterYearDropdown", "#luckysheet-filter-byvalue-select .yearBox .fa-caret-right",function(event){ - let $p = $(this).parents(".luckysheet-mousedown-cancel"); - if($p.hasClass("year")){ - $(this).parents(".yearBox").find(".monthList").slideToggle(); - } - if($p.hasClass("month")){ - $(this).parents(".monthBox").find(".dayList").slideToggle(); - } - - event.stopPropagation(); - }); - - //全选 - $("#luckysheet-filter-byvalue-btn-all").click(function () { - $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']").prop("checked", true); - $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']").parents(".luckysheet-mousedown-cancel").attr("data-check", "true"); - }); - - //清除 - $("#luckysheet-filter-byvalue-btn-clear").click(function () { - $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']").removeAttr("checked"); - $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']").parents(".luckysheet-mousedown-cancel").attr("data-check", "false"); - }); - - //反选 - $("#luckysheet-filter-byvalue-btn-contra").click(function () { - let $input = $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']"); - $input.each(function(i, e){ - if($(e).is(":checked")){ - $(e).removeAttr("checked"); - $(e).parents(".luckysheet-mousedown-cancel").attr("data-check", "false"); - } - else{ - $(e).prop("checked", true); - $(e).parents(".luckysheet-mousedown-cancel").attr("data-check", "true"); - } - }); - //天 对应的 月份 - let $month = $("#luckysheet-filter-byvalue-select .ListBox .monthBox"); - $month.each(function(index, event){ - let monthDayAllCheck = true; - let $monthDay = $(event).find(".day input[type='checkbox']"); - $monthDay.each(function(i,e){ - if($(e).is(":checked")){ - - } - else{ - monthDayAllCheck = false; - } - }); - if(monthDayAllCheck){ - $(event).find(".month input[type='checkbox']").prop("checked", true); - $(event).attr("data-check", "true"); - } - else{ - $(event).find(".month input[type='checkbox']").removeAttr("checked"); - $(event).attr("data-check", "false"); - } - }); - //天 对应的 年份 - let $year = $("#luckysheet-filter-byvalue-select .ListBox .yearBox"); - $year.each(function(index, event){ - let yearDayAllCheck = true; - let $yearDay = $(event).find(".day input[type='checkbox']"); - $yearDay.each(function(i,e){ - if($(e).is(":checked")){ - - } - else{ - yearDayAllCheck = false; - } - }); - if(yearDayAllCheck){ - $(event).find(".year input[type='checkbox']").prop("checked", true); - $(event).attr("data-check", "true"); - } - else{ - $(event).find(".year input[type='checkbox']").removeAttr("checked"); - $(event).attr("data-check", "false"); - } - }); - }); - - //清除筛选 - $("#luckysheet-filter-initial").click(function () { - $("#luckysheet-filter-menu .luckysheet-filter-selected-input").hide().find("input").val(); - $("#luckysheet-filter-selected span").data("type", "0").data("type", null).text(locale_filter.conditionNone); - - $('#luckysheet-filter-selected-sheet' + Store.currentSheetIndex + ', #luckysheet-filter-options-sheet' + Store.currentSheetIndex).remove(); - $("#luckysheet-filter-menu, #luckysheet-filter-submenu").hide(); - - let redo = {}; - redo["type"] = "datachangeAll_filter_clear"; - redo["sheetIndex"] = Store.currentSheetIndex; - - redo["config"] = $.extend(true, {}, Store.config); - Store.config["rowhidden"] = {}; - redo["curconfig"] = $.extend(true, {}, Store.config); - - redo["filter_save"] = $.extend(true, {}, Store.luckysheet_filter_save); - - let optiongroups = []; - $("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").each(function () { - let $t = $(this); - - let optionstate = $t.hasClass("luckysheet-filter-options-active"); - let rowhidden = json.parseJsonParm($t.data("rowhidden")); - let caljs = json.parseJsonParm($t.data("caljs")); - - optiongroups.push({ - "optionstate":optionstate, - "rowhidden": rowhidden, - "caljs":caljs, - "str": $t.data("str"), - "edr": $t.data("edr"), - "cindex": $t.data("cindex"), - "stc": $t.data("stc"), - "edc": $t.data("edc") - }); - }); - redo["optiongroups"] = optiongroups; - - Store.jfundo = []; - Store.jfredo.push(redo); - - //清除筛选发送给后台 - Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].filter = null; - Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].filter_select = null; - - server.saveParam("fsc", Store.currentSheetIndex, null); - - //config - Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].config = Store.config; - - server.saveParam("cg", Store.currentSheetIndex, {}, { "k": "rowhidden" }); - - //行高、列宽 刷新 - jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); - }); - - //按照值进行筛选 - $("#luckysheet-filter-byvalue-input").on('input propertychange', function () { - let v = $(this).val().toString(); - $("#luckysheet-filter-byvalue-select .ListBox .luckysheet-mousedown-cancel").show(); - - if(v != ""){ - $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']").each(function(i, e){ - if($(e).closest(".day").length > 0){ - let day = $(e).siblings("label").text().toString(); - let month = $(e).closest(".monthBox").find(".month label").text().toString(); - let year = $(e).closest(".yearBox").find(".year label").text().toString(); - let itemV = year + "-" + month + "-" + day; - - if(itemV.indexOf(v) == -1){ - $(e).closest(".day").hide(); - - //天 对应的 月份 - let $monthDay = $(e).closest(".dayList").find(".day:visible"); - if($monthDay.length == 0){ - $(e).closest(".monthBox").find(".month").hide(); - } - - //天 对应的 年份 - let $yearDay = $(e).closest(".monthList").find(".day:visible"); - if($yearDay.length == 0){ - $(e).closest(".yearBox").find(".year").hide(); - } - } - } - - if($(e).closest(".textBox").length > 0){ - let itemV = $(e).siblings("label").text().toString(); - - if(itemV.indexOf(v) == -1){ - $(e).parents(".textBox").hide(); - } - } - }); - } - }); - - //筛选取消 - $("#luckysheet-filter-cancel").click(function () { - $("#luckysheet-filter-menu, #luckysheet-filter-submenu").hide(); - }); - - //筛选 确认 - $("#luckysheet-filter-confirm").click(function () { - let $menu = $("#luckysheet-filter-menu"); - let st_r = $menu.data("str"), - ed_r = $menu.data("edr"), - cindex = $menu.data("cindex"), - st_c = $menu.data("stc"), - ed_c = $menu.data("edc"); - - let rowhiddenother = {}; //其它筛选列的隐藏行 - $("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").not($("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").eq(cindex - st_c).get(0)).each(function () { - let $t = $(this), rh = $t.data("rowhidden"); - - if (rh == "") { - return true; - } - - rh = JSON.parse(rh.replace(/\'/g, '"')); - - for (let r in rh) { - rowhiddenother[r] = 0; - } - }); - - let filterdata = {}; - let rowhidden = {}; - let caljs = {}; - - if ($("#luckysheet-filter-bycondition").next().is(":visible") && $("#luckysheet-filter-byvalue").next().is(":hidden") && $("#luckysheet-filter-selected span").data("value") != "null") { - let $t = $("#luckysheet-filter-selected span"); - let type = $t.data("type"), value = $t.data("value"); - - caljs["value"] = value; - caljs["text"] = $t.text(); - - if (type == "0") { - caljs["type"] = "0"; - } - else if (type == "2") { - let $input = $("#luckysheet-filter-menu .luckysheet-filter-selected-input2 input"); - caljs["type"] = "2"; - caljs["value1"] = $input.eq(0).val(); - caljs["value2"] = $input.eq(1).val(); - } - else { - caljs["type"] = "1"; - caljs["value1"] = $("#luckysheet-filter-menu .luckysheet-filter-selected-input").eq(0).find("input").val(); - } - - for (let r = st_r + 1; r <= ed_r; r++) { - if(r in rowhiddenother){ - continue; - } - - if(Store.flowdata[r] == null){ - continue; - } - - let cell = Store.flowdata[r][cindex]; - - if (value == "cellnull") { //单元格为空 - if(cell != null && !isRealNull(cell.v)){ - rowhidden[r] = 0; - } - } - else if (value == "cellnonull") { //单元格有数据 - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - } - else if (value == "textinclude") { //文本包含 - let value1 = caljs["value1"]; - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else{ - if(cell.m.indexOf(value1) == -1){ - rowhidden[r] = 0; - } - } - } - else if (value == "textnotinclude") { //文本不包含 - let value1 = caljs["value1"]; - - if(cell == null || isRealNull(cell.v)){ - - } - else{ - if(cell.m.indexOf(value1) > -1){ - rowhidden[r] = 0; - } - } - } - else if (value == "textstart") { //文本开头为 - let value1 = caljs["value1"], valuelen = value1.length; - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else{ - if(cell.m.substr(0, valuelen) != value1){ - rowhidden[r] = 0; - } - } - } - else if (value == "textend") { //文本结尾为 - let value1 = caljs["value1"], valuelen = value1.length; - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else{ - if(valuelen > cell.m.length || cell.m.substr(cell.m.length - valuelen, valuelen) != value1){ - rowhidden[r] = 0; - } - } - } - else if (value == "textequal") { //文本等于 - let value1 = caljs["value1"]; - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else{ - if(cell.m != value1){ - rowhidden[r] = 0; - } - } - } - else if (value == "dateequal") { //日期等于 - let value1 = genarate(caljs["value1"])[2]; - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else if(cell.ct != null && cell.ct.t == "d"){ - if(parseInt(cell.v) != value1){ - rowhidden[r] = 0; - } - } - else{ - rowhidden[r] = 0; - } - } - else if (value == "datelessthan") { //日期早于 - let value1 = genarate(caljs["value1"])[2]; - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else if(cell.ct != null && cell.ct.t == "d"){ - if(parseInt(cell.v) >= value1){ - rowhidden[r] = 0; - } - } - else{ - rowhidden[r] = 0; - } - } - else if (value == "datemorethan") { //日期晚于 - let value1 = genarate(caljs["value1"])[2]; - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else if(cell.ct != null && cell.ct.t == "d"){ - if(parseInt(cell.v) <= value1){ - rowhidden[r] = 0; - } - } - else{ - rowhidden[r] = 0; - } - } - else if (value == "morethan") { //大于 - let value1 = parseFloat(caljs["value1"]); - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else if(cell.ct != null && cell.ct.t == "n"){ - if(cell.v <= value1){ - rowhidden[r] = 0; - } - } - else{ - rowhidden[r] = 0; - } - } - else if (value == "moreequalthan") { //大于等于 - let value1 = parseFloat(caljs["value1"]); - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else if(cell.ct != null && cell.ct.t == "n"){ - if(cell.v < value1){ - rowhidden[r] = 0; - } - } - else{ - rowhidden[r] = 0; - } - } - else if (value == "lessthan") { //小于 - let value1 = parseFloat(caljs["value1"]); - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else if(cell.ct != null && cell.ct.t == "n"){ - if(cell.v >= value1){ - rowhidden[r] = 0; - } - } - else{ - rowhidden[r] = 0; - } - } - else if (value == "lessequalthan") { //小于等于 - let value1 = parseFloat(caljs["value1"]); - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else if(cell.ct != null && cell.ct.t == "n"){ - if(cell.v > value1){ - rowhidden[r] = 0; - } - } - else{ - rowhidden[r] = 0; - } - } - else if (value == "equal") { //等于 - let value1 = parseFloat(caljs["value1"]); - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else if(cell.ct != null && cell.ct.t == "n"){ - if(cell.v != value1){ - rowhidden[r] = 0; - } - } - else{ - rowhidden[r] = 0; - } - } - else if (value == "noequal") { //不等于 - let value1 = parseFloat(caljs["value1"]); - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else if(cell.ct != null && cell.ct.t == "n"){ - if(cell.v == value1){ - rowhidden[r] = 0; - } - } - else{ - rowhidden[r] = 0; - } - } - else if (value == "include") { //介于 - let value1 = parseFloat(caljs["value1"]), value2 = parseFloat(caljs["value2"]); - - let min, max; - if(value1 < value2){ - min = value1; - max = value2; - } - else{ - max = value1; - min = value2; - } - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else if(cell.ct != null && cell.ct.t == "n"){ - if(cell.v < min || cell.v > max){ - rowhidden[r] = 0; - } - } - else{ - rowhidden[r] = 0; - } - } - else if (value == "noinclude") { //不在其中 - let value1 = parseFloat(caljs["value1"]), value2 = parseFloat(caljs["value2"]); - - let min, max; - if(value1 < value2){ - min = value1; - max = value2; - } - else{ - max = value1; - min = value2; - } - - if(cell == null || isRealNull(cell.v)){ - rowhidden[r] = 0; - } - else if(cell.ct != null && cell.ct.t == "n"){ - if(cell.v >= min && cell.v <= max){ - rowhidden[r] = 0; - } - } - else{ - rowhidden[r] = 0; - } - } - } - } - else { - $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']").each(function(i, e){ - if($(e).is(":visible") && $(e).is(":checked")){ - return true; - } - - if($(e).closest(".day").length > 0){ - let day = $(e).siblings("label").text(); - if(Number(day) < 10){ - day = "0" + Number(day); - } - - let month = $(e).closest(".monthBox").find(".month label").text().replace(locale_filter.filiterMonthText, ""); - if(Number(month) < 10){ - month = "0" + Number(month); - } - - let year = $(e).closest(".yearBox").find(".year label").text().replace(locale_filter.filiterYearText, ""); - - let itemV = locale_filter.filterDateFormatTip +"#$$$#" + year + "-" + month + "-" + day; - - filterdata[itemV] = "1"; - } - - if($(e).closest(".textBox").length > 0){ - let itemV = $(e).closest(".textBox").data("filter"); - - filterdata[itemV] = "1"; - } - }); - - for (let r = st_r + 1; r <= ed_r; r++) { - if(r in rowhiddenother){ - continue; - } - - if(Store.flowdata[r] == null){ - continue; - } - - let cell = Store.flowdata[r][cindex]; - - let value; - if(cell == null || isRealNull(cell.v)){ - value = "null#$$$#null"; - } - else if(cell.ct != null && cell.ct.t == "d"){ - let fmt = update("YYYY-MM-DD", cell.v); - value = locale_filter.filterDateFormatTip +"#$$$#" + fmt; - } - else{ - value = cell.v + "#$$$#" + cell.m; - } - - if(value in filterdata){ - rowhidden[r] = 0; - } - } - } - - let $top = $("#luckysheet-filter-options-sheet" + Store.currentSheetIndex + " .luckysheet-filter-options").eq(cindex - st_c); - - let optionstate = $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']:visible:checked").length < $("#luckysheet-filter-byvalue-select .ListBox input[type='checkbox']:visible").length || $("#luckysheet-filter-byvalue-input").val().length > 0 || ($("#luckysheet-filter-bycondition").next().is(":visible") && $("#luckysheet-filter-byvalue").next().is(":hidden") && $("#luckysheet-filter-selected span").data("value") != "null"); - - let rowhiddenall = $.extend(true, rowhiddenother, rowhidden), - rowhidenPre = json.parseJsonParm($top.data("rowhidden")); - - labelFilterOptionState($top, optionstate, rowhidden, caljs, true, st_r, ed_r, cindex, st_c, ed_c); - - let cfg = $.extend(true, {}, Store.config); - cfg["rowhidden"] = rowhiddenall; - - //保存撤销 - if(Store.clearjfundo){ - let redo = {}; - redo["type"] = "datachangeAll_filter"; - redo["sheetIndex"] = Store.currentSheetIndex; - - redo["config"] = $.extend(true, {}, Store.config); - redo["curconfig"] = cfg; - - redo["optionstate"] = optionstate; - redo["optionsindex"] = cindex - st_c; - - redo["rowhidden"] = $.extend(true, {}, rowhidden); - redo["rowhidenPre"] = $.extend(true, {}, rowhidenPre); - - if (caljs != null) { - redo["caljs"] = caljs; - } - - Store.jfundo = []; - Store.jfredo.push(redo); - } - - //config - Store.config = cfg; - Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].config = Store.config; - - server.saveParam("cg", Store.currentSheetIndex, cfg["rowhidden"], { "k": "rowhidden" }); - - //行高、列宽 刷新 - jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); - - $("#luckysheet-filter-menu, #luckysheet-filter-submenu").hide(); - cleargridelement(); - }); - - //左上角返回按钮 - $("#luckysheet_info_detail_title").click(function(){ - window.open(luckysheetConfigsetting.myFolderUrl, "_self"); - }); - - $("#luckysheet_info_detail_input").val(server.title).css("width", getByteLen(server.title) * 10).keydown(function(){ - let ctrlKey = event.ctrlKey; - let altKey = event.altKey; - let shiftKey = event.shiftKey; - let kcode = event.keyCode; - let $t = $(this); - if(kcode == keycode.ENTER){ - $t.blur().change(); - } - }).bind('input propertychange', function() { - let $t = $(this); - let inputlen = getByteLen($t.val())*10; - let updatelen = $("#luckysheet_info_detail_update").outerWidth(); - let savelen = $("#luckysheet_info_detail_save").outerWidth(); - let userlen = $("#luckysheet_info_detail_user").parent().outerWidth()+60; - let containerlen = $("#" + Store.container).outerWidth(); - let otherlen = 100; - - let minuslen = containerlen- savelen - updatelen - userlen - otherlen; - if(inputlen > minuslen){ - $("#luckysheet_info_detail_input").css("width", minuslen); - } - else{ - $("#luckysheet_info_detail_input").css("width", inputlen); - } - }).change(function(){ - server.saveParam("na", null, $(this).val()); - }); - - //公式栏处理 - $("#luckysheet-functionbox-cell").focus(function () { - if(isEditMode()){//此模式下禁用公式栏 - return; - } - - if(Store.luckysheet_select_save.length > 0){ - let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]; - - let row_index = last["row_focus"], col_index = last["column_focus"]; - let row = Store.visibledatarow[row_index], - row_pre = row_index - 1 == -1 ? 0 : Store.visibledatarow[row_index - 1]; - let col = Store.visibledatacolumn[col_index], - col_pre = col_index - 1 == -1 ? 0 : Store.visibledatacolumn[col_index - 1]; - - let margeset = menuButton.mergeborer(Store.flowdata, row_index, col_index); - if(!!margeset){ - row = margeset.row[1]; - row_pre = margeset.row[0]; - row_index = margeset.row[2]; - col = margeset.column[1]; - col_pre = margeset.column[0]; - col_index = margeset.column[2]; - } - - luckysheetupdateCell(row, row_pre, row_index, col, col_pre, col_index, Store.flowdata, null, true); - formula.rangeResizeTo = $("#luckysheet-functionbox-cell"); - } - }).keydown(function (event) { - if(isEditMode()){//此模式下禁用公式栏 - return; - } - - let ctrlKey = event.ctrlKey; - let altKey = event.altKey; - let shiftKey = event.shiftKey; - let kcode = event.keyCode; - let $inputbox = $("#luckysheet-input-box"); - - if (kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0) { - if ($("#luckysheet-formula-search-c").is(":visible") && formula.searchFunctionCell != null) { - formula.searchFunctionEnter($("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active")); - } - else { - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - Store.luckysheet_select_save = [{ "row": [Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[0]], "column": [Store.luckysheetCellUpdate[1], Store.luckysheetCellUpdate[1]], "row_focus": Store.luckysheetCellUpdate[0], "column_focus": Store.luckysheetCellUpdate[1] }]; - luckysheetMoveHighlightCell("down", 1, "rangeOfSelect"); - $("#luckysheet-functionbox-cell").blur(); - } - event.preventDefault(); - } - else if (kcode == keycode.ESC && parseInt($inputbox.css("top")) > 0) { - formula.dontupdate(); - luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); - event.preventDefault(); - } - else if (kcode == keycode.F4 && parseInt($inputbox.css("top")) > 0) { - formula.setfreezonFuc(event); - event.preventDefault(); - } - else if (kcode == keycode.UP && parseInt($inputbox.css("top")) > 0) { - if ($("#luckysheet-formula-search-c").is(":visible")) { - let $up = $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active").prev(); - if ($up.length == 0) { - $up = $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item").last(); - } - $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item").removeClass("luckysheet-formula-search-item-active"); - $up.addClass("luckysheet-formula-search-item-active"); - event.preventDefault(); - } - } - else if (kcode == keycode.DOWN && parseInt($inputbox.css("top")) > 0) { - if ($("#luckysheet-formula-search-c").is(":visible")) { - let $up = $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active").next(); - if ($up.length == 0) { - $up = $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item").first(); - } - $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item").removeClass("luckysheet-formula-search-item-active"); - $up.addClass("luckysheet-formula-search-item-active"); - event.preventDefault(); - } - } - else if (kcode == keycode.LEFT && parseInt($inputbox.css("top")) > 0) { - formula.rangeHightlightselected($("#luckysheet-functionbox-cell")); - } - else if (kcode == keycode.RIGHT && parseInt($inputbox.css("top")) > 0) { - formula.rangeHightlightselected($("#luckysheet-functionbox-cell")); - } - else if (!((kcode >= 112 && kcode <= 123) || kcode <= 46 || kcode == 144 || kcode == 108 || event.ctrlKey || event.altKey || (event.shiftKey && (kcode == 37 || kcode == 38 || kcode == 39 || kcode == 40))) || kcode == 8 || kcode == 32 || kcode == 46 || (event.ctrlKey && kcode == 86)) { - formula.functionInputHanddler($("#luckysheet-rich-text-editor"), $("#luckysheet-functionbox-cell"), kcode); - } - }).click(function () { - if(isEditMode()){//此模式下禁用公式栏 - return; - } - - formula.rangeHightlightselected($("#luckysheet-functionbox-cell")); - }); - - //公式栏 取消(X)按钮 - $("#luckysheet-wa-functionbox-cancel").click(function () { - if (!$(this).hasClass("luckysheet-wa-calculate-active")) { - return; - } - //若有参数弹出框,隐藏 - if($("#luckysheet-search-formula-parm").is(":visible")){ - $("#luckysheet-search-formula-parm").hide(); - } - //若有参数选取范围弹出框,隐藏 - if($("#luckysheet-search-formula-parm-select").is(":visible")){ - $("#luckysheet-search-formula-parm-select").hide(); - } - - formula.dontupdate(); - luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); - }); - - //公式栏 确认()按钮 - $("#luckysheet-wa-functionbox-confirm").click(function () { - if (!$(this).hasClass("luckysheet-wa-calculate-active")) { - return; - } - //若有参数弹出框,隐藏 - if($("#luckysheet-search-formula-parm").is(":visible")){ - $("#luckysheet-search-formula-parm").hide(); - } - //若有参数选取范围弹出框,隐藏 - if($("#luckysheet-search-formula-parm-select").is(":visible")){ - $("#luckysheet-search-formula-parm-select").hide(); - } - - formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); - luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); - }); - - //公式栏 fx按钮 - $("#luckysheet-wa-functionbox-fx").click(function () { - //点击函数查找弹出框 - if(Store.luckysheet_select_save.length == 0){ - if(isEditMode()){ - alert(locale_formula.tipSelectCell); - } - else{ - tooltip.info(locale_formula.tipSelectCell,""); - } - - return; - } - - let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]; - - let row_index = last["row_focus"], col_index = last["column_focus"]; - let row = Store.visibledatarow[row_index], - row_pre = row_index - 1 == -1 ? 0 : Store.visibledatarow[row_index - 1]; - let col = Store.visibledatacolumn[col_index], - col_pre = col_index - 1 == -1 ? 0 : Store.visibledatacolumn[col_index - 1]; - - luckysheetupdateCell(row, row_pre, row_index, col, col_pre, col_index, Store.flowdata); - - let cell = Store.flowdata[row_index][col_index]; - if(cell != null && cell.f != null){ - //单元格有计算 - let functionStr = formula.getfunctionParam(cell.f); - if(functionStr.fn != null){ - //有函数公式 - insertFormula.formulaParmDialog(functionStr.fn, functionStr.param); - } - else{ - //无函数公式 - insertFormula.formulaListDialog(); - } - } - else{ - //单元格无计算 - $("#luckysheet-rich-text-editor").html('='); - $("#luckysheet-functionbox-cell").html($("#luckysheet-rich-text-editor").html()); - insertFormula.formulaListDialog(); - } - - insertFormula.init(); - }); - - //公式选区操作 - $("#luckysheet-formula-functionrange").on("mousedown", ".luckysheet-copy", function (event) { - formula.rangeMove = true; - Store.luckysheet_scroll_status = true; - formula.rangeMoveObj = $(this).parent(); - formula.rangeMoveIndex = $(this).parent().attr("rangeindex"); - - let mouse = mouseposition(event.pageX, event.pageY); - let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft(); - let y = mouse[1] + $("#luckysheet-cell-main").scrollTop(); - $("#luckysheet-formula-functionrange-highlight-" + formula.rangeMoveIndex).find(".luckysheet-selection-copy-hc").css("opacity", 0.13); - - let type = $(this).data("type"); - if (type == "top") { - y += 3; - } - else if (type == "right") { - x -= 3; - } - else if (type == "bottom") { - y -= 3; - } - else if (type == "left") { - x += 3; - } - - let row_index = rowLocation(y)[2]; - let col_index = colLocation(x)[2]; - - formula.rangeMovexy = [row_index, col_index]; - $("#luckysheet-sheettable").css("cursor", "move"); - event.stopPropagation(); - }); - - $("#luckysheet-formula-functionrange").on("mousedown", ".luckysheet-highlight", function (e) { - formula.rangeResize = $(this).data("type");//开始状态resize - formula.rangeResizeIndex = $(this).parent().attr("rangeindex"); - - let mouse = mouseposition(e.pageX, e.pageY), - scrollLeft = $("#luckysheet-cell-main").scrollLeft(), - scrollTop = $("#luckysheet-cell-main").scrollTop(); - let x = mouse[0] + scrollLeft; - let y = mouse[1] + scrollTop; - formula.rangeResizeObj = $(this).parent(); - $("#luckysheet-formula-functionrange-highlight-" + formula.rangeResizeIndex).find(".luckysheet-selection-copy-hc").css("opacity", 0.13); - - if (formula.rangeResize == "lt") { - x += 3; - y += 3; - } - else if (formula.rangeResize == "lb") { - x += 3; - y -= 3; - } - else if (formula.rangeResize == "rt") { - x -= 3; - y += 3; - } - else if (formula.rangeResize == "rb") { - x -= 3; - y -= 3; - } - - let row_location = rowLocation(y), - row = row_location[1], - row_pre = row_location[0], - row_index = row_location[2]; - let col_location = colLocation(x), - col = col_location[1], - col_pre = col_location[0], - col_index = col_location[2]; - - let position = formula.rangeResizeObj.position(); - formula.rangeResizexy = [ - col_pre, - row_pre, - formula.rangeResizeObj.width(), - formula.rangeResizeObj.height(), - position.left + scrollLeft, - position.top + scrollTop, col, row - ]; - formula.rangeResizeWinH = $("#luckysheet-cell-main")[0].scrollHeight; - formula.rangeResizeWinW = $("#luckysheet-cell-main")[0].scrollWidth; - Store.luckysheet_scroll_status = true; - event.stopPropagation(); - }); - //图表选区mousedown $("#luckysheet-chart-rangeShow").on("mousedown.chartRangeShowMove", ".luckysheet-chart-rangeShow-move", function(event){ Store.chart_selection.rangeMove = true; diff --git a/src/controllers/keyboard.js b/src/controllers/keyboard.js new file mode 100644 index 000000000..05137df30 --- /dev/null +++ b/src/controllers/keyboard.js @@ -0,0 +1,917 @@ +import luckysheetConfigsetting from './luckysheetConfigsetting'; +import menuButton from './menuButton'; +import conditionformat from './conditionformat'; +import server from './server'; +import luckysheetupdateCell from './updateCell'; +import { keycode } from './constant'; +import { + luckysheetMoveHighlightCell, + luckysheetMoveHighlightCell2, + luckysheetMoveHighlightRange, + luckysheetMoveHighlightRange2 +} from './sheetMove'; +import { selectHightlightShow, selectIsOverlap } from './select'; +import selection from './selection'; +import searchReplace from './searchReplace'; +import controlHistory from './controlHistory'; + +import { + getByteLen, + luckysheetactiveCell, +} from '../utils/util'; +import { getSheetIndex } from '../methods/get'; +import { hasPartMC, isEditMode } from '../global/validate'; +import formula from '../global/formula'; +import cleargridelement from '../global/cleargridelement'; +import tooltip from '../global/tooltip'; +import locale from '../locale/locale'; +import Store from '../store'; + + +let luckysheet_shiftkeydown = false; + +function formulaMoveEvent(dir, ctrlKey, shiftKey){ + if ($("#luckysheet-formula-search-c").is(":visible")) { + let $up = $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active").next(); + if ($up.length == 0) { + $up = $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item").first(); + } + + $("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item").removeClass("luckysheet-formula-search-item-active"); + $up.addClass("luckysheet-formula-search-item-active"); + + event.preventDefault(); + } + else{ + if($("#luckysheet-formula-functionrange-select").is(":visible")){ + if(ctrlKey && shiftKey){ + luckysheetMoveHighlightRange2(dir, "rangeOfFormula"); + } + else if(ctrlKey){ + luckysheetMoveHighlightCell2(dir, "rangeOfFormula"); + } + else if(shiftKey){ + let dir_n = dir, step = 1; + if(dir == 'up'){ + dir_n = 'down'; + step = -1; + } + if(dir == 'left'){ + dir_n = 'right'; + step = -1; + } + + luckysheetMoveHighlightRange(dir_n, step, "rangeOfFormula"); + } + else{ + let dir_n = dir, step = 1; + if(dir == 'up'){ + dir_n = 'down'; + step = -1; + } + if(dir == 'left'){ + dir_n = 'right'; + step = -1; + } + + luckysheetMoveHighlightCell(dir_n, step, "rangeOfFormula"); + } + } + else if(formula.israngeseleciton()){ + let anchor = $(window.getSelection().anchorNode); + + if(anchor.parent().next().text() == null || anchor.parent().next().text() == ""){ + let vText = $("#luckysheet-input-box #luckysheet-input-box-index").text(); + let range = formula.getcellrange(vText); + + if(range == null){ + range = formula.getcellrange($("#luckysheet-input-box-index").text()); + } + + let r1 = range["row"][0], r2 = range["row"][1]; + let c1 = range["column"][0], c2 = range["column"][1]; + + let row = Store.visibledatarow[r2], + row_pre = r1 - 1 == -1 ? 0 : Store.visibledatarow[r1 - 1]; + let col = Store.visibledatacolumn[c2], + col_pre = c1 - 1 == -1 ? 0 : Store.visibledatacolumn[c1 - 1]; + + formula.func_selectedrange = { + "left": col_pre, + "width": col - col_pre - 1, + "top": row_pre, + "height": row - row_pre - 1, + "left_move": col_pre, + "width_move": col - col_pre - 1, + "top_move": row_pre, + "height_move": row - row_pre - 1, + "row": [r1, r2], + "column": [c1, c2], + "row_focus": r1, + "column_focus": c1 + }; + + formula.rangeSetValue({ "row": [r1, r2], "column": [c1, c2] }); + + formula.rangestart = true; + formula.rangedrag_column_start = false; + formula.rangedrag_row_start = false; + + if(ctrlKey && shiftKey){ + luckysheetMoveHighlightRange2(dir, "rangeOfFormula"); + } + else if(ctrlKey){ + luckysheetMoveHighlightCell2(dir, "rangeOfFormula"); + } + else if(shiftKey){ + let dir_n = dir, step = 1; + if(dir == 'up'){ + dir_n = 'down'; + step = -1; + } + if(dir == 'left'){ + dir_n = 'right'; + step = -1; + } + + luckysheetMoveHighlightRange(dir_n, step, "rangeOfFormula"); + } + else{ + let dir_n = dir, step = 1; + if(dir == 'up'){ + dir_n = 'down'; + step = -1; + } + if(dir == 'left'){ + dir_n = 'right'; + step = -1; + } + + luckysheetMoveHighlightCell(dir_n, step, "rangeOfFormula"); + } + } + } + else if(!ctrlKey && !shiftKey){ + let anchor = $(window.getSelection().anchorNode); + let anchorOffset = window.getSelection().anchorOffset; + + if(dir == 'up'){ + if(anchor.parent().is("span") && anchor.parent().next().length == 0 && anchorOffset > 0){ + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + luckysheetMoveHighlightCell("down", -1, "rangeOfSelect"); + + event.preventDefault(); + } + else if(anchor.is("#luckysheet-rich-text-editor") && anchor.context.childElementCount == anchorOffset){ + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + luckysheetMoveHighlightCell("down", -1, "rangeOfSelect"); + + event.preventDefault(); + } + else if(anchor.parent().is("#luckysheet-rich-text-editor") && anchor.context.length == anchorOffset){ + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + luckysheetMoveHighlightCell("down", -1, "rangeOfSelect"); + + event.preventDefault(); + } + } + else if(dir == 'down'){ + if(anchor.parent().is("span") && anchor.parent().next().length == 0 && anchorOffset > 0){ + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + luckysheetMoveHighlightCell("down", 1, "rangeOfSelect"); + + event.preventDefault(); + } + else if(anchor.is("#luckysheet-rich-text-editor") && anchor.context.childElementCount == anchorOffset){ + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + luckysheetMoveHighlightCell("down", 1, "rangeOfSelect"); + + event.preventDefault(); + } + else if(anchor.parent().is("#luckysheet-rich-text-editor") && anchor.context.length == anchorOffset){ + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + luckysheetMoveHighlightCell("down", 1, "rangeOfSelect"); + + event.preventDefault(); + } + } + else if(dir == 'left'){ + if(anchor.parent().is("span") && anchor.parent().prev().length == 0 && anchorOffset == 0){ + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + luckysheetMoveHighlightCell("right", -1, "rangeOfSelect"); + + event.preventDefault(); + } + else if(anchor.is("#luckysheet-rich-text-editor") && anchorOffset == 1){ + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + luckysheetMoveHighlightCell("right", -1, "rangeOfSelect"); + + event.preventDefault(); + } + else if(anchor.parent().is("#luckysheet-rich-text-editor") && anchorOffset == 0){ + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + luckysheetMoveHighlightCell("right", -1, "rangeOfSelect"); + + event.preventDefault(); + } + } + else if(dir == 'right'){ + if(anchor.parent().is("span") && anchor.parent().next().length == 0 && anchorOffset > 0){ + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + luckysheetMoveHighlightCell("right", 1, "rangeOfSelect"); + + event.preventDefault(); + } + else if(anchor.is("#luckysheet-rich-text-editor") && anchor.context.childElementCount == anchorOffset){ + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + luckysheetMoveHighlightCell("right", 1, "rangeOfSelect"); + + event.preventDefault(); + } + else if(anchor.parent().is("#luckysheet-rich-text-editor") && anchor.context.length == anchorOffset){ + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + luckysheetMoveHighlightCell("right", 1, "rangeOfSelect"); + + event.preventDefault(); + } + } + } + } +} + +export function keyboardInitial(){ + const _locale = locale(); + const locale_drag = _locale.drag; + + //单元格编辑输入 + $("#luckysheet-input-box").click(function () { + formula.rangeHightlightselected($("#luckysheet-rich-text-editor")); + }).add("#" + Store.container).on("keydown", function (event) { + if ($("#luckysheet-modal-dialog-mask").is(":visible") || $(event.target).hasClass("luckysheet-mousedown-cancel") || $(event.target).hasClass("formulaInputFocus")) { + return; + } + + let ctrlKey = event.ctrlKey; + let altKey = event.altKey; + let shiftKey = event.shiftKey; + let kcode = event.keyCode; + + if ($("#luckysheet-modal-dialog-mask").is(":visible") || $(event.target).hasClass("luckysheet-mousedown-cancel") || $(event.target).hasClass("sp-input") || (parseInt($("#luckysheet-input-box").css("top")) > 0 && $(event.target).closest(".luckysheet-input-box").length > 0 && kcode != keycode.ENTER && kcode != keycode.TAB && kcode != keycode.UP && kcode != keycode.DOWN && kcode != keycode.LEFT && kcode != keycode.RIGHT)) { + let anchor = $(window.getSelection().anchorNode); + + if(anchor.parent().is("#luckysheet-helpbox-cell") || anchor.is("#luckysheet-helpbox-cell")){ + if(kcode == keycode.ENTER){ + let helpboxValue = $("#luckysheet-helpbox-cell").text(); + + if(formula.iscelldata(helpboxValue)){ + let cellrange = formula.getcellrange(helpboxValue); + + Store.luckysheet_select_save = [{ "row": cellrange["row"], "column": cellrange["column"], "row_focus": cellrange["row"][0], "column_focus": cellrange["column"][0] }]; + selectHightlightShow(); + + $("#luckysheet-helpbox-cell").blur(); + + let scrollLeft = $("#luckysheet-cell-main").scrollLeft(), + scrollTop = $("#luckysheet-cell-main").scrollTop(); + let winH = $("#luckysheet-cell-main").height(), + winW = $("#luckysheet-cell-main").width(); + + let row = Store.visibledatarow[cellrange["row"][1]], + row_pre = cellrange["row"][0] - 1 == -1 ? 0 : Store.visibledatarow[cellrange["row"][0] - 1]; + let col = Store.visibledatacolumn[cellrange["column"][1]], + col_pre = cellrange["column"][0] - 1 == -1 ? 0 : Store.visibledatacolumn[cellrange["column"][0] - 1]; + + if (col - scrollLeft - winW + 20 > 0) { + $("#luckysheet-scrollbar-x").scrollLeft(col - winW + 20); + } + else if (col_pre - scrollLeft - 20 < 0) { + $("#luckysheet-scrollbar-x").scrollLeft(col_pre - 20); + } + + if (row - scrollTop - winH + 20 > 0) { + $("#luckysheet-scrollbar-y").scrollTop(row - winH + 20); + } + else if (row_pre - scrollTop - 20 < 0) { + $("#luckysheet-scrollbar-y").scrollTop(row_pre - 20); + } + } + } + } + + return; + } + + let $inputbox = $("#luckysheet-input-box"); + + if (kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0) { + if ($("#luckysheet-formula-search-c").is(":visible") && formula.searchFunctionCell != null) { + formula.searchFunctionEnter($("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active")); + } + else { + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + Store.luckysheet_select_save = [{ + "row": [Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[0]], + "column": [Store.luckysheetCellUpdate[1], Store.luckysheetCellUpdate[1]], + "row_focus": Store.luckysheetCellUpdate[0], + "column_focus": Store.luckysheetCellUpdate[1] + }]; + luckysheetMoveHighlightCell("down", 1, "rangeOfSelect"); + } + + //若有参数弹出框,隐藏 + if($("#luckysheet-search-formula-parm").is(":visible")){ + $("#luckysheet-search-formula-parm").hide(); + } + //若有参数选取范围弹出框,隐藏 + if($("#luckysheet-search-formula-parm-select").is(":visible")){ + $("#luckysheet-search-formula-parm-select").hide(); + } + event.preventDefault(); + } + else if (kcode == keycode.TAB) { + if (parseInt($inputbox.css("top")) > 0) { + return; + } + + luckysheetMoveHighlightCell("right", 1, "rangeOfSelect"); + event.preventDefault(); + } + else if(kcode == keycode.F2){ + if (parseInt($inputbox.css("top")) > 0) { + return; + } + + let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]; + + let row_index = last["row_focus"], col_index = last["column_focus"]; + let row = Store.visibledatarow[row_index], + row_pre = row_index - 1 == -1 ? 0 : Store.visibledatarow[row_index - 1]; + let col = Store.visibledatacolumn[col_index], + col_pre = col_index - 1 == -1 ? 0 : Store.visibledatacolumn[col_index - 1]; + + luckysheetupdateCell(row, row_pre, row_index, col, col_pre, col_index, Store.flowdata); + event.preventDefault(); + } + else if (kcode == keycode.F4 && parseInt($inputbox.css("top")) > 0) { + formula.setfreezonFuc(event); + event.preventDefault(); + } + else if (kcode == keycode.ESC && parseInt($inputbox.css("top")) > 0) { + formula.dontupdate(); + luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); + event.preventDefault(); + } + else if (kcode == keycode.ENTER) { + if($(event.target).hasClass("formulaInputFocus") || $("#luckysheet-conditionformat-dialog").is(":visible")){ + return; + } + else if (String.fromCharCode(kcode) != null && $("#luckysheet-cell-selected").is(":visible")) { + let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]; + + let row_index = last["row_focus"], col_index = last["column_focus"]; + let row = Store.visibledatarow[row_index], + row_pre = row_index - 1 == -1 ? 0 : Store.visibledatarow[row_index - 1]; + let col = Store.visibledatacolumn[col_index], + col_pre = col_index - 1 == -1 ? 0 : Store.visibledatacolumn[col_index - 1]; + + let margeset = menuButton.mergeborer(Store.flowdata, row_index, col_index); + if(!!margeset){ + row = margeset.row[1]; + row_pre = margeset.row[0]; + row_index = margeset.row[2]; + col = margeset.column[1]; + col_pre = margeset.column[0]; + col_index = margeset.column[2]; + } + + luckysheetupdateCell(row, row_pre, row_index, col, col_pre, col_index, Store.flowdata); + event.preventDefault(); + } + } + else { + if (ctrlKey || event.metaKey) { + if (shiftKey) { + if (!luckysheet_shiftkeydown) { + Store.luckysheet_shiftpositon = $.extend(true, {}, Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]); + Store.luckysheet_shiftkeydown = true; + } + + //Ctrl + shift + 方向键 调整选区 + if (kcode == keycode.UP) { + if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { + return; + } + + luckysheetMoveHighlightRange2("up", "rangeOfSelect"); + } + else if (kcode == keycode.DOWN) { + if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { + return; + } + + luckysheetMoveHighlightRange2("down", "rangeOfSelect"); + } + else if (kcode == keycode.LEFT) { + if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { + return; + } + + luckysheetMoveHighlightRange2("left", "rangeOfSelect"); + } + else if (kcode == keycode.RIGHT) { + if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { + return; + } + + luckysheetMoveHighlightRange2("right", "rangeOfSelect"); + } + } + else if (kcode == 66) {//Ctrl + B 加粗 + $("#luckysheet-icon-bold").click(); + } + else if (kcode == 67) {//Ctrl + C 复制 + //复制时存在格式刷状态,取消格式刷 + if(menuButton.luckysheetPaintModelOn){ + menuButton.cancelPaintModel(); + } + + if(Store.luckysheet_select_save.length == 0){ + return; + } + + //复制范围内包含部分合并单元格,提示 + if(Store.config["merge"] != null){ + let has_PartMC = false; + + 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]; + let c1 = Store.luckysheet_select_save[s].column[0], + c2 = Store.luckysheet_select_save[s].column[1]; + + has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); + + if(has_PartMC){ + break; + } + } + + if(has_PartMC){ + if(isEditMode()){ + alert(locale_drag.noMerge); + } + else{ + tooltip.info(locale_drag.noMerge, ""); + } + return; + } + } + + //多重选区 有条件格式时 提示 + let cdformat = Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].luckysheet_conditionformat_save; + if(Store.luckysheet_select_save.length > 1 && cdformat != null && cdformat.length > 0){ + let hasCF = false; + + let cf_compute = conditionformat.getComputeMap(); + + label: + for(let s = 0; s < Store.luckysheet_select_save.length; s++){ + if(hasCF){ + break; + } + + let r1 = Store.luckysheet_select_save[s].row[0], + r2 = Store.luckysheet_select_save[s].row[1]; + let c1 = Store.luckysheet_select_save[s].column[0], + c2 = Store.luckysheet_select_save[s].column[1]; + + for(let r = r1; r <= r2; r++){ + for(let c = c1; c <= c2; c++){ + if(conditionformat.checksCF(r, c, cf_compute) != null){ + hasCF = true; + continue label; + } + } + } + } + + if(hasCF){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + } + + //多重选区 行不一样且列不一样时 提示 + if(Store.luckysheet_select_save.length > 1){ + let isSameRow = true, + str_r = luckysheet_select_save[0].row[0], + end_r = luckysheet_select_save[0].row[1]; + let isSameCol = true, + str_c = luckysheet_select_save[0].column[0], + end_c = luckysheet_select_save[0].column[1]; + + for(let s = 1; s < luckysheet_select_save.length; s++){ + if(luckysheet_select_save[s].row[0] != str_r || luckysheet_select_save[s].row[1] != end_r){ + isSameRow = false; + } + if(luckysheet_select_save[s].column[0] != str_c || luckysheet_select_save[s].column[1] != end_c){ + isSameCol = false; + } + } + + if((!isSameRow && !isSameCol) || selectIsOverlap()){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + } + + selection.copy(event); + + Store.luckysheet_paste_iscut = false; + luckysheetactiveCell(); + + event.stopPropagation(); + return; + } + else if (kcode == 70) {//Ctrl + F 查找 + searchReplace.createDialog(0); + searchReplace.init(); + + $("#luckysheet-search-replace #searchInput input").focus(); + } + else if (kcode == 72) {//Ctrl + H 替换 + searchReplace.createDialog(1); + searchReplace.init(); + + $("#luckysheet-search-replace #searchInput input").focus(); + } + else if (kcode == 73) {//Ctrl + I 斜体 + $("#luckysheet-icon-italic").click(); + } + else if (kcode == 86) {//Ctrl + V 粘贴 + if(isEditMode()){//此模式下禁用粘贴 + return; + } + + if($(event.target).hasClass("formulaInputFocus")){ + return; + } + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noPaste); + } + else{ + tooltip.info(locale_drag.noPaste, ""); + } + return; + } + + selection.isPasteAction = true; + luckysheetactiveCell(); + + event.stopPropagation(); + return; + } + else if (kcode == 88) {//Ctrl + X 剪切 + //复制时存在格式刷状态,取消格式刷 + if(menuButton.luckysheetPaintModelOn){ + menuButton.cancelPaintModel(); + } + + if(Store.luckysheet_select_save.length == 0){ + return; + } + + //复制范围内包含部分合并单元格,提示 + if(Store.config["merge"] != null){ + let has_PartMC = false; + + 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]; + let c1 = Store.luckysheet_select_save[s].column[0], + c2 = Store.luckysheet_select_save[s].column[1]; + + has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); + + if(has_PartMC){ + break; + } + } + + if(has_PartMC){ + if(luckysheetConfigsetting.editMode){ + alert(_locale_drag.noMerge); + } + else{ + tooltip.info(_locale_drag.noMerge, ""); + } + return; + } + } + + //多重选区时 提示 + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + selection.copy(event); + + Store.luckysheet_paste_iscut = true; + luckysheetactiveCell(); + + event.stopPropagation(); + return; + } + else if (kcode == 90) {//Ctrl + Z 撤销 + controlHistory.redo(event); + luckysheetactiveCell(); + event.stopPropagation(); + return; + } + else if (kcode == 89) {//Ctrl + Y 重做 + controlHistory.undo(event); + luckysheetactiveCell(); + event.stopPropagation(); + return; + } + else if (kcode == keycode.UP) {//Ctrl + up 调整单元格 + if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { + return; + } + + luckysheetMoveHighlightCell2("up", "rangeOfSelect"); + } + else if (kcode == keycode.DOWN) {//Ctrl + down 调整单元格 + if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { + return; + } + + luckysheetMoveHighlightCell2("down", "rangeOfSelect"); + } + else if (kcode == keycode.LEFT) {//Ctrl + top 调整单元格 + if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { + return; + } + + luckysheetMoveHighlightCell2("left", "rangeOfSelect"); + } + else if (kcode == keycode.RIGHT) {//Ctrl + right 调整单元格 + if (parseInt($inputbox.css("top")) > 0 || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { + return; + } + + luckysheetMoveHighlightCell2("right", "rangeOfSelect"); + } + else if (String.fromCharCode(kcode).toLocaleUpperCase() == "A") {//Ctrl + A 全选 + $("#luckysheet-left-top").trigger("mousedown"); + $(document).trigger("mouseup"); + } + + event.preventDefault(); + return; + } + else if (shiftKey && (kcode == keycode.UP || kcode == keycode.DOWN || kcode == keycode.LEFT || kcode == keycode.RIGHT || (altKey && (kcode == 53 || kcode == 101)))) { + if (parseInt($inputbox.css("top")) > 0 || $(event.target).hasClass("formulaInputFocus")) { + return; + } + + if (!luckysheet_shiftkeydown) { + Store.luckysheet_shiftpositon = $.extend(true, {}, Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]); + Store.luckysheet_shiftkeydown = true; + } + + //shift + 方向键 调整选区 + if (kcode == keycode.UP) { + if($("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")){ + return; + } + + luckysheetMoveHighlightRange("down", -1, "rangeOfSelect"); + } + else if (kcode == keycode.DOWN) { + if($("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")){ + return; + } + + luckysheetMoveHighlightRange("down", 1, "rangeOfSelect"); + } + else if (kcode == keycode.LEFT) { + if($("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")){ + return; + } + + luckysheetMoveHighlightRange("right", -1, "rangeOfSelect"); + } + else if (kcode == keycode.RIGHT) { + if($("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")){ + return; + } + + luckysheetMoveHighlightRange("right", 1, "rangeOfSelect"); + } + else if (altKey && (kcode == 53 || kcode == 101)) { + //Alt + Shift + 5(删除线) + $("#luckysheet-icon-strikethrough").click(); + } + + event.preventDefault(); + } + else if (kcode == keycode.ESC) { + if(menuButton.luckysheetPaintModelOn){ + menuButton.cancelPaintModel(); + } + else{ + cleargridelement(event); + event.preventDefault(); + } + + selectHightlightShow(); + } + else if (kcode == keycode.DELETE) { + $("#luckysheet-delete-text").click(); + + event.preventDefault(); + } + else if (kcode == keycode.UP) { + if (parseInt($inputbox.css("top")) > 0 || $(event.target).hasClass("formulaInputFocus") || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { + return; + } + + luckysheetMoveHighlightCell("down", -1, "rangeOfSelect"); + event.preventDefault(); + } + else if (kcode == keycode.DOWN) { + if (parseInt($inputbox.css("top")) > 0 || $(event.target).hasClass("formulaInputFocus") || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { + return; + } + + luckysheetMoveHighlightCell("down", 1, "rangeOfSelect"); + event.preventDefault(); + } + else if (kcode == keycode.LEFT) { + if (parseInt($inputbox.css("top")) > 0 || $(event.target).hasClass("formulaInputFocus") || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { + return; + } + + luckysheetMoveHighlightCell("right", -1, "rangeOfSelect"); + event.preventDefault(); + } + else if (kcode == keycode.RIGHT) { + if (parseInt($inputbox.css("top")) > 0 || $(event.target).hasClass("formulaInputFocus") || $("#luckysheet-singleRange-dialog").is(":visible") || $("#luckysheet-multiRange-dialog").is(":visible")) { + return; + } + + luckysheetMoveHighlightCell("right", 1, "rangeOfSelect"); + event.preventDefault(); + } + else if (!((kcode >= 112 && kcode <= 123) || kcode <= 46 || kcode == 144 || kcode == 108 || event.ctrlKey || event.altKey || (event.shiftKey && (kcode == 37 || kcode == 38 || kcode == 39 || kcode == 40))) || kcode == 8 || kcode == 32 || kcode == 46 || kcode == 0 || (event.ctrlKey && kcode == 86)) { + if (String.fromCharCode(kcode) != null && $("#luckysheet-cell-selected").is(":visible") && (kcode != keycode.CAPSLOCK && kcode != keycode.WIN && kcode != 18)) { + let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]; + + let row_index = last["row_focus"], col_index = last["column_focus"]; + let row = Store.visibledatarow[row_index], + row_pre = row_index - 1 == -1 ? 0 : Store.visibledatarow[row_index - 1]; + let col = Store.visibledatacolumn[col_index], + col_pre = col_index - 1 == -1 ? 0 : Store.visibledatacolumn[col_index - 1]; + + let margeset = menuButton.mergeborer(Store.flowdata, row_index, col_index); + if(!!margeset){ + row = margeset.row[1]; + row_pre = margeset.row[0]; + row_index = margeset.row[2]; + col = margeset.column[1]; + col_pre = margeset.column[0]; + col_index = margeset.column[2]; + } + + luckysheetupdateCell(row, row_pre, row_index, col, col_pre, col_index, Store.flowdata, true); + if(kcode == 8){ + $("#luckysheet-rich-text-editor").html("
"); + } + formula.functionInputHanddler($("#luckysheet-functionbox-cell"), $("#luckysheet-rich-text-editor"), kcode); + } + } + } + + luckysheetactiveCell(); + + event.stopPropagation(); + }); + + //单元格编辑 keydown (公式 上下左右键移动) + $("#" + Store.container).add("#luckysheet-input-box").keydown(function (event) { + if ($("#luckysheet-modal-dialog-mask").is(":visible") || $(event.target).hasClass("luckysheet-mousedown-cancel") || $(event.target).hasClass("formulaInputFocus")) { + return; + } + + let ctrlKey = event.ctrlKey; + let altKey = event.altKey; + let shiftKey = event.shiftKey; + let kcode = event.keyCode; + + let $inputbox = $("#luckysheet-input-box"); + if (kcode == keycode.ESC && parseInt($("#luckysheet-input-box").css("top")) > 0) { + formula.dontupdate(); + luckysheetMoveHighlightCell("down", 0, "rangeOfSelect"); + event.preventDefault(); + } + else if (kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0) { + if ($("#luckysheet-formula-search-c").is(":visible") && formula.searchFunctionCell != null) { + formula.searchFunctionEnter($("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active")); + event.preventDefault(); + } + } + else if(kcode == keycode.TAB && parseInt($inputbox.css("top")) > 0){ + if ($("#luckysheet-formula-search-c").is(":visible") && formula.searchFunctionCell != null) { + formula.searchFunctionEnter($("#luckysheet-formula-search-c").find(".luckysheet-formula-search-item-active")); + } + else{ + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + luckysheetMoveHighlightCell("right", 1, "rangeOfSelect"); + } + + event.preventDefault(); + } + else if (kcode == keycode.F4 && parseInt($inputbox.css("top")) > 0) { + formula.setfreezonFuc(event); + event.preventDefault(); + } + else if (kcode == keycode.UP && parseInt($inputbox.css("top")) > 0) { + formulaMoveEvent("up", ctrlKey, shiftKey); + } + else if (kcode == keycode.DOWN && parseInt($inputbox.css("top")) > 0) { + formulaMoveEvent("down", ctrlKey, shiftKey); + } + else if (kcode == keycode.LEFT && parseInt($inputbox.css("top")) > 0) { + formulaMoveEvent("left", ctrlKey, shiftKey); + } + else if (kcode == keycode.RIGHT && parseInt($inputbox.css("top")) > 0) { + formulaMoveEvent("right", ctrlKey, shiftKey); + } + else if (!((kcode >= 112 && kcode <= 123) || kcode <= 46 || kcode == 144 || kcode == 108 || event.ctrlKey || event.altKey || (event.shiftKey && (kcode == 37 || kcode == 38 || kcode == 39 || kcode == 40))) || kcode == 8 || kcode == 32 || kcode == 46 || (event.ctrlKey && kcode == 86)) { + formula.functionInputHanddler($("#luckysheet-functionbox-cell"), $("#luckysheet-rich-text-editor"), kcode); + } + }).keyup(function (e) { + let kcode = e.keyCode; + + if (!e.shiftKey && kcode == 16) { + Store.luckysheet_shiftkeydown = false; + Store.luckysheet_shiftpositon = null; + } + + //输入框中文输入后 shift 和 空格 处理 + if(parseInt($("#luckysheet-input-box").css("top")) > 0 && (kcode == 13 || kcode == 16 || kcode == 32)){ + formula.functionInputHanddler($("#luckysheet-functionbox-cell"), $("#luckysheet-rich-text-editor"), kcode); + } + + e.preventDefault(); + }); + + //top workBook rename + $("#luckysheet_info_detail_input").val(server.title).css("width", getByteLen(server.title) * 10).keydown(function(){ + let ctrlKey = event.ctrlKey; + let altKey = event.altKey; + let shiftKey = event.shiftKey; + let kcode = event.keyCode; + let $t = $(this); + if(kcode == keycode.ENTER){ + $t.blur().change(); + } + }).bind('input propertychange', function() { + let $t = $(this); + let inputlen = getByteLen($t.val())*10; + let updatelen = $("#luckysheet_info_detail_update").outerWidth(); + let savelen = $("#luckysheet_info_detail_save").outerWidth(); + let userlen = $("#luckysheet_info_detail_user").parent().outerWidth()+60; + let containerlen = $("#" + Store.container).outerWidth(); + let otherlen = 100; + + let minuslen = containerlen- savelen - updatelen - userlen - otherlen; + if(inputlen > minuslen){ + $("#luckysheet_info_detail_input").css("width", minuslen); + } + else{ + $("#luckysheet_info_detail_input").css("width", inputlen); + } + }).change(function(){ + server.saveParam("na", null, $(this).val()); + }); +} \ No newline at end of file diff --git a/src/controllers/matrixOperation.js b/src/controllers/matrixOperation.js new file mode 100644 index 000000000..382e90796 --- /dev/null +++ b/src/controllers/matrixOperation.js @@ -0,0 +1,1241 @@ +import selection from './selection'; +import { + numFormat, +} from '../utils/util'; +import { hasPartMC, isEditMode } from '../global/validate'; +import { getdatabyselection, getcellvalue } from '../global/getdata'; +import tooltip from '../global/tooltip'; +import editor from '../global/editor'; +import Store from '../store'; + +export function initialMatrixOperation(){ + //右键功能键 + //复制为json格式字符串,首行为标题 + $("#luckysheet-copy-json-head").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + //复制范围内包含部分合并单元格,提示 + if(Store.config["merge"] != null){ + let has_PartMC = false; + + 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]; + let c1 = Store.luckysheet_select_save[s].column[0], + c2 = Store.luckysheet_select_save[s].column[1]; + + has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); + + if(has_PartMC){ + break; + } + } + + if(has_PartMC){ + if(isEditMode()){ + alert(locale_drag.noPartMerge); + } + else{ + tooltip.info(locale_drag.noPartMerge, ""); + } + return; + } + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + let arr = []; + if (getdata.length == 0) { + return; + } + + if (getdata.length == 1) { + let obj = {}; + for (let i = 0; i < getdata[0].length; i++) { + obj[getcellvalue(0, i, getdata)] = ""; + } + arr.push(obj); + } + else { + for (let r = 1; r < getdata.length; r++) { + let obj = {}; + for (let c = 0; c < getdata[0].length; c++) { + if(getcellvalue(0, c, getdata) == undefined){ + obj[""] = getcellvalue(r, c, getdata); + }else{ + obj[getcellvalue(0, c, getdata)] = getcellvalue(r, c, getdata); + } + } + arr.push(obj); + } + } + + selection.copybyformat(event, JSON.stringify(arr)); + }); + + //复制为json格式字符串,无标题,采用ABCD作为标题 + $("#luckysheet-copy-json-nohead").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + //复制范围内包含部分合并单元格,提示 + if(Store.config["merge"] != null){ + let has_PartMC = false; + + 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]; + let c1 = Store.luckysheet_select_save[s].column[0], + c2 = Store.luckysheet_select_save[s].column[1]; + + has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); + + if(has_PartMC){ + break; + } + } + + if(has_PartMC){ + if(isEditMode()){ + alert(locale_drag.noPartMerge); + } + else{ + tooltip.info(locale_drag.noPartMerge, ""); + } + return; + } + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + let arr = []; + if (getdata.length == 0) { + return; + } + let st = Store.luckysheet_select_save[0]["column"][0]; + for (let r = 0; r < getdata.length; r++) { + let obj = {}; + for (let c = 0; c < getdata[0].length; c++) { + obj[chatatABC(c + st)] = getcellvalue(r, c, getdata); + } + arr.push(obj); + } + + selection.copybyformat(event, JSON.stringify(arr)); + }); + + //复制为一维数组 + $("#luckysheet-copy-array1").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + //复制范围内包含部分合并单元格,提示 + if(Store.config["merge"] != null){ + let has_PartMC = false; + + 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]; + let c1 = Store.luckysheet_select_save[s].column[0], + c2 = Store.luckysheet_select_save[s].column[1]; + + has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); + + if(has_PartMC){ + break; + } + } + + if(has_PartMC){ + if(isEditMode()){ + alert(locale_drag.noPartMerge); + } + else{ + tooltip.info(locale_drag.noPartMerge, ""); + } + return; + } + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + let arr = []; + if (getdata.length == 0) { + return; + } + for (let r = 0; r < getdata.length; r++) { + for (let c = 0; c < getdata[0].length; c++) { + arr.push(getcellvalue(r, c, getdata)); + } + } + + selection.copybyformat(event, JSON.stringify(arr)); + }); + + //复制为二维数组 + $("#luckysheet-copy-array2").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + //复制范围内包含部分合并单元格,提示 + if(Store.config["merge"] != null){ + let has_PartMC = false; + + 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]; + let c1 = Store.luckysheet_select_save[s].column[0], + c2 = Store.luckysheet_select_save[s].column[1]; + + has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); + + if(has_PartMC){ + break; + } + } + + if(has_PartMC){ + if(isEditMode()){ + alert(locale_drag.noPartMerge); + } + else{ + tooltip.info(locale_drag.noPartMerge, ""); + } + return; + } + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + let arr = []; + if (getdata.length == 0) { + return; + } + for (let r = 0; r < getdata.length; r++) { + let a = []; + for (let c = 0; c < getdata[0].length; c++) { + a.push(getcellvalue(r, c, getdata)); + } + arr.push(a); + } + + selection.copybyformat(event, JSON.stringify(arr)); + }); + + //复制为多维数组 + $("#luckysheet-copy-arraymore-confirm").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + //复制范围内包含部分合并单元格,提示 + if(Store.config["merge"] != null){ + let has_PartMC = false; + + 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]; + let c1 = Store.luckysheet_select_save[s].column[0], + c2 = Store.luckysheet_select_save[s].column[1]; + + has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); + + if(has_PartMC){ + break; + } + } + + if(has_PartMC){ + if(isEditMode()){ + alert(locale_drag.noPartMerge); + } + else{ + tooltip.info(locale_drag.noPartMerge, ""); + } + return; + } + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + let arr = []; + if (getdata.length == 0) { + return; + } + + for (let r = 0; r < getdata.length; r++) { + for (let c = 0; c < getdata[0].length; c++) { + arr.push(getdata[r][c]); + } + } + + let row = $("#luckysheet-copy-arraymore-row").val(), col = $("#luckysheet-copy-arraymore-col").val(); + + if (row == "" && col == "") { + selection.copybyformat(event, JSON.stringify(arr)); + $("body .luckysheet-cols-menu").hide(); + return; + } + + if (row == "") { + row = 1; + } + else { + row = parseInt(row); + if (row == null) { + row = 1; + } + } + + if (col == "") { + col = 1; + } + else { + col = parseInt(col); + if (col == null) { + col = 1; + } + } + + if(row.toString() == "NaN" || col.toString() == "NaN"){ + if(isEditMode()){ + alert(locale_drag.inputCorrect); + } + else{ + tooltip.info(locale_drag.inputCorrect, ""); + } + return; + } + + if(row < 1 || col < 1){ + if(isEditMode()){ + alert(locale_drag.notLessOne); + } + else{ + tooltip.info(locale_drag.notLessOne, ""); + } + return; + } + + let arrlen = arr.length, i = 0, ret = []; + for (let r = 0; r < row; r++) { + let a = []; + for (let c = 0; c < col; c++) { + a.push(arr[i++]); + if (i >= arrlen) { + selection.copybyformat(event, JSON.stringify(ret)); + $("body .luckysheet-cols-menu").hide(); + return; + } + } + ret.push(a); + } + + selection.copybyformat(event, JSON.stringify(ret)); + }); + + //复制为对角线 + $("#luckysheet-copy-diagonal").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + //复制范围内包含部分合并单元格,提示 + if(Store.config["merge"] != null){ + let has_PartMC = false; + + 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]; + let c1 = Store.luckysheet_select_save[s].column[0], + c2 = Store.luckysheet_select_save[s].column[1]; + + has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); + + if(has_PartMC){ + break; + } + } + + if(has_PartMC){ + if(isEditMode()){ + alert(locale_drag.noPartMerge); + } + else{ + tooltip.info(locale_drag.noPartMerge, ""); + } + return; + } + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + let arr = []; + if (getdata.length == 0) { + return; + } + + let clen = getdata[0].length; + for (let r = 0; r < getdata.length; r++) { + if (r >= clen) { + break; + } + arr.push(getdata[r][r]); + } + + selection.copybyformat(event, JSON.stringify(arr)); + }); + + //复制为反对角线 + $("#luckysheet-copy-antidiagonal").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + //复制范围内包含部分合并单元格,提示 + if(Store.config["merge"] != null){ + let has_PartMC = false; + + 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]; + let c1 = Store.luckysheet_select_save[s].column[0], + c2 = Store.luckysheet_select_save[s].column[1]; + + has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); + + if(has_PartMC){ + break; + } + } + + if(has_PartMC){ + if(isEditMode()){ + alert(locale_drag.noPartMerge); + } + else{ + tooltip.info(locale_drag.noPartMerge, ""); + } + return; + } + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + let arr = []; + if (getdata.length == 0) { + return; + } + + let clen = getdata[0].length; + for (let r = 0; r < getdata.length; r++) { + if (r >= clen) { + break; + } + arr.push(getdata[r][clen - r - 1]); + } + + selection.copybyformat(event, JSON.stringify(arr)); + }); + + //复制为对角偏移n列 + $("#luckysheet-copy-diagonaloffset").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + //复制范围内包含部分合并单元格,提示 + if(Store.config["merge"] != null){ + let has_PartMC = false; + + 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]; + let c1 = Store.luckysheet_select_save[s].column[0], + c2 = Store.luckysheet_select_save[s].column[1]; + + has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); + + if(has_PartMC){ + break; + } + } + + if(has_PartMC){ + if(isEditMode()){ + alert(locale_drag.noPartMerge); + } + else{ + tooltip.info(locale_drag.noPartMerge, ""); + } + return; + } + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + let arr = []; + if (getdata.length == 0) { + return; + } + + let clen = getdata[0].length, + offset = parseInt($("#luckysheet-copy-diagonaloffset-value").val()); + + if(offset.toString() == "NaN"){ + if(isEditMode()){ + alert(locale_drag.inputCorrect); + } + else{ + tooltip.info(locale_drag.inputCorrect, ""); + } + return; + } + + if(offset < 0){ + if(isEditMode()){ + alert(locale_drag.offsetColumnLessZero); + } + else{ + tooltip.info(locale_drag.offsetColumnLessZero, ""); + } + return; + } + + if (offset == null) { + offset = 1; + } + + for (let r = 0; r < getdata.length; r++) { + if (r + offset >= clen) { + break; + } + arr.push(getdata[r][r + offset]); + } + + selection.copybyformat(event, JSON.stringify(arr)); + }); + + //复制为布尔值 + $("#luckysheet-copy-boolvalue").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + //复制范围内包含部分合并单元格,提示 + if(Store.config["merge"] != null){ + let has_PartMC = false; + + 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]; + let c1 = Store.luckysheet_select_save[s].column[0], + c2 = Store.luckysheet_select_save[s].column[1]; + + has_PartMC = hasPartMC(Store.config, r1, r2, c1, c2); + + if(has_PartMC){ + break; + } + } + + if(has_PartMC){ + if(isEditMode()){ + alert(locale_drag.noPartMerge); + } + else{ + tooltip.info(locale_drag.noPartMerge, ""); + } + return; + } + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + let arr = []; + if (getdata.length == 0) { + return; + } + for (let r = 0; r < getdata.length; r++) { + let a = []; + for (let c = 0; c < getdata[0].length; c++) { + let bool = false; + + if(getObjType(getdata[r][c]) == "object"){ + let v = getdata[r][c].v; + } + else{ + let v = getdata[r][c]; + } + + if (v == null || v == "") { + bool = false; + } + else { + v = parseInt(v); + if (v == null || v > 0) { + bool = true; + } + else { + bool = false; + } + } + a.push(bool); + } + arr.push(a); + } + + selection.copybyformat(event, JSON.stringify(arr)); + }); + + //矩阵操作选区 翻转 上下 + $("#luckysheet-matrix-turn-up").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + if (getdata.length == 0) { + return; + } + + let arr = []; + for (let r = getdata.length - 1; r >= 0; r--) { + let a = []; + for (let c = 0; c < getdata[0].length; c++) { + let value = ""; + if (getdata[r] != null && getdata[r][c] != null) { + value = getdata[r][c]; + } + a.push(value); + } + arr.push(a); + } + + editor.controlHandler(arr); + }); + + //矩阵操作选区 翻转 左右 + $("#luckysheet-matrix-turn-left").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + if (getdata.length == 0) { + return; + } + + let arr = []; + for (let r = 0; r < getdata.length; r++) { + let a = []; + for (let c = getdata[0].length - 1; c >= 0; c--) { + let value = ""; + if (getdata[r] != null && getdata[r][c] != null) { + value = getdata[r][c]; + } + a.push(value); + } + arr.push(a); + } + + editor.controlHandler(arr); + }); + + //矩阵操作选区 翻转 顺时针 + $("#luckysheet-matrix-turn-cw").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + if (getdata.length == 0) { + return; + } + + let arr = []; + for (let c = 0; c < getdata[0].length; c++) { + let a = []; + for (let r = getdata.length - 1; r >= 0; r--) { + let value = ""; + if (getdata[r] != null && getdata[r][c] != null) { + value = getdata[r][c]; + } + a.push(value); + } + arr.push(a); + } + + editor.controlHandlerD(arr); + }); + + //矩阵操作选区 翻转 逆时针 + $("#luckysheet-matrix-turn-anticw").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + if (getdata.length == 0) { + return; + } + + let arr = []; + for (let c = getdata[0].length - 1; c >= 0; c--) { + let a = []; + for (let r = 0; r < getdata.length; r++) { + let value = ""; + if (getdata[r] != null && getdata[r][c] != null) { + value = getdata[r][c]; + } + a.push(value); + } + arr.push(a); + } + + editor.controlHandlerD(arr); + }); + + //矩阵操作选区 转置 + $("#luckysheet-matrix-turn-trans").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + if (getdata.length == 0) { + return; + } + + let arr = []; + for (let c = 0; c < getdata[0].length; c++) { + let a = []; + for (let r = 0; r < getdata.length; r++) { + let value = ""; + if (getdata[r] != null && getdata[r][c] != null) { + value = getdata[r][c]; + } + a.push(value); + } + arr.push(a); + } + + editor.controlHandlerD(arr); + }); + + let jfnqrt = function (x, p) { + if (x == 0) + return 0; + let x0, x1; + x0 = x; + x1 = ((p - 1) * x0 / p) + (x / (Math.pow(x0, p - 1) * p));//利用迭代法求解 + while (Math.abs(x1 - x0) > 0.000001) { + x0 = x1; + x1 = ((p - 1) * x0 / p) + (x / (Math.pow(x0, p - 1) * p)); + } + return x1; + } + + //矩阵操作选区 矩阵计算 + $("#luckysheet-matrix-cal-confirm").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + if (getdata.length == 0) { + return; + } + + let caltype = $("#luckysheet-matrix-cal-type").val(), + calvalue = parseInt($("#luckysheet-matrix-cal-value").val()); + + if(calvalue.toString() == "NaN"){ + if(isEditMode()){ + alert(locale_drag.inputCorrect); + } + else{ + tooltip.info(locale_drag.inputCorrect, ""); + } + return; + } + + if (calvalue == null) { + calvalue = 2; + } + + let arr = []; + + for (let r = 0; r < getdata.length; r++) { + let a = []; + + for (let c = 0; c < getdata[0].length; c++) { + let value = ""; + if (getdata[r] != null && getdata[r][c] != null) { + value = getdata[r][c]; + if (parseInt(value) != null && getdata[r][c].ct != undefined && getdata[r][c].ct.t == "n") { + if (caltype == "minus") { + value.v = value.v - calvalue; + } + else if (caltype == "multiply") { + value.v = value.v * calvalue; + } + else if (caltype == "divided") { + value.v = numFormat(value.v / calvalue, 4); + } + else if (caltype == "power") { + value.v = Math.pow(value.v, calvalue); + } + else if (caltype == "root") { + if (calvalue == 2) { + value.v = numFormat(Math.sqrt(value.v), 4); + } + else if (calvalue == 3 && Math.cbrt) { + value.v = numFormat(Math.cbrt(value.v), 4); + } + else { + value.v = numFormat(jfnqrt(value.v, calvalue), 4); + } + } + else if (caltype == "log") { + value.v = numFormat(Math.log(value.v) * 10000 / Math.log(Math.abs(calvalue)), 4); + } + else { + value.v = value.v + calvalue; + } + + if(value.v == null){ + value.m = ""; + } + else{ + value.m = value.v.toString(); + } + } + } + a.push(value); + } + arr.push(a); + } + + editor.controlHandler(arr); + }); + + //矩阵操作选区 删除两端0值 按行 + $("#luckysheet-matrix-delezero-row").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + if (getdata.length == 0) { + return; + } + + let arr = []; + let getdatalen = getdata[0].length; + for (let r = 0; r < getdata.length; r++) { + let a = [], stdel = true, eddel = true; + for (let c = 0; c < getdatalen; c++) { + let value = ""; + if (getdata[r] != null && getdata[r][c] != null) { + value = getdata[r][c]; + if ((value.v == "0" || value.v == 0) && stdel) { + continue; + } + else { + stdel = false; + } + } + a.push(value); + } + + let a1 = []; + if (a.length == getdatalen) { + a1 = a; + } + else { + for (let c = a.length - 1; c >= 0; c--) { + let value = ""; + if (a[c] != null) { + value = a[c]; + if ((value.v == "0" || value.v == 0) && eddel) { + continue; + } + else { + eddel = false; + } + } + a1.unshift(value); + } + + let l = getdatalen - a1.length; + for (let c1 = 0; c1 < l; c1++) { + a1.push(""); + } + } + arr.push(a1); + } + + editor.controlHandler(arr); + }); + + //矩阵操作选区 删除两端0值 按列 + $("#luckysheet-matrix-delezero-column").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + if (getdata.length == 0) { + return; + } + + let arr = []; + let getdatalen = getdata.length, collen = getdata[0].length; + for (let c = 0; c < collen; c++) { + let a = [], stdel = true, eddel = true; + for (let r = 0; r < getdatalen; r++) { + let value = ""; + if (getdata[r] != null && getdata[r][c] != null) { + value = getdata[r][c]; + if ((value.v == "0" || value.v == 0) && stdel) { + continue; + } + else { + stdel = false; + } + } + a.push(value); + } + + let a1 = []; + if (a.length == getdatalen) { + a1 = a; + } + else { + for (let r = a.length - 1; r >= 0; r--) { + let value = ""; + if (a[r] != null) { + value = a[r]; + if ((value.v == "0" || value.v == 0) && eddel) { + continue; + } + else { + eddel = false; + } + } + a1.unshift(value); + } + + let l = getdatalen - a1.length; + for (let r1 = 0; r1 < l; r1++) { + a1.push(""); + } + } + arr.push(a1); + } + + let arr1 = []; + for (let c = 0; c < arr[0].length; c++) { + let a = []; + for (let r = 0; r < arr.length; r++) { + let value = ""; + if (arr[r] != null && arr[r][c] != null) { + value = arr[r][c]; + } + a.push(value); + } + arr1.push(a); + } + + editor.controlHandler(arr1); + }); + + //矩阵操作选区 删除重复值 按行 + $("#luckysheet-matrix-delerpt-row").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + if (getdata.length == 0) { + return; + } + + let arr = []; + let getdatalen = getdata[0].length; + for (let r = 0; r < getdata.length; r++) { + let a = [], repeat = {}; + + for (let c = 0; c < getdatalen; c++) { + let value = null; + if (getdata[r] != null && getdata[r][c] != null) { + value = getdata[r][c]; + + if(value.v in repeat){ + repeat[value.v].push(value); + } + else{ + repeat[value.v] = []; + repeat[value.v].push(value); + } + } + } + + for (let c = 0; c < getdatalen; c++) { + let value = null; + if (getdata[r] != null && getdata[r][c] != null) { + value = getdata[r][c]; + + if(repeat[value.v].length == 1){ + a.push(value); + } + } + } + + let l = getdatalen - a.length; + for (let c1 = 0; c1 < l; c1++) { + a.push(null); + } + arr.push(a); + } + + editor.controlHandler(arr); + }); + + //矩阵操作选区 删除重复值 按列 + $("#luckysheet-matrix-delerpt-column").click(function (event) { + $("body .luckysheet-cols-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + return; + } + + let getdata = getdatabyselection(Store.luckysheet_select_save[0]); + if (getdata.length == 0) { + return; + } + + let arr = []; + let getdatalen = getdata.length, collen = getdata[0].length; + for (let c = 0; c < collen; c++) { + let a = [], repeat = {}; + + for (let r = 0; r < getdatalen; r++) { + let value = null; + if (getdata[r] != null && getdata[r][c] != null) { + value = getdata[r][c]; + + if(value.v in repeat){ + repeat[value.v].push(value); + } + else{ + repeat[value.v] = []; + repeat[value.v].push(value); + } + } + } + + for (let r = 0; r < getdatalen; r++) { + let value = null; + if (getdata[r] != null && getdata[r][c] != null) { + value = getdata[r][c]; + + if(repeat[value.v].length == 1){ + a.push(value); + } + } + } + + a1 = a; + let l = getdatalen - a1.length; + for (let r1 = 0; r1 < l; r1++) { + a1.push(null); + } + arr.push(a1); + } + + let arr1 = []; + for (let c = 0; c < arr[0].length; c++) { + let a = []; + for (let r = 0; r < arr.length; r++) { + let value = null; + if (arr[r] != null && arr[r][c] != null) { + value = arr[r][c]; + } + a.push(value); + } + arr1.push(a); + } + + editor.controlHandler(arr1); + }); +} \ No newline at end of file diff --git a/src/controllers/orderBy.js b/src/controllers/orderBy.js new file mode 100644 index 000000000..f8550401b --- /dev/null +++ b/src/controllers/orderBy.js @@ -0,0 +1,273 @@ + +import { modelHTML } from './constant'; + +import { selectHightlightShow } from './select'; + +import { + replaceHtml, + chatatABC, +} from '../utils/util'; +import { rowlenByRange } from '../global/getRowlen'; +import { isEditMode } from '../global/validate'; +import cleargridelement from '../global/cleargridelement'; +import { + jfrefreshgrid, +} from '../global/refresh'; +import { getcellvalue } from '../global/getdata'; +import { orderbydata, sortColumnSeletion } from '../global/sort'; +import tooltip from '../global/tooltip'; +import editor from '../global/editor'; +import { isdatatype } from '../global/datecontroll'; +import Store from '../store'; +import locale from '../locale/locale'; + + +export function orderByInitial(){ + const _locale = locale(); + //菜单栏 排序按钮 + $("#luckysheetorderbyasc, #luckysheetorderbyasc_t").mousedown(function (event) { + cleargridelement(event); + sortColumnSeletion(Store.orderbyindex, true); + selectHightlightShow(); + }); + + $("#luckysheetorderbydesc, #luckysheetorderbydesc_t").click(function (event) { + cleargridelement(event); + sortColumnSeletion(Store.orderbyindex, false); + selectHightlightShow(); + }); + + //排序事件 + let luckysheet_sort_initial = true; + $("#luckysheetorderby").click(function () { + $("body .luckysheet-cols-menu").hide(); + const locale_sort = _locale.sort; + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_sort.noRangeError); + } + else{ + tooltip.info(locale_sort.noRangeError, ""); + } + return; + } + + let last = Store.luckysheet_select_save[0]; + let r1 = last["row"][0], r2 = last["row"][1]; + let c1 = last["column"][0], c2 = last["column"][1]; + + if (luckysheet_sort_initial) { + luckysheet_sort_initial = false; + + let content = `
${locale_sort.hasTitle}
+ ${locale_sort.addOthers}
`; + + $("body").append(replaceHtml(modelHTML, { "id": "luckysheet-sort-dialog", "addclass": "", "title": _locale.sort.sortTitle, "content": content, "botton": ``})); + + $("#luckysheet-sort-dialog .luckysheet-sort-dialog-additem").click(function () { + let last = Store.luckysheet_select_save[0]; + let r1 = last["row"][0], r2 = last["row"][1]; + let c1 = last["column"][0], c2 = last["column"][1]; + + let option = "", i = $("#luckysheet-sort-dialog table").data("itemcount") + 1; + let t = $("#luckysheet-sort-haveheader").is(':checked'); + + for (let c = c1; c <= c2; c++) { + if (t) { + let v = getcellvalue(r1, c, Store.flowdata, "m"); + + if(v == null){ + v = locale_sort.columnOperation + (c - c1 + 1); + } + + option += ''; + } + else { + option += ''; + } + } + + $("#luckysheet-sort-dialog table").append(` + + ${locale_sort.secondaryTitle} + +
+
+
+ + + `); + $("#luckysheet-sort-dialog table").data("itemcount", i); + }); + + $("#luckysheet-sort-haveheader").change(function () { + let last = Store.luckysheet_select_save[0]; + let r1 = last["row"][0], r2 = last["row"][1]; + let c1 = last["column"][0], c2 = last["column"][1]; + + let t = $(this).is(':checked'); + let option = ""; + + for (let c = c1; c <= c2; c++) { + if (t) { + let v = getcellvalue(r1, c, Store.flowdata, "m"); + + if(v == null){ + v = locale_sort.columnOperation + (c - c1 + 1); + } + + option += ''; + } + else { + option += ''; + } + } + + $("#luckysheet-sort-dialog tr select").each(function () { + $(this).html(option); + }); + }); + + //Custom sort + $("#luckysheet-sort-modal-confirm").click(function () { + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_sort.noRangeError); + } + else{ + tooltip.info(locale_sort.noRangeError, ""); + } + + return; + } + + let d = editor.deepCopyFlowData(Store.flowdata); + + let last = Store.luckysheet_select_save[0]; + let r1 = last["row"][0], r2 = last["row"][1]; + let c1 = last["column"][0], c2 = last["column"][1]; + + //Data has header row + let t = $("#luckysheet-sort-haveheader").is(':checked'); + + let str; + if(t){ + str = r1 + 1; + } + else{ + str = r1; + } + + let hasMc = false; //Whether the sort selection has merged cells + + let data = []; + + for(let r = str; r <= r2; r++){ + let data_row = []; + + for(let c = c1; c <= c2; c++){ + if(d[r][c] != null && d[r][c].mc != null){ + hasMc = true; + break; + } + + data_row.push(d[r][c]); + } + + data.push(data_row); + } + + if(hasMc){ + if(isEditMode()){ + alert(locale_sort.mergeError); + } + else{ + tooltip.info(locale_sort.mergeError, ""); + } + + return; + } + + $($("#luckysheet-sort-dialog table tr").toArray().reverse()).each(function () { + let i = $(this).find("select").val(), + asc = $(this).find('input:radio:checked').val(); + + i -= c1; + + if (asc == "asc") { + asc = true; + } + else { + asc = false; + } + + data = orderbydata([].concat(data), i, asc); + }); + + for(let r = str; r <= r2; r++){ + for(let c = c1; c <= c2; c++){ + d[r][c] = data[r - str][c - c1]; + } + } + + if(Store.config["rowlen"] != null){ + let cfg = $.extend(true, {}, Store.config); + cfg = rowlenByRange(d, str, r2, cfg); + + jfrefreshgrid(d, [{ "row": [str, r2], "column": [c1, c2] }], cfg, null, true); + } + else{ + jfrefreshgrid(d, [{ "row": [str, r2], "column": [c1, c2] }]); + } + + $("#luckysheet-sort-dialog").hide(); + $("#luckysheet-modal-dialog-mask").hide(); + }); + } + + let option = ""; + for (let c = c1; c <= c2; c++) { + option += ''; + } + + $("#luckysheet-sort-dialog select").html(option); + + $("#luckysheet-sort-dialog .luckysheet-sort-dialog-tr").remove(); + + $("#luckysheet-sort-haveheader").prop("checked", false); + $("#luckysheet-sort-dialog input:radio:first").prop("checked", "checked"); + + $("#luckysheet-sort-dialog .luckysheet-modal-dialog-title-text").html(locale_sort.sortRangeTitle+"" + chatatABC(c1) + (r1 + 1) + ""+ locale_sort.sortRangeTitleTo +"" + chatatABC(c2) + (r2 + 1) + ""); + + let $t = $("#luckysheet-sort-dialog"), myh = $t.outerHeight(), myw = $t.outerWidth(); + let winw = $(window).width(), winh = $(window).height(); + let scrollLeft = $(document).scrollLeft(), scrollTop = $(document).scrollTop(); + + $("#luckysheet-sort-dialog-tablec").css("max-height", (winh - myh) / 2); + $("#luckysheet-sort-dialog").css({ "left": (winw + scrollLeft - myw) / 2, "top": (winh + scrollTop - myh) / 2 }).show(); + $("#luckysheet-modal-dialog-mask").show(); + + if (r1 < r2) { + setTimeout(function () { + let flowrowdata1 = Store.flowdata[r1], + flowrowdata2 = Store.flowdata[r1 + 1], + hastitle = false; + + for (let i = c1; i <= c2; i++) { + let isdatatype_r1 = isdatatype(flowrowdata1[i]), + isdatatype_r2 = isdatatype(flowrowdata2[i]); + + if (isdatatype_r1 != isdatatype_r2) { + hastitle = true; + } + } + + if (hastitle) { + $("#luckysheet-sort-haveheader").prop("checked", true).change(); + } + }, 10); + } + }); +} \ No newline at end of file diff --git a/src/controllers/pivotTable.js b/src/controllers/pivotTable.js index 888e12908..aea4af5f9 100644 --- a/src/controllers/pivotTable.js +++ b/src/controllers/pivotTable.js @@ -873,7 +873,7 @@ const pivotTable = { if (_this.initial) { _this.initial = false; - $("body").append(luckysheetPivotTableHTML); + $("body").append(luckysheetPivotTableHTML()); $("#luckysheet-modal-dialog-slider-close").click(function () { $("#luckysheet-modal-dialog-slider-pivot").hide(); luckysheetsizeauto(); diff --git a/src/controllers/rowColumnOperation.js b/src/controllers/rowColumnOperation.js new file mode 100644 index 000000000..5ba87e118 --- /dev/null +++ b/src/controllers/rowColumnOperation.js @@ -0,0 +1,1620 @@ + +import pivotTable from './pivotTable'; +import luckysheetPostil from './postil'; +import menuButton from './menuButton'; +import server from './server'; +import { selectHightlightShow, luckysheet_count_show } from './select'; +import { + getObjType, + showrightclickmenu, +} from '../utils/util'; +import { getSheetIndex, getRangetxt } from '../methods/get'; +import { + rowLocation, + rowLocationByIndex, + colLocation, + colLocationByIndex, + mouseposition +} from '../global/location'; +import { isRealNull, isRealNum, hasPartMC, isEditMode } from '../global/validate'; +import { countfunc } from '../global/count'; +import formula from '../global/formula'; +import { luckysheetextendtable, luckysheetdeletetable } from '../global/extend'; +import { + jfrefreshgrid, + jfrefreshgridall, + jfrefreshgrid_rhcw, +} from '../global/refresh'; +import { getcellvalue } from '../global/getdata'; +import tooltip from '../global/tooltip'; +import editor from '../global/editor'; +import locale from '../locale/locale'; +import Store from '../store'; + + + +export function rowColumnOperationInitial(){ + + + //表格行标题 mouse事件 + $("#luckysheet-rows-h").mousedown(function (event) { + //有批注在编辑时 + luckysheetPostil.removeActivePs(); + + let mouse = mouseposition(event.pageX, event.pageY); + let y = mouse[1] + $("#luckysheet-rows-h").scrollTop(); + + let row_location = rowLocation(y), + row = row_location[1], + row_pre = row_location[0], + row_index = row_location[2]; + let col_index = Store.visibledatacolumn.length - 1, + col = Store.visibledatacolumn[col_index], col_pre = 0; + + $("#luckysheet-rightclick-menu").hide(); + $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); + + //mousedown是右键 + if (event.which == "3") { + let isright = false; + + for(let s = 0; s < Store.luckysheet_select_save.length; s++){ + let obj_s = Store.luckysheet_select_save[s]; + + if(obj_s["row"] != null && (row_index >= obj_s["row"][0] && row_index <= obj_s["row"][1]) && (obj_s["column"][0] == 0 && obj_s["column"][1] == Store.flowdata[0].length - 1)){ + isright = true; + break; + } + } + + if(isright){ + return; + } + } + + let top = row_pre, height = row - row_pre - 1; + let rowseleted = [row_index, row_index]; + + Store.luckysheet_scroll_status = true; + + //公式相关 + let $input = $("#luckysheet-input-box"); + if (parseInt($input.css("top")) > 0) { + if (formula.rangestart || formula.rangedrag_column_start || formula.rangedrag_row_start || formula.israngeseleciton() || $("#luckysheet-ifFormulaGenerator-multiRange-dialog").is(":visible")) { + //公式选区 + let changeparam = menuButton.mergeMoveMain([0, col_index], rowseleted, {"row_focus": row_index, "column_focus": 0}, top, height, col_pre, col); + if(changeparam != null){ + //columnseleted = changeparam[0]; + rowseleted = changeparam[1]; + top = changeparam[2]; + height = changeparam[3]; + //left = changeparam[4]; + //width = changeparam[5]; + } + + if(event.shiftKey){ + let last = formula.func_selectedrange; + + let top = 0, height = 0, rowseleted = []; + if (last.top > row_pre) { + top = row_pre; + height = last.top + last.height - row_pre; + + if(last.row[1] > last.row_focus){ + last.row[1] = last.row_focus; + } + + rowseleted = [row_index, last.row[1]]; + } + else if (last.top == row_pre) { + top = row_pre; + height = last.top + last.height - row_pre; + rowseleted = [row_index, last.row[0]]; + } + else { + top = last.top; + height = row - last.top - 1; + + if(last.row[0] < last.row_focus){ + last.row[0] = last.row_focus; + } + + rowseleted = [last.row[0], row_index]; + } + + let changeparam = menuButton.mergeMoveMain([0, col_index], rowseleted, {"row_focus": row_index, "column_focus": 0}, top, height, col_pre, col); + if(changeparam != null){ + // columnseleted = changeparam[0]; + rowseleted = changeparam[1]; + top = changeparam[2]; + height = changeparam[3]; + // left = changeparam[4]; + // width = changeparam[5]; + } + + last["row"] = rowseleted; + + last["top_move"] = top; + last["height_move"] = height; + + formula.func_selectedrange = last; + } + else if(event.ctrlKey && $("#luckysheet-rich-text-editor").find("span").last().text() != ","){ + //按住ctrl 选择选区时 先处理上一个选区 + let vText = $("#luckysheet-rich-text-editor").text() + ","; + if(vText.length > 0 && vText.substr(0, 1) == "="){ + vText = formula.functionHTMLGenerate(vText); + + if (window.getSelection) { // all browsers, except IE before version 9 + let currSelection = window.getSelection(); + formula.functionRangeIndex = [$(currSelection.anchorNode).parent().index(), currSelection.anchorOffset]; + } + else { // Internet Explorer before version 9 + let textRange = document.selection.createRange(); + formula.functionRangeIndex = textRange; + } + + $("#luckysheet-rich-text-editor").html(vText); + + formula.canceFunctionrangeSelected(); + formula.createRangeHightlight(); + } + + formula.rangestart = false; + formula.rangedrag_column_start = false; + formula.rangedrag_row_start = false; + + $("#luckysheet-functionbox-cell").html(vText); + formula.rangeHightlightselected($("#luckysheet-rich-text-editor")); + + //再进行 选区的选择 + formula.israngeseleciton(); + formula.func_selectedrange = { + "left": colLocationByIndex(0)[0], + "width": colLocationByIndex(0)[1] - colLocationByIndex(0)[0] - 1, + "top": top, + "height": height, + "left_move": col_pre, + "width_move": col - col_pre - 1, + "top_move": top, + "height_move": height, + "row": rowseleted, + "column": [0, col_index], + "row_focus": row_index, + "column_focus": 0 + } + } + else{ + formula.func_selectedrange = { + "left": colLocationByIndex(0)[0], + "width": colLocationByIndex(0)[1] - colLocationByIndex(0)[0] - 1, + "top": top, + "height": height, + "left_move": col_pre, + "width_move": col - col_pre - 1, + "top_move": top, + "height_move": height, + "row": rowseleted, + "column": [0, col_index], + "row_focus": row_index, + "column_focus": 0 + } + } + + if(formula.rangestart || formula.rangedrag_column_start || formula.rangedrag_row_start || formula.israngeseleciton()){ + formula.rangeSetValue({ "row": rowseleted, "column": [null, null] }); + } + else if($("#luckysheet-ifFormulaGenerator-multiRange-dialog").is(":visible")){//if公式生成器 + let range = getRangetxt(Store.currentSheetIndex, { "row": rowseleted, "column": [0, col_index] }, Store.currentSheetIndex); + $("#luckysheet-ifFormulaGenerator-multiRange-dialog input").val(range); + } + + formula.rangedrag_row_start = true; + formula.rangestart = false; + formula.rangedrag_column_start = false; + + $("#luckysheet-formula-functionrange-select").css({ + "left": col_pre, + "width": col - col_pre - 1, + "top": top, + "height": height + }).show(); + $("#luckysheet-formula-help-c").hide(); + + luckysheet_count_show(col_pre, top, col - col_pre - 1, height, rowseleted, [0, col_index]); + + setTimeout(function(){ + let currSelection = window.getSelection(); + let anchorOffset = currSelection.anchorNode; + + let $editor; + if($("#luckysheet-search-formula-parm").is(":visible")||$("#luckysheet-search-formula-parm-select").is(":visible")){ + $editor = $("#luckysheet-rich-text-editor"); + formula.rangechangeindex = formula.data_parm_index; + } + else{ + $editor = $(anchorOffset).closest("div"); + } + + let $span = $editor.find("span[rangeindex='" + formula.rangechangeindex + "']"); + + formula.setCaretPosition($span.get(0), 0, $span.html().length); + }, 1); + + return; + } + else { + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + Store.luckysheet_rows_selected_status = true; + } + } + else { + Store.luckysheet_rows_selected_status = true; + } + + if (Store.luckysheet_rows_selected_status) { + if(event.shiftKey){ + //按住shift点击行索引选取范围 + let last = $.extend(true, {}, Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]); //选区最后一个 + + let top = 0, height = 0, rowseleted = []; + if (last.top > row_pre) { + top = row_pre; + height = last.top + last.height - row_pre; + + if(last.row[1] > last.row_focus){ + last.row[1] = last.row_focus; + } + + rowseleted = [row_index, last.row[1]]; + } + else if (last.top == row_pre) { + top = row_pre; + height = last.top + last.height - row_pre; + rowseleted = [row_index, last.row[0]]; + } + else { + top = last.top; + height = row - last.top - 1; + + if(last.row[0] < last.row_focus){ + last.row[0] = last.row_focus; + } + + rowseleted = [last.row[0], row_index]; + } + + last["row"] = rowseleted; + + last["top_move"] = top; + last["height_move"] = height; + + Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1] = last; + } + else if(event.ctrlKey){ + Store.luckysheet_select_save.push({ + "left": colLocationByIndex(0)[0], + "width": colLocationByIndex(0)[1] - colLocationByIndex(0)[0] - 1, + "top": top, + "height": height, + "left_move": col_pre, + "width_move": col - col_pre - 1, + "top_move": top, + "height_move": height, + "row": rowseleted, + "column": [0, col_index], + "row_focus": row_index, + "column_focus": 0 + }); + } + else{ + Store.luckysheet_select_save = []; + Store.luckysheet_select_save.push({ + "left": colLocationByIndex(0)[0], + "width": colLocationByIndex(0)[1] - colLocationByIndex(0)[0] - 1, + "top": top, + "height": height, + "left_move": col_pre, + "width_move": col - col_pre - 1, + "top_move": top, + "height_move": height, + "row": rowseleted, + "column": [0, col_index], + "row_focus": row_index, + "column_focus": 0 + }); + } + + selectHightlightShow(); + + if(server.allowUpdate){ + //允许编辑后的后台更新时 + server.saveParam("mv", Store.currentSheetIndex, Store.luckysheet_select_save); + } + } + + $("#luckysheet-helpbox-cell").text(getRangetxt(Store.currentSheetIndex, Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1])); + + setTimeout(function () { + clearTimeout(Store.countfuncTimeout); + countfunc(); + }, 101); + }).mousemove(function (event) { + if (Store.luckysheet_rows_selected_status || Store.luckysheet_rows_change_size || Store.luckysheet_select_status) { + $("#luckysheet-rows-h-hover").hide(); + return; + } + + let mouse = mouseposition(event.pageX, event.pageY); + let y = mouse[1] + $("#luckysheet-rows-h").scrollTop(); + + let row_location = rowLocation(y), + row = row_location[1], + row_pre = row_location[0], + row_index = row_location[2]; + + $("#luckysheet-rows-h-hover").css({ "top": row_pre, "height": row - row_pre - 1, "display": "block" }); + + if (y < row - 1 && y >= row - 5) { + $("#luckysheet-rows-change-size").css({ "top": row - 3, "opacity": 0 }); + } + else { + $("#luckysheet-rows-change-size").css("opacity", 0); + } + }).mouseleave(function (event) { + $("#luckysheet-rows-h-hover").hide(); + $("#luckysheet-rows-change-size").css("opacity", 0); + }).mouseup(function (event) { + if (event.which == 3) { + if(isEditMode()){ //非编辑模式下禁止右键功能框 + return; + } + + $("#luckysheet-cols-rows-shift").hide(); + Store.luckysheetRightHeadClickIs = "row"; + $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-word").text(locale().rightclick.row); + $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-size").text(locale().rightclick.height); + $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-left").text(locale().rightclick.top); + $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-right").text(locale().rightclick.bottom); + + $("#luckysheet-cols-rows-add").show(); + $("#luckysheet-cols-rows-data").show(); + $("#luckysheet-cols-rows-shift").hide(); + $("#luckysheet-cols-rows-handleincell").hide(); + + showrightclickmenu($("#luckysheet-rightclick-menu"), $(this).offset().left + 46, event.pageY); + Store.luckysheet_cols_menu_status = true; + + //行高默认值 + let cfg = $.extend(true, {}, Store.config); + if(cfg["rowlen"] == null){ + cfg["rowlen"] = {}; + } + + let first_rowlen = cfg["rowlen"][Store.luckysheet_select_save[0].row[0]] == null ? Store.defaultrowlen : cfg["rowlen"][Store.luckysheet_select_save[0].row[0]]; + let isSame = true; + + for(let i = 0; i < Store.luckysheet_select_save.length; i++){ + let s = Store.luckysheet_select_save[i]; + let r1 = s.row[0], r2 = s.row[1]; + + for(let r = r1; r <= r2; r++){ + let rowlen = cfg["rowlen"][r] == null ? Store.defaultrowlen : cfg["rowlen"][r]; + + if(rowlen != first_rowlen){ + isSame = false; + break; + } + } + } + + if(isSame){ + $("#luckysheet-cols-rows-add").find("input[type='number'].rcsize").val(first_rowlen); + } + else{ + $("#luckysheet-cols-rows-add").find("input[type='number'].rcsize").val(""); + } + } + }); + + //表格列标题 mouse事件 + $("#luckysheet-cols-h-c").mousedown(function (event) { + //有批注在编辑时 + luckysheetPostil.removeActivePs(); + + let mouse = mouseposition(event.pageX, event.pageY); + let x = mouse[0] + $(this).scrollLeft(); + + let row_index = Store.visibledatarow.length - 1, + row = Store.visibledatarow[row_index], row_pre = 0; + let col_location = colLocation(x), + col = col_location[1], + col_pre = col_location[0], + col_index = col_location[2]; + + Store.orderbyindex = col_index;//排序全局函数 + + $("#luckysheet-rightclick-menu").hide(); + $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); + $("#luckysheet-filter-menu, #luckysheet-filter-submenu").hide(); + + //mousedown是右键 + if (event.which == "3") { + let isright = false; + + for(let s = 0; s < Store.luckysheet_select_save.length; s++){ + let obj_s = Store.luckysheet_select_save[s]; + + if(obj_s["column"] != null && (col_index >= obj_s["column"][0] && col_index <= obj_s["column"][1]) && (obj_s["row"][0] == 0 && obj_s["row"][1] == Store.flowdata.length - 1)){ + isright = true; + break; + } + } + + if(isright){ + return; + } + } + + let left = col_pre, width = col - col_pre - 1; + let columnseleted = [col_index, col_index]; + + Store.luckysheet_scroll_status = true; + + //公式相关 + let $input = $("#luckysheet-input-box"); + if (parseInt($input.css("top")) > 0) { + if (formula.rangestart || formula.rangedrag_column_start || formula.rangedrag_row_start || formula.israngeseleciton() || $("#luckysheet-ifFormulaGenerator-multiRange-dialog").is(":visible")) { + //公式选区 + let changeparam = menuButton.mergeMoveMain(columnseleted, [0, row_index], {"row_focus": 0, "column_focus": col_index}, row_pre, row, left, width); + if(changeparam != null){ + columnseleted = changeparam[0]; + //rowseleted= changeparam[1]; + //top = changeparam[2]; + //height = changeparam[3]; + left = changeparam[4]; + width = changeparam[5]; + } + + if(event.shiftKey){ + let last = formula.func_selectedrange; + + let left = 0, width = 0, columnseleted = []; + if (last.left > col_pre) { + left = col_pre; + width = last.left + last.width - col_pre; + + if(last.column[1] > last.column_focus){ + last.column[1] = last.column_focus; + } + + columnseleted = [col_index, last.column[1]]; + } + else if (last.left == col_pre) { + left = col_pre; + width = last.left + last.width - col_pre; + columnseleted = [col_index, last.column[0]]; + } + else { + left = last.left; + width = col - last.left - 1; + + if(last.column[0] < last.column_focus){ + last.column[0] = last.column_focus; + } + + columnseleted = [last.column[0], col_index]; + } + + let changeparam = menuButton.mergeMoveMain(columnseleted , [0, row_index], {"row_focus": 0, "column_focus": col_index}, row_pre, row, left, width); + if(changeparam != null){ + columnseleted = changeparam[0]; + //rowseleted= changeparam[1]; + //top = changeparam[2]; + //height = changeparam[3]; + left = changeparam[4]; + width = changeparam[5]; + } + + last["column"] = columnseleted; + + last["left_move"] = left; + last["width_move"] = width; + + formula.func_selectedrange = last; + } + else if(event.ctrlKey && $("#luckysheet-rich-text-editor").find("span").last().text() != ","){ + //按住ctrl 选择选区时 先处理上一个选区 + let vText = $("#luckysheet-rich-text-editor").text() + ","; + if(vText.length > 0 && vText.substr(0, 1) == "="){ + vText = formula.functionHTMLGenerate(vText); + + if (window.getSelection) { // all browsers, except IE before version 9 + let currSelection = window.getSelection(); + formula.functionRangeIndex = [$(currSelection.anchorNode).parent().index(), currSelection.anchorOffset]; + } + else { // Internet Explorer before version 9 + let textRange = document.selection.createRange(); + formula.functionRangeIndex = textRange; + } + + $("#luckysheet-rich-text-editor").html(vText); + + formula.canceFunctionrangeSelected(); + formula.createRangeHightlight(); + } + + formula.rangestart = false; + formula.rangedrag_column_start = false; + formula.rangedrag_row_start = false; + + $("#luckysheet-functionbox-cell").html(vText); + formula.rangeHightlightselected($("#luckysheet-rich-text-editor")); + + //再进行 选区的选择 + formula.israngeseleciton(); + formula.func_selectedrange = { + "left": left, + "width": width, + "top": rowLocationByIndex(0)[0], + "height": rowLocationByIndex(0)[1] - rowLocationByIndex(0)[0] - 1, + "left_move": left, + "width_move": width, + "top_move": row_pre, + "height_move": row - row_pre - 1, + "row": [0, row_index], + "column": columnseleted, + "row_focus": 0, + "column_focus": col_index + } + } + else{ + formula.func_selectedrange = { + "left": left, + "width": width, + "top": rowLocationByIndex(0)[0], + "height": rowLocationByIndex(0)[1] - rowLocationByIndex(0)[0] - 1, + "left_move": left, + "width_move": width, + "top_move": row_pre, + "height_move": row - row_pre - 1, + "row": [0, row_index], + "column": columnseleted, + "row_focus": 0, + "column_focus": col_index + } + } + + if(formula.rangestart || formula.rangedrag_column_start || formula.rangedrag_row_start || formula.israngeseleciton()){ + formula.rangeSetValue({ "row": [null, null], "column": columnseleted }); + } + else if($("#luckysheet-ifFormulaGenerator-multiRange-dialog").is(":visible")){//if公式生成器 + let range = getRangetxt(Store.currentSheetIndex, { "row": [0, row_index], "column": columnseleted }, Store.currentSheetIndex); + $("#luckysheet-ifFormulaGenerator-multiRange-dialog input").val(range); + } + + formula.rangedrag_column_start = true; + formula.rangestart = false; + formula.rangedrag_row_start = false; + + $("#luckysheet-formula-functionrange-select").css({ + "left": left, + "width": width, + "top": row_pre, + "height": row - row_pre - 1 + }).show(); + $("#luckysheet-formula-help-c").hide(); + + luckysheet_count_show(left, row_pre, width, row - row_pre - 1, [0, row_index], columnseleted); + + return; + } + else { + formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]); + Store.luckysheet_cols_selected_status = true; + } + } + else { + Store.luckysheet_cols_selected_status = true; + } + + if (Store.luckysheet_cols_selected_status) { + if(event.shiftKey){ + //按住shift点击列索引选取范围 + let last = $.extend(true, {}, Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1]); //选区最后一个 + + let left = 0, width = 0, columnseleted = []; + if (last.left > col_pre) { + left = col_pre; + width = last.left + last.width - col_pre; + + if(last.column[1] > last.column_focus){ + last.column[1] = last.column_focus; + } + + columnseleted = [col_index, last.column[1]]; + } + else if (last.left == col_pre) { + left = col_pre; + width = last.left + last.width - col_pre; + columnseleted = [col_index, last.column[0]]; + } + else { + left = last.left; + width = col - last.left - 1; + + if(last.column[0] < last.column_focus){ + last.column[0] = last.column_focus; + } + + columnseleted = [last.column[0], col_index]; + } + + last["column"] = columnseleted; + + last["left_move"] = left; + last["width_move"] = width; + + Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1] = last; + } + else if(event.ctrlKey){ + //选区添加 + Store.luckysheet_select_save.push({ + "left": left, + "width": width, + "top": rowLocationByIndex(0)[0], + "height": rowLocationByIndex(0)[1] - rowLocationByIndex(0)[0] - 1, + "left_move": left, + "width_move": width, + "top_move": row_pre, + "height_move": row - row_pre - 1, + "row": [0, row_index], + "column": columnseleted, + "row_focus": 0, + "column_focus": col_index + }); + } + else{ + Store.luckysheet_select_save = []; + Store.luckysheet_select_save.push({ + "left": left, + "width": width, + "top": rowLocationByIndex(0)[0], + "height": rowLocationByIndex(0)[1] - rowLocationByIndex(0)[0] - 1, + "left_move": left, + "width_move": width, + "top_move": row_pre, + "height_move": row - row_pre - 1, + "row": [0, row_index], + "column": columnseleted, + "row_focus": 0, + "column_focus": col_index + }); + } + + selectHightlightShow(); + + if(server.allowUpdate){ + //允许编辑后的后台更新时 + server.saveParam("mv", Store.currentSheetIndex, Store.luckysheet_select_save); + } + } + + $("#luckysheet-helpbox-cell").text(getRangetxt(Store.currentSheetIndex, Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1])); + + setTimeout(function () { + clearTimeout(Store.countfuncTimeout); + countfunc(); + }, 101); + + if (Store.luckysheet_cols_menu_status) { + $("#luckysheet-rightclick-menu").hide(); + $("#luckysheet-cols-h-hover").hide(); + $("#luckysheet-cols-menu-btn").hide(); + Store.luckysheet_cols_menu_status = false; + } + event.stopPropagation(); + }).mousemove(function (event) { + if (Store.luckysheet_cols_selected_status || Store.luckysheet_select_status) { + $("#luckysheet-cols-h-hover").hide(); + $("#luckysheet-cols-menu-btn").hide(); + return; + } + + if (Store.luckysheet_cols_menu_status || Store.luckysheet_cols_change_size) { + return; + } + + let mouse = mouseposition(event.pageX, event.pageY); + let x = mouse[0] + $("#luckysheet-cols-h-c").scrollLeft(); + + let col_location = colLocation(x), + col = col_location[1], + col_pre = col_location[0], + col_index = col_location[2]; + + $("#luckysheet-cols-h-hover").css({ "left": col_pre, "width": col - col_pre - 1, "display": "block" }); + $("#luckysheet-cols-menu-btn").css({ "left": col - 19, "display": "block" }); + + $("#luckysheet-cols-change-size").css({ "left": col - 5 }); + if (x < col && x >= col - 5) { + $("#luckysheet-cols-change-size").css({ "opacity": 0 }); + $("#luckysheet-cols-menu-btn").hide(); + } + else { + $("#luckysheet-change-size-line").hide(); + $("#luckysheet-cols-change-size").css("opacity", 0); + } + }).mouseleave(function (event) { + if (Store.luckysheet_cols_menu_status || Store.luckysheet_cols_change_size) { + return; + } + + $("#luckysheet-cols-h-hover").hide(); + $("#luckysheet-cols-menu-btn").hide(); + $("#luckysheet-cols-change-size").css("opacity", 0); + }).mouseup(function (event) { + if (event.which == 3) { + if(isEditMode()){ //非编辑模式下禁止右键功能框 + return; + } + + Store.luckysheetRightHeadClickIs = "column"; + $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-word").text(locale().rightclick.column); + $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-size").text(locale().rightclick.width); + $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-left").text(locale().rightclick.left); + $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-right").text(locale().rightclick.right); + + $("#luckysheet-cols-rows-add").show(); + $("#luckysheet-cols-rows-data").show(); + $("#luckysheet-cols-rows-shift").hide(); + $("#luckysheet-cols-rows-handleincell").hide(); + + showrightclickmenu($("#luckysheet-rightclick-menu"), event.pageX, $(this).offset().top + 18); + Store.luckysheet_cols_menu_status = true; + + //列宽默认值 + let cfg = $.extend(true, {}, Store.config); + if(cfg["columlen"] == null){ + cfg["columlen"] = {}; + } + + let first_collen = cfg["columlen"][Store.luckysheet_select_save[0].column[0]] == null ? Store.defaultcollen : cfg["columlen"][Store.luckysheet_select_save[0].column[0]]; + let isSame = true; + + for(let i = 0; i < Store.luckysheet_select_save.length; i++){ + let s = Store.luckysheet_select_save[i]; + let c1 = s.column[0], c2 = s.column[1]; + + for(let c = c1; c <= c2; c++){ + let collen = cfg["columlen"][c] == null ? Store.defaultcollen : cfg["columlen"][c]; + + if(collen != first_collen){ + isSame = false; + break; + } + } + } + + if(isSame){ + $("#luckysheet-cols-rows-add").find("input[type='number'].rcsize").val(first_collen); + } + else{ + $("#luckysheet-cols-rows-add").find("input[type='number'].rcsize").val(""); + } + } + }); + + + //表格行标题 改变行高按钮 + $("#luckysheet-rows-change-size").mousedown(function (event) { + //有批注在编辑时 + luckysheetPostil.removeActivePs(); + + $("#luckysheet-input-box").hide(); + $("#luckysheet-rows-change-size").css({ "opacity": 1 }); + + let mouse = mouseposition(event.pageX, event.pageY); + let y = mouse[1] + $("#luckysheet-rows-h").scrollTop(); + + let scrollLeft = $("#luckysheet-cell-main").scrollLeft(); + let winW = $("#luckysheet-cell-main").width(); + + let row_location = rowLocation(y), + row = row_location[1], + row_pre = row_location[0], + row_index = row_location[2]; + + Store.luckysheet_rows_change_size = true; + Store.luckysheet_scroll_status = true; + $("#luckysheet-change-size-line").css({ + "height": "1px", + "border-width": + "0 0px 1px 0", + "top": row - 3, + "left": 0, + "width": scrollLeft + winW, + "display": "block", + "cursor": "ns-resize" + }); + $("#luckysheet-sheettable, #luckysheet-rows-h, #luckysheet-rows-h canvas").css("cursor", "ns-resize"); + Store.luckysheet_rows_change_size_start = [row_pre, row_index]; + $("#luckysheet-rightclick-menu").hide(); + $("#luckysheet-rows-h-hover").hide(); + $("#luckysheet-cols-menu-btn").hide(); + event.stopPropagation(); + }); + + //表格列标题 改变列宽按钮 + $("#luckysheet-cols-change-size").mousedown(function (event) { + //有批注在编辑时 + luckysheetPostil.removeActivePs(); + + $("#luckysheet-input-box").hide(); + $("#luckysheet-cols-change-size").css({ "opacity": 1 }); + + let mouse = mouseposition(event.pageX, event.pageY); + let scrollLeft = $("#luckysheet-cols-h-c").scrollLeft(); + let scrollTop = $("#luckysheet-cell-main").scrollTop(); + let winH = $("#luckysheet-cell-main").height(); + let x = mouse[0] + scrollLeft; + + let row_index = Store.visibledatarow.length - 1, + row = Store.visibledatarow[row_index], row_pre = 0; + let col_location = colLocation(x), + col = col_location[1], + col_pre = col_location[0], + col_index = col_location[2]; + + Store.luckysheet_cols_change_size = true; + Store.luckysheet_scroll_status = true; + $("#luckysheet-change-size-line").css({ + "height": winH + scrollTop, + "border-width": "0 1px 0 0", + "top": 0, + "left": col - 3, + "width": "1px", + "display": "block", + "cursor": "ew-resize" + }); + $("#luckysheet-sheettable, #luckysheet-cols-h-c, .luckysheet-cols-h-cells, .luckysheet-cols-h-cells canvas").css("cursor", "ew-resize"); + Store.luckysheet_cols_change_size_start = [col_pre, col_index]; + $("#luckysheet-rightclick-menu").hide(); + $("#luckysheet-cols-h-hover").hide(); + $("#luckysheet-cols-menu-btn").hide(); + Store.luckysheet_cols_dbclick_times = 0; + event.stopPropagation(); + }).dblclick(function () { + luckysheetcolsdbclick(); + }); + + $("#luckysheet-cols-menu-btn").click(function (event) { + let $menu = $("#luckysheet-rightclick-menu"); + let offset = $(this).offset(); + $("#luckysheet-cols-rows-shift").show(); + Store.luckysheetRightHeadClickIs = "column"; + $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-word").text(locale().rightclick.column); + $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-left").text(locale().rightclick.left); + $("#luckysheet-rightclick-menu .luckysheet-cols-rows-shift-right").text(locale().rightclick.right); + + $("#luckysheet-cols-rows-add").show(); + $("#luckysheet-cols-rows-data").hide(); + $("#luckysheet-cols-rows-shift").show(); + $("#luckysheet-cols-rows-handleincell").hide(); + + showrightclickmenu($menu, offset.left, offset.top + 18); + Store.luckysheet_cols_menu_status = true; + }); + + //向左增加列,向上增加行 + $("#luckysheet-add-lefttop, #luckysheet-add-lefttop_t").click(function (event) { + $("#luckysheet-rightclick-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + + return; + } + + let $t = $(this), value = $t.parent().find("input").val(); + if (!isRealNum(value)) { + if(isEditMode()){ + alert(locale_info.tipInputNumber); + } + else{ + tooltip.info(locale_info.tipInputNumber, ""); + } + + return; + } + + value = parseInt(value); + + if (value < 1 || value > 100) { + if(isEditMode()){ + alert(locale_info.tipInputNumberLimit); + } + else{ + tooltip.info(locale_info.tipInputNumberLimit, ""); + } + return; + } + + let st_index = Store.luckysheet_select_save[0][Store.luckysheetRightHeadClickIs][0]; + luckysheetextendtable(Store.luckysheetRightHeadClickIs, st_index, value, "lefttop"); + }); + $("#luckysheet-addTopRows").click(function (event) { + $("#luckysheet-rightclick-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + + return; + } + + let $t = $(this), value = $t.parent().find("input").val(); + if (!isRealNum(value)) { + if(isEditMode()){ + alert(locale_info.tipInputNumber); + } + else{ + tooltip.info(locale_info.tipInputNumber, ""); + } + + return; + } + + value = parseInt(value); + + if (value < 1 || value > 100) { + if(isEditMode()){ + alert(llocale_info.tipInputNumberLimit); + } + else{ + tooltip.info(llocale_info.tipInputNumberLimit, ""); + } + return; + } + + let st_index = Store.luckysheet_select_save[0].row[0]; + luckysheetextendtable('row', st_index, value, "lefttop"); + }) + $("#luckysheet-addLeftCols").click(function (event) { + $("#luckysheet-rightclick-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + + return; + } + + let $t = $(this), value = $t.parent().find("input").val(); + if (!isRealNum(value)) { + if(isEditMode()){ + alert(locale_info.tipInputNumber); + } + else{ + tooltip.info(locale_info.tipInputNumber, ""); + } + + return; + } + + value = parseInt(value); + + if (value < 1 || value > 100) { + if(isEditMode()){ + alert(llocale_info.tipInputNumberLimit); + } + else{ + tooltip.info(llocale_info.tipInputNumberLimit, ""); + } + return; + } + + let st_index = Store.luckysheet_select_save[0].column[0]; + luckysheetextendtable('column', st_index, value, "lefttop"); + }) + + //向右增加列,向下增加行 + $("#luckysheet-add-rightbottom, #luckysheet-add-rightbottom_t").click(function (event) { + $("#luckysheet-rightclick-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + + return; + } + + let $t = $(this), value = $t.parent().find("input").val(); + if (!isRealNum(value)) { + if(isEditMode()){ + alert(locale_info.tipInputNumber); + } + else{ + tooltip.info(locale_info.tipInputNumber, ""); + } + + return; + } + + value = parseInt(value); + + if (value < 1 || value > 100) { + if(isEditMode()){ + alert(llocale_info.tipInputNumberLimit); + } + else{ + tooltip.info(llocale_info.tipInputNumberLimit, ""); + } + + return; + } + + let st_index = Store.luckysheet_select_save[0][Store.luckysheetRightHeadClickIs][1]; + luckysheetextendtable(Store.luckysheetRightHeadClickIs, st_index, value, "rightbottom"); + }); + $("#luckysheet-addBottomRows").click(function (event) { + $("#luckysheet-rightclick-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + + return; + } + + let $t = $(this), value = $t.parent().find("input").val(); + if (!isRealNum(value)) { + if(isEditMode()){ + alert(locale_info.tipInputNumber); + } + else{ + tooltip.info(locale_info.tipInputNumber, ""); + } + + return; + } + + value = parseInt(value); + + if (value < 1 || value > 100) { + if(isEditMode()){ + alert(llocale_info.tipInputNumberLimit); + } + else{ + tooltip.info(llocale_info.tipInputNumberLimit, ""); + } + + return; + } + + let st_index = Store.luckysheet_select_save[0].row[1]; + luckysheetextendtable('row', st_index, value, "rightbottom"); + }); + $("#luckysheet-addRightCols").click(function (event) { + $("#luckysheet-rightclick-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + + return; + } + + let $t = $(this), value = $t.parent().find("input").val(); + if (!isRealNum(value)) { + if(isEditMode()){ + alert(locale_info.tipInputNumber); + } + else{ + tooltip.info(locale_info.tipInputNumber, ""); + } + + return; + } + + value = parseInt(value); + + if (value < 1 || value > 100) { + if(isEditMode()){ + alert(llocale_info.tipInputNumberLimit); + } + else{ + tooltip.info(llocale_info.tipInputNumberLimit, ""); + } + + return; + } + + let st_index = Store.luckysheet_select_save[0].column[1]; + luckysheetextendtable('column', st_index, value, "rightbottom"); + }); + + //删除选中行列 + $("#luckysheet-del-selected, #luckysheet-del-selected_t").click(function (event) { + $("#luckysheet-rightclick-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(Store.luckysheetRightHeadClickIs == "row"){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + } + else if(Store.luckysheetRightHeadClickIs == "column"){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + } + return; + } + + let st_index = Store.luckysheet_select_save[0][Store.luckysheetRightHeadClickIs][0], + ed_index = Store.luckysheet_select_save[0][Store.luckysheetRightHeadClickIs][1]; + luckysheetdeletetable(Store.luckysheetRightHeadClickIs, st_index, ed_index); + }); + $("#luckysheet-delRows").click(function (event) { + $("#luckysheet-rightclick-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(Store.luckysheetRightHeadClickIs == "row"){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + } + else if(Store.luckysheetRightHeadClickIs == "column"){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + } + return; + } + + let st_index = Store.luckysheet_select_save[0].row[0], + ed_index = Store.luckysheet_select_save[0].row[1]; + luckysheetdeletetable('row', st_index, ed_index); + }) + $("#luckysheet-delCols").click(function (event) { + $("#luckysheet-rightclick-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 1){ + if(Store.luckysheetRightHeadClickIs == "row"){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + } + else if(Store.luckysheetRightHeadClickIs == "column"){ + if(isEditMode()){ + alert(locale_drag.noMulti); + } + else{ + tooltip.info(locale_drag.noMulti, ""); + } + } + return; + } + + let st_index = Store.luckysheet_select_save[0].column[0], + ed_index = Store.luckysheet_select_save[0].column[1]; + luckysheetdeletetable('column', st_index, ed_index); + }) + + //隐藏、显示行 + $("#luckysheet-hidRows").click(function (event) { + $("#luckysheet-rightclick-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + let cfg = $.extend(true, {}, Store.config); + if(cfg["rowhidden"] == null){ + cfg["rowhidden"] = {}; + } + + 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]; + + for(let r = r1; r <= r2; r++){ + cfg["rowhidden"][r] = 0; + } + } + + //保存撤销 + if(Store.clearjfundo){ + let redo = {}; + redo["type"] = "showHidRows"; + 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["rowhidden"], { "k": "rowhidden" }); + + //行高、列宽 刷新 + jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); + }) + $("#luckysheet-showHidRows").click(function (event) { + $("#luckysheet-rightclick-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + let cfg = $.extend(true, {}, Store.config); + if(cfg["rowhidden"] == null){ + return; + } + + 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]; + + for(let r = r1; r <= r2; r++){ + delete cfg["rowhidden"][r]; + } + } + + //保存撤销 + if(Store.clearjfundo){ + let redo = {}; + redo["type"] = "showHidRows"; + 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["rowhidden"], { "k": "rowhidden" }); + + //行高、列宽 刷新 + jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length); + }) + + //清除单元格内容 + $("#luckysheet-delete-text").click(function(){ + $("#luckysheet-rightclick-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + if(Store.luckysheet_select_save.length > 0){ + let d = editor.deepCopyFlowData(Store.flowdata); + + let has_PartMC = false; + + 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]; + let c1 = Store.luckysheet_select_save[s].column[0], + c2 = Store.luckysheet_select_save[s].column[1]; + + if(hasPartMC(Store.config, r1, r2, c1, c2)){ + has_PartMC = true; + break; + } + } + + if(has_PartMC){ + if(isEditMode()){ + alert(locale_drag.noPartMerge); + } + else{ + tooltip.info(locale_drag.noPartMerge, ""); + } + + return; + } + + 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]; + let c1 = Store.luckysheet_select_save[s].column[0], + c2 = Store.luckysheet_select_save[s].column[1]; + + for(let r = r1; r <= r2; r++){ + for(let c = c1; c <= c2; c++){ + if(pivotTable.isPivotRange(r, c)){ + continue; + } + + if(getObjType(d[r][c]) == "object"){ + delete d[r][c]["m"]; + delete d[r][c]["v"]; + + if(d[r][c]["f"] != null){ + delete d[r][c]["f"]; + formula.delFunctionGroup(r, c, Store.currentSheetIndex); + + delete d[r][c]["spl"]; + } + } + else{ + d[r][c] = null; + } + } + } + } + + jfrefreshgrid(d, Store.luckysheet_select_save); + } + }); + + //行高列宽设置 + $("#luckysheet-rows-cols-changesize").click(function(){ + $("#luckysheet-rightclick-menu").hide(); + $("#" + Store.container).attr("tabindex", 0).focus(); + + let size = parseInt($(this).siblings("input[type='number']").val().trim()); + + if(size < 0 || size > 255){ + if(isEditMode()){ + alert(llocale_info.tipRowHeightLimit); + } + else{ + tooltip.info(llocale_info.tipRowHeightLimit, ""); + } + + return; + } + + let cfg = $.extend(true, {}, Store.config); + let type; + + if(Store.luckysheetRightHeadClickIs == "row"){ + type = "resizeR"; + + if(cfg["rowlen"] == null){ + cfg["rowlen"] = {}; + } + + for(let s = 0; s < Store.luckysheet_select_save.length; s++){ + let r1 = Store.luckysheet_select_save[s].row[0]; + let r2 = Store.luckysheet_select_save[s].row[1]; + + for(let r = r1; r <= r2; r++){ + cfg["rowlen"][r] = size; + } + } + } + else if(Store.luckysheetRightHeadClickIs == "column"){ + type = "resizeC"; + + if(cfg["columlen"] == null){ + cfg["columlen"] = {}; + } + + for(let s = 0; s < Store.luckysheet_select_save.length; s++){ + let c1 = Store.luckysheet_select_save[s].column[0]; + let c2 = Store.luckysheet_select_save[s].column[1]; + + for(let c = c1; c <= c2; c++){ + cfg["columlen"][c] = size; + } + } + } + + if (Store.clearjfundo) { + Store.jfundo = []; + Store.jfredo.push({ + "type": "resize", + "ctrlType": type, + "config": $.extend(true, {}, Store.config), + "curconfig": $.extend(true, {}, cfg), + "sheetIndex": Store.currentSheetIndex + }); + } + + //config + Store.config = cfg; + Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].config = Store.config; + + if(Store.luckysheetRightHeadClickIs == "row"){ + server.saveParam("cg", Store.currentSheetIndex, cfg["rowlen"], { "k": "rowlen" }); + jfrefreshgrid_rhcw(Store.flowdata.length, null); + } + else if(Store.luckysheetRightHeadClickIs == "column"){ + server.saveParam("cg", Store.currentSheetIndex, cfg["columlen"], { "k": "columlen" }); + jfrefreshgrid_rhcw(null, Store.flowdata[0].length); + } + }); +} + + +function luckysheetcolsdbclick() { + 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; + let winW = $(window).width(); + + let row_index = Store.visibledatarow.length - 1, + row = Store.visibledatarow[row_index], + row_pre = 0; + let col_location = colLocation(x), + col = col_location[1], + col_pre = col_location[0], + col_index = col_location[2]; + Store.luckysheet_cols_change_size_start = [col_pre, col_index]; + let dataflow = $("#luckysheetTableContent").get(0).getContext("2d"); + let cfg = $.extend(true, {}, Store.config); + + let matchColumn = {}; + 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]; + + if (col_index < c1 || col_index > c2) { + if(col_index in matchColumn){//此列已计算过 + continue; + } + + x = -Infinity; + let countret = 0; + let fontsize = 13; + for (let r = 0; r < Store.flowdata.length; r++) { + if (countret >= 15) { + break; + } + + let value = getcellvalue(r, Store.luckysheet_cols_change_size_start[1], Store.flowdata); + let mask = getcellvalue(r, Store.luckysheet_cols_change_size_start[1], Store.flowdata, "m"); + + if(mask != null){ + value = mask; + } + + let cell = Store.flowdata[r][Store.luckysheet_cols_change_size_start[1]]; + if(getObjType(cell) == "object" && ("fs" in cell)){ + if(cell.fs > fontsize){ + fontsize = cell.fs; + } + } + + if (value == null || value.toString().length == 0) { + countret++; + continue; + } + let textMetrics = dataflow.measureText(value).width; + if (textMetrics > x) { + x = textMetrics; + } + } + + let size = x + fontsize * 1.5; + if ((x + 3) < 30) { + size = 30; + } + + if (x >= winW - 100 + scrollLeft) { + size = winW - 100 + scrollLeft; + } + + if (cfg["columlen"] == null) { + cfg["columlen"] = {}; + } + + cfg["columlen"][Store.luckysheet_cols_change_size_start[1]] = Math.ceil(size); + + matchColumn[col_index] = 1; + } + else { + for (let c = c1; c <= c2; c++) { + if(c in matchColumn){//此列已计算过 + continue; + } + + x = -Infinity; + let countret = 0; + let fontsize = 13; + for (let r = 0; r < Store.flowdata.length; r++) { + if (countret >= 15) { + break; + } + let value = getcellvalue(r, c, Store.flowdata); + + let cell = Store.flowdata[r][c]; + if(getObjType(cell) == "object" && ("fs" in cell)){ + if(cell.fs > fontsize){ + fontsize = cell.fs; + } + } + + if (isRealNull(value)) { + countret++; + continue; + } + + let textMetrics = dataflow.measureText(value).width; + if (textMetrics > x) { + x = textMetrics; + } + } + + let size = x + fontsize*1.5;; + if ((x + 3) < 30) { + size = 30; + } + + if (x >= winW - 100 + scrollLeft) { + size = winW - 100 + scrollLeft; + } + + if (cfg["columlen"] == null) { + cfg["columlen"] = {}; + } + cfg["columlen"][c] = Math.ceil(size); + + matchColumn[c] = 1; + } + } + } + + jfrefreshgridall(Store.flowdata[0].length, Store.flowdata.length, Store.flowdata, cfg, Store.luckysheet_select_save, "resizeC", "columlen"); +} \ No newline at end of file diff --git a/src/controllers/sheetBar.js b/src/controllers/sheetBar.js new file mode 100644 index 000000000..4d5300b3d --- /dev/null +++ b/src/controllers/sheetBar.js @@ -0,0 +1,454 @@ + +import sheetmanage from './sheetmanage'; +import server from './server'; +import { sheetselectlistitemHTML, sheetselectlistHTML, keycode } from './constant'; +import { + replaceHtml, + mouseclickposition, +} from '../utils/util'; +import { getSheetIndex } from '../methods/get'; +import { isEditMode } from '../global/validate'; +import formula from '../global/formula'; +import cleargridelement from '../global/cleargridelement'; +import tooltip from '../global/tooltip'; +import locale from '../locale/locale'; +import Store from '../store'; + + + + +//表格底部名称栏区域 相关事件(增、删、改、隐藏显示、颜色等等) +let isInitialSheetConfig = false, luckysheetcurrentSheetitem = null, jfdbclicklagTimeout = null; +function showsheetconfigmenu() { + if (!isInitialSheetConfig) { + isInitialSheetConfig = true; + const _locale = locale(); + let locale_toolbar = _locale.toolbar; + $("#luckysheetsheetconfigcolorur").spectrum({ + showPalette: true, + preferredFormat: "hex", + clickoutFiresChange: false, + showInitial: true, + showInput: true, + flat: true, + hideAfterPaletteSelect: false, + showSelectionPalette: true, + maxPaletteSize: 10, + cancelText: _locale.sheetconfig.cancelText, + chooseText: _locale.sheetconfig.chooseText, + togglePaletteMoreText: locale_toolbar.toolMore, + togglePaletteLessText: locale_toolbar.toolLess, + clearText: locale_toolbar.clearText, + noColorSelectedText: locale_toolbar.noColorSelectedText, + palette: [["rgb(0, 0, 0)", "rgb(67, 67, 67)", "rgb(102, 102, 102)", "rgb(204, 204, 204)", "rgb(217, 217, 217)", "rgb(255, 255, 255)"], ["rgb(152, 0, 0)", "rgb(255, 0, 0)", "rgb(255, 153, 0)", "rgb(255, 255, 0)", "rgb(0, 255, 0)", "rgb(0, 255, 255)", "rgb(74, 134, 232)", "rgb(0, 0, 255)", "rgb(153, 0, 255)", "rgb(255, 0, 255)"], ["rgb(230, 184, 175)", "rgb(244, 204, 204)", "rgb(252, 229, 205)", "rgb(255, 242, 204)", "rgb(217, 234, 211)", "rgb(208, 224, 227)", "rgb(201, 218, 248)", "rgb(207, 226, 243)", "rgb(217, 210, 233)", "rgb(234, 209, 220)"], ["rgb(221, 126, 107)", "rgb(234, 153, 153)", "rgb(249, 203, 156)", "rgb(255, 229, 153)", "rgb(182, 215, 168)", "rgb(162, 196, 201)", "rgb(164, 194, 244)", "rgb(159, 197, 232)", "rgb(180, 167, 214)", "rgb(213, 166, 189)"], ["rgb(204, 65, 37)", "rgb(224, 102, 102)", "rgb(246, 178, 107)", "rgb(255, 217, 102)", "rgb(147, 196, 125)", "rgb(118, 165, 175)", "rgb(109, 158, 235)", "rgb(111, 168, 220)", "rgb(142, 124, 195)", "rgb(194, 123, 160)"], ["rgb(166, 28, 0)", "rgb(204, 0, 0)", "rgb(230, 145, 56)", "rgb(241, 194, 50)", "rgb(106, 168, 79)", "rgb(69, 129, 142)", "rgb(60, 120, 216)", "rgb(61, 133, 198)", "rgb(103, 78, 167)", "rgb(166, 77, 121)"], ["rgb(91, 15, 0)", "rgb(102, 0, 0)", "rgb(120, 63, 4)", "rgb(127, 96, 0)", "rgb(39, 78, 19)", "rgb(12, 52, 61)", "rgb(28, 69, 135)", "rgb(7, 55, 99)", "rgb(32, 18, 77)", "rgb(76, 17, 48)"], ["#c1232b", "#27727b", "#fcce10", "#e87c25", "#b5c334", "#fe8463", "#9bca63", "#fad860", "#f3a43b", "#60c0dd", "#d7504b", "#c6e579", "#f4e001", "#f0805a", "#26c0c0", "#c12e34", "#e6b600", "#0098d9", "#2b821d", "#005eaa", "#339ca8", "#cda819", "#32a487", "#3fb1e3", "#6be6c1", "#626c91", "#a0a7e6", "#c4ebad", "#96dee8"]], + change: function (color) { + let $input = $(this); + if (color != null) { + color = color.toHexString(); + } + else { + color = "rgb(0, 0, 0)"; + } + + let oldcolor = null; + if(luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").length>0){ + oldcolor = luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").css("background-color"); + } + + luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").remove(); + luckysheetcurrentSheetitem.append('
'); + let index = getSheetIndex(Store.currentSheetIndex); + Store.luckysheetfile[index].color = color; + server.saveParam("all", Store.currentSheetIndex, color, { "k": "color" }); + + if (Store.clearjfundo) { + let redo = {}; + redo["type"] = "sheetColor"; + redo["sheetIndex"] = Store.currentSheetIndex; + + redo["oldcolor"] = oldcolor; + redo["color"] = color; + + Store.jfundo = []; + Store.jfredo.push(redo); + } + } + }); + + $("#luckysheetsheetconfigcolorreset").click(function () { + let oldcolor = null; + if(luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").length>0){ + oldcolor = luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").css("background-color"); + } + + luckysheetcurrentSheetitem.find(".luckysheet-sheets-item-color").remove(); + let index = getSheetIndex(Store.currentSheetIndex); + Store.luckysheetfile[index].color = null; + server.saveParam("all", Store.currentSheetIndex, null, { "k": "color" } ); + + if (Store.clearjfundo) { + let redo = {}; + redo["type"] = "sheetColor"; + redo["sheetIndex"] = Store.currentSheetIndex; + + redo["oldcolor"] = oldcolor; + redo["color"] = null; + + Store.jfundo = []; + Store.jfredo.push(redo); + } + }); + } + + let index = getSheetIndex(Store.currentSheetIndex); + if (Store.luckysheetfile[index].color != null && Store.luckysheetfile[index].color.length > 0) { + $("#luckysheetsheetconfigcolorur").spectrum("set", Store.luckysheetfile[index].color); + + } + + $("#luckysheetsheetconfigcolorur").parent().find("span, div, button, input, a").addClass("luckysheet-mousedown-cancel"); + setTimeout(function(){ + mouseclickposition($("#luckysheet-rightclick-sheet-menu"), luckysheetcurrentSheetitem.offset().left + luckysheetcurrentSheetitem.width(), luckysheetcurrentSheetitem.offset().top - 18, "leftbottom"); + },1); +} + +let luckysheetsheetrightclick = function ($t, $cur, e) { + clearTimeout(jfdbclicklagTimeout); + if ($cur.hasClass("luckysheet-sheets-item-name") && $cur.attr("contenteditable") == "true") { + return; + } + if (formula.rangestart || formula.rangedrag_column_start || formula.rangedrag_row_start || formula.israngeseleciton()) { + setTimeout(function () { + formula.setCaretPosition(formula.rangeSetValueTo.get(0), 0, formula.rangeSetValueTo.text().length); + formula.createRangeHightlight(); + $("#luckysheet-input-box-index").find(".luckysheet-input-box-index-sheettxt").remove().end().prepend("" + sheetmanage.getSheetName(formula.rangetosheet) + "!").show(); + $("#luckysheet-input-box-index").css({"left": $("#luckysheet-input-box").css("left"), "top": (parseInt($("#luckysheet-input-box").css("top")) - 20) + "px", "z-index": $("#luckysheet-input-box").css("z-index")}); + }, 1); + } + else { + $("#luckysheet-input-box").removeAttr("style"); + $("#luckysheet-formula-functionrange .luckysheet-formula-functionrange-highlight").remove(); + } + + $("#luckysheet-sheet-area div.luckysheet-sheets-item").removeClass("luckysheet-sheets-item-active"); + $t.addClass("luckysheet-sheets-item-active"); + cleargridelement(e); + sheetmanage.changeSheet($t.data("index")); + + $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); + + if ($cur.hasClass("luckysheet-sheets-item-menu") || $cur.hasClass("fa-sort-desc") || e.which == "3") { + luckysheetcurrentSheetitem = $cur.closest(".luckysheet-sheets-item"); + showsheetconfigmenu(); + } +} + + +export function initialSheetBar(){ + const _locale = locale(); + const locale_sheetconfig = _locale.sheetconfig; + + $("#luckysheet-sheet-area").on("mousedown", "div.luckysheet-sheets-item", function (e) { + if(isEditMode()){ + // alert("非编辑模式下不允许该操作!"); + return; + } + + let $t = $(this), $cur = $(e.target), $item = $cur.closest(".luckysheet-sheets-item"); + + if (e.which == "3") { + luckysheetsheetrightclick($t, $cur, e); + luckysheetcurrentSheetitem = $item; + showsheetconfigmenu(); + return; + } + + if ($item.hasClass("luckysheet-sheets-item-active") && $item.find(".luckysheet-sheets-item-name").attr("contenteditable") == "false") { + jfdbclicklagTimeout = setTimeout(function () { + Store.luckysheet_sheet_move_status = true; + Store.luckysheet_sheet_move_data = {}; + Store.luckysheet_sheet_move_data.widthlist = []; + + $("#luckysheet-sheet-area div.luckysheet-sheets-item:visible").each(function (i) { + if (i == 0) { + Store.luckysheet_sheet_move_data.widthlist.push(parseInt($(this).outerWidth())); + } + else { + Store.luckysheet_sheet_move_data.widthlist.push(parseInt($(this).outerWidth()) + Store.luckysheet_sheet_move_data.widthlist[i - 1]); + } + }); + + Store.luckysheet_sheet_move_data.curindex = $("#luckysheet-sheet-area div.luckysheet-sheets-item").index($item); + let x = e.pageX; + Store.luckysheet_sheet_move_data.curleft = x - $item.offset().left; + Store.luckysheet_sheet_move_data.pageX = x; + Store.luckysheet_sheet_move_data.activeobject = $item; + Store.luckysheet_sheet_move_data.cursorobject = $cur; + let $itemclone = $item.clone().css("visibility", "hidden").attr("id", "luckysheet-sheets-item-clone"); + $item.after($itemclone); + $item.css({ "position": "absolute", "opacity": 0.8, "cursor": "move", "transition": "initial", "z-index": 10 }); + }, 200); + } + }).on("click", "div.luckysheet-sheets-item", function (e) { + if(isEditMode()){ + // alert("非编辑模式下不允许该操作!"); + return; + } + + let $t = $(this), $cur = $(e.target); + luckysheetsheetrightclick($t, $cur, e); + }); + + let luckysheetsheetnameeditor = function ($t) { + $t.attr("contenteditable", "true").addClass("luckysheet-mousedown-cancel").data("oldtxt", $t.text()); + + setTimeout(function () { + if (document.selection) { + let range = document.body.createTextRange(); + range.moveToElementText($t.get(0)); + range.select(); + } else if (window.getSelection) { + let range = document.createRange(); + range.selectNodeContents($t.get(0)); + window.getSelection().removeAllRanges(); + window.getSelection().addRange(range); + } + }, 1); + } + + $("#luckysheet-sheet-area").on("dblclick", "span.luckysheet-sheets-item-name", function (e) { + luckysheetsheetnameeditor($(this)); + }); + + $("#luckysheet-sheet-area").on("blur", "span.luckysheet-sheets-item-name", function (e) { + let $t = $(this); + let txt = $t.text(), oldtxt = $t.data("oldtxt"); + + let index = getSheetIndex(Store.currentSheetIndex); + for (let i = 0; i < Store.luckysheetfile.length; i++) { + if (index != i && Store.luckysheetfile[i].name == txt) { + if(isEditMode()){ + alert(locale_sheetconfig.tipNameRepeat); + } + else{ + tooltip.info("", locale_sheetconfig.tipNameRepeat); + } + $t.text(oldtxt).attr("contenteditable", "false"); + return; + } + } + + let winW = $(window).width(); + + let c_width = 0; + $("#luckysheet-sheet-container-c > div.luckysheet-sheets-item:visible").each(function(){ + c_width += $(this).outerWidth(); + }); + + if (c_width >= winW * 0.7) { + $("#luckysheet-sheet-area .luckysheet-sheets-scroll").css("display", "inline-block"); + $("#luckysheet-sheet-container .docs-sheet-fade-left").show(); + } + + Store.luckysheetfile[index].name = txt; + server.saveParam("all", Store.currentSheetIndex, txt, { "k": "name" }); + + $t.attr("contenteditable", "false").removeClass("luckysheet-mousedown-cancel"); + + if (Store.clearjfundo) { + let redo = {}; + redo["type"] = "sheetName"; + redo["sheetIndex"] = Store.currentSheetIndex; + + redo["oldtxt"] = oldtxt; + redo["txt"] = txt; + + Store.jfundo = []; + Store.jfredo.push(redo); + } + }); + + $("#luckysheet-sheet-area").on("keydown", "span.luckysheet-sheets-item-name", function (e) { + let kcode = e.keyCode; + let $t = $(this); + if (kcode == keycode.ENTER) { + let index = getSheetIndex(Store.currentSheetIndex); + Store.luckysheetfile[index].name = $t.text(); + $t.attr("contenteditable", "false"); + } + }); + + $("#luckysheetsheetconfigrename").click(function () { + luckysheetsheetnameeditor(luckysheetcurrentSheetitem.find("span.luckysheet-sheets-item-name")); + $("#luckysheet-input-box").removeAttr("style"); + $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); + }); + + $("#luckysheetsheetconfigshow").click(function () { + $("#luckysheet-sheets-m").click(); + $("#luckysheet-input-box").removeAttr("style"); + $("#luckysheet-rightclick-sheet-menu").hide(); + }); + + $("#luckysheetsheetconfigmoveleft").click(function () { + if (luckysheetcurrentSheetitem.prevAll(":visible").length > 0) { + luckysheetcurrentSheetitem.insertBefore(luckysheetcurrentSheetitem.prevAll(":visible").eq(0)); + sheetmanage.reOrderAllSheet(); + } + $("#luckysheet-input-box").removeAttr("style"); + $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); + }); + + $("#luckysheetsheetconfigmoveright").click(function () { + if (luckysheetcurrentSheetitem.nextAll(":visible").length > 0) { + luckysheetcurrentSheetitem.insertAfter(luckysheetcurrentSheetitem.nextAll(":visible").eq(0)); + sheetmanage.reOrderAllSheet(); + } + $("#luckysheet-input-box").removeAttr("style"); + $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); + }); + + $("#luckysheetsheetconfigdelete").click(function (e) { + $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); + + if($("#luckysheet-sheet-container-c .luckysheet-sheets-item:visible").length <= 1){ + if(isEditMode()){ + alert(locale_sheetconfig.noMoreSheet); + } + else{ + tooltip.info(locale_sheetconfig.noMoreSheet, ""); + } + + return; + } + + let index = getSheetIndex(Store.currentSheetIndex); + + tooltip.confirm(locale_sheetconfig.confirmDelete+"【" + Store.luckysheetfile[index].name + "】?", ""+locale_sheetconfig.redoDelete+"", function () { + sheetmanage.deleteSheet(luckysheetcurrentSheetitem.data("index")); + }, null); + + $("#luckysheet-input-box").removeAttr("style"); + }); + + $("#luckysheetsheetconfigcopy").click(function (e) { + sheetmanage.copySheet(luckysheetcurrentSheetitem.data("index"), e); + $("#luckysheet-input-box").removeAttr("style"); + $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); + }); + + $("#luckysheetsheetconfighide").click(function () { + if ($("#luckysheet-sheet-area div.luckysheet-sheets-item:visible").length == 1) { + if(isEditMode()){ + alert(locale_sheetconfig.noHide); + } + else{ + tooltip.info("", locale_sheetconfig.noHide); + } + return; + } + sheetmanage.setSheetHide(luckysheetcurrentSheetitem.data("index")); + $("#luckysheet-input-box").removeAttr("style"); + $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu").hide(); + }); + + $("#luckysheet-sheets-add").click(function (e) { + sheetmanage.addNewSheet(e); + sheetmanage.locationSheet(); + $("#luckysheet-input-box").removeAttr("style"); + }); + + let sheetscrollani = null, sheetscrollstart = 0, sheetscrollend = 0, sheetscrollstep = 150; + $("#luckysheet-sheets-leftscroll").click(function () { + let $c = $("#luckysheet-sheet-container-c"); + sheetscrollstart = $c.scrollLeft(); + sheetscrollend = $c.scrollLeft() - sheetscrollstep; + + if (sheetscrollend <= 0) { + $("#luckysheet-sheet-container .docs-sheet-fade-left").hide(); + } + $("#luckysheet-sheet-container .docs-sheet-fade-right").show(); + + clearInterval(sheetscrollani); + sheetscrollani = setInterval(function () { + sheetscrollstart -= 4; + $c.scrollLeft(sheetscrollstart); + if (sheetscrollstart <= sheetscrollend) { + clearInterval(sheetscrollani); + } + }, 1); + }); + + $("#luckysheet-sheets-rightscroll").click(function () { + let $c = $("#luckysheet-sheet-container-c"); + sheetscrollstart = $c.scrollLeft(); + sheetscrollend = $c.scrollLeft() + sheetscrollstep; + + if (sheetscrollstart > 0) { + $("#luckysheet-sheet-container .docs-sheet-fade-right").hide(); + } + $("#luckysheet-sheet-container .docs-sheet-fade-left").show(); + + clearInterval(sheetscrollani); + sheetscrollani = setInterval(function () { + sheetscrollstart += 4; + $c.scrollLeft(sheetscrollstart); + if (sheetscrollstart >= sheetscrollend) { + clearInterval(sheetscrollani); + } + }, 1); + }); + + let initialOpenSheet = true; + $("#luckysheet-sheets-m").click(function (e) { + $("#luckysheet-sheet-list").html(""); + + let item = ""; + for (let i = 0; i < Store.luckysheetfile.length; i++) { + let f = Store.luckysheetfile[i], icon = '', style = ""; + if (f["status"] == 1) { + icon = ''; + } + + if (f["hide"] == 1) { + icon = ''; + style += "color:#BBBBBB;"; + } + + if (f["color"] != null && f["color"].length > 0) { + style += "border-right:4px solid " + f["color"] + ";"; + } + + item += replaceHtml(sheetselectlistitemHTML, { "index": f["index"], "name": f["name"], "icon": icon, "style": style }); + } + + if (initialOpenSheet) { + $("#" + Store.container).append(replaceHtml(sheetselectlistHTML, { "item": item })); + $("#luckysheet-sheet-list").on("click", ".luckysheet-cols-menuitem", function (e) { + if(isEditMode()){ + // tooltip.info("提示", "图表编辑模式下不允许该操作!"); + alert(locale_sheetconfig.chartEditNoOpt); + return; + } + + let $item = $(this), index = $item.data("index"); + + if ($item.data("index") != Store.currentSheetIndex) { + sheetmanage.setSheetShow(index); + sheetmanage.locationSheet(); + } + }); + + initialOpenSheet = false; + } + else { + $("#luckysheet-sheet-list").html(item); + } + + let $t = $("#luckysheet-sheet-list"); + + mouseclickposition($t, $(this).offset().left, $(this).offset().top - 12, "leftbottom"); + $("#luckysheet-input-box").removeAttr("style"); + }); + +} \ No newline at end of file diff --git a/src/core.js b/src/core.js index 1714f628d..6440e5490 100644 --- a/src/core.js +++ b/src/core.js @@ -7,6 +7,13 @@ import luckysheetConfigsetting from './controllers/luckysheetConfigsetting'; import sheetmanage from './controllers/sheetmanage'; import luckysheetsizeauto from './controllers/resize'; import luckysheetHandler from './controllers/handler'; +import {initialFilterHandler} from './controllers/filter'; +import {initialMatrixOperation} from './controllers/matrixOperation'; +import {initialSheetBar} from './controllers/sheetBar'; +import {formulaBarInitial} from './controllers/formulaBar'; +import {rowColumnOperationInitial} from './controllers/rowColumnOperation'; +import {keyboardInitial} from './controllers/keyboard'; +import {orderByInitial} from './controllers/orderBy'; import {initPlugins} from './controllers/expendPlugins'; import { getluckysheetfile, @@ -99,7 +106,7 @@ luckysheet.create = function (setting) { if (loadurl == "") { sheetmanage.initialjfFile(menu, title); luckysheetsizeauto(); - luckysheetHandler(); + initialWorkBook(); } else { $.post(loadurl, {"gridKey" : server.gridKey}, function (d) { @@ -108,7 +115,7 @@ luckysheet.create = function (setting) { sheetmanage.initialjfFile(menu, title); luckysheetsizeauto(); - luckysheetHandler(); + initialWorkBook(); //需要更新数据给后台时,建立WebSocket连接 if(server.allowUpdate){ @@ -118,6 +125,17 @@ luckysheet.create = function (setting) { } } +function initialWorkBook(){ + luckysheetHandler();//Overall dom initialization + initialFilterHandler();//Filter initialization + initialMatrixOperation();//Right click matrix initialization + initialSheetBar();//bottom sheet bar initialization + formulaBarInitial();//top formula bar initialization + rowColumnOperationInitial();//row and coloumn operate initialization + keyboardInitial();//Keyboard operate initialization + orderByInitial();//menu bar orderby function initialization +} + //获取所有表格数据 luckysheet.getluckysheetfile = getluckysheetfile; diff --git a/src/global/refresh.js b/src/global/refresh.js index 4f3abe81f..32c6c16d9 100644 --- a/src/global/refresh.js +++ b/src/global/refresh.js @@ -268,7 +268,7 @@ function jfrefreshrange(data, range, cdformat) { "curdata": data, "range": range, "sheetIndex": Store.currentSheetIndex, - "cdformat": $.extend(true, [], luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["luckysheet_conditionformat_save"]), + "cdformat": $.extend(true, [], Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["luckysheet_conditionformat_save"]), "curCdformat": cdformat }); } diff --git a/src/locale/en.js b/src/locale/en.js index 5a22c5e3e..e933a23f7 100644 --- a/src/locale/en.js +++ b/src/locale/en.js @@ -645,6 +645,13 @@ export default { resetColor: 'Reset color', cancelText: 'Cancel', chooseText: 'Confirm color', + + tipNameRepeat:"The name of the tab page cannot be repeated! Please revise", + noMoreSheet:"The workbook contains at least one visual worksheet. To delete the selected worksheet, please insert a new worksheet or show a hidden worksheet.", + confirmDelete:"Are you sure to delete", + redoDelete:"Can be undo by Ctrl+Z", + noHide:"Can't hide, at least keep one sheet tag", + chartEditNoOpt:"This operation is not allowed in chart editing mode!", }, conditionformat: { rule: 'Rule', @@ -798,6 +805,9 @@ export default { inputCorrect:"Please enter the correct value", notLessOne:"The number of rows and columns cannot be less than 1", offsetColumnLessZero:"The offset column cannot be negative!", + }, + pivotTable:{ + } }; \ No newline at end of file diff --git a/src/locale/zh.js b/src/locale/zh.js index 5ef1e9b95..e5f8cb342 100644 --- a/src/locale/zh.js +++ b/src/locale/zh.js @@ -829,5 +829,8 @@ export default { inputCorrect:"请输入正确的数值", notLessOne:"行列数不能小于1", offsetColumnLessZero:"偏移列不能为负数!", + }, + pivotTable:{ + } };