123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497 |
- import { replaceHtml } from '../utils/util';
- import { getSheetIndex } from '../methods/get';
- import { isRealNull } from '../global/validate';
- import { isEditMode } from '../global/validate';
- import tooltip from '../global/tooltip';
- import { modelHTML } from './constant';
- import { selectHightlightShow } from './select';
- import conditionformat from './conditionformat';
- import Store from '../store';
- import locale from '../locale/locale';
- //定位
- const luckysheetLocationCell = {
- createDialog: function(){
- $("#luckysheet-modal-dialog-mask").show();
- $("#luckysheet-locationCell-dialog").remove();
- const _locale = locale();
- const locale_location = _locale.findAndReplace;
- const locale_button = _locale.button;
- let content = '<div class="listbox">'+
- '<div class="listItem">'+
- '<input type="radio" name="locationType" checked="checked" id="locationConstant">'+
- '<label for="locationConstant">'+locale_location.locationConstant+'</label>'+
- '<div class="subbox">'+
- '<div class="subItem">'+
- '<input type="checkbox" checked="checked" class="date" id="locationConstantDate">'+
- '<label for="locationConstantDate">'+locale_location.locationDate+'</label>'+
- '</div>'+
- '<div class="subItem">'+
- '<input type="checkbox" checked="checked" class="number" id="locationConstantNumber">'+
- '<label for="locationConstantNumber">'+locale_location.locationDigital+'</label>'+
- '</div>'+
- '<div class="subItem">'+
- '<input type="checkbox" checked="checked" class="string" id="locationConstantString">'+
- '<label for="locationConstantString">'+locale_location.locationString+'</label>'+
- '</div>'+
- '<div class="subItem">'+
- '<input type="checkbox" checked="checked" class="boolean" id="locationConstantBoolean">'+
- '<label for="locationConstantBoolean">'+locale_location.locationBool+'</label>'+
- '</div>'+
- '<div class="subItem">'+
- '<input type="checkbox" checked="checked" class="error" id="locationConstantError">'+
- '<label for="locationConstantError">'+locale_location.locationBool+'</label>'+
- '</div>'+
- '</div>'+
- '</div>'+
- '<div class="listItem">'+
- '<input type="radio" name="locationType" id="locationFormula">'+
- '<label for="locationFormula">'+locale_location.locationFormula+'</label>'+
- '<div class="subbox">'+
- '<div class="subItem">'+
- '<input type="checkbox" checked="checked" class="date" id="locationFormulaDate" disabled="true">'+
- '<label for="locationFormulaDate" style="color: #666">'+locale_location.locationDate+'</label>'+
- '</div>'+
- '<div class="subItem">'+
- '<input type="checkbox" checked="checked" class="number" id="locationFormulaNumber" disabled="true">'+
- '<label for="locationFormulaNumber" style="color: #666">'+locale_location.locationDigital+'</label>'+
- '</div>'+
- '<div class="subItem">'+
- '<input type="checkbox" checked="checked" class="string" id="locationFormulaString" disabled="true">'+
- '<label for="locationFormulaString" style="color: #666">'+locale_location.locationString+'</label>'+
- '</div>'+
- '<div class="subItem">'+
- '<input type="checkbox" checked="checked" class="boolean" id="locationFormulaBoolean" disabled="true">'+
- '<label for="locationFormulaBoolean" style="color: #666">'+locale_location.locationBool+'</label>'+
- '</div>'+
- '<div class="subItem">'+
- '<input type="checkbox" checked="checked" class="error" id="locationFormulaError" disabled="true">'+
- '<label for="locationFormulaError" style="color: #666">'+locale_location.locationError+'</label>'+
- '</div>'+
- '</div>'+
- '</div>'+
- '<div class="listItem">'+
- '<input type="radio" name="locationType" id="locationNull">'+
- '<label for="locationNull">'+locale_location.locationNull+'</label>'+
- '</div>'+
- '<div class="listItem">'+
- '<input type="radio" name="locationType" id="locationCF">'+
- '<label for="locationCF">'+locale_location.locationCondition+'</label>'+
- '</div>'+
- '<div class="listItem">'+
- '<input type="radio" name="locationType" id="locationStepRow">'+
- '<label for="locationStepRow">'+locale_location.locationRowSpan+'</label>'+
- '</div>'+
- '<div class="listItem">'+
- '<input type="radio" name="locationType" id="locationStepColumn">'+
- '<label for="locationStepColumn">'+locale_location.locationColumnSpan+'</label>'+
- '</div>'+
- '</div>';
- $("body").first().append(replaceHtml(modelHTML, {
- "id": "luckysheet-locationCell-dialog",
- "addclass": "luckysheet-locationCell-dialog",
- "title": locale_location.location,
- "content": content,
- "botton": '<button id="luckysheet-locationCell-dialog-confirm" class="btn btn-primary">'+locale_button.confirm+'</button><button class="btn btn-default luckysheet-model-close-btn">'+locale_button.cancel+'</button>',
- "style": "z-index:100003"
- }));
- let $t = $("#luckysheet-locationCell-dialog").find(".luckysheet-modal-dialog-content").css("min-width", 400).end(),
- myh = $t.outerHeight(),
- myw = $t.outerWidth();
- let winw = $(window).width(), winh = $(window).height();
- let scrollLeft = $(document).scrollLeft(), scrollTop = $(document).scrollTop();
- $("#luckysheet-locationCell-dialog").css({ "left": (winw + scrollLeft - myw) / 2, "top": (winh + scrollTop - myh) / 3 }).show();
- },
- init: function(){
- let _this = this;
- const locale_location = locale().findAndReplace;
- $(document).on("click", "#luckysheet-locationCell-dialog .listItem input:radio", function(e){
- $("#luckysheet-locationCell-dialog .listItem input:checkbox").prop("disabled", true);
- $("#luckysheet-locationCell-dialog .listItem .subbox label").css("color", "#666");
- $(this).siblings(".subbox").find("input:checkbox").removeAttr("disabled");
- $(this).siblings(".subbox").find("label").css("color", "#000");
- });
- $(document).off("click.locationCellConfirm").on("click.locationCellConfirm", "#luckysheet-locationCell-dialog #luckysheet-locationCell-dialog-confirm", function(){
- $("#luckysheet-modal-dialog-mask").hide();
- $("#luckysheet-locationCell-dialog").hide();
- let $radio = $("#luckysheet-locationCell-dialog .listItem input:radio:checked");
- let id = $radio.attr("id");
- if(id == "locationConstant" || id == "locationFormula"){
- let $checkbox = $radio.siblings(".subbox").find("input:checkbox:checked");
- let value;
- if($checkbox.length == 0){
- return;
- }
- else if($checkbox.length == 5){
- value = "all";
- }
- else{
- let arr = [];
-
- for(let i = 0; i < $checkbox.length; i++){
- if($($checkbox[i]).hasClass("date")){
- arr.push("d");
- }
- else if($($checkbox[i]).hasClass("number")){
- arr.push("n");
- }
- else if($($checkbox[i]).hasClass("string")){
- arr.push("s,g");
- }
- else if($($checkbox[i]).hasClass("boolean")){
- arr.push("b");
- }
- else if($($checkbox[i]).hasClass("error")){
- arr.push("e");
- }
- }
- value = arr.join(",");
- }
- let range;
- if(Store.luckysheet_select_save.length == 0 || (Store.luckysheet_select_save.length == 1 && Store.luckysheet_select_save[0].row[0] == Store.luckysheet_select_save[0].row[1] && Store.luckysheet_select_save[0].column[0] == Store.luckysheet_select_save[0].column[1])){
- //单个单元格
- range = [{"row": [0, Store.flowdata.length - 1], "column": [0, Store.flowdata[0].length - 1]}];
- }
- else{
- range = $.extend(true, [], Store.luckysheet_select_save);
- }
- _this.apply(range, id, value);
- }
- else if(id == "locationStepRow"){
- if(Store.luckysheet_select_save.length == 0 || (Store.luckysheet_select_save.length == 1 && Store.luckysheet_select_save[0].row[0] == Store.luckysheet_select_save[0].row[1])){
- if(isEditMode()){
- alert(locale_location.locationTiplessTwoRow);
- }
- else{
- tooltip.info("", locale_location.locationTiplessTwoRow);
- }
- return;
- }
- let range = $.extend(true, [], Store.luckysheet_select_save);
- _this.apply(range, "locationStepRow");
- }
- else if(id == "locationStepColumn"){
- if(Store.luckysheet_select_save.length == 0 || (Store.luckysheet_select_save.length == 1 && Store.luckysheet_select_save[0].column[0] == Store.luckysheet_select_save[0].column[1])){
- if(isEditMode()){
- alert(locale_location.locationTiplessTwoColumn);
- }
- else{
- tooltip.info("", locale_location.locationTiplessTwoColumn);
- }
- return;
- }
- let range = $.extend(true, [], Store.luckysheet_select_save);
- _this.apply(range, "locationStepColumn");
- }
- else{
- let range;
- if(Store.luckysheet_select_save.length == 0 || (Store.luckysheet_select_save.length == 1 && Store.luckysheet_select_save[0].row[0] == Store.luckysheet_select_save[0].row[1] && Store.luckysheet_select_save[0].column[0] == Store.luckysheet_select_save[0].column[1])){
- //单个单元格
- range = [{"row": [0, Store.flowdata.length - 1], "column": [0, Store.flowdata[0].length - 1]}];
- }
- else{
- range = $.extend(true, [], Store.luckysheet_select_save);
- }
- _this.apply(range, id);
- }
- });
- },
- apply: function(range, type, value){
- const locale_location = locale().findAndReplace;
- let rangeArr = [];
- if(type == "locationFormula" || type == "locationConstant" || type == "locationNull"){ //公式 常量 空值
- let minR = null, maxR = null, minC = null, maxC = null, cellSave = {};
- for(let s = 0; s < range.length; s++){
- let st_r = range[s].row[0],
- ed_r = range[s].row[1],
- st_c = range[s].column[0],
- ed_c = range[s].column[1];
- if(minR == null || minR < st_r){
- minR = st_r;
- }
- if(maxR == null || maxR > ed_r){
- maxR = ed_r;
- }
- if(minC == null || minC < st_c){
- minC = st_c;
- }
- if(maxC == null || maxC > ed_c){
- maxC = ed_c;
- }
- for(let r = st_r; r <= ed_r; r++){
- for(let c = st_c; c <= ed_c; c++){
- let cell = Store.flowdata[r][c];
- if(cell != null && cell.mc != null){
- cell = Store.flowdata[cell.mc.r][cell.mc.c];
- }
- if(type == 'locationFormula' && cell != null && !isRealNull(cell.v) && cell.f != null && (value == 'all' || (cell.ct != null && value.indexOf(cell.ct.t) > -1))){
- cellSave[r + '_' + c] = 0;
- }
- else if(type == 'locationConstant' && cell != null && !isRealNull(cell.v) && (value == 'all' || (cell.ct != null && value.indexOf(cell.ct.t) > -1))){
- cellSave[r + '_' + c] = 0;
- }
- else if(type == 'locationNull' && (cell == null || isRealNull(cell.v))){
- cellSave[r + '_' + c] = 0;
- }
- }
- }
- }
- rangeArr = this.getRangeArr(minR, maxR, minC, maxC, cellSave, rangeArr);
- }
- else if(type == "locationCF"){ //条件格式
- let index = getSheetIndex(Store.currentSheetIndex);
- let ruleArr = Store.luckysheetfile[index]["luckysheet_conditionformat_save"];
- let data = Store.luckysheetfile[index]["data"];
- if(ruleArr == null || ruleArr.length == 0){
- if(isEditMode()){
- alert(locale_location.locationTipNotFindCell);
- }
- else{
- tooltip.info("", locale_location.locationTipNotFindCell);
- }
- return;
- }
- computeMap = conditionformat.compute(ruleArr, data);
- if(Object.keys(computeMap).length == 0){
- if(isEditMode()){
- alert(locale_location.locationTipNotFindCell);
- }
- else{
- tooltip.info("", locale_location.locationTipNotFindCell);
- }
- return;
- }
- let minR = null, maxR = null, minC = null, maxC = null, cellSave = {};
- for(let s = 0; s < range.length; s++){
- let st_r = range[s].row[0],
- ed_r = range[s].row[1],
- st_c = range[s].column[0],
- ed_c = range[s].column[1];
- if(minR == null || minR < st_r){
- minR = st_r;
- }
- if(maxR == null || maxR > ed_r){
- maxR = ed_r;
- }
- if(minC == null || minC < st_c){
- minC = st_c;
- }
- if(maxC == null || maxC > ed_c){
- maxC = ed_c;
- }
- for(let r = st_r; r <= ed_r; r++){
- for(let c = st_c; c <= ed_c; c++){
- if((r + '_' + c) in computeMap){
- cellSave[r + '_' + c] = 0;
- }
- }
- }
- }
- rangeArr = this.getRangeArr(minR, maxR, minC, maxC, cellSave, rangeArr);
- }
- else if(type == "locationStepRow"){ //间隔行
- for(let s = 0; s < range.length; s++){
- if(range[s].row[0] == range[s].row[1]){
- continue;
- }
- let st_r = range[s].row[0], ed_r = range[s].row[1];
- let st_c = range[s].column[0], ed_c = range[s].column[1];
- for(let r = st_r; r <= ed_r; r++){
- if((r - st_r) % 2 == 0){
- rangeArr.push({"row": [r, r], "column": [st_c, ed_c]});
- }
- }
- }
- }
- else if(type == "locationStepColumn"){ //间隔列
- for(let s = 0; s < range.length; s++){
- if(range[s].column[0] == range[s].column[1]){
- continue;
- }
- let st_r = range[s].row[0], ed_r = range[s].row[1];
- let st_c = range[s].column[0], ed_c = range[s].column[1];
- for(let c = st_c; c <= ed_c; c++){
- if((c - st_c) % 2 == 0){
- rangeArr.push({"row": [st_r, ed_r], "column": [c, c]});
- }
- }
- }
- }
- if(rangeArr.length == 0){
- if(isEditMode()){
- alert(locale_location.locationTipNotFindCell);
- }
- else{
- tooltip.info("", locale_location.locationTipNotFindCell);
- }
- }
- else{
- Store.luckysheet_select_save = rangeArr;
- selectHightlightShow();
- let scrollLeft = $("#luckysheet-cell-main").scrollLeft(),
- scrollTop = $("#luckysheet-cell-main").scrollTop();
- let winH = $("#luckysheet-cell-main").height(),
- winW = $("#luckysheet-cell-main").width();
- let r1 = Store.luckysheet_select_save[0]["row"][0],
- r2 = Store.luckysheet_select_save[0]["row"][1],
- c1 = Store.luckysheet_select_save[0]["column"][0],
- c2 = Store.luckysheet_select_save[0]["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];
- 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);
- }
- }
- },
- getRangeArr(minR, maxR, minC, maxC, cellSave, rangeArr){
- if(Object.keys(cellSave).length == 0){
- return rangeArr;
- }
- let _this = this;
- let stack_str = null,
- stack_edr = null,
- stack_stc = null,
- stack_edc = null;
- for(let r = minR; r <= maxR; r++){
- for(let c = minC; c <= maxC; c++){
- let cell = Store.flowdata[r][c];
-
- if((r + '_' + c) in cellSave){
- if(cell != null && cell.mc != null){
- if(stack_stc == null){
- let range = {
- 'row': [cell.mc.r, cell.mc.r + cell.mc.rs - 1],
- 'column': [cell.mc.c, cell.mc.c + cell.mc.cs - 1]
- };
- rangeArr.push(range);
- cellSave = _this.deleteCellInSave(cellSave, range);
- return _this.getRangeArr(minR, maxR, minC, maxC, cellSave, rangeArr);
- }
- else if(c < stack_edc){
- let range = {
- 'row': [stack_str, stack_edr],
- 'column': [stack_stc, stack_edc]
- }
- rangeArr.push(range);
- cellSave = _this.deleteCellInSave(cellSave, range);
- return _this.getRangeArr(minR, maxR, minC, maxC, cellSave, rangeArr);
- }
- else{
- break;
- }
- }
- else if(stack_stc == null){
- stack_stc = c;
- stack_edc = c;
- stack_str = r;
- stack_edr = r;
- }
- else if(c > stack_edc){
- stack_edc = c;
- }
- }
- else if(stack_stc != null){
- if(cell != null && cell.mc != null){
- break;
- }
- else if(c < stack_stc){
- }
- else if(c <= stack_edc){
- let range = {
- 'row': [stack_str, stack_edr],
- 'column': [stack_stc, stack_edc]
- }
- rangeArr.push(range);
- cellSave = _this.deleteCellInSave(cellSave, range);
- return _this.getRangeArr(minR, maxR, minC, maxC, cellSave, rangeArr);
- }
- else{
- stack_edr = r;
- }
- }
- }
- }
- if(stack_stc != null){
- let range = {
- 'row': [stack_str, stack_edr],
- 'column': [stack_stc, stack_edc]
- }
- rangeArr.push(range);
- cellSave = _this.deleteCellInSave(cellSave, range);
- return _this.getRangeArr(minR, maxR, minC, maxC, cellSave, rangeArr);
- }
- },
- deleteCellInSave(cellSave, range){
- for(let r = range.row[0]; r <= range.row[1]; r++){
- for(let c = range.column[0]; c <= range.column[1]; c++){
- delete cellSave[r + '_' + c];
- }
- }
- return cellSave;
- }
- }
- export default luckysheetLocationCell;
|