diff --git a/src/controllers/constant.js b/src/controllers/constant.js
index e79f2f9..11a2e3e 100644
--- a/src/controllers/constant.js
+++ b/src/controllers/constant.js
@@ -181,6 +181,9 @@ const gridHTML = function(){
+
+
+
\${flow}
@@ -243,7 +246,9 @@ const columeHeader_word = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K'
//右键菜单dom
function rightclickHTML(){
- const rightclick = locale().rightclick;
+ const _locale = locale();
+ const rightclick = _locale.rightclick;
+ const toolbar = _locale.toolbar;
return `
+
- `;
+ `;
}
const luckysheetlodingHTML = function(){
diff --git a/src/controllers/controlHistory.js b/src/controllers/controlHistory.js
index d0d962e..881d25a 100644
--- a/src/controllers/controlHistory.js
+++ b/src/controllers/controlHistory.js
@@ -4,6 +4,7 @@ import pivotTable from './pivotTable';
import conditionformat from './conditionformat';
import luckysheetPostil from './postil';
import imageCtrl from './imageCtrl';
+import dataVerificationCtrl from './dataVerificationCtrl';
import {zoomRefreshView,zoomNumberDomBind} from './zoom';
import { createFilter, createFilterOptions, labelFilterOptionState } from './filter';
import formula from '../global/formula';
@@ -58,7 +59,15 @@ const controlHistory = {
}
formula.execFunctionGroup(null, null, null, null, ctr.data);//取之前的数据
- jfrefreshgrid(ctr.data, ctr.range, ctr.config, ctr.cdformat, ctr.RowlChange);
+ let allParam = {
+ "cfg": ctr.config,
+ "RowlChange": ctr.RowlChange,
+ "cdformat": ctr.cdformat,
+ "dataVerification": ctr.dataVerification,
+ "dynamicArray": ctr.dynamicArray
+ }
+
+ jfrefreshgrid(ctr.data, ctr.range, allParam);
}
else if (ctr.type == "pasteCut") {
let s = {
@@ -69,6 +78,8 @@ const controlHistory = {
"curConfig": ctr.source["config"],
"cdformat": ctr.source["curCdformat"],
"curCdformat": ctr.source["cdformat"],
+ "dataVerification": ctr.source["curDataVerification"],
+ "curDataVerification": ctr.source["dataVerification"],
"range": ctr.source["range"]
}
let t = {
@@ -79,6 +90,8 @@ const controlHistory = {
"curConfig": ctr.target["config"],
"cdformat": ctr.target["curCdformat"],
"curCdformat": ctr.target["cdformat"],
+ "dataVerification": ctr.target["curDataVerification"],
+ "curDataVerification": ctr.target["dataVerification"],
"range": ctr.target["range"]
}
jfrefreshgrid_pastcut(s, t, ctr.RowlChange);
@@ -139,17 +152,47 @@ const controlHistory = {
ctrlValue.index = ctrlValue.index + 1;
}
- jfrefreshgrid_adRC(ctr.data, ctr.config, "delRC", ctrlValue, ctr.calc, ctr.filterObj, ctr.cf, ctr.af, ctr.freezen);
+ jfrefreshgrid_adRC(
+ ctr.data,
+ ctr.config,
+ "delRC",
+ ctrlValue,
+ ctr.calc,
+ ctr.filterObj,
+ ctr.cf,
+ ctr.af,
+ ctr.freezen,
+ ctr.dataVerification
+ );
}
else if (ctr.type == "delRC") { //删除行列撤销操作
let ctrlValue = $.extend(true, {}, ctr.ctrlValue);
ctrlValue.restore = true;
ctrlValue.direction = "lefttop";
- jfrefreshgrid_adRC(ctr.data, ctr.config, "addRC", ctrlValue, ctr.calc, ctr.filterObj, ctr.cf, ctr.af, ctr.freezen);
+ jfrefreshgrid_adRC(
+ ctr.data,
+ ctr.config,
+ "addRC",
+ ctrlValue,
+ ctr.calc,
+ ctr.filterObj,
+ ctr.cf,
+ ctr.af,
+ ctr.freezen,
+ ctr.dataVerification
+ );
}
else if (ctr.type == "deleteCell") { //删除单元格撤销操作
- jfrefreshgrid_deleteCell(ctr.data, ctr.config, ctr.ctrl, ctr.calc, ctr.filterObj, ctr.cf);
+ jfrefreshgrid_deleteCell(
+ ctr.data,
+ ctr.config,
+ ctr.ctrl,
+ ctr.calc,
+ ctr.filterObj,
+ ctr.cf,
+ ctr.dataVerification
+ );
}
else if (ctr.type == "showHidRows") { // 隐藏、显示行 撤销操作
//config
@@ -285,7 +328,17 @@ const controlHistory = {
server.saveParam("all", ctr.sheetIndex, ctr.oldcolor, { "k": "color" });
}
else if (ctr.type == "mergeChange") {
- jfrefreshgrid(ctr.data, ctr.range, ctr.config);
+ let allParam = {
+ "cfg": ctr.config,
+ }
+
+ jfrefreshgrid(ctr.data, ctr.range, allParam);
+ }
+ else if (ctr.type == "updateDataVerification"){
+ dataVerificationCtrl.ref(ctr.currentDataVerification, ctr.historyDataVerification, ctr.sheetIndex);
+ }
+ else if (ctr.type == "updateDataVerificationOfCheckbox"){
+ dataVerificationCtrl.refOfCheckbox(ctr.currentDataVerification, ctr.historyDataVerification, ctr.sheetIndex, ctr.data, ctr.range);
}
else if (ctr.type == "updateCF"){
let historyRules = ctr["data"]["historyRules"];
@@ -375,7 +428,15 @@ const controlHistory = {
if (ctr.type == "datachange") {
formula.execFunctionGroup();
- jfrefreshgrid(ctr.curdata, ctr.range, ctr.curConfig, ctr.curCdformat, ctr.RowlChange);
+ let allParam = {
+ "cfg": ctr.curConfig,
+ "RowlChange": ctr.RowlChange,
+ "cdformat": ctr.curCdformat,
+ "dataVerification": ctr.curDataVerification,
+ "dynamicArray": ctr.curDynamicArray
+ }
+
+ jfrefreshgrid(ctr.curdata, ctr.range, allParam);
}
else if (ctr.type == "pasteCut") {
jfrefreshgrid_pastcut(ctr.source, ctr.target, ctr.RowlChange);
@@ -415,13 +476,43 @@ const controlHistory = {
jfrefreshgridall(ctr.curdata[0].length, ctr.curdata.length, ctr.curdata, ctr.curconfig, ctr.currange, ctr.ctrlType, ctr.ctrlValue);
}
else if (ctr.type == "addRC") { //增加行列重做操作
- jfrefreshgrid_adRC(ctr.curData, ctr.curConfig, "addRC", ctr.ctrlValue, ctr.curCalc, ctr.curFilterObj, ctr.curCf, ctr.curAf, ctr.curFreezen);
+ jfrefreshgrid_adRC(
+ ctr.curData,
+ ctr.curConfig,
+ "addRC",
+ ctr.ctrlValue,
+ ctr.curCalc,
+ ctr.curFilterObj,
+ ctr.curCf,
+ ctr.curAf,
+ ctr.curFreezen,
+ ctr.curDataVerification
+ );
}
else if (ctr.type == "delRC") { //删除行列重做操作
- jfrefreshgrid_adRC(ctr.curData, ctr.curConfig, "delRC", ctr.ctrlValue, ctr.curCalc, ctr.curFilterObj, ctr.curCf, ctr.curAf, ctr.curFreezen);
+ jfrefreshgrid_adRC(
+ ctr.curData,
+ ctr.curConfig,
+ "delRC",
+ ctr.ctrlValue,
+ ctr.curCalc,
+ ctr.curFilterObj,
+ ctr.curCf,
+ ctr.curAf,
+ ctr.curFreezen,
+ ctr.curDataVerification
+ );
}
else if (ctr.type == "deleteCell") { //删除单元格重做操作
- jfrefreshgrid_deleteCell(ctr.curData, ctr.curConfig, ctr.ctrl, ctr.curCalc, ctr.curFilterObj, ctr.curCf);
+ jfrefreshgrid_deleteCell(
+ ctr.curData,
+ ctr.curConfig,
+ ctr.ctrl,
+ ctr.curCalc,
+ ctr.curFilterObj,
+ ctr.curCf,
+ ctr.curDataVerification
+ );
}
else if (ctr.type == "showHidRows") { // 隐藏、显示行 重做操作
//config
@@ -540,7 +631,17 @@ const controlHistory = {
server.saveParam("all", ctr.sheetIndex, ctr.color, { "k": "color" });
}
else if (ctr.type == "mergeChange") {
- jfrefreshgrid(ctr.curData, ctr.range, ctr.curConfig);
+ let allParam = {
+ "cfg": ctr.curConfig,
+ }
+
+ jfrefreshgrid(ctr.curData, ctr.range, allParam);
+ }
+ else if (ctr.type == "updateDataVerification"){
+ dataVerificationCtrl.ref(ctr.historyDataVerification, ctr.currentDataVerification, ctr.sheetIndex);
+ }
+ else if (ctr.type == "updateDataVerificationOfCheckbox"){
+ dataVerificationCtrl.refOfCheckbox(ctr.historyDataVerification, ctr.currentDataVerification, ctr.sheetIndex, ctr.curData, ctr.range);
}
else if (ctr.type == "updateCF"){
let currentRules = ctr["data"]["currentRules"];
diff --git a/src/controllers/dataVerificationCtrl.js b/src/controllers/dataVerificationCtrl.js
new file mode 100644
index 0000000..37c2688
--- /dev/null
+++ b/src/controllers/dataVerificationCtrl.js
@@ -0,0 +1,1438 @@
+import { replaceHtml } from '../utils/util';
+import formula from '../global/formula';
+import { isRealNum } from '../global/validate';
+import { isdatetime, diff } from '../global/datecontroll';
+import { luckysheetrefreshgrid } from '../global/refresh';
+import tooltip from '../global/tooltip';
+import { setcellvalue } from '../global/setdata';
+import { getcellvalue } from '../global/getdata';
+import editor from '../global/editor';
+import { modelHTML } from './constant';
+import { selectionCopyShow } from './select';
+import server from './server';
+import menuButton from './menuButton';
+import { getSheetIndex, getRangetxt } from '../methods/get';
+import locale from '../locale/locale';
+import Store from '../store';
+
+const dataVerificationCtrl = {
+ defaultItem: {
+ type: 'dropdown', //类型
+ type2: null, //
+ value1: '', //
+ value2: '', //
+ checked: false,
+ remote: false, //自动远程获取选项
+ prohibitInput: false, //输入数据无效时禁止输入
+ hintShow: false, //选中单元格时显示提示语
+ hintText: '', //
+ },
+ curItem: null,
+ dataVerification: null,
+ selectRange: [],
+ selectStatus: false,
+ optionLabel: {
+ 'number': '数值',
+ 'number_integer': '整数',
+ 'number_decimal': '小数',
+ 'bw': '介于',
+ 'nb': '不介于',
+ 'eq': '等于',
+ 'ne': '不等于',
+ 'gt': '大于',
+ 'lt': '小于',
+ 'gte': '大于等于',
+ 'lte': '小于等于',
+ 'include': '包括',
+ 'exclude': '不包括',
+ 'equal': '等于',
+ 'bf': '早于',
+ 'nbf': '不早于',
+ 'af': '晚于',
+ 'naf': '不晚于',
+ 'card': '身份证号码',
+ 'phone': '手机号'
+ },
+ createDialog: function(){
+ let _this = this;
+
+ const _locale = locale();
+ const dvText = _locale.dataVerification;
+ const toolbarText = _locale.toolbar;
+ const buttonText = _locale.button;
+
+ $("#luckysheet-modal-dialog-mask").show();
+ $("#luckysheet-dataVerification-dialog").remove();
+
+ let content = `
+
+
${dvText.cellRange}
+
+
+
+
+
+
+
${dvText.verificationCondition}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
`;
+
+ $("body").append(replaceHtml(modelHTML, {
+ "id": "luckysheet-dataVerification-dialog",
+ "addclass": "luckysheet-dataVerification-dialog",
+ "title": toolbarText.dataVerification,
+ "content": content,
+ "botton": `
+
+ `,
+ "style": "z-index:100003"
+ }));
+ let $t = $("#luckysheet-dataVerification-dialog").find(".luckysheet-modal-dialog-content").css("min-width", 350).end(),
+ myh = $t.outerHeight(),
+ myw = $t.outerWidth();
+ let winw = $(window).width(),
+ winh = $(window).height();
+ let scrollLeft = $(document).scrollLeft(),
+ scrollTop = $(document).scrollTop();
+ $("#luckysheet-dataVerification-dialog").css({
+ "left": (winw + scrollLeft - myw) / 2,
+ "top": (winh + scrollTop - myh) / 3
+ }).show();
+
+ _this.dataAllocation();
+ },
+ init: function(){
+ let _this = this;
+
+ const dvText = locale().dataVerification;
+
+ //单元格数据验证 类型是 下拉列表
+ $(document).off("click.dropdownBtn").on("click.dropdownBtn", "#luckysheet-dataVerification-dropdown-btn", function(e) {
+ _this.dropdownListShow();
+ e.stopPropagation();
+ });
+ $(document).off("click.dropdownListItem").on("click.dropdownListItem", "#luckysheet-dataVerification-dropdown-List .dropdown-List-item", function(e) {
+ $("#luckysheet-dataVerification-dropdown-List").hide();
+
+ let value = e.target.innerText;
+ let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1];
+ let rowIndex = last.row_focus;
+ let colIndex = last.column_focus;
+
+ $("#luckysheet-rich-text-editor").text(value);
+ formula.updatecell(rowIndex, colIndex);
+
+ e.stopPropagation();
+ });
+
+ //单元格范围
+ $(document).off("click.dvRange").on("click.dvRange", "#data-verification-range .fa-table", function(e) {
+ $("#luckysheet-dataVerification-dialog").hide();
+
+ let dataSource = "0";
+ let txt = $(this).siblings("input").val().trim();
+
+ _this.rangeDialog(dataSource, txt);
+
+ _this.selectRange = [];
+
+ let range = _this.getRangeByTxt(txt);
+ if(range.length > 0){
+ for(let s = 0; s < range.length; s++){
+ let r1 = range[s].row[0], r2 = range[s].row[1];
+ let c1 = range[s].column[0], c2 = range[s].column[1];
+
+ let row = Store.visibledatarow[r2],
+ 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];
+
+ _this.selectRange.push({
+ "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
+ });
+ }
+ }
+
+ selectionCopyShow(_this.selectRange);
+ });
+ $(document).off("click.dvRange2").on("click.dvRange2", "#luckysheet-dataVerification-dialog .show-box-item-dropdown .range .fa-table", function(e) {
+ $("#luckysheet-dataVerification-dialog").hide();
+
+ let dataSource = "1";
+ let txt = $(this).siblings("input").val().trim();
+
+ _this.rangeDialog(dataSource, txt);
+
+ _this.selectRange = [];
+
+ let range = _this.getRangeByTxt(txt);
+ if(range.length > 0){
+ for(let s = 0; s < range.length; s++){
+ let r1 = range[s].row[0], r2 = range[s].row[1];
+ let c1 = range[s].column[0], c2 = range[s].column[1];
+
+ let row = Store.visibledatarow[r2],
+ 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];
+
+ _this.selectRange.push({
+ "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
+ });
+ }
+ }
+
+ selectionCopyShow(_this.selectRange);
+ });
+ $(document).off("click.dvRangeConfirm").on("click.dvRangeConfirm", "#luckysheet-dataVerificationRange-dialog-confirm", function(e) {
+ let dataSource = $(this).attr("data-source");
+ let txt = $(this).parents("#luckysheet-dataVerificationRange-dialog").find("input").val();
+
+ if(_this.getRangeByTxt(txt).length > 1){
+ tooltip.info('', '不能对多重选择区域执行此操作,请选择单个区域,然后再试');
+ return;
+ }
+
+ if(dataSource == '0'){
+ $("#luckysheet-dataVerification-dialog #data-verification-range input").val(txt);
+ }
+ else if(dataSource == '1'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-dropdown .range input").val(txt);
+ }
+
+ $("#luckysheet-dataVerificationRange-dialog").hide();
+ $("#luckysheet-modal-dialog-mask").show();
+ $("#luckysheet-dataVerification-dialog").show();
+
+ let range = [];
+ selectionCopyShow(range);
+ });
+ $(document).off("click.dvRangeClose").on("click.dvRangeClose", "#luckysheet-dataVerificationRange-dialog-close", function(e) {
+ $("#luckysheet-dataVerificationRange-dialog").hide();
+ $("#luckysheet-modal-dialog-mask").show();
+ $("#luckysheet-dataVerification-dialog").show();
+
+ let range = [];
+ selectionCopyShow(range);
+ });
+ $(document).on("click", "#luckysheet-dataVerificationRange-dialog .luckysheet-modal-dialog-title-close", function(e) {
+ $("#luckysheet-dataVerificationRange-dialog").hide();
+ $("#luckysheet-modal-dialog-mask").show();
+ $("#luckysheet-dataVerification-dialog").show();
+
+ let range = [];
+ selectionCopyShow(range);
+ })
+
+ //验证条件 下拉框
+ $(document).off("change.typeSelect").on("change.typeSelect", "#data-verification-type-select", function(e) {
+ $("#luckysheet-dataVerification-dialog .show-box .show-box-item").hide();
+
+ let value = this.value;
+ let item = _this.curItem;
+
+ if(value == 'dropdown'){
+ $("#luckysheet-dataVerification-dialog .show-box .show-box-item-dropdown").show();
+
+ let value1 = "";
+
+ if(value == item.type){
+ value1 = item.value1;
+ }
+
+ $("#luckysheet-dataVerification-dialog .show-box-item-dropdown .data-verification-value1").val(value1);
+ }
+ else if(value == 'checkbox'){
+ $("#luckysheet-dataVerification-dialog .show-box .show-box-item-checkbox").show();
+
+ let value1 = "";
+ let value2 = "";
+
+ if(value == item.type){
+ value1 = item.value1;
+ value2 = item.value2;
+ }
+
+ $("#luckysheet-dataVerification-dialog .show-box-item-checkbox .data-verification-value1").val(value1);
+ $("#luckysheet-dataVerification-dialog .show-box-item-checkbox .data-verification-value2").val(value2);
+ }
+ else if(value == 'number' || value == 'number_integer' || value == 'number_decimal'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-number").show();
+ $("#luckysheet-dataVerification-dialog .show-box-item-number .input").hide();
+
+ let type2 = "bw";
+ let value1 = "";
+ let value2 = "";
+
+ if(item.type == 'number' || item.type == 'number_integer' || item.type == 'number_decimal'){
+ type2 = item.type2;
+ value1 = item.value1;
+ value2 = item.value2;
+ }
+
+ $("#luckysheet-dataVerification-dialog #data-verification-number-select").val(type2);
+
+ if(type2 == 'bw' || type2 == 'nb'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-number .input1").show();
+ }
+ else{
+ $("#luckysheet-dataVerification-dialog .show-box-item-number .input2").show();
+ }
+
+ $("#luckysheet-dataVerification-dialog .show-box-item-number .data-verification-value1").val(value1);
+ $("#luckysheet-dataVerification-dialog .show-box-item-number .data-verification-value2").val(value2);
+ }
+ else if(value == 'text_content'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-text").show();
+
+ let type2 = "include";
+ let value1 = "";
+
+ if(value == item.type){
+ type2 = item.type2;
+ value1 = item.value1;
+ }
+
+ $("#luckysheet-dataVerification-dialog #data-verification-text-select").val(type2);
+ $("#luckysheet-dataVerification-dialog .show-box-item-text .data-verification-value1").val(value1);
+ }
+ else if(value == 'text_length'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-textLength").show();
+ $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input").hide();
+
+ let type2 = "bw";
+ let value1 = "";
+ let value2 = "";
+
+ if(value == item.type){
+ type2 = item.type2;
+ value1 = item.value1;
+ value2 = item.value2;
+ }
+
+ $("#luckysheet-dataVerification-dialog #data-verification-textLength-select").val(type2);
+
+ if(type2 == 'bw' || type2 == 'nb'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input1").show();
+ }
+ else{
+ $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input2").show();
+ }
+
+ $("#luckysheet-dataVerification-dialog .show-box-item-textLength .data-verification-value1").val(value1);
+ $("#luckysheet-dataVerification-dialog .show-box-item-textLength .data-verification-value2").val(value2);
+ }
+ else if(value == 'date'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-date").show();
+ $("#luckysheet-dataVerification-dialog .show-box-item-date .input").hide();
+
+ let type2 = "bw";
+ let value1 = "";
+ let value2 = "";
+
+ if(value == item.type){
+ type2 = item.type2;
+ value1 = item.value1;
+ value2 = item.value2;
+ }
+
+ $("#luckysheet-dataVerification-dialog #data-verification-date-select").val(type2);
+
+ if(type2 == 'bw' || type2 == 'nb'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-date .input1").show();
+ }
+ else{
+ $("#luckysheet-dataVerification-dialog .show-box-item-date .input2").show();
+ }
+
+ $("#luckysheet-dataVerification-dialog .show-box-item-date .data-verification-value1").val(value1);
+ $("#luckysheet-dataVerification-dialog .show-box-item-date .data-verification-value2").val(value2);
+ }
+ else if(value == 'validity'){
+ $("#luckysheet-dataVerification-dialog .show-box .show-box-item-validity").show();
+
+ let type2 = "card";
+
+ if(value == item.type){
+ type2 = item.type2;
+ }
+
+ $("#luckysheet-dataVerification-dialog #data-verification-validity-select").val(type2);
+ }
+ });
+
+ $(document).off("change.numberSelect").on("change.numberSelect", "#data-verification-number-select", function(e) {
+ $("#luckysheet-dataVerification-dialog .show-box-item-number .input").hide();
+
+ let value = this.value;
+
+ if(value == 'bw' || value == 'nb'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-number .input1").show();
+ }
+ else{
+ $("#luckysheet-dataVerification-dialog .show-box-item-number .input2").show();
+ }
+ });
+
+ $(document).off("change.dateSelect").on("change.dateSelect", "#data-verification-date-select", function(e) {
+ $("#luckysheet-dataVerification-dialog .show-box-item-date .input").hide();
+
+ let value = this.value;
+
+ if(value == 'bw' || value == 'nb'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-date .input1").show();
+ }
+ else{
+ $("#luckysheet-dataVerification-dialog .show-box-item-date .input2").show();
+ }
+ });
+
+ //选中单元格时显示提示语
+ $(document).off("change.hintShow").on("change.hintShow", "#data-verification-hint-show", function(e) {
+ if(this.checked){
+ $("#luckysheet-dataVerification-dialog .data-verification-hint-text").show();
+ }
+ else{
+ $("#luckysheet-dataVerification-dialog .data-verification-hint-text").hide();
+ }
+ });
+
+ //确认按钮
+ $(document).off("click.confirm").on("click.confirm", "#luckysheet-dataVerification-dialog-confirm", function(e) {
+ let rangeTxt = $("#luckysheet-dataVerification-dialog #data-verification-range input").val().trim();
+ let range = _this.getRangeByTxt(rangeTxt);
+
+ if(range.length == 0){
+ tooltip.info('', dvText.selectCellRange2);
+ return;
+ }
+
+ let type = $("#luckysheet-dataVerification-dialog #data-verification-type-select").val();
+ let type2 = null, value1 = "", value2 = "";
+
+ if(type == 'dropdown'){
+ value1 = $("#luckysheet-dataVerification-dialog .show-box-item-dropdown .data-verification-value1").val().trim();
+
+ if(value1.length == 0){
+ tooltip.info('', dvText.tooltipInfo1);
+ return;
+ }
+ }
+ else if(type == 'checkbox'){
+ value1 = $("#luckysheet-dataVerification-dialog .show-box-item-checkbox .data-verification-value1").val().trim();
+ value2 = $("#luckysheet-dataVerification-dialog .show-box-item-checkbox .data-verification-value2").val().trim();
+
+ if(value1.length == 0 || value2.length == 0){
+ tooltip.info('', dvText.tooltipInfo2);
+ return;
+ }
+ }
+ else if(type == 'number' || type == 'number_integer' || type == 'number_decimal'){
+ type2 = $("#luckysheet-dataVerification-dialog #data-verification-number-select").val();
+ value1 = $("#luckysheet-dataVerification-dialog .show-box-item-number .data-verification-value1").val().trim();
+
+ if(!isRealNum(value1)){
+ tooltip.info('', dvText.tooltipInfo3);
+ return;
+ }
+
+ if(type2 == 'bw' || type2 == 'nb'){
+ value2 = $("#luckysheet-dataVerification-dialog .show-box-item-number .data-verification-value2").val().trim();
+
+ if(!isRealNum(value2)){
+ tooltip.info('', dvText.tooltipInfo3);
+ return;
+ }
+
+ if(Number(value2) < Number(value1)){
+ tooltip.info('', dvText.tooltipInfo4);
+ return;
+ }
+ }
+ }
+ else if(type == 'text_content'){
+ type2 = $("#luckysheet-dataVerification-dialog #data-verification-text-select").val();
+ value1 = $("#luckysheet-dataVerification-dialog .show-box-item-text .data-verification-value1").val().trim();
+
+ if(value1.length == 0){
+ tooltip.info('', dvText.tooltipInfo5);
+ return;
+ }
+ }
+ else if(type == 'text_length'){
+ type2 = $("#luckysheet-dataVerification-dialog #data-verification-textLength-select").val();
+ value1 = $("#luckysheet-dataVerification-dialog .show-box-item-textLength .data-verification-value1").val().trim();
+
+ if(!isRealNum(value1)){
+ tooltip.info('', dvText.tooltipInfo3);
+ return;
+ }
+
+ if(type2 == 'bw' || type2 == 'nb'){
+ value2 = $("#luckysheet-dataVerification-dialog .show-box-item-textLength .data-verification-value2").val().trim();
+
+ if(!isRealNum(value2)){
+ tooltip.info('', dvText.tooltipInfo3);
+ return;
+ }
+
+ if(Number(value2) < Number(value1)){
+ tooltip.info('', dvText.tooltipInfo4);
+ return;
+ }
+ }
+ }
+ else if(type == 'date'){
+ type2 = $("#luckysheet-dataVerification-dialog #data-verification-date-select").val();
+ value1 = $("#luckysheet-dataVerification-dialog .show-box-item-date .data-verification-value1").val().trim();
+
+ if(!isdatetime(value1)){
+ tooltip.info('', dvText.tooltipInfo6);
+ return;
+ }
+
+ if(type2 == 'bw' || type2 == 'nb'){
+ value2 = $("#luckysheet-dataVerification-dialog .show-box-item-date .data-verification-value2").val().trim();
+
+ if(!isdatetime(value2)){
+ tooltip.info('', dvText.tooltipInfo6);
+ return;
+ }
+
+ if(diff(value1, value2) > 0){
+ tooltip.info('', dvText.tooltipInfo7);
+ return;
+ }
+ }
+ }
+ else if(type == 'validity'){
+ type2 = $("#luckysheet-dataVerification-dialog #data-verification-validity-select").val();
+ }
+
+ let remote = $("#luckysheet-dataVerification-dialog #data-verification-remote").is(":checked");
+ let prohibitInput = $("#luckysheet-dataVerification-dialog #data-verification-prohibitInput").is(":checked");
+ let hintShow = $("#luckysheet-dataVerification-dialog #data-verification-hint-show").is(":checked");
+ let hintText = "";
+
+ if(hintShow){
+ hintText = $("#luckysheet-dataVerification-dialog .data-verification-hint-text input").val().trim();
+ }
+
+ let item = {
+ type: type,
+ type2: type2,
+ value1: value1,
+ value2: value2,
+ checked: false,
+ remote: remote,
+ prohibitInput: prohibitInput,
+ hintShow: hintShow,
+ hintText: hintText,
+ }
+
+ let historyDataVerification = $.extend(true, {}, _this.dataVerification);
+ let currentDataVerification = $.extend(true, {}, _this.dataVerification);
+
+ let str = range[range.length - 1].row[0],
+ edr = range[range.length - 1].row[1],
+ stc = range[range.length - 1].column[0],
+ edc = range[range.length - 1].column[1];
+
+ let d = editor.deepCopyFlowData(Store.flowdata);
+
+ for(let r = str; r <= edr; r++){
+ for(let c = stc; c <= edc; c++){
+ currentDataVerification[r + '_' + c] = item;
+
+ if(type == 'checkbox'){
+ setcellvalue(r, c, d, item.value2);
+ }
+ }
+ }
+
+ if(type == 'checkbox'){
+ _this.refOfCheckbox(historyDataVerification, currentDataVerification, Store.currentSheetIndex, d, range[range.length - 1]);
+ }
+ else{
+ _this.ref(historyDataVerification, currentDataVerification, Store.currentSheetIndex);
+ }
+
+ $("#luckysheet-modal-dialog-mask").hide();
+ $("#luckysheet-dataVerification-dialog").hide();
+ });
+
+ //删除验证按钮
+ $(document).off("click.delete").on("click.delete", "#luckysheet-dataVerification-dialog-delete", function(e) {
+ let rangeTxt = $("#luckysheet-dataVerification-dialog #data-verification-range input").val().trim();
+ let range = _this.getRangeByTxt(rangeTxt);
+
+ if(range.length == 0){
+ tooltip.info('', dvText.selectCellRange2);
+ return;
+ }
+
+ let historyDataVerification = $.extend(true, {}, _this.dataVerification);
+ let currentDataVerification = $.extend(true, {}, _this.dataVerification);
+
+ let str = range[range.length - 1].row[0],
+ edr = range[range.length - 1].row[1],
+ stc = range[range.length - 1].column[0],
+ edc = range[range.length - 1].column[1];
+
+ for(let r = str; r <= edr; r++){
+ for(let c = stc; c <= edc; c++){
+ delete currentDataVerification[r + '_' + c];
+ }
+ }
+
+ _this.ref(historyDataVerification, currentDataVerification, Store.currentSheetIndex);
+
+ $("#luckysheet-modal-dialog-mask").hide();
+ $("#luckysheet-dataVerification-dialog").hide();
+ });
+
+ //info提示弹框 关闭
+ $(document).on("click", "#luckysheet-info .luckysheet-modal-dialog-title-close, #luckysheet-info .luckysheet-model-close-btn", function(e) {
+ $(this).parents("#luckysheet-info").hide();
+
+ if($("#luckysheet-dataVerification-dialog").is(":visible")){
+ $("#luckysheet-modal-dialog-mask").show();
+ }
+ e.stopPropagation();
+ });
+ },
+ dataAllocation: function(){
+ let _this = this;
+
+ //单元格范围
+ let range = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1];
+ let rangeTxt = getRangetxt(Store.currentSheetIndex, range, Store.currentSheetIndex);
+ $("#luckysheet-dataVerification-dialog #data-verification-range input").val(rangeTxt);
+
+ //focus单元格
+ let rowIndex = range.row_focus || range.row[0];
+ let colIndex = range.column_focus || range.column[0];
+ let dataVerification = $.extend(true, {}, _this.dataVerification);
+ let item = dataVerification[rowIndex + '_' + colIndex];
+
+ if(item == null){
+ item = $.extend(true, {}, _this.defaultItem);
+ }
+
+ _this.curItem = item;
+
+ //验证条件
+ $("#luckysheet-dataVerification-dialog #data-verification-type-select").val(item.type);
+ $("#luckysheet-dataVerification-dialog .show-box .show-box-item").hide();
+
+ if(item.type == 'dropdown'){
+ $("#luckysheet-dataVerification-dialog .show-box .show-box-item-dropdown").show();
+ $("#luckysheet-dataVerification-dialog .show-box-item-dropdown .data-verification-value1").val(item.value1);
+ }
+ else if(item.type == 'checkbox'){
+ $("#luckysheet-dataVerification-dialog .show-box .show-box-item-checkbox").show();
+ $("#luckysheet-dataVerification-dialog .show-box-item-checkbox .data-verification-value1").val(item.value1);
+ $("#luckysheet-dataVerification-dialog .show-box-item-checkbox .data-verification-value2").val(item.value2);
+ }
+ else if(item.type == 'number' || item.type == 'number_integer' || item.type == 'number_decimal'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-number").show();
+ $("#luckysheet-dataVerification-dialog #data-verification-number-select").val(item.type2);
+ $("#luckysheet-dataVerification-dialog .show-box-item-number .input").hide();
+
+ if(item.type2 == 'bw' || item.type2 == 'nb'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-number .input1").show();
+ }
+ else{
+ $("#luckysheet-dataVerification-dialog .show-box-item-number .input2").show();
+ }
+
+ $("#luckysheet-dataVerification-dialog .show-box-item-number .data-verification-value1").val(item.value1);
+ $("#luckysheet-dataVerification-dialog .show-box-item-number .data-verification-value2").val(item.value2);
+ }
+ else if(item.type == 'text_content'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-text").show();
+ $("#luckysheet-dataVerification-dialog #data-verification-text-select").val(item.type2);
+ $("#luckysheet-dataVerification-dialog .show-box-item-text .data-verification-value1").val(item.value1);
+ }
+ else if(item.type == 'text_length'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-textLength").show();
+ $("#luckysheet-dataVerification-dialog #data-verification-textLength-select").val(item.type2);
+ $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input").hide();
+
+ if(item.type2 == 'bw' || item.type2 == 'nb'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input1").show();
+ }
+ else{
+ $("#luckysheet-dataVerification-dialog .show-box-item-textLength .input2").show();
+ }
+
+ $("#luckysheet-dataVerification-dialog .show-box-item-textLength .data-verification-value1").val(item.value1);
+ $("#luckysheet-dataVerification-dialog .show-box-item-textLength .data-verification-value2").val(item.value2);
+ }
+ else if(item.type == 'date'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-date").show();
+ $("#luckysheet-dataVerification-dialog #data-verification-date-select").val(item.type2);
+ $("#luckysheet-dataVerification-dialog .show-box-item-date .input").hide();
+
+ if(item.type2 == 'bw' || item.type2 == 'nb'){
+ $("#luckysheet-dataVerification-dialog .show-box-item-date .input1").show();
+ }
+ else{
+ $("#luckysheet-dataVerification-dialog .show-box-item-date .input2").show();
+ }
+
+ $("#luckysheet-dataVerification-dialog .show-box-item-date .data-verification-value1").val(item.value1);
+ $("#luckysheet-dataVerification-dialog .show-box-item-date .data-verification-value2").val(item.value2);
+ }
+ else if(item.type == 'validity'){
+ $("#luckysheet-dataVerification-dialog .show-box .show-box-item-validity").show();
+ $("#luckysheet-dataVerification-dialog #data-verification-validity-select").val(item.type2);
+ }
+
+ //自动远程获取选项
+ $("#luckysheet-dataVerification-dialog #data-verification-remote").prop("checked", item.remote);
+
+ //输入数据无效时禁止输入
+ $("#luckysheet-dataVerification-dialog #data-verification-prohibitInput").prop("checked", item.prohibitInput);
+
+ //选中单元格时显示提示语
+ $("#luckysheet-dataVerification-dialog #data-verification-hint-show").prop("checked", item.hintShow);
+
+ if(item.hintShow){
+ $("#luckysheet-dataVerification-dialog .data-verification-hint-text").show();
+ }
+ else{
+ $("#luckysheet-dataVerification-dialog .data-verification-hint-text").hide();
+ }
+
+ $("#luckysheet-dataVerification-dialog .data-verification-hint-text input").val(item.hintText);
+ },
+ rangeDialog: function(dataSource, txt){
+ let _this = this;
+
+ const _locale = locale();
+ const dvText = _locale.dataVerification;
+ const buttonText = _locale.button;
+
+ $("#luckysheet-modal-dialog-mask").hide();
+ $("#luckysheet-dataVerificationRange-dialog").remove();
+
+ $("body").append(replaceHtml(modelHTML, {
+ "id": "luckysheet-dataVerificationRange-dialog",
+ "addclass": "luckysheet-dataVerificationRange-dialog",
+ "title": dvText.selectCellRange,
+ "content": ``,
+ "botton": `
+ `,
+ "style": "z-index:100003"
+ }));
+ let $t = $("#luckysheet-dataVerificationRange-dialog")
+ .find(".luckysheet-modal-dialog-content")
+ .css("min-width", 300)
+ .end(),
+ myh = $t.outerHeight(),
+ myw = $t.outerWidth();
+ let winw = $(window).width(), winh = $(window).height();
+ let scrollLeft = $(document).scrollLeft(), scrollTop = $(document).scrollTop();
+ $("#luckysheet-dataVerificationRange-dialog").css({
+ "left": (winw + scrollLeft - myw) / 2,
+ "top": (winh + scrollTop - myh) / 3
+ }).show();
+ },
+ getTxtByRange: function(range){
+ if(range.length > 0){
+ let txt = [];
+
+ for(let s = 0; s < range.length; s++){
+ let r1 = range[s].row[0], r2 = range[s].row[1];
+ let c1 = range[s].column[0], c2 = range[s].column[1];
+
+ txt.push(getRangetxt(Store.currentSheetIndex, { "row": [r1, r2], "column": [c1, c2] }, Store.currentSheetIndex));
+ }
+
+ return txt.join(",");
+ }
+ },
+ getRangeByTxt: function(txt){
+ let range = [];
+
+ if(txt.indexOf(",") != -1){
+ let arr = txt.split(",");
+ for(let i = 0; i < arr.length; i++){
+ if(formula.iscelldata(arr[i])){
+ range.push(formula.getcellrange(arr[i]));
+ }
+ else{
+ range = [];
+ break;
+ }
+ }
+ }
+ else{
+ if(formula.iscelldata(txt)){
+ range.push(formula.getcellrange(txt));
+ }
+ }
+
+ return range;
+ },
+ cellFocus: function(r, c, clickMode){
+ $("#luckysheet-dataVerification-dropdown-btn").hide();
+ $("#luckysheet-dataVerification-showHintBox").hide();
+
+ let _this = this;
+
+ if(_this.dataVerification == null || _this.dataVerification[r + '_' + c] == null){
+ $("#luckysheet-dataVerification-dropdown-List").hide();
+ return;
+ }
+
+ let row = Store.visibledatarow[r],
+ row_pre = r == 0 ? 0 : Store.visibledatarow[r - 1];
+ let col = Store.visibledatacolumn[c],
+ col_pre = c == 0 ? 0 : Store.visibledatacolumn[c - 1];
+
+ let margeset = menuButton.mergeborer(Store.flowdata, r, c);
+ if(!!margeset){
+ row = margeset.row[1];
+ row_pre = margeset.row[0];
+
+ col = margeset.column[1];
+ col_pre = margeset.column[0];
+ }
+
+ let item = _this.dataVerification[r + '_' + c];
+
+ //单元格数据验证 类型是 复选框
+ if(clickMode && item.type == 'checkbox'){
+ _this.checkboxChange(r, c);
+ return;
+ }
+
+ //单元格数据验证 类型是 下拉列表
+ if(item.type == 'dropdown'){
+ $("#luckysheet-dataVerification-dropdown-btn").show().css({
+ 'max-width': col - col_pre,
+ 'max-height': row - row_pre,
+ 'left': col - 20,
+ 'top': row_pre + (row - row_pre - 20) / 2
+ })
+
+ if($("#luckysheet-dataVerification-dropdown-List").is(":visible")){
+ let dataIndex = $("#luckysheet-dataVerification-dropdown-List").prop("data-index");
+
+ if(dataIndex != (r + '_' + c)){
+ $("#luckysheet-dataVerification-dropdown-List").hide();
+ }
+ }
+ }
+ else{
+ $("#luckysheet-dataVerification-dropdown-List").hide();
+ }
+
+ //提示语
+ if(item.hintShow){
+ let hintText = item.hintText;
+
+ if(hintText.length == 0){
+ hintText += '提示:';
+
+ if(item.type == 'dropdown'){
+ hintText += '请选择下拉列表中的选项';
+ }
+ else if(item.type == 'checkbox'){
+
+ }
+ else if(item.type == 'number' || item.type == 'number_integer' || item.type == 'number_decimal'){
+ hintText += '请输入' + _this.optionLabel[item.type2] + item.value1;
+
+ if(item.type2 == 'bw' || item.type2 == 'nb'){
+ hintText += '和' + item.value2 + '之间';
+ }
+
+ hintText += '的' + _this.optionLabel[item.type];
+ }
+ else if(item.type == 'text_content'){
+ hintText += '请输入内容' + _this.optionLabel[item.type2] + item.value1 + '的文本';
+ }
+ else if(item.type == 'text_length'){
+ hintText += '请输入长度' + _this.optionLabel[item.type2] + item.value1;
+
+ if(item.type2 == 'bw' || item.type2 == 'nb'){
+ hintText += '和' + item.value2 + '之间';
+ }
+
+ hintText += '的文本';
+ }
+ else if(item.type == 'date'){
+ hintText += '请输入' + _this.optionLabel[item.type2] + item.value1;
+
+ if(item.type2 == 'bw' || item.type2 == 'nb'){
+ hintText += '和' + item.value2 + '之间';
+ }
+
+ hintText += '的日期';
+ }
+ else if(item.type == 'validity'){
+ hintText += '请输入正确的' + _this.optionLabel[item.type2];
+ }
+ }
+ else{
+ hintText = '提示:' + hintText;
+ }
+
+ $("#luckysheet-dataVerification-showHintBox").html(hintText).show().css({
+ 'left': col_pre,
+ 'top': row
+ });
+
+ return;
+ }
+
+ //数据验证未通过
+ let cellValue = getcellvalue(r, c, null, 'm');
+
+ if(cellValue == null || cellValue == ""){
+ return;
+ }
+
+ let validate = _this.validateCellData(cellValue, item);
+
+ if(!validate){
+ let hintText = '失效:';
+
+ if(item.type == 'dropdown'){
+ hintText += '你选择的不是下拉列表中的选项';
+ }
+ else if(item.type == 'checkbox'){
+
+ }
+ else if(item.type == 'number' || item.type == 'number_integer' || item.type == 'number_decimal'){
+ hintText += '你输入的不是' + _this.optionLabel[item.type2] + item.value1;
+
+ if(item.type2 == 'bw' || item.type2 == 'nb'){
+ hintText += '和' + item.value2 + '之间';
+ }
+
+ hintText += '的' + _this.optionLabel[item.type];
+ }
+ else if(item.type == 'text_content'){
+ hintText += '你输入的不是内容' + _this.optionLabel[item.type2] + item.value1 + '的文本';
+ }
+ else if(item.type == 'text_length'){
+ hintText += '你输入的不是长度' + _this.optionLabel[item.type2] + item.value1;
+
+ if(item.type2 == 'bw' || item.type2 == 'nb'){
+ hintText += '和' + item.value2 + '之间';
+ }
+
+ hintText += '的文本';
+ }
+ else if(item.type == 'date'){
+ hintText += '你输入的不是' + _this.optionLabel[item.type2] + item.value1;
+
+ if(item.type2 == 'bw' || item.type2 == 'nb'){
+ hintText += '和' + item.value2 + '之间';
+ }
+
+ hintText += '的日期';
+ }
+ else if(item.type == 'validity'){
+ hintText += '你输入的不是一个正确的' + _this.optionLabel[item.type2];
+ }
+
+ $("#luckysheet-dataVerification-showHintBox").html(hintText).show().css({
+ 'left': col_pre,
+ 'top': row
+ });
+ }
+ },
+ validateCellData: function(cellValue, item){
+ let _this = this;
+
+ let type = item.type,
+ type2 = item.type2,
+ value1 = item.value1,
+ value2 = item.value2;
+
+ if(type == 'dropdown'){
+ let list = _this.getDropdownList(value1);
+
+ if(!list.includes(cellValue)){
+ return false;
+ }
+ }
+ else if(type == 'checkbox'){
+
+ }
+ else if(type == 'number' || type == 'number_integer' || type == 'number_decimal'){
+ if(!isRealNum(cellValue)){
+ return false;
+ }
+
+ cellValue = Number(cellValue);
+
+ if(type == 'number_integer' && cellValue % 1 !== 0){
+ return false;
+ }
+
+ if(type == 'number_decimal' && cellValue % 1 === 0){
+ return false;
+ }
+
+ value1 = Number(value1);
+ value2 = Number(value2);
+
+ if(type2 == 'bw' && (cellValue < value1 || cellValue > value2)){
+ return false;
+ }
+
+ if(type2 == 'nb' && (cellValue >= value1 && cellValue <= value2)){
+ return false;
+ }
+
+ if(type2 == 'eq' && cellValue != value1){
+ return false;
+ }
+
+ if(type2 == 'ne' && cellValue == value1){
+ return false;
+ }
+
+ if(type2 == 'gt' && cellValue <= value1){
+ return false;
+ }
+
+ if(type2 == 'lt' && cellValue >= value1){
+ return false;
+ }
+
+ if(type2 == 'gte' && cellValue < value1){
+ return false;
+ }
+
+ if(type2 == 'lte' && cellValue > value1){
+ return false;
+ }
+ }
+ else if(type == 'text_content'){
+ cellValue = cellValue.toString();
+ value1 = value1.toString();
+
+ if(type2 == 'include' && cellValue.indexOf(value1) == -1){
+ return false;
+ }
+
+ if(type2 == 'exclude' && cellValue.indexOf(value1) > -1){
+ return false;
+ }
+
+ if(type2 == 'equal' && cellValue != value1){
+ return false;
+ }
+ }
+ else if(type == 'text_length'){
+ cellValue = cellValue.toString().length;
+
+ value1 = Number(value1);
+ value2 = Number(value2);
+
+ if(type2 == 'bw' && (cellValue < value1 || cellValue > value2)){
+ return false;
+ }
+
+ if(type2 == 'nb' && (cellValue >= value1 && cellValue <= value2)){
+ return false;
+ }
+
+ if(type2 == 'eq' && cellValue != value1){
+ return false;
+ }
+
+ if(type2 == 'ne' && cellValue == value1){
+ return false;
+ }
+
+ if(type2 == 'gt' && cellValue <= value1){
+ return false;
+ }
+
+ if(type2 == 'lt' && cellValue >= value1){
+ return false;
+ }
+
+ if(type2 == 'gte' && cellValue < value1){
+ return false;
+ }
+
+ if(type2 == 'lte' && cellValue > value1){
+ return false;
+ }
+ }
+ else if(type == 'date'){
+ if(!isdatetime(cellValue)){
+ return false;
+ }
+
+ if(type2 == 'bw' && (diff(cellValue, value1) < 0 || diff(cellValue, value2) > 0)){
+ return false;
+ }
+
+ if(type2 == 'nb' && (diff(cellValue, value1) >= 0 && diff(cellValue, value2) <= 0)){
+ return false;
+ }
+
+ if(type2 == 'eq' && diff(cellValue, value1) != 0){
+ return false;
+ }
+
+ if(type2 == 'ne' && diff(cellValue, value1) == 0){
+ return false;
+ }
+
+ if(type2 == 'bf' && diff(cellValue, value1) >= 0){
+ return false;
+ }
+
+ if(type2 == 'nbf' && diff(cellValue, value1) < 0){
+ return false;
+ }
+
+ if(type2 == 'af' && diff(cellValue, value1) <= 0){
+ return false;
+ }
+
+ if(type2 == 'naf' && diff(cellValue, value1) > 0){
+ return false;
+ }
+ }
+ else if(type == 'validity'){
+ if(type2 == 'card' && !/(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/.test(cellValue)){
+ return false;
+ }
+
+ if(type2 == 'phone' && !/^[1][3,4,5,7,8][0-9]{9}$/.test(cellValue)){
+ return false;
+ }
+ }
+
+ return true;
+ },
+ dropdownListShow: function(){
+ $("#luckysheet-dataVerification-showHintBox").hide();
+
+ let _this = this;
+
+ let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1];
+ let rowIndex = last.row_focus;
+ let colIndex = last.column_focus;
+
+ let row = Store.visibledatarow[rowIndex],
+ row_pre = rowIndex == 0 ? 0 : Store.visibledatarow[rowIndex - 1];
+ let col = Store.visibledatacolumn[colIndex],
+ col_pre = colIndex == 0 ? 0 : Store.visibledatacolumn[colIndex - 1];
+
+ let margeset = menuButton.mergeborer(Store.flowdata, rowIndex, colIndex);
+ if(!!margeset){
+ row = margeset.row[1];
+ row_pre = margeset.row[0];
+
+ col = margeset.column[1];
+ col_pre = margeset.column[0];
+ }
+
+ let item = _this.dataVerification[rowIndex + '_' + colIndex];
+ let list = _this.getDropdownList(item.value1);
+
+ let optionHtml = '';
+ list.forEach(i => {
+ optionHtml += `${i}
`;
+ })
+
+ $("#luckysheet-dataVerification-dropdown-List")
+ .html(optionHtml)
+ .prop("data-index", rowIndex + '_' + colIndex)
+ .show()
+ .css({
+ 'width': col - col_pre - 1,
+ 'left': col_pre,
+ 'top': row,
+ });
+ },
+ getDropdownList: function(txt){
+ let list = [];
+
+ if(formula.iscelldata(txt)){
+ let range = formula.getcellrange(txt);
+ let d = Store.luckysheetfile[getSheetIndex(range.sheetIndex)].data;
+
+ for(let r = range.row[0]; r <= range.row[1]; r++){
+ for(let c = range.column[0]; c <= range.column[1]; c++){
+ if(d[r] == null){
+ continue;
+ }
+
+ let cell = d[r][c];
+
+ if(cell == null || cell.v == null){
+ continue;
+ }
+
+ let v = cell.m || cell.v;
+
+ if(!list.includes(v)){
+ list.push(v);
+ }
+ }
+ }
+ }
+ else{
+ let arr = txt.split(",");
+
+ for(let i = 0; i < arr.length; i++){
+ let v = arr[i];
+
+ if(v.length == 0){
+ continue;
+ }
+
+ if(!list.includes(v)){
+ list.push(v);
+ }
+ }
+ }
+
+ return list;
+ },
+ checkboxChange: function(r, c){
+ let _this = this;
+
+ let historyDataVerification = $.extend(true, {}, _this.dataVerification);
+ let currentDataVerification = $.extend(true, {}, _this.dataVerification);
+
+ let item = currentDataVerification[r + '_' + c];
+ item.checked = !item.checked;
+
+ let value = item.value2;
+ if(item.checked){
+ value = item.value1;
+ }
+
+ let d = editor.deepCopyFlowData(Store.flowdata);
+ setcellvalue(r, c, d, value);
+
+ _this.refOfCheckbox(
+ historyDataVerification,
+ currentDataVerification,
+ Store.currentSheetIndex,
+ d,
+ { "row": [r, r], "column": [c, c] }
+ );
+ },
+ ref: function(historyDataVerification, currentDataVerification, sheetIndex){
+ let _this = this;
+
+ if (Store.clearjfundo) {
+ Store.jfundo = [];
+
+ let redo = {};
+ redo["type"] = "updateDataVerification";
+ redo["sheetIndex"] = sheetIndex;
+ redo["historyDataVerification"] = historyDataVerification;
+ redo["currentDataVerification"] = currentDataVerification;
+ Store.jfredo.push(redo);
+ }
+
+ _this.dataVerification = currentDataVerification;
+ Store.luckysheetfile[getSheetIndex(sheetIndex)].dataVerification = currentDataVerification;
+
+ //共享编辑模式
+ if(server.allowUpdate){
+ server.saveParam("all", sheetIndex, currentDataVerification, { "k": "dataVerification" });
+ }
+
+ setTimeout(function () {
+ luckysheetrefreshgrid();
+ }, 1);
+ },
+ refOfCheckbox: function(historyDataVerification, currentDataVerification, sheetIndex, d, range){
+ let _this = this;
+
+ if (Store.clearjfundo) {
+ Store.jfundo = [];
+
+ let redo = {};
+ redo["type"] = "updateDataVerificationOfCheckbox";
+ redo["sheetIndex"] = sheetIndex;
+ redo["historyDataVerification"] = historyDataVerification;
+ redo["currentDataVerification"] = currentDataVerification;
+ redo["data"] = Store.flowdata;
+ redo["curData"] = d;
+ redo["range"] = range;
+ Store.jfredo.push(redo);
+ }
+
+ _this.dataVerification = currentDataVerification;
+ Store.luckysheetfile[getSheetIndex(sheetIndex)].dataVerification = currentDataVerification;
+
+ Store.flowdata = d;
+ editor.webWorkerFlowDataCache(Store.flowdata);//worker存数据
+ Store.luckysheetfile[getSheetIndex(sheetIndex)].data = Store.flowdata;
+
+ //共享编辑模式
+ if(server.allowUpdate){
+ server.saveParam("all", sheetIndex, currentDataVerification, { "k": "dataVerification" });
+ server.historyParam(Store.flowdata, sheetIndex, range);
+ }
+
+ setTimeout(function () {
+ luckysheetrefreshgrid();
+ }, 1);
+ },
+}
+
+export default dataVerificationCtrl;
\ No newline at end of file
diff --git a/src/controllers/dropCell.js b/src/controllers/dropCell.js
index 0c728a3..2d37a67 100644
--- a/src/controllers/dropCell.js
+++ b/src/controllers/dropCell.js
@@ -450,6 +450,7 @@ const luckysheetDropCell = {
let cfg = $.extend(true, {}, Store.config);
let borderInfoCompute = getBorderInfoCompute();
+ let dataVerification = $.extend(true, {}, file["dataVerification"]);
let direction = _this.direction;
let type = _this.applyType;
@@ -563,6 +564,11 @@ const luckysheetDropCell = {
cfg["borderInfo"].push(bd_obj);
}
+
+ //数据验证
+ if(dataVerification[bd_r + "_" + bd_c]){
+ dataVerification[j + "_" + i] = dataVerification[bd_r + "_" + bd_c];
+ }
}
}
if(direction == "up"){
@@ -647,6 +653,11 @@ const luckysheetDropCell = {
cfg["borderInfo"].push(bd_obj);
}
+
+ //数据验证
+ if(dataVerification[bd_r + "_" + bd_c]){
+ dataVerification[j + "_" + i] = dataVerification[bd_r + "_" + bd_c];
+ }
}
}
}
@@ -741,6 +752,11 @@ const luckysheetDropCell = {
cfg["borderInfo"].push(bd_obj);
}
+
+ //数据验证
+ if(dataVerification[bd_r + "_" + bd_c]){
+ dataVerification[i + "_" + j] = dataVerification[bd_r + "_" + bd_c];
+ }
}
}
if(direction == "left"){
@@ -825,6 +841,11 @@ const luckysheetDropCell = {
cfg["borderInfo"].push(bd_obj);
}
+
+ //数据验证
+ if(dataVerification[bd_r + "_" + bd_c]){
+ dataVerification[i + "_" + j] = dataVerification[bd_r + "_" + bd_c];
+ }
}
}
}
@@ -852,7 +873,12 @@ const luckysheetDropCell = {
}
//刷新一次表格
- jfrefreshgrid(d, Store.luckysheet_select_save, cfg, cdformat);
+ let allParam = {
+ "cfg": cfg,
+ "cdformat": cdformat,
+ "dataVerification": dataVerification
+ }
+ jfrefreshgrid(d, Store.luckysheet_select_save, allParam);
selectHightlightShow();
},
diff --git a/src/controllers/filter.js b/src/controllers/filter.js
index 980b72c..675ab45 100644
--- a/src/controllers/filter.js
+++ b/src/controllers/filter.js
@@ -120,15 +120,18 @@ function orderbydatafiler(str, stc, edr, edc, index, asc) {
}
}
+ let allParam = {};
if(Store.config["rowlen"] != null){
let cfg = $.extend(true, {}, Store.config);
cfg = rowlenByRange(d, str, edr, cfg);
- jfrefreshgrid(d, [{ "row": [str, edr], "column": [stc, edc] }], cfg, null, true);
- }
- else{
- jfrefreshgrid(d, [{ "row": [str, edr], "column": [stc, edc] }]);
+ allParam = {
+ "cfg": cfg,
+ "RowlChange": true
+ }
}
+
+ jfrefreshgrid(d, [{ "row": [str, edr], "column": [stc, edc] }], allParam);
}
//创建筛选按钮
@@ -1250,9 +1253,6 @@ function initialFilterHandler(){
$("#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;
@@ -1287,6 +1287,9 @@ function initialFilterHandler(){
Store.jfundo = [];
Store.jfredo.push(redo);
+ $('#luckysheet-filter-selected-sheet' + Store.currentSheetIndex + ', #luckysheet-filter-options-sheet' + Store.currentSheetIndex).remove();
+ $("#luckysheet-filter-menu, #luckysheet-filter-submenu").hide();
+
//清除筛选发送给后台
Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].filter = null;
Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].filter_select = null;
diff --git a/src/controllers/formulaBar.js b/src/controllers/formulaBar.js
index 2919942..7ee5da4 100644
--- a/src/controllers/formulaBar.js
+++ b/src/controllers/formulaBar.js
@@ -33,10 +33,10 @@ export function formulaBarInitial(){
let row_index = last["row_focus"], col_index = last["column_focus"];
- let $input = $("#luckysheet-rich-text-editor"),value = $input.text();
- if(value) {
- formula.updatecell(row_index, col_index);
- }
+ // let $input = $("#luckysheet-rich-text-editor"),value = $input.text();
+ // if(value) {
+ // formula.updatecell(row_index, col_index);
+ // }
luckysheetupdateCell(row_index, col_index, Store.flowdata, null, true);
formula.rangeResizeTo = $("#luckysheet-functionbox-cell");
}
diff --git a/src/controllers/freezen.js b/src/controllers/freezen.js
index 3b69887..f07b018 100644
--- a/src/controllers/freezen.js
+++ b/src/controllers/freezen.js
@@ -1624,186 +1624,183 @@ const luckysheetFreezen = {
Store.luckysheetfile[order]["frozen"] = frozen[operate];
},
frozenTofreezen: function() {
-
// get frozen type
- const frozen = Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["frozen"];
+ let file = Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)];
+ const frozen = file["frozen"];
if(frozen == null){
return;
}
-
- let freezen = null;
- // transform to freezen
- if(frozen.type === 'row'){
- let scrollTop = $("#luckysheet-cell-main").scrollTop();
- let row_st = luckysheet_searcharray(Store.visibledatarow, scrollTop);
- if(row_st == -1){
- row_st = 0;
- }
- let top = Store.visibledatarow[row_st] - 2 - scrollTop + Store.columeHeaderHeight;
- let freezenhorizontaldata = [Store.visibledatarow[row_st], row_st + 1, scrollTop, luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1), top];
-
- freezen = {
- horizontal:{
- freezenhorizontaldata: freezenhorizontaldata,
- top: top
- }
- }
-
- }
- else if(frozen.type === 'column'){
- let scrollLeft = $("#luckysheet-cell-main").scrollLeft();
- let col_st = luckysheet_searcharray(Store.visibledatacolumn, scrollLeft);
- if(col_st == -1){
- col_st = 0;
- }
- let left = Store.visibledatacolumn[col_st] - 2 - scrollLeft + Store.rowHeaderWidth;
- let freezenverticaldata = [Store.visibledatacolumn[col_st], col_st + 1, scrollLeft, luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1), left];
+ if(file["freezen"] == null){
+ let freezen = null;
- freezen = {
- vertical:{
- freezenverticaldata: freezenverticaldata,
- left: left
+ // transform to freezen
+ if(frozen.type === 'row'){
+ let scrollTop = 0;
+ let row_st = luckysheet_searcharray(Store.visibledatarow, scrollTop);
+ if(row_st == -1){
+ row_st = 0;
+ }
+ let top = Store.visibledatarow[row_st] - 2 - scrollTop + Store.columeHeaderHeight;
+ let freezenhorizontaldata = [Store.visibledatarow[row_st], row_st + 1, scrollTop, luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1), top];
+
+ freezen = {
+ horizontal:{
+ freezenhorizontaldata: freezenhorizontaldata,
+ top: top
+ }
}
- }
- }
- else if(frozen.type === 'both'){
- let scrollTop = $("#luckysheet-cell-main").scrollTop();
- let row_st = luckysheet_searcharray(Store.visibledatarow, scrollTop);
- if(row_st == -1){
- row_st = 0;
- }
- let top = Store.visibledatarow[row_st] - 2 - scrollTop + Store.columeHeaderHeight;
- let freezenhorizontaldata = [Store.visibledatarow[row_st], row_st + 1, scrollTop, luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1), top];
-
- freezen = {
}
-
- let scrollLeft = $("#luckysheet-cell-main").scrollLeft();
- let col_st = luckysheet_searcharray(Store.visibledatacolumn, scrollLeft);
- if(col_st == -1){
- col_st = 0;
- }
- let left = Store.visibledatacolumn[col_st] - 2 - scrollLeft + Store.rowHeaderWidth;
- let freezenverticaldata = [Store.visibledatacolumn[col_st], col_st + 1, scrollLeft, luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1), left];
-
- freezen = {
- horizontal:{
- freezenhorizontaldata: freezenhorizontaldata,
- top: top
- },
- vertical:{
- freezenverticaldata: freezenverticaldata,
- left: left
+ else if(frozen.type === 'column'){
+ let scrollLeft = 0;
+ let col_st = luckysheet_searcharray(Store.visibledatacolumn, scrollLeft);
+ if(col_st == -1){
+ col_st = 0;
+ }
+ let left = Store.visibledatacolumn[col_st] - 2 - scrollLeft + Store.rowHeaderWidth;
+ let freezenverticaldata = [Store.visibledatacolumn[col_st], col_st + 1, scrollLeft, luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1), left];
+
+ freezen = {
+ vertical:{
+ freezenverticaldata: freezenverticaldata,
+ left: left
+ }
}
}
+ else if(frozen.type === 'both'){
+ let scrollTop = 0;
+ let row_st = luckysheet_searcharray(Store.visibledatarow, scrollTop);
+ if(row_st == -1){
+ row_st = 0;
+ }
+ let top = Store.visibledatarow[row_st] - 2 - scrollTop + Store.columeHeaderHeight;
+ let freezenhorizontaldata = [Store.visibledatarow[row_st], row_st + 1, scrollTop, luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1), top];
+
+ let scrollLeft = 0;
+ let col_st = luckysheet_searcharray(Store.visibledatacolumn, scrollLeft);
+ if(col_st == -1){
+ col_st = 0;
+ }
+ let left = Store.visibledatacolumn[col_st] - 2 - scrollLeft + Store.rowHeaderWidth;
+ let freezenverticaldata = [Store.visibledatacolumn[col_st], col_st + 1, scrollLeft, luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1), left];
+
+ freezen = {
+ horizontal:{
+ freezenhorizontaldata: freezenhorizontaldata,
+ top: top
+ },
+ vertical:{
+ freezenverticaldata: freezenverticaldata,
+ left: left
+ }
+ }
- }
- else if(frozen.type === 'rangeRow'){
- let scrollTop = $("#luckysheet-cell-main").scrollTop();
- let row_st = luckysheet_searcharray(Store.visibledatarow, scrollTop);
-
- let row_focus = frozen.range["row_focus"];
-
- if(row_focus > row_st){
- row_st = row_focus;
- }
-
- if(row_st == -1){
- row_st = 0;
}
+ else if(frozen.type === 'rangeRow'){
+ let scrollTop = 0;
+ let row_st = luckysheet_searcharray(Store.visibledatarow, scrollTop);
- let top = Store.visibledatarow[row_st] - 2 - scrollTop + Store.columeHeaderHeight;
- let freezenhorizontaldata = [Store.visibledatarow[row_st], row_st + 1, scrollTop, luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1), top];
+ let row_focus = frozen.range["row_focus"];
- freezen = {
- horizontal:{
- freezenhorizontaldata: freezenhorizontaldata,
- top: top
+ if(row_focus > row_st){
+ row_st = row_focus;
+ }
+
+ if(row_st == -1){
+ row_st = 0;
}
- }
- }
- else if(frozen.type === 'rangeColumn'){
- let scrollLeft = $("#luckysheet-cell-main").scrollLeft();
- let col_st = luckysheet_searcharray(Store.visibledatacolumn, scrollLeft);
+ let top = Store.visibledatarow[row_st] - 2 - scrollTop + Store.columeHeaderHeight;
+ let freezenhorizontaldata = [Store.visibledatarow[row_st], row_st + 1, scrollTop, luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1), top];
- let column_focus = frozen.range["column_focus"];
+ freezen = {
+ horizontal:{
+ freezenhorizontaldata: freezenhorizontaldata,
+ top: top
+ }
+ }
- if(column_focus > col_st){
- col_st = column_focus;
}
+ else if(frozen.type === 'rangeColumn'){
+ let scrollLeft = 0;
+ let col_st = luckysheet_searcharray(Store.visibledatacolumn, scrollLeft);
- if(col_st == -1){
- col_st = 0;
- }
+ let column_focus = frozen.range["column_focus"];
- let left = Store.visibledatacolumn[col_st] - 2 - scrollLeft + Store.rowHeaderWidth;
- let freezenverticaldata = [Store.visibledatacolumn[col_st], col_st + 1, scrollLeft, luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1), left];
+ if(column_focus > col_st){
+ col_st = column_focus;
+ }
- freezen = {
- vertical:{
- freezenverticaldata: freezenverticaldata,
- left: left
+ if(col_st == -1){
+ col_st = 0;
}
- }
- }
- else if(frozen.type === 'rangeBoth'){
- let scrollTop = $("#luckysheet-cell-main").scrollTop();
- let row_st = luckysheet_searcharray(Store.visibledatarow, scrollTop);
+ let left = Store.visibledatacolumn[col_st] - 2 - scrollLeft + Store.rowHeaderWidth;
+ let freezenverticaldata = [Store.visibledatacolumn[col_st], col_st + 1, scrollLeft, luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1), left];
- let row_focus = frozen.range["row_focus"];
+ freezen = {
+ vertical:{
+ freezenverticaldata: freezenverticaldata,
+ left: left
+ }
+ }
- if(row_focus > row_st){
- row_st = row_focus;
- }
-
- if(row_st == -1){
- row_st = 0;
}
+ else if(frozen.type === 'rangeBoth'){
+ let scrollTop = 0;
+ let row_st = luckysheet_searcharray(Store.visibledatarow, scrollTop);
- let top = Store.visibledatarow[row_st] - 2 - scrollTop + Store.columeHeaderHeight;
- let freezenhorizontaldata = [Store.visibledatarow[row_st], row_st + 1, scrollTop, luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1), top];
+ let row_focus = frozen.range["row_focus"];
- let scrollLeft = $("#luckysheet-cell-main").scrollLeft();
- let col_st = luckysheet_searcharray(Store.visibledatacolumn, scrollLeft);
+ if(row_focus > row_st){
+ row_st = row_focus;
+ }
+
+ if(row_st == -1){
+ row_st = 0;
+ }
- let column_focus = frozen.range["column_focus"];
+ let top = Store.visibledatarow[row_st] - 2 - scrollTop + Store.columeHeaderHeight;
+ let freezenhorizontaldata = [Store.visibledatarow[row_st], row_st + 1, scrollTop, luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1), top];
- if(column_focus > col_st){
- col_st = column_focus;
- }
+ let scrollLeft = 0;
+ let col_st = luckysheet_searcharray(Store.visibledatacolumn, scrollLeft);
- if(col_st == -1){
- col_st = 0;
- }
+ let column_focus = frozen.range["column_focus"];
+
+ if(column_focus > col_st){
+ col_st = column_focus;
+ }
- let left = Store.visibledatacolumn[col_st] - 2 - scrollLeft + Store.rowHeaderWidth;
- let freezenverticaldata = [Store.visibledatacolumn[col_st], col_st + 1, scrollLeft, luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1), left];
+ if(col_st == -1){
+ col_st = 0;
+ }
+
+ let left = Store.visibledatacolumn[col_st] - 2 - scrollLeft + Store.rowHeaderWidth;
+ let freezenverticaldata = [Store.visibledatacolumn[col_st], col_st + 1, scrollLeft, luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1), left];
- freezen = {
- horizontal:{
- freezenhorizontaldata: freezenhorizontaldata,
- top: top
- },
- vertical:{
- freezenverticaldata: freezenverticaldata,
- left: left
+ freezen = {
+ horizontal:{
+ freezenhorizontaldata: freezenhorizontaldata,
+ top: top
+ },
+ vertical:{
+ freezenverticaldata: freezenverticaldata,
+ left: left
+ }
}
}
- }
- else if(frozen.type === 'cancel'){
- freezen = {
- horizontal: null,
- vertical: null
+ else if(frozen.type === 'cancel'){
+ freezen = {
+ horizontal: null,
+ vertical: null
+ }
}
- }
-
- Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["freezen"] = freezen;
+ file["freezen"] = freezen;
+ }
}
}
diff --git a/src/controllers/handler.js b/src/controllers/handler.js
index 898ba8c..7812ceb 100644
--- a/src/controllers/handler.js
+++ b/src/controllers/handler.js
@@ -5,6 +5,7 @@ import pivotTable from './pivotTable';
import luckysheetDropCell from './dropCell';
import luckysheetPostil from './postil';
import imageCtrl from './imageCtrl';
+import dataVerificationCtrl from './dataVerificationCtrl';
import menuButton from './menuButton';
import conditionformat from './conditionformat';
import alternateformat from './alternateformat';
@@ -21,6 +22,7 @@ import { selectHightlightShow, selectIsOverlap, selectionCopyShow, luckysheet_co
import selection from './selection';
import controlHistory from './controlHistory';
import splitColumn from './splitColumn';
+import {hideMenuByCancel} from '../global/cursorPos';
import { luckysheetdefaultstyle } from './constant';
import {
@@ -231,8 +233,16 @@ export default function luckysheetHandler() {
}
});
+ $("#luckysheet-rich-text-editor").mouseup(function(e){
+ menuButton.inputMenuButtonFocus(e.target);
+ });
+
//表格mousedown
$("#luckysheet-cell-main, #luckysheetTableContent").mousedown(function (event) {
+ if($(event.target).hasClass('luckysheet-mousedown-cancel')){
+ return;
+ }
+
$("#luckysheet-cell-selected").find(".luckysheet-cs-fillhandle")
.css("cursor","default")
.end()
@@ -289,6 +299,9 @@ export default function luckysheetHandler() {
col_index_ed = margeset.column[3];
}
+ //数据验证 单元格聚焦
+ dataVerificationCtrl.cellFocus(row_index, col_index, true);
+
//若点击单元格部分不在视图内
if (col_pre < $("#luckysheet-cell-main").scrollLeft()) {
$("#luckysheet-scrollbar-x").scrollLeft(col_pre);
@@ -300,6 +313,8 @@ export default function luckysheetHandler() {
//mousedown是右键
if (event.which == "3") {
+ $("#luckysheet-dataVerification-showHintBox").hide();
+
let isright = false;
for (let s = 0; s < Store.luckysheet_select_save.length; s++) {
@@ -669,6 +684,134 @@ export default function luckysheetHandler() {
return;
}
+ //数据验证 单元格范围选择
+ if($("#luckysheet-dataVerificationRange-dialog").is(":visible")){
+ dataVerificationCtrl.selectStatus = true;
+ Store.luckysheet_select_status = false;
+
+ if (event.shiftKey) {
+ let last = dataVerificationCtrl.selectRange[dataVerificationCtrl.selectRange.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];
+ }
+
+ 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, rowseleted, last, top, height, left, width);
+ 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["column"] = columnseleted;
+
+ last["left_move"] = left;
+ last["width_move"] = width;
+ last["top_move"] = top;
+ last["height_move"] = height;
+
+ dataVerificationCtrl.selectRange[dataVerificationCtrl.selectRange.length - 1] = last;
+ }
+ else if (event.ctrlKey) {
+ dataVerificationCtrl.selectRange.push({
+ "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": [row_index, row_index_ed],
+ "column": [col_index, col_index_ed],
+ "row_focus": row_index,
+ "column_focus": col_index
+ });
+ }
+ else {
+ dataVerificationCtrl.selectRange = [];
+ dataVerificationCtrl.selectRange.push({
+ "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": [row_index, row_index_ed],
+ "column": [col_index, col_index_ed],
+ "row_focus": row_index,
+ "column_focus": col_index
+ });
+ }
+
+ selectionCopyShow(dataVerificationCtrl.selectRange);
+
+ let range = dataVerificationCtrl.getTxtByRange(dataVerificationCtrl.selectRange);
+ $("#luckysheet-dataVerificationRange-dialog input").val(range);
+
+ return;
+ }
+ else{
+ dataVerificationCtrl.selectStatus = false;
+ dataVerificationCtrl.selectRange = [];
+ }
+
//if公式生成器
if (ifFormulaGenerator.singleRangeFocus) {
$("#luckysheet-ifFormulaGenerator-dialog .singRange").click();
@@ -1023,6 +1166,10 @@ export default function luckysheetHandler() {
showrightclickmenu($("#luckysheet-rightclick-menu"), x, y);
}
}).dblclick(function (event) {
+ if($(event.target).hasClass('luckysheet-mousedown-cancel')){
+ return;
+ }
+
//禁止前台编辑(只可 框选单元格、滚动查看表格)
if (!Store.allowEdit) {
return;
@@ -1569,6 +1716,101 @@ export default function luckysheetHandler() {
let range = conditionformat.getTxtByRange(conditionformat.selectRange);
$("#luckysheet-multiRange-dialog input").val(range);
}
+ else if (dataVerificationCtrl.selectStatus) {
+ let mouse = mouseposition(event.pageX, event.pageY);
+ let x = mouse[0] + $("#luckysheet-cell-main").scrollLeft();
+ let y = mouse[1] + $("#luckysheet-cell-main").scrollTop();
+
+ 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 last = dataVerificationCtrl.selectRange[dataVerificationCtrl.selectRange.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];
+ }
+
+ 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, rowseleted, last, top, height, left, width);
+ 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["column"] = columnseleted;
+
+ last["left_move"] = left;
+ last["width_move"] = width;
+ last["top_move"] = top;
+ last["height_move"] = height;
+
+ dataVerificationCtrl.selectRange[dataVerificationCtrl.selectRange.length - 1] = last;
+
+ selectionCopyShow(dataVerificationCtrl.selectRange);
+
+ let range = dataVerificationCtrl.getTxtByRange(dataVerificationCtrl.selectRange);
+ $("#luckysheet-dataVerificationRange-dialog input").val(range);
+ }
else if (formula.rangestart) {
formula.rangedrag(event);
}
@@ -2909,6 +3151,12 @@ export default function luckysheetHandler() {
cfg["rowlen"] = {};
}
+ if (cfg["customHeight"] == null) {
+ cfg["customHeight"] = {};
+ }
+
+ cfg["customHeight"][Store.luckysheet_rows_change_size_start[1]] = 1;
+
cfg["rowlen"][Store.luckysheet_rows_change_size_start[1]] = Math.ceil(size/Store.zoomRatio);
let images = imageCtrl.moveChangeSize("row", Store.luckysheet_rows_change_size_start[1], size);
@@ -2985,6 +3233,12 @@ export default function luckysheetHandler() {
cfg["columnlen"] = {};
}
+ if (cfg["customWidth"] == null) {
+ cfg["customWidth"] = {};
+ }
+
+ cfg["customWidth"][Store.luckysheet_cols_change_size_start[1]] = 1;
+
cfg["columnlen"][Store.luckysheet_cols_change_size_start[1]] = Math.ceil(size/Store.zoomRatio);
let images = imageCtrl.moveChangeSize("column", Store.luckysheet_cols_change_size_start[1], size);
@@ -3257,7 +3511,13 @@ export default function luckysheetHandler() {
last["row_focus"] = rf;
last["column_focus"] = cf;
- jfrefreshgrid(d, range, cfg, cdformat, RowlChange);
+ let allParam = {
+ "cfg": cfg,
+ "RowlChange": RowlChange,
+ "cdformat": cdformat
+ }
+
+ jfrefreshgrid(d, range, allParam);
selectHightlightShow();
@@ -4040,6 +4300,10 @@ export default function luckysheetHandler() {
$("#luckysheet-insertImg-btn-title").click(function () {
$("#luckysheet-imgUpload").click();
});
+ $("#luckysheetInsertImage").click(function () {
+ $("#luckysheet-imgUpload").click();
+ $("#luckysheet-rightclick-menu").hide();
+ })
$("#luckysheet-imgUpload").click(function (e) {
e.stopPropagation();
});
@@ -4055,6 +4319,20 @@ export default function luckysheetHandler() {
}
});
+ //菜单栏 数据验证按钮
+ $("#luckysheet-dataVerification-btn-title").click(function () {
+ if (Store.luckysheet_select_save == null || Store.luckysheet_select_save.length == 0) {
+ return;
+ }
+
+ dataVerificationCtrl.createDialog();
+ dataVerificationCtrl.init();
+ })
+ $("#luckysheetDataVerification").click(function () {
+ $("#luckysheet-dataVerification-btn-title").click();
+ $("#luckysheet-rightclick-menu").hide();
+ })
+
//冻结行列
$("#luckysheet-freezen-btn-horizontal").click(function () {
if ($.trim($(this).text()) == locale().freezen.freezenCancel) {
@@ -4130,19 +4408,11 @@ export default function luckysheetHandler() {
//有批注在编辑时
luckysheetPostil.removeActivePs();
- if (!$(event.target).hasClass("luckysheet-mousedown-cancel") && $(event.target).filter("[class*='sp-palette']").length == 0 && $(event.target).filter("[class*='sp-thumb']").length == 0 && $(event.target).filter("[class*='sp-']").length == 0) {
- $("#luckysheet-rightclick-menu").hide();
- $("#luckysheet-cols-h-hover").hide();
- $("#luckysheet-cols-menu-btn").hide();
- $("#luckysheet-rightclick-menu").hide();
- $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu, #luckysheet-user-menu").hide();
- $("body > .luckysheet-filter-menu, body > .luckysheet-filter-submenu, body > .luckysheet-cols-menu").hide();
- //$("body > luckysheet-menuButton").hide();
- Store.luckysheet_cols_menu_status = false;
- }
+ hideMenuByCancel(event);
//点击功能栏时 如果是单元格编辑模式 则退出编辑模式
if ($(event.target).closest("#luckysheet-wa-editor").length > 0 && parseInt($("#luckysheet-input-box").css("top")) > 0) {
+ console.log(event);
formula.updatecell(Store.luckysheetCellUpdate[0], Store.luckysheetCellUpdate[1]);
luckysheetMoveHighlightCell("down", 0, "rangeOfSelect");
}
@@ -4397,8 +4667,6 @@ export default function luckysheetHandler() {
clipboardData = e.originalEvent.clipboardData;
}
-
-
let txtdata = clipboardData.getData("text/html");
//如果标示是qksheet复制的内容,判断剪贴板内容是否是当前页面复制的内容
@@ -4480,7 +4748,6 @@ export default function luckysheetHandler() {
}
}
-
const locale_fontjson = locale().fontjson;
if (txtdata.indexOf("luckysheet_copy_action_table") > - 1 && Store.luckysheet_copy_save["copyRange"] != null && Store.luckysheet_copy_save["copyRange"].length > 0 && isEqual) {
@@ -4720,7 +4987,6 @@ export default function luckysheetHandler() {
else if(clipboardData.files.length == 1 && clipboardData.files[0].type.indexOf('image') > -1){
let render = new FileReader();
render.readAsDataURL(clipboardData.files[0]);
-
render.onload = function(event){
let src = event.target.result;
imageCtrl.inserImg(src);
diff --git a/src/controllers/inlineString.js b/src/controllers/inlineString.js
new file mode 100644
index 0000000..73b965d
--- /dev/null
+++ b/src/controllers/inlineString.js
@@ -0,0 +1,494 @@
+import {getFontStyleByCell, textTrim} from "../global/getdata";
+import {selectTextContent,selectTextContentCross,selectTextContentCollapse} from '../global/cursorPos';
+import locale from '../locale/locale';
+import Store from '../store';
+
+export const inlineStyleAffectAttribute = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1,"fs":1,"fc":1};
+
+export function isInlineStringCell(cell){
+ let isIs = cell && cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.s!=null && cell.ct.s.length>0;
+ return isIs;
+}
+
+export function isInlineStringCT(ct){
+ let isIs = ct!=null && ct.t=="inlineStr" && ct.s!=null && ct.s.length>0;
+ return isIs;
+}
+
+export function updateInlineStringFormat(cell, attr, value, $input){
+ // let s = Store.inlineStringEditCache;
+ var w = window.getSelection();
+ var range;
+ if(w.type=="None"){
+ range = Store.inlineStringEditRange;
+ }
+ else{
+ range = w.getRangeAt(0);
+ }
+
+
+ // if(isInlineStringCell(cell)){
+ // if(Store.inlineStringEditCache==null){
+ // Store.inlineStringEditCache = JSON.parse(JSON.stringify(cell.ct.s));
+ // }
+ // }
+ // else{
+ // Store.inlineStringEditCache = [{
+ // v:cell.v
+ // }];
+ // }
+
+ let cac = range.commonAncestorContainer;
+ let $textEditor;
+ if(cac.id=="luckysheet-rich-text-editor"){
+ $textEditor = $(cac);
+ }
+ else{
+ $textEditor = $(cac).closest("#luckysheet-rich-text-editor");
+ }
+ let $functionbox = $(cac).closest("#luckysheet-functionbox-cell");
+
+ if($textEditor.length==0 && $functionbox.length==0 && Store.inlineStringEditRange!=null){
+ range = Store.inlineStringEditRange;
+ cac = range.commonAncestorContainer;
+ if(cac.id=="luckysheet-rich-text-editor"){
+ $textEditor = $(cac);
+ }
+ else{
+ $textEditor = $(cac).closest("#luckysheet-rich-text-editor");
+ }
+ $functionbox = $(cac).closest("#luckysheet-functionbox-cell");
+ }
+
+ if(range.collapsed===true){
+ return;
+ }
+
+ let endContainer = range.endContainer, startContainer = range.startContainer;
+ let endOffset = range.endOffset, startOffset = range.startOffset;
+
+ if($textEditor.length>0){
+ if(startContainer===endContainer){
+ let span = startContainer.parentNode, spanIndex;
+
+ let content = span.innerHTML;
+ let left="" , mid="" , right="";
+ let s1=0, s2=startOffset, s3 = endOffset, s4=content.length;
+ left = content.substring(s1, s2);
+ mid = content.substring(s2, s3);
+ right = content.substring(s3, s4);
+
+ let cont = "";
+ if(left!=""){
+ cont += "" + left + "";
+ }
+
+ if(mid!=""){
+ // let styleObj = {};
+ // styleObj[attr] = value;
+ // let s = getFontStyleByCell(styleObj, undefined, undefined, false);
+ // let ukey = textTrim(s.substr(0, s.indexOf(':')));
+ // let uvalue = textTrim(s.substr(s.indexOf(':')+1));
+ // uvalue = uvalue.substr(0, uvalue.length-1);
+ // let cssText = span.style.cssText;
+ // cssText = removeClassWidthCss(cssText, attr);
+
+ let cssText = getCssText(span.style.cssText, attr, value);
+
+ cont += "" + mid + "";
+ }
+
+ if(right!=""){
+ cont += "" + right + "";
+ }
+
+ if(startContainer.parentNode.tagName=="SPAN"){
+ spanIndex = $textEditor.find("span").index(span);
+ $(span).replaceWith(cont);
+ }
+ else{
+ spanIndex = 0;
+ $(span).html(cont);
+ }
+
+
+ let seletedNodeIndex = 0;
+ if(s1==s2){
+ seletedNodeIndex = spanIndex;
+ }
+ else{
+ seletedNodeIndex = spanIndex+1;
+ }
+
+ selectTextContent($textEditor.find("span").get(seletedNodeIndex));
+ }
+ else{
+ if(startContainer.parentNode.tagName=="SPAN" && endContainer.parentNode.tagName=="SPAN"){
+ let startSpan = startContainer.parentNode, startSpanIndex;
+ let endSpan = endContainer.parentNode, endSpanIndex;
+
+ startSpanIndex = $textEditor.find("span").index(startSpan);
+ endSpanIndex = $textEditor.find("span").index(endSpan);
+
+ let startContent = startSpan.innerHTML, endContent = endSpan.innerHTML;
+ let sleft="" , sright="", eleft="" , eright="";
+ let s1=0, s2=startOffset, s3 = endOffset, s4=endContent.length;
+
+ sleft = startContent.substring(s1, s2);
+ sright = startContent.substring(s2, startContent.length);
+
+ eleft = endContent.substring(0, s3);
+ eright = endContent.substring(s3, s4);
+ let spans = $textEditor.find("span");
+ let replaceSpans = spans.slice(startSpanIndex, endSpanIndex+1);
+ let cont = "";
+ for(let i=0;i" + content + "";
+ }
+ if(sleft!=""){
+ cont += "" + sleft + "";
+ }
+
+ if(sright!=""){
+ let cssText = getCssText(startSpan.style.cssText, attr, value);
+ cont += "" + sright + "";
+ }
+
+ if(startSpanIndex" + content + "";
+ }
+ }
+
+ if(eleft!=""){
+ let cssText = getCssText(endSpan.style.cssText, attr, value);
+ cont += "" + eleft + "";
+ }
+
+ if(eright!=""){
+ cont += "" + eright + "";
+ }
+
+ for(let i=endSpanIndex+1;i" + content + "";
+ }
+
+ $textEditor.html(cont);
+
+ // console.log(replaceSpans, cont);
+ // replaceSpans.replaceWith(cont);
+
+ let startSeletedNodeIndex, endSeletedNodeIndex;
+ if(s1==s2){
+ startSeletedNodeIndex = startSpanIndex;
+ endSeletedNodeIndex = endSpanIndex;
+ }
+ else{
+ startSeletedNodeIndex = startSpanIndex+1;
+ endSeletedNodeIndex = endSpanIndex+1;
+ }
+
+ spans = $textEditor.find("span");
+
+ selectTextContentCross(spans.get(startSeletedNodeIndex), spans.get(endSeletedNodeIndex));
+ }
+ }
+ }
+ else if($functionbox.length>0){
+
+ }
+}
+
+export function enterKeyControll(){
+ var w = window.getSelection();
+
+ if(w.type=="None"){
+ return
+ }
+ var range = w.getRangeAt(0);
+ let cac = range.commonAncestorContainer;
+ let $textEditor;
+ if(cac.id=="luckysheet-rich-text-editor"){
+ $textEditor = $(cac);
+ }
+ else{
+ $textEditor = $(cac).closest("#luckysheet-rich-text-editor");
+ }
+ let $functionbox = $(cac).closest("#luckysheet-functionbox-cell");
+
+ // if(range.collapsed===true){
+ // return;
+ // }
+
+ let endContainer = range.endContainer, startContainer = range.startContainer;
+ let endOffset = range.endOffset, startOffset = range.startOffset;
+
+ if($textEditor.length>0){
+ let startSpan = startContainer.parentNode;
+ let startSpanIndex = $textEditor.find("span").index(startSpan);
+ if(range.collapsed===false){
+ range.deleteContents();
+ }
+
+ let startContent = startSpan.innerHTML;
+ let sleft="" , sright="";
+ let s1=0, s2=startOffset;
+
+ sleft = startContent.substring(s1, s2);
+ sright = startContent.substring(s2, startContent.length);
+
+ let cont = "" + sleft + "\n" + sright + "";
+ let spanIndex;
+ if(startContainer.parentNode.tagName=="SPAN"){
+ spanIndex = $textEditor.find("span").index(startSpan);
+ $(startSpan).replaceWith(cont);
+ }
+ else{
+ spanIndex = 0;
+ $(startSpan).html(cont);
+ }
+
+ selectTextContentCollapse($textEditor.find("span").get(spanIndex), startOffset+1);
+
+ }
+ else if($functionbox.length>0){
+
+ }
+}
+
+export function updateInlineStringFormatOutside(cell, key, value){
+ let s = cell.ct.s;
+ for(let i=0;i {
+ s = s.toLowerCase();
+ let key = textTrim(s.substr(0, s.indexOf(':')));
+ let value = textTrim(s.substr(s.indexOf(':') + 1));
+ if(key=="font-weight"){
+ if(value=="bold"){
+ styleList["bl"] = 1;
+ }
+ else{
+ styleList["bl"] = 0;
+ }
+ }
+
+ if(key=="font-style"){
+ if(value=="italic"){
+ styleList["it"] = 1;
+ }
+ else{
+ styleList["it"] = 0;
+ }
+ }
+
+ if(key=="font-family"){
+ let ff = locale_fontjson[value];
+ if(ff==null){
+ styleList["ff"] = value;
+ }
+ else{
+ styleList["ff"] = ff;
+ }
+ }
+
+ if(key=="font-size"){
+ styleList["fs"] = parseInt(value);
+ }
+
+ if(key=="color"){
+ styleList["fc"] = value;
+ }
+
+ if(key=="text-decoration"){
+ styleList["cl"] = 1;
+ }
+
+ if(key=="border-bottom"){
+ styleList["un"] = 1;
+ }
+
+ if(key=="lucky-strike"){
+ styleList["cl"] = value;
+ }
+
+ if(key=="lucky-underline"){
+ styleList["un"] = value;
+ }
+
+ });
+
+ return styleList;
+}
+
+const luckyToCssName = {
+ "bl":"font-weight",
+ "it":"font-style",
+ "ff":"font-family",
+ "fs":"font-size",
+ "fc":"color",
+ "cl":"text-decoration",
+ "un":"border-bottom",
+}
+
+function getClassWithcss(cssText, ukey){
+ let cssTextArray = cssText.split(";");
+ if(ukey==null || ukey.length==0){
+ return cssText;
+ }
+ if(cssText.indexOf(ukey)>-1){
+ for(let i=0;i-1){
+ for(let i=0;i0){
+ newCss += key + ":" + value + ";";
+ }
+ }
+ }
+ else if(ukey.length>0){
+ cssText += ukey + ":" + uvalue + ";";
+ newCss = cssText;
+ }
+
+ return newCss;
+}
+
+function removeClassWidthCss(cssText, ukey){
+ let cssTextArray = cssText.split(";");
+ let newCss = "";
+ let oUkey = ukey;
+ if(ukey==null || ukey.length==0){
+ return cssText;
+ }
+ if(ukey in luckyToCssName){
+ ukey = luckyToCssName[ukey];
+ }
+ if(cssText.indexOf(ukey)>-1){
+ for(let i=0;i0){
+ newCss += key + ":" + value + ";";
+ }
+ }
+ }
+ else{
+ newCss = cssText;
+ }
+
+ return newCss;
+}
+
+function getCssText(cssText, attr, value){
+ let styleObj = {};
+ styleObj[attr] = value;
+ if(attr=="un"){
+ let fontColor = getClassWithcss(cssText,"color");
+ if(fontColor==""){
+ fontColor = "#000000";
+ }
+ let fs = getClassWithcss(cssText,"font-size");
+ if(fs==""){
+ fs = 11;
+ }
+ fs = parseInt(fs);
+ styleObj["_fontSize"] = fs;
+ styleObj["_color"] = fontColor;
+ }
+ let s = getFontStyleByCell(styleObj, undefined, undefined, false);
+ let ukey = textTrim(s.substr(0, s.indexOf(':')));
+ let uvalue = textTrim(s.substr(s.indexOf(':')+1));
+ uvalue = uvalue.substr(0, uvalue.length-1);
+ // let cssText = span.style.cssText;
+ cssText = removeClassWidthCss(cssText, attr);
+
+ cssText = upsetClassWithCss(cssText, ukey, uvalue);
+
+ return cssText;
+}
+
+
+
+
+
diff --git a/src/controllers/insertFormula.js b/src/controllers/insertFormula.js
index d113412..532338d 100644
--- a/src/controllers/insertFormula.js
+++ b/src/controllers/insertFormula.js
@@ -15,7 +15,7 @@ const insertFormula = {
let _this = this;
let _locale = locale();
let locale_formulaMore = _locale.formulaMore;
- let locale_button = _locale.button
+ let locale_button = _locale.button;
$(document).off("keyup.fxSFLI").on("keyup.fxSFLI", "#searchFormulaListInput", function(){
$("#formulaTypeList").empty();
diff --git a/src/controllers/keyboard.js b/src/controllers/keyboard.js
index 4db7733..5356c00 100644
--- a/src/controllers/keyboard.js
+++ b/src/controllers/keyboard.js
@@ -25,6 +25,7 @@ import formula from '../global/formula';
import cleargridelement from '../global/cleargridelement';
import tooltip from '../global/tooltip';
import locale from '../locale/locale';
+import {enterKeyControll} from './inlineString';
import Store from '../store';
@@ -300,10 +301,16 @@ export function keyboardInitial(){
return;
}
+
+
let $inputbox = $("#luckysheet-input-box");
- if (kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0) {
+ if((altKey || event.metaKey) && kcode == keycode.ENTER && parseInt($inputbox.css("top")) > 0){
+ enterKeyControll();
+ 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"));
}
diff --git a/src/controllers/menuButton.js b/src/controllers/menuButton.js
index 81efbdc..6b64e4e 100644
--- a/src/controllers/menuButton.js
+++ b/src/controllers/menuButton.js
@@ -26,9 +26,12 @@ import { rowLocationByIndex, colLocationByIndex } from '../global/location';
import { isdatatypemulti } from '../global/datecontroll';
import { rowlenByRange, getCellTextSplitArr } from '../global/getRowlen';
import { setcellvalue } from '../global/setdata';
+import { getFontStyleByCell, checkstatusByCell} from '../global/getdata';
import { countfunc } from '../global/count';
+import { hideMenuByCancel } from '../global/cursorPos';
import { getSheetIndex, getRangetxt, getluckysheetfile } from '../methods/get';
import { setluckysheetfile } from '../methods/set';
+import {isInlineStringCell,updateInlineStringFormat,convertCssToStyleList,inlineStyleAffectAttribute,updateInlineStringFormatOutside} from './inlineString';
import { replaceHtml, getObjType, rgbTohex, mouseclickposition, luckysheetfontformat,luckysheetContainerFocus } from '../utils/util';
import Store from '../store';
import locale from '../locale/locale';
@@ -455,7 +458,10 @@ const menuButton = {
});
//字体设置
- $("#luckysheet-icon-font-family").click(function(){
+ $("#luckysheet-icon-font-family").mousedown(function(e){
+ hideMenuByCancel(e);
+ e.stopPropagation();
+ }).click(function(){
let menuButtonId = $(this).attr("id")+"-menuButton";
let $menuButton = $("#"+menuButtonId);
if($menuButton.length == 0){
@@ -504,7 +510,10 @@ const menuButton = {
});
//字体颜色
- $("#luckysheet-icon-text-color").click(function(){
+ $("#luckysheet-icon-text-color").mousedown(function(e){
+ hideMenuByCancel(e);
+ e.stopPropagation();
+ }).click(function(){
let d = editor.deepCopyFlowData(Store.flowdata);
let color = $(this).attr("color");
if(color == null){
@@ -513,7 +522,10 @@ const menuButton = {
_this.updateFormat(d, "fc", color);
});
- $("#luckysheet-icon-text-color-menu").click(function(){
+ $("#luckysheet-icon-text-color-menu").mousedown(function(e){
+ hideMenuByCancel(e);
+ e.stopPropagation();
+ }).click(function(){
let menuButtonId = $(this).attr("id") + "-menuButton";
let $menuButton = $("#"+menuButtonId);
@@ -785,7 +797,19 @@ const menuButton = {
//字体大小
let luckysheet_fs_setTimeout = null;
- $("#luckysheet-icon-font-size").click(function(e){
+ $("#luckysheet-icon-font-size").mousedown(function(e){
+ if (parseInt($("#luckysheet-input-box").css("top")) > 0){
+ let w = window.getSelection();
+ if(w.type!="None"){
+ let range = w.getRangeAt(0);
+ if(!range.collapsed){
+ Store.inlineStringEditRange = range.cloneRange();
+ }
+ }
+ }
+ hideMenuByCancel(e);
+ e.stopPropagation();
+ }).click(function(){
let menuButtonId = $(this).attr("id") + "-menuButton";
let $menuButton = $("#" + menuButtonId);
@@ -846,8 +870,13 @@ const menuButton = {
menuleft = menuleft - tlen + userlen;
}
mouseclickposition($menuButton, menuleft, $(this).offset().top + 25, "lefttop");
+
+
})
- .find("input.luckysheet-toolbar-textinput").keyup(function(e){
+ .find("input.luckysheet-toolbar-textinput").keydown(function(e){
+ hideMenuByCancel(e);
+ e.stopPropagation();
+ }).keyup(function(e){
if(e.keyCode != 13){//Enter
return;
}
@@ -2096,7 +2125,10 @@ const menuButton = {
});
//加粗
- $("#luckysheet-icon-bold").click(function(){
+ $("#luckysheet-icon-bold").mousedown(function(e){
+ hideMenuByCancel(e);
+ e.stopPropagation();
+ }).click(function(e){
let d = editor.deepCopyFlowData(Store.flowdata);
let row_index = Store.luckysheet_select_save[0]["row_focus"],
col_index = Store.luckysheet_select_save[0]["column_focus"];
@@ -2114,7 +2146,10 @@ const menuButton = {
});
//斜体
- $("#luckysheet-icon-italic").click(function(){
+ $("#luckysheet-icon-italic").mousedown(function(e){
+ hideMenuByCancel(e);
+ e.stopPropagation();
+ }).click(function(){
let d = editor.deepCopyFlowData(Store.flowdata);
let row_index = Store.luckysheet_select_save[0]["row_focus"],
col_index = Store.luckysheet_select_save[0]["column_focus"];
@@ -2132,7 +2167,10 @@ const menuButton = {
});
//删除线
- $("#luckysheet-icon-strikethrough").click(function(){
+ $("#luckysheet-icon-strikethrough").mousedown(function(e){
+ hideMenuByCancel(e);
+ e.stopPropagation();
+ }).click(function(){
let d = editor.deepCopyFlowData(Store.flowdata);
let row_index = Store.luckysheet_select_save[0]["row_focus"],
col_index = Store.luckysheet_select_save[0]["column_focus"];
@@ -2836,6 +2874,17 @@ const menuButton = {
let canvasElement = document.createElement('canvas');
let canvas = canvasElement.getContext("2d");
+ if(attr in inlineStyleAffectAttribute ){
+ if (parseInt($("#luckysheet-input-box").css("top")) > 0 ) {
+ let value = $("#luckysheet-input-box").text();
+ if(value.substr(0,1)!="="){
+ let cell = d[Store.luckysheetCellUpdate[0]][Store.luckysheetCellUpdate[1]];
+ updateInlineStringFormat(cell, attr, foucsStatus, luckysheetformula.rangeResizeTo);
+ return;
+ }
+ }
+ }
+
let cfg = $.extend(true, {}, Store.config);
if(cfg["rowlen"] == null){
cfg["rowlen"] = {};
@@ -2958,7 +3007,13 @@ const menuButton = {
let value = d[r][c];
if (getObjType(value) == "object") {
- d[r][c][attr] = foucsStatus;
+ if(attr in inlineStyleAffectAttribute && isInlineStringCell(value)){
+ updateInlineStringFormatOutside(value, attr, foucsStatus);
+ }
+ else{
+ d[r][c][attr] = foucsStatus;
+ }
+
}
else{
d[r][c] = { v: value };
@@ -2972,15 +3027,20 @@ const menuButton = {
}
}
- cfg = rowlenByRange(d, row_st, row_ed, cfg);
+ if(attr == "tb" || attr == "tr" || attr == "fs"){
+ cfg = rowlenByRange(d, row_st, row_ed, cfg);
+ }
}
+ let allParam = {};
if(attr == "tb" || attr == "tr" || attr == "fs"){
- jfrefreshgrid(d, Store.luckysheet_select_save, cfg, null, true, false);
- }
- else{
- jfrefreshgrid(d, Store.luckysheet_select_save, undefined, undefined,undefined,false);
+ allParam = {
+ "cfg": cfg,
+ "RowlChange": true
+ }
}
+
+ jfrefreshgrid(d, Store.luckysheet_select_save, allParam, false);
},
updateFormat_mc: function(d, foucsStatus){
let cfg = $.extend(true, {}, Store.config);
@@ -3181,7 +3241,7 @@ const menuButton = {
}
Store.clearjfundo = false;
- jfrefreshgrid(d, Store.luckysheet_select_save, cfg);
+ jfrefreshgrid(d, Store.luckysheet_select_save, {"cfg": cfg});
Store.clearjfundo = true;
},
borderfix: function(d, r, c){
@@ -3201,316 +3261,183 @@ const menuButton = {
//return [-2, -2, 1, 0];
}
},
- menuButtonFocus: function(d, r, c){
+ changeMenuButtonDom:function(attr, foucsStatus, _locale){
let _this = this;
- let foucsList = ["bl", "it", "cl", "ff", "ht", "vt", "fs", "tb", "tr"];
- const _locale = locale();
+ if(_locale==null){
+ _locale = locale();
+ }
+
const locale_fontarray = _locale.fontarray;
const locale_fontjson = _locale.fontjson;
- for(let i = 0; i < foucsList.length; i++){
- let attr = foucsList[i];
- let foucsStatus = _this.checkstatus(d, r, c, attr);
-
- if(attr == "bl"){
- if(foucsStatus != "0"){
- $("#luckysheet-icon-bold").addClass("luckysheet-toolbar-button-hover");
- }
- else{
- $("#luckysheet-icon-bold").removeClass("luckysheet-toolbar-button-hover");
- }
- }
- else if(attr == "it"){
- if(foucsStatus != "0"){
- $("#luckysheet-icon-italic").addClass("luckysheet-toolbar-button-hover");
- }
- else{
- $("#luckysheet-icon-italic").removeClass("luckysheet-toolbar-button-hover");
- }
- }
- else if(attr == "cl"){
- if(foucsStatus != "0"){
- $("#luckysheet-icon-strikethrough").addClass("luckysheet-toolbar-button-hover");
- }
- else{
- $("#luckysheet-icon-strikethrough").removeClass("luckysheet-toolbar-button-hover");
- }
- }
- else if(attr == "ff"){
- let menuButtonId = "luckysheet-icon-font-family-menuButton";
- let $menuButton = $("#" + menuButtonId);
- // const locale_fontarray = locale().fontarray;
- let itemname = locale_fontarray[0], itemvalue = 0;
- if(foucsStatus != null){
- if(isdatatypemulti(foucsStatus)["num"]){
- itemvalue = parseInt(foucsStatus);
- itemname = locale_fontarray[itemvalue];
- }
- else{
- itemvalue = locale_fontjson[foucsStatus];
- itemname = locale_fontarray[itemvalue];
- }
- }
-
- _this.focus($menuButton, itemvalue);
- $("#luckysheet-icon-font-family").find(".luckysheet-toolbar-menu-button-caption").html(" "+ itemname +" ");
- }
- else if(attr == "fs"){
- let $menuButton = $("#luckysheet-icon-font-size-menuButton");
- let itemvalue = foucsStatus, $input = $("#luckysheet-icon-font-size input");
- _this.focus($menuButton, itemvalue);
- $("#luckysheet-icon-font-size").attr("itemvalue", itemvalue);
- $input.val(itemvalue);
- }
- else if(attr == "ht"){
- let $menuButton = $("#luckysheet-icon-align-menu-menuButton");
- let $t = $("luckysheet-icon-align"), itemvalue = "left";
-
- if(foucsStatus == "0"){
- itemvalue = "center";
- }
- else if(foucsStatus == "2"){
- itemvalue = "right";
- }
-
- _this.focus($menuButton, itemvalue);
-
- // add iconfont
- const iconfontObject = iconfontObjects.align;
-
- let $icon = $("#luckysheet-icon-align").attr("type", itemvalue).find(".luckysheet-icon-img-container");
- $icon.removeAttr("class").addClass("luckysheet-icon-img-container luckysheet-icon-img luckysheet-icon-align-" + itemvalue + iconfontObject[itemvalue]);
- $menuButton.hide();
- }
- else if(attr == "vt"){
- let $menuButton = $("#luckysheet-icon-valign-menu-menuButton");
- let $t = $("luckysheet-icon-valign"), itemvalue = "bottom";
-
- if(foucsStatus == "1"){
- itemvalue = "top";
- }
- else if(foucsStatus == "0"){
- itemvalue = "middle";
- }
-
- _this.focus($menuButton, itemvalue);
-
- // add iconfont
- const iconfontObject = iconfontObjects.align;
-
- let $icon = $("#luckysheet-icon-valign").attr("type", itemvalue).find(".luckysheet-icon-img-container");
- $icon.removeAttr("class").addClass("luckysheet-icon-img-container luckysheet-icon-img luckysheet-icon-valign-" + itemvalue + iconfontObject[itemvalue]);
- $menuButton.hide();
- }
- else if(attr == "tb"){
- let $menuButton = $("#luckysheet-icon-textwrap-menu-menuButton");
- let $t = $("luckysheet-icon-textwrap"), itemvalue = "clip";
-
- if(foucsStatus == "1"){
- itemvalue = "overflow";
- }
- else if(foucsStatus == "2"){
- itemvalue = "wrap";
- }
-
- _this.focus($menuButton, itemvalue);
-
- // add iconfont
- const iconfontObject = iconfontObjects.textWrap;
-
- let $icon = $("#luckysheet-icon-textwrap").attr("type", itemvalue).find(".luckysheet-icon-img-container");
- $icon.removeAttr("class").addClass("luckysheet-icon-img-container luckysheet-icon-img luckysheet-icon-textwrap-" + itemvalue + iconfontObject[itemvalue]);
- $menuButton.hide();
- }
- else if(attr == "tr"){
- let $menuButton = $("#luckysheet-icon-rotation-menu-menuButton");
- let $t = $("luckysheet-icon-rotation"), itemvalue = "none";
-
- if(foucsStatus == "1"){
- itemvalue = "angleup";
- }
- else if(foucsStatus == "2"){
- itemvalue = "angledown";
- }
- else if(foucsStatus == "3"){
- itemvalue = "vertical";
- }
- else if(foucsStatus == "4"){
- itemvalue = "rotation-up";
- }
- else if(foucsStatus == "5"){
- itemvalue = "rotation-down";
- }
-
- _this.focus($menuButton, itemvalue);
- // add iconfont
- const iconfontObject = iconfontObjects.rotation;
-
- let $icon = $("#luckysheet-icon-rotation").attr("type", itemvalue).find(".luckysheet-icon-img-container");
- $icon.removeAttr("class").addClass("luckysheet-icon-img-container luckysheet-icon-img luckysheet-icon-rotation-" + itemvalue + iconfontObject[itemvalue]);
- $menuButton.hide();
- }
- }
- },
- checkstatusByCell:function(cell, a){
- let foucsStatus =cell;
- let tf = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1};
-
- if(a in tf){
- if(foucsStatus == null){
- foucsStatus = "0";
+ if(attr == "bl"){
+ if(foucsStatus != "0"){
+ $("#luckysheet-icon-bold").addClass("luckysheet-toolbar-button-hover");
}
else{
- foucsStatus = foucsStatus[a];
- if(foucsStatus == null){
- foucsStatus = "0";
- }
+ $("#luckysheet-icon-bold").removeClass("luckysheet-toolbar-button-hover");
}
}
- else if(a == "fc"){
- if(foucsStatus == null){
- foucsStatus = "#000000";
+ else if(attr == "it"){
+ if(foucsStatus != "0"){
+ $("#luckysheet-icon-italic").addClass("luckysheet-toolbar-button-hover");
}
else{
- foucsStatus = foucsStatus[a];
-
- if(foucsStatus == null){
- foucsStatus = "#000000";
- }
-
- if(foucsStatus.indexOf("rgba") > -1){
- foucsStatus = rgbTohex(foucsStatus);
- }
+ $("#luckysheet-icon-italic").removeClass("luckysheet-toolbar-button-hover");
}
}
- else if(a == "bg"){
- if(foucsStatus == null){
- foucsStatus = null;
+ else if(attr == "cl"){
+ if(foucsStatus != "0"){
+ $("#luckysheet-icon-strikethrough").addClass("luckysheet-toolbar-button-hover");
}
else{
- foucsStatus = foucsStatus[a];
-
- if(foucsStatus == null){
- foucsStatus = null;
- }
- else if(foucsStatus.toString().indexOf("rgba") > -1){
- foucsStatus = rgbTohex(foucsStatus);
- }
+ $("#luckysheet-icon-strikethrough").removeClass("luckysheet-toolbar-button-hover");
}
}
- else if(a.substr(0, 2) == "bs"){
- if(foucsStatus == null){
- foucsStatus = "none";
- }
- else{
- foucsStatus = foucsStatus[a];
- if(foucsStatus == null){
- foucsStatus = "none";
+ else if(attr == "ff"){
+ let menuButtonId = "luckysheet-icon-font-family-menuButton";
+ let $menuButton = $("#" + menuButtonId);
+ // const locale_fontarray = locale().fontarray;
+ let itemname = locale_fontarray[0], itemvalue = 0;
+ if(foucsStatus != null){
+ if(isdatatypemulti(foucsStatus)["num"]){
+ itemvalue = parseInt(foucsStatus);
+ itemname = locale_fontarray[itemvalue];
}
+ else{
+ itemvalue = locale_fontjson[foucsStatus];
+ itemname = locale_fontarray[itemvalue];
+ }
}
+
+ _this.focus($menuButton, itemvalue);
+ $("#luckysheet-icon-font-family").find(".luckysheet-toolbar-menu-button-caption").html(" "+ itemname +" ");
}
- else if(a.substr(0, 2) == "bc"){
- if(foucsStatus == null){
- foucsStatus = "#000000";
- }
- else{
- foucsStatus = foucsStatus[a];
- if(foucsStatus == null){
- foucsStatus = "#000000";
- }
- }
+ else if(attr == "fs"){
+ let $menuButton = $("#luckysheet-icon-font-size-menuButton");
+ let itemvalue = foucsStatus, $input = $("#luckysheet-icon-font-size input");
+ _this.focus($menuButton, itemvalue);
+ $("#luckysheet-icon-font-size").attr("itemvalue", itemvalue);
+ $input.val(itemvalue);
}
- else if(a == "ht"){
- if(foucsStatus == null){
- foucsStatus = "1";
+ else if(attr == "ht"){
+ let $menuButton = $("#luckysheet-icon-align-menu-menuButton");
+ let $t = $("luckysheet-icon-align"), itemvalue = "left";
+
+ if(foucsStatus == "0"){
+ itemvalue = "center";
}
- else{
- foucsStatus = foucsStatus[a];
- if(foucsStatus == null){
- foucsStatus = "1";
- }
+ else if(foucsStatus == "2"){
+ itemvalue = "right";
}
- if(["0", "1", "2"].indexOf(foucsStatus.toString()) == -1){
- foucsStatus = "1";
- }
+ _this.focus($menuButton, itemvalue);
+
+ // add iconfont
+ const iconfontObject = iconfontObjects.align;
+
+ let $icon = $("#luckysheet-icon-align").attr("type", itemvalue).find(".luckysheet-icon-img-container");
+ $icon.removeAttr("class").addClass("luckysheet-icon-img-container luckysheet-icon-img luckysheet-icon-align-" + itemvalue + iconfontObject[itemvalue]);
+ $menuButton.hide();
}
- else if(a == "vt"){
- if(foucsStatus == null){
- foucsStatus = "2";
+ else if(attr == "vt"){
+ let $menuButton = $("#luckysheet-icon-valign-menu-menuButton");
+ let $t = $("luckysheet-icon-valign"), itemvalue = "bottom";
+
+ if(foucsStatus == "1"){
+ itemvalue = "top";
}
- else{
- foucsStatus = foucsStatus[a];
- if(foucsStatus == null){
- foucsStatus = "2";
- }
+ else if(foucsStatus == "0"){
+ itemvalue = "middle";
}
- if(["0", "1", "2"].indexOf(foucsStatus.toString()) == -1){
- foucsStatus = "2";
- }
+ _this.focus($menuButton, itemvalue);
+
+ // add iconfont
+ const iconfontObject = iconfontObjects.align;
+
+ let $icon = $("#luckysheet-icon-valign").attr("type", itemvalue).find(".luckysheet-icon-img-container");
+ $icon.removeAttr("class").addClass("luckysheet-icon-img-container luckysheet-icon-img luckysheet-icon-valign-" + itemvalue+ iconfontObject[itemvalue]);
+ $menuButton.hide();
}
- else if(a == "ct"){
- if(foucsStatus == null){
- foucsStatus = null;
+ else if(attr == "tb"){
+ let $menuButton = $("#luckysheet-icon-textwrap-menu-menuButton");
+ let $t = $("luckysheet-icon-textwrap"), itemvalue = "clip";
+
+ if(foucsStatus == "1"){
+ itemvalue = "overflow";
}
- else{
- foucsStatus = foucsStatus[a];
- if(foucsStatus == null){
- foucsStatus = null;
- }
+ else if(foucsStatus == "2"){
+ itemvalue = "wrap";
}
+
+ _this.focus($menuButton, itemvalue);
+
+ // add iconfont
+ const iconfontObject = iconfontObjects.textWrap;
+
+ let $icon = $("#luckysheet-icon-textwrap").attr("type", itemvalue).find(".luckysheet-icon-img-container");
+ $icon.removeAttr("class").addClass("luckysheet-icon-img-container luckysheet-icon-img luckysheet-icon-textwrap-" + itemvalue + iconfontObject[itemvalue]);
+ $menuButton.hide();
}
- else if(a == "fs"){
- if(foucsStatus == null){
- foucsStatus = "10";
+ else if(attr == "tr"){
+ let $menuButton = $("#luckysheet-icon-rotation-menu-menuButton");
+ let $t = $("luckysheet-icon-rotation"), itemvalue = "none";
+
+ if(foucsStatus == "1"){
+ itemvalue = "angleup";
}
- else{
- foucsStatus = foucsStatus[a];
- if(foucsStatus == null){
- foucsStatus = "10";
- }
+ else if(foucsStatus == "2"){
+ itemvalue = "angledown";
}
- }
- else if(a == "tb"){
- if(foucsStatus == null){
- foucsStatus = "0";
+ else if(foucsStatus == "3"){
+ itemvalue = "vertical";
}
- else{
- foucsStatus = foucsStatus[a];
- if(foucsStatus == null){
- foucsStatus = "0";
- }
- }
- }
- else if(a == "tr"){
- if(foucsStatus == null){
- foucsStatus = "0";
+ else if(foucsStatus == "4"){
+ itemvalue = "rotation-up";
}
- else{
- foucsStatus = foucsStatus[a];
- if(foucsStatus == null){
- foucsStatus = "0";
- }
+ else if(foucsStatus == "5"){
+ itemvalue = "rotation-down";
}
+
+ _this.focus($menuButton, itemvalue);
+
+ // add iconfont
+ const iconfontObject = iconfontObjects.rotation;
+
+ let $icon = $("#luckysheet-icon-rotation").attr("type", itemvalue).find(".luckysheet-icon-img-container");
+ $icon.removeAttr("class").addClass("luckysheet-icon-img-container luckysheet-icon-img luckysheet-icon-rotation-" + itemvalue + iconfontObject[itemvalue]);
+ $menuButton.hide();
}
- else if(a == "rt"){
- if(foucsStatus == null){
- foucsStatus = null;
- }
- else{
- foucsStatus = foucsStatus[a];
- if(foucsStatus == null){
- foucsStatus = null;
- }
+ },
+ inputMenuButtonFocus:function(focusTarget){
+ var w = window.getSelection();
+ var range = w.getRangeAt(0);
+ let startContainer = range.startContainer;
+ Store.inlineStringEditRange = null;
+ const _locale = locale();
+ if(startContainer.parentNode.tagName=="SPAN"){
+ let cssText = startContainer.parentNode.style.cssText;
+ let stylelist = convertCssToStyleList(cssText);
+ for(let key in stylelist){
+ this.changeMenuButtonDom(key, stylelist[key], _locale);
}
}
+ },
+ menuButtonFocus: function(d, r, c){
+ let _this = this;
+ let foucsList = ["bl", "it", "cl", "ff", "ht", "vt", "fs", "tb", "tr"];
+ const _locale = locale();
+ for(let i = 0; i < foucsList.length; i++){
+ let attr = foucsList[i];
+ let foucsStatus = _this.checkstatus(d, r, c, attr);
- return foucsStatus;
+ this.changeMenuButtonDom(attr, foucsStatus, _locale);
+ }
},
checkstatus: function(d, r, c, a){
let foucsStatus = d[r][c];
- return this.checkstatusByCell(foucsStatus, a);
+ return checkstatusByCell(foucsStatus, a);
},
setLineDash: function(canvasborder, type, hv, m_st, m_ed, line_st, line_ed){
let borderType = {
@@ -4272,6 +4199,10 @@ const menuButton = {
const locale_fontarray = locale().fontarray;
let cell = d[r][c];
+ let ct = cell.ct, isInline=false;
+ if(isInlineStringCell(cell)){
+ isInline = true;
+ }
for(let key in cell){
let value = _this.checkstatus(d, r, c , key);
@@ -4300,37 +4231,39 @@ const menuButton = {
}
}
- if(key == "bl" && value != "0"){
- style += "font-weight: bold;";
- }
-
- if(key == "it" && value != "0"){
- style += "font-style:italic;";
- }
-
- if(key == "ff" && value != "0"){
- let f = value;
- if(!isNaN(parseInt(value))){
- f = locale_fontarray[parseInt(value)];
- }
- style += "font-family: " + f + ";";
- }
-
- if(key == "fs" && value != "10"){
- style += "font-size: "+ value + "pt;";
- }
-
- if((key == "fc" && value != "#000000") || checksAF != null || (checksCF != null && checksCF["textColor"] != null)){
- if(checksCF != null && checksCF["textColor"] != null){
- style += "color: " + checksCF["textColor"] + ";";
- }
- else if(checksAF != null){
- style += "color: " + checksAF[0] + ";";
- }
- else{
- style += "color: " + value + ";";
- }
- }
+ // if(!isInline){
+ // if(key == "bl" && value != "0"){
+ // style += "font-weight: bold;";
+ // }
+
+ // if(key == "it" && value != "0"){
+ // style += "font-style:italic;";
+ // }
+
+ // if(key == "ff" && value != "0"){
+ // let f = value;
+ // if(!isNaN(parseInt(value))){
+ // f = locale_fontarray[parseInt(value)];
+ // }
+ // style += "font-family: " + f + ";";
+ // }
+
+ // if(key == "fs" && value != "10"){
+ // style += "font-size: "+ value + "pt;";
+ // }
+
+ // if((key == "fc" && value != "#000000") || checksAF != null || (checksCF != null && checksCF["textColor"] != null)){
+ // if(checksCF != null && checksCF["textColor"] != null){
+ // style += "color: " + checksCF["textColor"] + ";";
+ // }
+ // else if(checksAF != null){
+ // style += "color: " + checksAF[0] + ";";
+ // }
+ // else{
+ // style += "color: " + value + ";";
+ // }
+ // }
+ // }
if(key == "ht" && value != "1"){
if(value == "0"){
@@ -4351,6 +4284,10 @@ const menuButton = {
}
}
+ if(!isInline){
+ style += getFontStyleByCell(cell,checksAF,checksCF);
+ }
+
return style;
}
}
diff --git a/src/controllers/orderBy.js b/src/controllers/orderBy.js
index f855040..c658753 100644
--- a/src/controllers/orderBy.js
+++ b/src/controllers/orderBy.js
@@ -212,16 +212,19 @@ export function orderByInitial(){
}
}
+ let allParam = {};
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] }]);
+ allParam = {
+ "cfg": cfg,
+ "RowlChange": true
+ }
}
+ jfrefreshgrid(d, [{ "row": [str, r2], "column": [c1, c2] }], allParam);
+
$("#luckysheet-sort-dialog").hide();
$("#luckysheet-modal-dialog-mask").hide();
});
diff --git a/src/controllers/pivotTable.js b/src/controllers/pivotTable.js
index 3cb8692..dea760b 100644
--- a/src/controllers/pivotTable.js
+++ b/src/controllers/pivotTable.js
@@ -733,7 +733,7 @@ const pivotTable = {
jfrefreshgridall(data[0].length, data.length, data, null, Store.luckysheet_select_save, "datachangeAll", undefined, undefined,isRefreshCanvas);
}
else {
- jfrefreshgrid(data, Store.luckysheet_select_save, undefined, undefined, undefined, undefined,isRefreshCanvas);
+ jfrefreshgrid(data, Store.luckysheet_select_save, {}, null, isRefreshCanvas);
selectHightlightShow();
}
diff --git a/src/controllers/postil.js b/src/controllers/postil.js
index d7ab028..cac84b3 100644
--- a/src/controllers/postil.js
+++ b/src/controllers/postil.js
@@ -825,7 +825,14 @@ const luckysheetPostil = {
let r = id.split("luckysheet-postil-show_")[1].split("_")[0];
let c = id.split("luckysheet-postil-show_")[1].split("_")[1];
- _this.buildPs(r, c, Store.flowdata[r][c].ps);
+ let cell = Store.flowdata[r][c];
+
+ if(cell != null && cell.ps != null){
+ _this.buildPs(r, c, cell.ps);
+ }
+ else{
+ $("#" + id).hide();
+ }
});
}
}
diff --git a/src/controllers/resize.js b/src/controllers/resize.js
index bbd04cb..14fea21 100644
--- a/src/controllers/resize.js
+++ b/src/controllers/resize.js
@@ -306,6 +306,7 @@ export function menuToolBarWidth() {
$('#luckysheet-freezen-btn-horizontal').offset().left,
$('#luckysheet-icon-autofilter').offset().left,
$('#luckysheet-icon-conditionformat').offset().left,
+ $('#luckysheet-dataVerification-btn-title').offset().left,
$('#luckysheet-splitColumn-btn-title').offset().left,
$('#luckysheet-chart-btn-screenshot').offset().left,
$('#luckysheet-icon-seachmore').offset().left,
@@ -341,6 +342,7 @@ export function menuToolBarWidth() {
['#luckysheet-freezen-btn-horizontal','#luckysheet-icon-freezen-menu'],
'#luckysheet-icon-autofilter',
'#luckysheet-icon-conditionformat',
+ '#luckysheet-dataVerification-btn-title',
'#luckysheet-splitColumn-btn-title',
'#luckysheet-chart-btn-screenshot',
'#luckysheet-icon-seachmore'
diff --git a/src/controllers/rowColumnOperation.js b/src/controllers/rowColumnOperation.js
index f8b039c..7dd6965 100644
--- a/src/controllers/rowColumnOperation.js
+++ b/src/controllers/rowColumnOperation.js
@@ -32,8 +32,9 @@ import { getcellvalue } from '../global/getdata';
import tooltip from '../global/tooltip';
import editor from '../global/editor';
import locale from '../locale/locale';
-import {getMeasureText} from '../global/getRowlen';
+import {getMeasureText,getCellTextInfo} from '../global/getRowlen';
import { luckysheet_searcharray } from '../controllers/sheetSearch';
+import {isInlineStringCell} from './inlineString';
import Store from '../store';
export function rowColumnOperationInitial(){
@@ -1711,24 +1712,39 @@ function luckysheetcolsdbclick() {
for(let r = dataset_row_st; r <= dataset_row_ed; r++){
let cell = d[r][colIndex];
- if(cell == null || isRealNull(cell.v)){
+ if(cell == null || (isRealNull(cell.v) && !isInlineStringCell(cell)) ){
continue;
}
- let fontset = luckysheetfontformat(cell);
- canvas.font = fontset;
+ // let fontset = luckysheetfontformat(cell);
+ // canvas.font = fontset;
- let value = getcellvalue(r, colIndex, d, "m").toString(); //单元格文本
- let textMetrics = getMeasureText(value, canvas).width; //文本宽度
+ // let value = getcellvalue(r, colIndex, d, "m").toString(); //单元格文本
+ // let textMetrics = getMeasureText(value, canvas).width; //文本宽度
+ let cellWidth = colLocationByIndex(colIndex)[1] - colLocationByIndex(colIndex)[0] - 2;
+ let textInfo = getCellTextInfo(cell, canvas,{
+ r:r,
+ c:colIndex,
+ cellWidth:cellWidth
+ });
+
+ let computeRowlen = 0;
+ // console.log("rowlen", textInfo);
+ if(textInfo!=null){
+ computeRowlen = textInfo.textWidthAll;
+ }
- if(textMetrics + 6 > currentColLen){
- currentColLen = textMetrics + 6;
+ if(computeRowlen + 6 > currentColLen){
+ currentColLen = computeRowlen + 6;
}
}
if(currentColLen != Store.defaultcollen){
cfg["columnlen"][colIndex] = currentColLen;
+ if(cfg["customWidth"]){
+ delete cfg["customWidth"][colIndex];
+ }
}
matchColumn[colIndex] = 1;
@@ -1744,24 +1760,44 @@ function luckysheetcolsdbclick() {
for(let r = dataset_row_st; r <= dataset_row_ed; r++){
let cell = d[r][c];
- if(cell == null || isRealNull(cell.v)){
+ if(cell == null || (isRealNull(cell.v) && !isInlineStringCell(cell)) ){
continue;
}
- let fontset = luckysheetfontformat(cell);
- canvas.font = fontset;
+ // let fontset = luckysheetfontformat(cell);
+ // canvas.font = fontset;
+
+ // let value = getcellvalue(r, c, d, "m").toString(); //单元格文本
+ // let textMetrics = getMeasureText(value, canvas).width; //文本宽度
- let value = getcellvalue(r, c, d, "m").toString(); //单元格文本
- let textMetrics = getMeasureText(value, canvas).width; //文本宽度
+ // if(textMetrics + 6 > currentColLen){
+ // currentColLen = textMetrics + 6;
+ // }
- if(textMetrics + 6 > currentColLen){
- currentColLen = textMetrics + 6;
+ let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 2;
+ let textInfo = getCellTextInfo(cell, canvas,{
+ r:r,
+ c:c,
+ cellWidth:cellWidth
+ });
+
+ let computeRowlen = 0;
+ // console.log("rowlen", textInfo);
+ if(textInfo!=null){
+ computeRowlen = textInfo.textWidthAll;
+ }
+
+ if(computeRowlen + 6 > currentColLen){
+ currentColLen = computeRowlen + 6;
}
}
if(currentColLen != Store.defaultcollen){
cfg["columnlen"][c] = currentColLen;
+ if(cfg["customWidth"]){
+ delete cfg["customWidth"][c];
+ }
}
matchColumn[c] = 1;
diff --git a/src/controllers/searchReplace.js b/src/controllers/searchReplace.js
index 9d64f11..666d43e 100644
--- a/src/controllers/searchReplace.js
+++ b/src/controllers/searchReplace.js
@@ -476,6 +476,11 @@ const luckysheetSearchReplace = {
const _locale = locale();
const locale_findAndReplace = _locale.findAndReplace;
+ if(!Store.allowEdit){
+ tooltip.info(locale_findAndReplace.modeTip, "");
+ return;
+ }
+
let searchText = $("#luckysheet-search-replace #searchInput input").val();
if(searchText == "" || searchText == null){
if(isEditMode()){
@@ -628,6 +633,11 @@ const luckysheetSearchReplace = {
const _locale = locale();
const locale_findAndReplace = _locale.findAndReplace;
+ if(!Store.allowEdit){
+ tooltip.info(locale_findAndReplace.modeTip, "");
+ return;
+ }
+
let searchText = $("#luckysheet-search-replace #searchInput input").val();
if(searchText == "" || searchText == null){
if(isEditMode()){
diff --git a/src/controllers/select.js b/src/controllers/select.js
index 2ab6b17..e726e21 100644
--- a/src/controllers/select.js
+++ b/src/controllers/select.js
@@ -3,6 +3,7 @@ import formula from '../global/formula';
import { dynamicArrayHightShow } from '../global/dynamicArray';
import { rowLocationByIndex, colLocationByIndex } from '../global/location';
import browser from '../global/browser';
+import dataVerificationCtrl from './dataVerificationCtrl';
import { getSheetIndex, getRangetxt } from '../methods/get';
import Store from '../store';
import locale from '../locale/locale';
@@ -163,6 +164,8 @@ function selectHightlightShow() {
);
//左上角选择区域框
formula.fucntionboxshow(rf, cf);
+ //focus单元格数据验证
+ dataVerificationCtrl.cellFocus(rf, cf);
}
}
@@ -283,15 +286,19 @@ function selectTitlesRange(map) {
}
//选区是否重叠
-function selectIsOverlap() {
+function selectIsOverlap(range) {
+ if(range == null){
+ range = Store.luckysheet_select_save;
+ }
+
let overlap = false;
let map = {};
- for(let s = 0; s < Store.luckysheet_select_save.length; s++){
- let str_r = Store.luckysheet_select_save[s].row[0],
- end_r = Store.luckysheet_select_save[s].row[1];
- let str_c = Store.luckysheet_select_save[s].column[0],
- end_c = Store.luckysheet_select_save[s].column[1];
+ for(let s = 0; s < range.length; s++){
+ let str_r = range[s].row[0],
+ end_r = range[s].row[1];
+ let str_c = range[s].column[0],
+ end_c = range[s].column[1];
for(let r = str_r; r <= end_r; r++){
for(let c = str_c; c <= end_c; c++){
diff --git a/src/controllers/selection.js b/src/controllers/selection.js
index 73ac1c0..239a95f 100644
--- a/src/controllers/selection.js
+++ b/src/controllers/selection.js
@@ -26,7 +26,7 @@ const selection = {
Store.luckysheet_selection_range = [];
selectionCopyShow();
- Store.luckysheet_copy_save = {};
+ // Store.luckysheet_copy_save = {};
if (!clipboardData) {
let textarea = $("#luckysheet-copy-content").css("visibility", "hidden");
@@ -721,11 +721,19 @@ const selection = {
Store.luckysheet_select_save = [{ "row": [minh, maxh], "column": [minc, maxc] }];
+
if(addr > 0 || addc > 0 || RowlChange){
- jfrefreshgrid(d, Store.luckysheet_select_save, cfg, null, true);
+ let allParam = {
+ "cfg": cfg,
+ "RowlChange": true
+ }
+ jfrefreshgrid(d, Store.luckysheet_select_save, allParam);
}
else{
- jfrefreshgrid(d, Store.luckysheet_select_save, cfg);
+ let allParam = {
+ "cfg": cfg
+ }
+ jfrefreshgrid(d, Store.luckysheet_select_save, allParam);
selectHightlightShow();
}
}
@@ -790,7 +798,10 @@ const selection = {
last["column"] = [curC, curC + clen - 1];
if (addr > 0 || addc > 0) {
- jfrefreshgrid(d, Store.luckysheet_select_save, null, null, true);
+ let allParam = {
+ "RowlChange": true
+ }
+ jfrefreshgrid(d, Store.luckysheet_select_save, allParam);
}
else {
jfrefreshgrid(d, Store.luckysheet_select_save);
@@ -799,9 +810,10 @@ const selection = {
}
},
pasteHandlerOfCutPaste: function(copyRange){
- if(Store.allowEdit===false){
+ if(Store.allowEdit === false){
return;
}
+
let cfg = $.extend(true, {}, Store.config);
if(cfg["merge"] == null){
cfg["merge"] = {};
@@ -810,9 +822,14 @@ const selection = {
//复制范围
let copyHasMC = copyRange["HasMC"];
let copyRowlChange = copyRange["RowlChange"];
-
let copySheetIndex = copyRange["dataSheetIndex"];
- let copyData = $.extend(true, [], getdatabyselection({"row": copyRange["copyRange"][0].row, "column": copyRange["copyRange"][0].column}, copySheetIndex));
+
+ let c_r1 = copyRange["copyRange"][0].row[0],
+ c_r2 = copyRange["copyRange"][0].row[1],
+ c_c1 = copyRange["copyRange"][0].column[0],
+ c_c2 = copyRange["copyRange"][0].column[1];
+
+ let copyData = $.extend(true, [], getdatabyselection({"row": [c_r1, c_r2], "column": [c_c1, c_c2]}, copySheetIndex));
let copyh = copyData.length, copyc = copyData[0].length;
@@ -847,11 +864,13 @@ const selection = {
}
let borderInfoCompute = getBorderInfoCompute(copySheetIndex);
+ let c_dataVerification = $.extend(true, {}, Store.luckysheetfile[getSheetIndex(copySheetIndex)]["dataVerification"]);
+ let dataVerification = $.extend(true, {}, Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dataVerification"]);
- //剪切粘贴在当前表操作,删除剪切范围内数据和合并单元格
+ //剪切粘贴在当前表操作,删除剪切范围内数据、合并单元格和数据验证
if(Store.currentSheetIndex == copySheetIndex){
- for(let i = copyRange["copyRange"][0].row[0]; i <= copyRange["copyRange"][0].row[1]; i++){
- for(let j = copyRange["copyRange"][0].column[0]; j <= copyRange["copyRange"][0].column[1]; j++){
+ for(let i = c_r1; i <= c_r2; i++){
+ for(let j = c_c1; j <= c_c2; j++){
let cell = d[i][j];
if(getObjType(cell) == "object" && ("mc" in cell)){
@@ -862,6 +881,8 @@ const selection = {
}
d[i][j] = null;
+
+ delete dataVerification[i + "_" + j];
}
}
@@ -877,7 +898,12 @@ const selection = {
let bd_emptyRange = [];
for(let j = 0; j < bd_range.length; j++){
- bd_emptyRange = bd_emptyRange.concat(conditionformat.CFSplitRange(bd_range[j], {"row": copyRange["copyRange"][0].row, "column": copyRange["copyRange"][0].column}, {"row": [minh, maxh], "column": [minc, maxc]}, "restPart"));
+ bd_emptyRange = bd_emptyRange.concat(conditionformat.CFSplitRange(
+ bd_range[j],
+ {"row": [c_r1, c_r2], "column": [c_c1, c_c2]},
+ {"row": [minh, maxh], "column": [minc, maxc]},
+ "restPart"
+ ));
}
cfg["borderInfo"][i].range = bd_emptyRange;
@@ -888,7 +914,7 @@ const selection = {
let bd_r = cfg["borderInfo"][i].value.row_index;
let bd_c = cfg["borderInfo"][i].value.col_index;
- if(!(bd_r >= copyRange["copyRange"][0].row[0] && bd_r <= copyRange["copyRange"][0].row[1] && bd_c >= copyRange["copyRange"][0].column[0] && bd_c <= copyRange["copyRange"][0].column[1])){
+ if(!(bd_r >= c_r1 && bd_r <= c_r2 && bd_c >= c_c1 && bd_c <= c_c2)){
source_borderInfo.push(cfg["borderInfo"][i]);
}
}
@@ -903,16 +929,16 @@ const selection = {
let x = [].concat(d[h]);
for (let c = minc; c <= maxc; c++) {
- if(borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - minh) + "_" + (copyRange["copyRange"][0].column[0] + c - minc)]){
+ if(borderInfoCompute[(c_r1 + h - minh) + "_" + (c_c1 + c - minc)]){
let bd_obj = {
"rangeType": "cell",
"value": {
"row_index": h,
"col_index": c,
- "l": borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - minh) + "_" + (copyRange["copyRange"][0].column[0] + c - minc)].l,
- "r": borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - minh) + "_" + (copyRange["copyRange"][0].column[0] + c - minc)].r,
- "t": borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - minh) + "_" + (copyRange["copyRange"][0].column[0] + c - minc)].t,
- "b": borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - minh) + "_" + (copyRange["copyRange"][0].column[0] + c - minc)].b
+ "l": borderInfoCompute[(c_r1 + h - minh) + "_" + (c_c1 + c - minc)].l,
+ "r": borderInfoCompute[(c_r1 + h - minh) + "_" + (c_c1 + c - minc)].r,
+ "t": borderInfoCompute[(c_r1 + h - minh) + "_" + (c_c1 + c - minc)].t,
+ "b": borderInfoCompute[(c_r1 + h - minh) + "_" + (c_c1 + c - minc)].b
}
}
@@ -942,6 +968,11 @@ const selection = {
cfg["borderInfo"].push(bd_obj);
}
+ //数据验证 剪切
+ if(c_dataVerification[(c_r1 + h - minh) + "_" + (c_c1 + c - minc)]){
+ dataVerification[h + "_" + c] = c_dataVerification[(c_r1 + h - minh) + "_" + (c_c1 + c - minc)];
+ }
+
if(getObjType(x[c]) == "object" && ("mc" in x[c])){
if("rs" in x[c].mc){
delete cfg["merge"][x[c]["mc"].r + "_" + x[c]["mc"].c];
@@ -983,7 +1014,7 @@ const selection = {
cfg = rowlenByRange(d, minh, maxh, cfg);
}
else{
- cfg = rowlenByRange(d, copyRange["copyRange"][0].row[0], copyRange["copyRange"][0].row[1], cfg);
+ cfg = rowlenByRange(d, c_r1, c_r2, cfg);
cfg = rowlenByRange(d, minh, maxh, cfg);
}
}
@@ -1000,13 +1031,8 @@ const selection = {
sourceCurConfig["merge"] = {};
}
- let source_r1 = copyRange["copyRange"][0].row[0],
- source_r2 = copyRange["copyRange"][0].row[1];
- let source_c1 = copyRange["copyRange"][0].column[0],
- source_c2 = copyRange["copyRange"][0].column[1];
-
- for(let source_r = source_r1; source_r <= source_r2; source_r++){
- for(let source_c = source_c1; source_c <= source_c2; source_c++){
+ for(let source_r = c_r1; source_r <= c_r2; source_r++){
+ for(let source_c = c_c1; source_c <= c_c2; source_c++){
let cell = sourceCurData[source_r][source_c];
if(getObjType(cell) == "object" && ("mc" in cell)){
@@ -1020,7 +1046,7 @@ const selection = {
}
if(copyRowlChange){
- sourceCurConfig = rowlenByRange(sourceCurData, source_r1, source_r2, sourceCurConfig);
+ sourceCurConfig = rowlenByRange(sourceCurData, c_r1, c_r2, sourceCurConfig);
}
//边框
@@ -1035,7 +1061,12 @@ const selection = {
let bd_emptyRange = [];
for(let j = 0; j < bd_range.length; j++){
- bd_emptyRange = bd_emptyRange.concat(conditionformat.CFSplitRange(bd_range[j], {"row": copyRange["copyRange"][0].row, "column": copyRange["copyRange"][0].column}, {"row": [minh, maxh], "column": [minc, maxc]}, "restPart"));
+ bd_emptyRange = bd_emptyRange.concat(conditionformat.CFSplitRange(
+ bd_range[j],
+ {"row": [c_r1, c_r2], "column": [c_c1, c_c2]},
+ {"row": [minh, maxh], "column": [minc, maxc]},
+ "restPart"
+ ));
}
sourceCurConfig["borderInfo"][i].range = bd_emptyRange;
@@ -1046,7 +1077,7 @@ const selection = {
let bd_r = sourceCurConfig["borderInfo"][i].value.row_index;
let bd_c = sourceCurConfig["borderInfo"][i].value.col_index;
- if(!(bd_r >= copyRange["copyRange"][0].row[0] && bd_r <= copyRange["copyRange"][0].row[1] && bd_c >= copyRange["copyRange"][0].column[0] && bd_c <= copyRange["copyRange"][0].column[1])){
+ if(!(bd_r >= c_r1 && bd_r <= c_r2 && bd_c >= c_c1 && bd_c <= c_c2)){
source_borderInfo.push(sourceCurConfig["borderInfo"][i]);
}
}
@@ -1066,10 +1097,22 @@ const selection = {
let emptyRange2 = [];
for(let j = 0; j < source_curCdformat_cellrange.length; j++){
- let range = conditionformat.CFSplitRange(source_curCdformat_cellrange[j], {"row": copyRange["copyRange"][0].row, "column": copyRange["copyRange"][0].column}, {"row": [minh, maxh], "column": [minc, maxc]}, "restPart");
+ let range = conditionformat.CFSplitRange(
+ source_curCdformat_cellrange[j],
+ {"row": [c_r1, c_r2], "column": [c_c1, c_c2]},
+ {"row": [minh, maxh], "column": [minc, maxc]},
+ "restPart"
+ );
+
emptyRange = emptyRange.concat(range);
- let range2 = conditionformat.CFSplitRange(source_curCdformat_cellrange[j], {"row": copyRange["copyRange"][0].row, "column": copyRange["copyRange"][0].column}, {"row": [minh, maxh], "column": [minc, maxc]}, "operatePart");
+ let range2 = conditionformat.CFSplitRange(
+ source_curCdformat_cellrange[j],
+ {"row": [c_r1, c_r2], "column": [c_c1, c_c2]},
+ {"row": [minh, maxh], "column": [minc, maxc]},
+ "operatePart"
+ );
+
if(range2.length > 0){
emptyRange2 = emptyRange2.concat(range2);
}
@@ -1091,6 +1134,13 @@ const selection = {
target_curCdformat = target_curCdformat.concat(ruleArr);
}
+ //数据验证
+ for(let i = c_r1; i <= c_r2; i++){
+ for(let j = c_c1; j <= c_c2; j++){
+ delete c_dataVerification[i + "_" + j];
+ }
+ }
+
source = {
"sheetIndex": copySheetIndex,
"data": sourceData,
@@ -1099,9 +1149,11 @@ const selection = {
"curConfig": sourceCurConfig,
"cdformat": source_cdformat,
"curCdformat": source_curCdformat,
+ "dataVerification": $.extend(true, {}, Store.luckysheetfile[getSheetIndex(copySheetIndex)]["dataVerification"]),
+ "curDataVerification": c_dataVerification,
"range": {
- "row": copyRange["copyRange"][0].row,
- "column": copyRange["copyRange"][0].column
+ "row": [c_r1, c_r2],
+ "column": [c_c1, c_c2]
}
}
target = {
@@ -1112,6 +1164,8 @@ const selection = {
"curConfig": cfg,
"cdformat": target_cdformat,
"curCdformat": target_curCdformat,
+ "dataVerification": $.extend(true, {}, Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dataVerification"]),
+ "curDataVerification": dataVerification,
"range": {
"row": [minh, maxh],
"column": [minc, maxc]
@@ -1128,7 +1182,13 @@ const selection = {
let emptyRange = [];
for(let j = 0; j < cellrange.length; j++){
- let range = conditionformat.CFSplitRange(cellrange[j], {"row": copyRange["copyRange"][0].row, "column": copyRange["copyRange"][0].column}, {"row": [minh, maxh], "column": [minc, maxc]}, "allPart");
+ let range = conditionformat.CFSplitRange(
+ cellrange[j],
+ {"row": [c_r1, c_r2], "column": [c_c1, c_c2]},
+ {"row": [minh, maxh], "column": [minc, maxc]},
+ "allPart"
+ );
+
emptyRange = emptyRange.concat(range);
}
@@ -1145,9 +1205,11 @@ const selection = {
"curConfig": cfg,
"cdformat": cdformat,
"curCdformat": curCdformat,
+ "dataVerification": $.extend(true, {}, Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dataVerification"]),
+ "curDataVerification": dataVerification,
"range": {
- "row": copyRange["copyRange"][0].row,
- "column": copyRange["copyRange"][0].column
+ "row": [c_r1, c_r2],
+ "column": [c_c1, c_c2]
}
}
target = {
@@ -1158,6 +1220,8 @@ const selection = {
"curConfig": cfg,
"cdformat": cdformat,
"curCdformat": curCdformat,
+ "dataVerification": $.extend(true, {}, Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["dataVerification"]),
+ "curDataVerification": dataVerification,
"range": {
"row": [minh, maxh],
"column": [minc, maxc]
@@ -1183,11 +1247,16 @@ const selection = {
let copyRowlChange = copyRange["RowlChange"];
let copySheetIndex = copyRange["dataSheetIndex"];
+ let c_r1 = copyRange["copyRange"][0].row[0],
+ c_r2 = copyRange["copyRange"][0].row[1],
+ c_c1 = copyRange["copyRange"][0].column[0],
+ c_c2 = copyRange["copyRange"][0].column[1];
+
let arr = [], isSameRow = false;
for(let i = 0; i < copyRange["copyRange"].length; i++){
let arrData = getdatabyselection({"row": copyRange["copyRange"][i].row, "column": copyRange["copyRange"][i].column}, copySheetIndex);
if(copyRange["copyRange"].length > 1){
- if(copyRange["copyRange"][0].row[0] == copyRange["copyRange"][1].row[0] && copyRange["copyRange"][0].row[1] == copyRange["copyRange"][1].row[1]){
+ if(c_r1 == copyRange["copyRange"][1].row[0] && c_r2 == copyRange["copyRange"][1].row[1]){
arrData = arrData[0].map(function(col, a){
return arrData.map(function(row){
return row[a];
@@ -1198,7 +1267,7 @@ const selection = {
isSameRow = true;
}
- else if(copyRange["copyRange"][0].column[0] == copyRange["copyRange"][1].column[0] && copyRange["copyRange"][0].column[1] == copyRange["copyRange"][1].column[1]){
+ else if(c_c1 == copyRange["copyRange"][1].column[0] && c_c2 == copyRange["copyRange"][1].column[1]){
arr = arr.concat(arrData);
}
}
@@ -1274,6 +1343,8 @@ const selection = {
}
let borderInfoCompute = getBorderInfoCompute(copySheetIndex);
+ let c_dataVerification = $.extend(true, {}, Store.luckysheetfile[getSheetIndex(copySheetIndex)].dataVerification);
+ let dataVerification = null;
let mth = 0, mtc = 0, maxcellCahe = 0, maxrowCache = 0;
for(let th = 1; th <= timesH; th++){
@@ -1284,24 +1355,24 @@ const selection = {
maxcellCahe = minc + tc * copyc;
//行列位移值 用于单元格有函数
- let offsetRow = mth - copyRange["copyRange"][0].row[0];
- let offsetCol = mtc - copyRange["copyRange"][0].column[0];
+ let offsetRow = mth - c_r1;
+ let offsetCol = mtc - c_c1;
let offsetMC = {};
for (let h = mth; h < maxrowCache; h++) {
let x = [].concat(d[h]);
for (let c = mtc; c < maxcellCahe; c++) {
- if(borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - mth) + "_" + (copyRange["copyRange"][0].column[0] + c - mtc)]){
+ if(borderInfoCompute[(c_r1 + h - mth) + "_" + (c_c1 + c - mtc)]){
let bd_obj = {
"rangeType": "cell",
"value": {
"row_index": h,
"col_index": c,
- "l": borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - mth) + "_" + (copyRange["copyRange"][0].column[0] + c - mtc)].l,
- "r": borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - mth) + "_" + (copyRange["copyRange"][0].column[0] + c - mtc)].r,
- "t": borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - mth) + "_" + (copyRange["copyRange"][0].column[0] + c - mtc)].t,
- "b": borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - mth) + "_" + (copyRange["copyRange"][0].column[0] + c - mtc)].b
+ "l": borderInfoCompute[(c_r1 + h - mth) + "_" + (c_c1 + c - mtc)].l,
+ "r": borderInfoCompute[(c_r1 + h - mth) + "_" + (c_c1 + c - mtc)].r,
+ "t": borderInfoCompute[(c_r1 + h - mth) + "_" + (c_c1 + c - mtc)].t,
+ "b": borderInfoCompute[(c_r1 + h - mth) + "_" + (c_c1 + c - mtc)].b
}
}
@@ -1331,6 +1402,15 @@ const selection = {
cfg["borderInfo"].push(bd_obj);
}
+ //数据验证 复制
+ if(c_dataVerification[(c_r1 + h - mth) + "_" + (c_c1 + c - mtc)]){
+ if(dataVerification == null){
+ dataVerification = $.extend(true, {}, Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].dataVerification)
+ }
+
+ dataVerification[h + "_" + c] = c_dataVerification[(c_r1 + h - mth) + "_" + (c_c1 + c - mtc)];
+ }
+
if(getObjType(x[c]) == "object" && "mc" in x[c]){
if("rs" in x[c].mc){
delete cfg["merge"][x[c]["mc"].r + "_" + x[c]["mc"].c];
@@ -1401,21 +1481,17 @@ const selection = {
}
}
- //复制范围 是否有 条件格式
- let ruleArr_cf = [], cdformat = [];
+ //复制范围 是否有 条件格式和数据验证
+ let cdformat = null;
if(copyRange["copyRange"].length == 1){
let c_file = Store.luckysheetfile[getSheetIndex(copySheetIndex)];
let a_file = Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)];
-
- let c_r1 = copyRange["copyRange"][0].row[0],
- c_r2 = copyRange["copyRange"][0].row[1],
- c_c1 = copyRange["copyRange"][0].column[0],
- c_c2 = copyRange["copyRange"][0].column[1];
- ruleArr_cf = $.extend(true, [], c_file["luckysheet_conditionformat_save"]);
- cdformat = $.extend(true, [], a_file["luckysheet_conditionformat_save"]);
+ let ruleArr_cf = $.extend(true, [], c_file["luckysheet_conditionformat_save"]);
if(ruleArr_cf != null && ruleArr_cf.length > 0){
+ cdformat = $.extend(true, [], a_file["luckysheet_conditionformat_save"]);
+
for(let i = 0; i < ruleArr_cf.length; i++){
let cf_range = ruleArr_cf[i].cellrange;
@@ -1429,7 +1505,13 @@ const selection = {
maxcellCahe = minc + tc * copyc;
for(let j = 0; j < cf_range.length; j++){
- let range = conditionformat.CFSplitRange(cf_range[j], {"row": [c_r1, c_r2], "column": [c_c1, c_c2]}, {"row": [mth, maxrowCache - 1], "column": [mtc, maxcellCahe - 1]}, "operatePart");
+ let range = conditionformat.CFSplitRange(
+ cf_range[j],
+ {"row": [c_r1, c_r2], "column": [c_c1, c_c2]},
+ {"row": [mth, maxrowCache - 1], "column": [mtc, maxcellCahe - 1]},
+ "operatePart"
+ );
+
if(range.length > 0){
emptyRange = emptyRange.concat(range);
}
@@ -1451,21 +1533,22 @@ const selection = {
if(copyRowlChange || addr > 0 || addc > 0){
cfg = rowlenByRange(d, minh, maxh, cfg);
- if(copyRange["copyRange"].length == 1 && ruleArr_cf != null && ruleArr_cf.length > 0){
- jfrefreshgrid(d, Store.luckysheet_select_save, cfg, cdformat, true);
- }
- else{
- jfrefreshgrid(d, Store.luckysheet_select_save, cfg, null, true);
+ let allParam = {
+ "cfg": cfg,
+ "RowlChange": true,
+ "cdformat": cdformat,
+ "dataVerification": dataVerification
}
+ jfrefreshgrid(d, Store.luckysheet_select_save, allParam);
}
else{
- if(copyRange["copyRange"].length == 1 && ruleArr_cf != null && ruleArr_cf.length > 0){
- jfrefreshgrid(d, Store.luckysheet_select_save, cfg, cdformat);
- }
- else{
- jfrefreshgrid(d, Store.luckysheet_select_save, cfg);
+ let allParam = {
+ "cfg": cfg,
+ "cdformat": cdformat,
+ "dataVerification": dataVerification
}
-
+ jfrefreshgrid(d, Store.luckysheet_select_save, allParam);
+
selectHightlightShow();
}
},
@@ -1478,9 +1561,14 @@ const selection = {
//复制范围
let copyHasMC = copyRange["HasMC"];
let copyRowlChange = copyRange["RowlChange"];
-
let copySheetIndex = copyRange["dataSheetIndex"];
- let copyData = $.extend(true, [], getdatabyselection({"row": copyRange["copyRange"][0].row, "column": copyRange["copyRange"][0].column}, copySheetIndex));
+
+ let c_r1 = copyRange["copyRange"][0].row[0],
+ c_r2 = copyRange["copyRange"][0].row[1],
+ c_c1 = copyRange["copyRange"][0].column[0],
+ c_c2 = copyRange["copyRange"][0].column[1];
+
+ let copyData = $.extend(true, [], getdatabyselection({"row": [c_r1, c_r2], "column": [c_c1, c_c2]}, copySheetIndex));
//应用范围
let last = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1];
@@ -1518,6 +1606,8 @@ const selection = {
let rowMaxLength = d.length;
let borderInfoCompute = getBorderInfoCompute(copySheetIndex);
+ let c_dataVerification = $.extend(true, {}, Store.luckysheetfile[getSheetIndex(copySheetIndex)].dataVerification);
+ let dataVerification = null;
let mth = 0, mtc = 0, maxcellCahe = 0, maxrowCache = 0;
for (let th = 1; th <= timesH; th++) {
@@ -1540,16 +1630,16 @@ const selection = {
let x = [].concat(d[h]);
for (let c = mtc; c < maxcellCahe; c++) {
- if(borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - mth) + "_" + (copyRange["copyRange"][0].column[0] + c - mtc)]){
+ if(borderInfoCompute[(c_r1 + h - mth) + "_" + (c_c1 + c - mtc)]){
let bd_obj = {
"rangeType": "cell",
"value": {
"row_index": h,
"col_index": c,
- "l": borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - mth) + "_" + (copyRange["copyRange"][0].column[0] + c - mtc)].l,
- "r": borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - mth) + "_" + (copyRange["copyRange"][0].column[0] + c - mtc)].r,
- "t": borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - mth) + "_" + (copyRange["copyRange"][0].column[0] + c - mtc)].t,
- "b": borderInfoCompute[(copyRange["copyRange"][0].row[0] + h - mth) + "_" + (copyRange["copyRange"][0].column[0] + c - mtc)].b
+ "l": borderInfoCompute[(c_r1 + h - mth) + "_" + (c_c1 + c - mtc)].l,
+ "r": borderInfoCompute[(c_r1 + h - mth) + "_" + (c_c1 + c - mtc)].r,
+ "t": borderInfoCompute[(c_r1 + h - mth) + "_" + (c_c1 + c - mtc)].t,
+ "b": borderInfoCompute[(c_r1 + h - mth) + "_" + (c_c1 + c - mtc)].b
}
}
@@ -1579,6 +1669,15 @@ const selection = {
cfg["borderInfo"].push(bd_obj);
}
+ //数据验证 复制
+ if(c_dataVerification[(c_r1 + h - mth) + "_" + (c_c1 + c - mtc)]){
+ if(dataVerification == null){
+ dataVerification = $.extend(true, {}, Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].dataVerification)
+ }
+
+ dataVerification[h + "_" + c] = c_dataVerification[(c_r1 + h - mth) + "_" + (c_c1 + c - mtc)];
+ }
+
if(getObjType(x[c]) == "object" && ("mc" in x[c])){
if("rs" in x[c].mc){
delete cfg["merge"][x[c]["mc"].r + "_" + x[c]["mc"].c];
@@ -1642,16 +1741,24 @@ const selection = {
}
//复制范围 是否有 条件格式
+ let cdformat = null;
let ruleArr = $.extend(true, [], Store.luckysheetfile[getSheetIndex(copySheetIndex)]["luckysheet_conditionformat_save"]);
- let cdformat = $.extend(true, [], Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["luckysheet_conditionformat_save"]);
if(ruleArr != null && ruleArr.length > 0){
+ cdformat = $.extend(true, [], Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["luckysheet_conditionformat_save"]);
+
for(let i = 0; i < ruleArr.length; i++){
let cdformat_cellrange = ruleArr[i].cellrange;
let emptyRange = [];
for(let j = 0; j < cdformat_cellrange.length; j++){
- let range = conditionformat.CFSplitRange(cdformat_cellrange[j], {"row": copyRange["copyRange"][0]["row"], "column": copyRange["copyRange"][0]["column"]}, {"row": [minh, maxh], "column": [minc, maxc]}, "operatePart");
+ let range = conditionformat.CFSplitRange(
+ cdformat_cellrange[j],
+ {"row": [c_r1, c_r2], "column": [c_c1, c_c2]},
+ {"row": [minh, maxh], "column": [minc, maxc]},
+ "operatePart"
+ );
+
if(range.length > 0){
emptyRange = emptyRange.concat(range);
}
@@ -1670,21 +1777,22 @@ const selection = {
if(copyRowlChange){
cfg = rowlenByRange(d, minh, maxh, cfg);
- if(ruleArr != null && ruleArr.length > 0){
- jfrefreshgrid(d, Store.luckysheet_select_save, cfg, cdformat, true);
- }
- else{
- jfrefreshgrid(d, Store.luckysheet_select_save, cfg, null, true);
+ let allParam = {
+ "cfg": cfg,
+ "RowlChange": true,
+ "cdformat": cdformat,
+ "dataVerification": dataVerification
}
+ jfrefreshgrid(d, Store.luckysheet_select_save, allParam);
}
else{
- if(ruleArr != null && ruleArr.length > 0){
- jfrefreshgrid(d, Store.luckysheet_select_save, cfg, cdformat);
- }
- else{
- jfrefreshgrid(d, Store.luckysheet_select_save, cfg);
+ let allParam = {
+ "cfg": cfg,
+ "cdformat": cdformat,
+ "dataVerification": dataVerification
}
-
+ jfrefreshgrid(d, Store.luckysheet_select_save, allParam);
+
selectHightlightShow();
}
},
diff --git a/src/controllers/server.js b/src/controllers/server.js
index 086e246..b38a2b3 100644
--- a/src/controllers/server.js
+++ b/src/controllers/server.js
@@ -714,15 +714,12 @@ const server = {
multipleRangeShow: function(id, name, r, c) {
let _this = this;
- let r1 = r2 = r;
- let c1 = c2 = c;
+ let row = Store.visibledatarow[r],
+ row_pre = r - 1 == -1 ? 0 : Store.visibledatarow[r - 1],
+ col = Store.visibledatacolumn[c],
+ col_pre = c - 1 == -1 ? 0 : Store.visibledatacolumn[c - 1];
- let row = visibledatarow[r2],
- row_pre = r1 - 1 == -1 ? 0 : visibledatarow[r1 - 1],
- col = visibledatacolumn[c2],
- col_pre = c1 - 1 == -1 ? 0 : visibledatacolumn[c1 - 1];
-
- let margeset = menuButton.mergeborer(Store.flowdata, r1, c1);
+ let margeset = menuButton.mergeborer(Store.flowdata, r, c);
if(!!margeset){
row = margeset.row[1];
row_pre = margeset.row[0];
diff --git a/src/controllers/sheetBar.js b/src/controllers/sheetBar.js
index c048ee6..cfcb4cb 100644
--- a/src/controllers/sheetBar.js
+++ b/src/controllers/sheetBar.js
@@ -11,6 +11,8 @@ import { isEditMode } from '../global/validate';
import formula from '../global/formula';
import cleargridelement from '../global/cleargridelement';
import tooltip from '../global/tooltip';
+ selectTextDom
+import {selectTextDom} from '../global/cursorPos';
import locale from '../locale/locale';
import Store from '../store';
@@ -206,16 +208,7 @@ export function initialSheetBar(){
$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);
- }
+ selectTextDom($t.get(0));
}, 1);
}
diff --git a/src/controllers/sheetmanage.js b/src/controllers/sheetmanage.js
index 07aa443..e680a32 100644
--- a/src/controllers/sheetmanage.js
+++ b/src/controllers/sheetmanage.js
@@ -18,6 +18,7 @@ import pivotTable from './pivotTable';
import luckysheetsizeauto from './resize';
import luckysheetPostil from './postil';
import imageCtrl from './imageCtrl';
+import dataVerificationCtrl from './dataVerificationCtrl';
import luckysheetFreezen from './freezen';
import { createFilterOptions, labelFilterOptionState } from './filter';
import { selectHightlightShow, selectionCopyShow } from './select';
@@ -864,13 +865,6 @@ const sheetmanage = {
formula.execFunctionGroupData = null;
window.luckysheet_getcelldata_cache = null;
- //批注
- luckysheetPostil.buildAllPs(Store.flowdata);
-
- //图片
- imageCtrl.images = file.images;
- imageCtrl.allImagesShow();
-
this.sheetParamRestore(file, Store.flowdata);
if(file["freezen"] == null){
@@ -883,10 +877,18 @@ const sheetmanage = {
}
rhchInit(Store.flowdata.length, Store.flowdata[0].length);
+
+ //批注
+ luckysheetPostil.buildAllPs(Store.flowdata);
+
+ //图片
+ imageCtrl.images = file.images;
+ imageCtrl.allImagesShow();
+
+ //数据验证
+ dataVerificationCtrl.dataVerification = file.dataVerification;
createFilterOptions(file["filter_select"], file["filter"]);
-
-
},
restoreselect: function() {
let index = this.getSheetIndex(Store.currentSheetIndex);
@@ -1424,18 +1426,18 @@ const sheetmanage = {
let index = this.getSheetIndex(sheetIndex);
let file = Store.luckysheetfile[index];
- if($('#luckysheet-filter-selected-sheet' + sheetIndex).length > 0 || file.filter_select == null || JSON.stringify(file.filter_select) == "{}"){
- if(file.config != null && file.config.rowhidden != null){
- file.config.rowhidden = {};
- Store.config = file.config;
+ // if($('#luckysheet-filter-selected-sheet' + sheetIndex).length > 0 || file.filter_select == null || JSON.stringify(file.filter_select) == "{}"){
+ // if(file.config != null && file.config.rowhidden != null){
+ // file.config.rowhidden = {};
+ // Store.config = file.config;
- jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length,false);
- }
+ // jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length,false);
+ // }
- return;
- }
+ // return;
+ // }
- if(getObjType(file.filter_select) != "object"){
+ if(getObjType(file.filter_select) == "string"){
file.filter_select = JSON.parse(file.filter_select);
}
diff --git a/src/controllers/updateCell.js b/src/controllers/updateCell.js
index 1d18577..b60fd8a 100644
--- a/src/controllers/updateCell.js
+++ b/src/controllers/updateCell.js
@@ -3,13 +3,15 @@ import luckysheetFreezen from './freezen';
import menuButton from './menuButton';
import conditionformat from './conditionformat';
import alternateformat from './alternateformat';
+import dataVerificationCtrl from './dataVerificationCtrl';
import { chatatABC } from '../utils/util';
import { isEditMode } from '../global/validate';
-import { getcellvalue } from '../global/getdata';
+import { getcellvalue,getInlineStringStyle } from '../global/getdata';
import { valueShowEs } from '../global/format';
import formula from '../global/formula';
import { luckysheetRangeLast } from '../global/cursorPos';
import cleargridelement from '../global/cleargridelement';
+import {isInlineStringCell} from './inlineString';
import Store from '../store';
export function luckysheetupdateCell(row_index1, col_index1, d, cover, isnotfocus) {
@@ -17,6 +19,16 @@ export function luckysheetupdateCell(row_index1, col_index1, d, cover, isnotfocu
return;
}
+ if(dataVerificationCtrl.dataVerification != null && dataVerificationCtrl.dataVerification[row_index1 + '_' + col_index1] != null){
+ let dataVerificationItem = dataVerificationCtrl.dataVerification[row_index1 + '_' + col_index1];
+ if(dataVerificationItem.type == 'dropdown'){
+ dataVerificationCtrl.dropdownListShow();
+ }
+ else if(dataVerificationItem.type == 'checkbox'){
+ return;
+ }
+ }
+
let size = getColumnAndRowSize(row_index1, col_index1, d);
let row = size.row, row_pre = size.row_pre, col = size.col, col_pre = size.col_pre, row_index = size.row_index, col_index = size.col_index;
@@ -124,7 +136,10 @@ export function luckysheetupdateCell(row_index1, col_index1, d, cover, isnotfocu
if (!cover) {
- if(cell.f!=null){
+ if(isInlineStringCell(cell)){
+ value = getInlineStringStyle(row_index, col_index, d);
+ }
+ else if(cell.f!=null){
value = getcellvalue(row_index, col_index, d, "f");
}
else{
diff --git a/src/css/luckysheet-core.css b/src/css/luckysheet-core.css
index 04f2ef6..28663c2 100644
--- a/src/css/luckysheet-core.css
+++ b/src/css/luckysheet-core.css
@@ -7049,4 +7049,177 @@ fieldset[disabled] .btn-danger.focus {
margin-left: 5px;
margin-bottom: -5px;
cursor: pointer;
-}
\ No newline at end of file
+}
+/* 数据验证 */
+#luckysheet-dataVerification-dialog{
+ user-select: none;
+}
+#luckysheet-dataVerification-dialog .box{
+ font-size: 12px;
+}
+#luckysheet-dataVerification-dialog .box select{
+ width: 100%;
+ height: 30px;
+ border-color: #d4d4d4;
+ outline-style: none;
+}
+#luckysheet-dataVerification-dialog .box input::-webkit-input-placeholder {
+ color: #d4d4d4;
+}
+#luckysheet-dataVerification-dialog .box input:-moz-placeholder {
+ color: #d4d4d4;
+}
+#luckysheet-dataVerification-dialog .box input::-moz-placeholder {
+ color: #d4d4d4;
+}
+#luckysheet-dataVerification-dialog .box input:-ms-input-placeholder {
+ color: #d4d4d4;
+}
+#luckysheet-dataVerification-dialog .box-item{
+ padding: 10px;
+ border-bottom: 1px solid #E1E4E8;
+}
+#luckysheet-dataVerification-dialog .box-item .box-item-title{
+ font-size: 14px;
+ font-weight: 600;
+ margin-bottom: 10px;
+}
+#luckysheet-dataVerification-dialog .box-item .range{
+ width: 100%;
+ height: 30px;
+ border: 1px solid #d4d4d4;
+}
+#luckysheet-dataVerification-dialog .box-item .range input{
+ width: calc(100% - 30px);
+ height: 30px;
+ padding: 0 10px;
+ float: left;
+ border: none;
+ outline-style: none;
+ box-sizing: border-box;
+}
+#luckysheet-dataVerification-dialog .box-item .range i.fa-table{
+ float: right;
+ margin-top: 9px;
+ margin-right: 5px;
+ cursor: pointer;
+ color: #6598F3;
+}
+#luckysheet-dataVerification-dialog .box-item .show-box{
+ margin-top: 10px;
+}
+#luckysheet-dataVerification-dialog .box-item .check-box{
+ height: 30px;
+ line-height: 30px;
+ margin-bottom: 10px;
+}
+#luckysheet-dataVerification-dialog .box-item .check-box:last-child{
+ margin-bottom: 0;
+}
+#luckysheet-dataVerification-dialog .box-item .check-box input{
+ height: 30px;
+ padding: 0 10px;
+ border: 1px solid #d4d4d4;
+ box-sizing: border-box;
+}
+#luckysheet-dataVerification-dialog .box-item .check{
+ line-height: 30px;
+}
+#luckysheet-dataVerification-dialog .box-item .check input{
+ vertical-align: text-top;
+}
+#luckysheet-dataVerification-dialog .box-item .input{
+ height: 30px;
+ line-height: 30px;
+ margin-top: 10px;
+}
+#luckysheet-dataVerification-dialog .box-item .input input{
+ height: 30px;
+ padding: 4px 10px 4px 10px;
+ border: 1px solid #d4d4d4;
+ box-sizing: border-box;
+}
+#luckysheet-dataVerification-dialog .box-item .input1 input{
+ width: 150px;
+}
+#luckysheet-dataVerification-dialog .box-item .input2 input{
+ width: 100%;
+}
+#luckysheet-dataVerification-dialog .box-item .input span{
+ display: inline-block;
+ width: 30px;
+ text-align: center;
+}
+#luckysheet-dataVerification-dialog .data-verification-hint-text{
+ width: 100%;
+ height: 30px;
+ border: 1px solid #d4d4d4;
+ margin-top: 10px;
+}
+#luckysheet-dataVerification-dialog .data-verification-hint-text input{
+ display: block;
+ width: 100%;
+ height: 100%;
+ padding: 0 10px;
+ border: none;
+ outline-style: none;
+ box-sizing: border-box;
+}
+#luckysheet-dataVerification-dialog .show-box .show-box-item{
+ display: none;
+}
+#luckysheet-dataVerificationRange-dialog input{
+ height: 30px;
+ padding: 0 10px;
+ border: 1px solid #d4d4d4;
+ outline-style: none;
+}
+#luckysheet-dataVerification-dropdown-btn{
+ display: none;
+ width: 20px;
+ height: 20px;
+ background-color: #fff;
+ position: absolute;
+ z-index: 10;
+ overflow: hidden;
+}
+#luckysheet-dataVerification-dropdown-btn::after{
+ content: '';
+ width: 10px;
+ height: 10px;
+ background: url(arrow-down.png) center no-repeat;
+ position: absolute;
+ left: 50%;
+ top: 50%;
+ margin-left: -5px;
+ margin-top: -5px;
+}
+#luckysheet-dataVerification-dropdown-List{
+ display: none;
+ background-color: #fff;
+ border: 1px solid #ccc;
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
+ position: absolute;
+ z-index: 1000;
+ box-sizing: border-box;
+}
+#luckysheet-dataVerification-dropdown-List .dropdown-List-item{
+ padding: 5px 10px;
+ box-sizing: border-box;
+ cursor: pointer;
+}
+#luckysheet-dataVerification-dropdown-List .dropdown-List-item:hover{
+ background-color: #E1E1E1;
+}
+#luckysheet-dataVerification-showHintBox{
+ display: none;
+ padding: 10px;
+ background-color: #fff;
+ border: 1px solid #ccc;
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2);
+ position: absolute;
+ z-index: 1000;
+ user-select: none;
+ cursor: default;
+ white-space: nowrap;
+}
diff --git a/src/function/functionImplementation.js b/src/function/functionImplementation.js
index 3f2280b..2e54cbb 100644
--- a/src/function/functionImplementation.js
+++ b/src/function/functionImplementation.js
@@ -15806,7 +15806,7 @@ const functionImplementation = {
values = values.concat(func_methods.getDataArr(data_values, false));
}
else if(getObjType(data_values) == "object" && data_values.startCell != null){
- values = values.concat(func_methods.getCellDataArr(data_values, "number", false));
+ values = values.concat(func_methods.getCellDataArr(data_values, "number", true));
}
else{
values.push(data_values);
diff --git a/src/global/api.js b/src/global/api.js
index 59d17d8..370f0a7 100644
--- a/src/global/api.js
+++ b/src/global/api.js
@@ -1,32 +1,36 @@
import Store from "../store";
-import { getObjType, chatatABC } from "../utils/util";
-import formula from './formula';
+import { replaceHtml, getObjType, chatatABC } from "../utils/util";
import { getSheetIndex, getluckysheet_select_save } from "../methods/get";
-import { isRealNull, valueIsError, isRealNum, isEditMode, hasPartMC } from "./validate";
-import { genarate, update } from './format';
-import server from "../controllers/server";
-import luckysheetConfigsetting from "../controllers/luckysheetConfigsetting";
-import { setAccuracy } from "./setdata";
-import func_methods from "./func_methods";
-import luckysheetFreezen from "../controllers/freezen";
-import { luckysheetrefreshgrid, jfrefreshgrid, jfrefreshgrid_rhcw } from "./refresh";
import locale from "../locale/locale";
+
+import formula from './formula';
+import func_methods from "./func_methods";
import tooltip from "./tooltip";
-import { luckysheet_searcharray } from "../controllers/sheetSearch";
-import { luckysheetDeleteCell, luckysheetextendtable, luckysheetdeletetable } from "./extend";
-import { getdatabyselection, getcellvalue } from "./getdata";
-import selection from "../controllers/selection";
import json from "./json";
-import { orderbydata } from "./sort";
import editor from "./editor";
-import { rowlenByRange } from "./getRowlen";
import luckysheetformula from './formula';
+import cleargridelement from './cleargridelement';
+import { genarate, update } from './format';
+import { setAccuracy } from "./setdata";
+import { orderbydata } from "./sort";
+import { rowlenByRange } from "./getRowlen";
+import { getdatabyselection, getcellvalue } from "./getdata";
+import { luckysheetrefreshgrid, jfrefreshgrid, jfrefreshgrid_rhcw } from "./refresh";
+import { luckysheetDeleteCell, luckysheetextendtable, luckysheetdeletetable } from "./extend";
+import { isRealNull, valueIsError, isRealNum, isEditMode, hasPartMC } from "./validate";
+
+import server from "../controllers/server";
+import selection from "../controllers/selection";
+import luckysheetConfigsetting from "../controllers/luckysheetConfigsetting";
+import luckysheetFreezen from "../controllers/freezen";
import luckysheetsizeauto from '../controllers/resize';
import sheetmanage from '../controllers/sheetmanage';
+import { luckysheet_searcharray } from "../controllers/sheetSearch";
+import { selectIsOverlap } from '../controllers/select';
+import { sheetHTML } from '../controllers/constant';
const IDCardReg = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3}(\d|X)$/i;
-
/**
* 获取单元格的值
* @param {Number} row 单元格所在行数;从0开始的整数,0表示第一行
@@ -37,7 +41,7 @@ const IDCardReg = /^\d{6}(18|19|20)?\d{2}(0[1-9]|1[12])(0[1-9]|[12]\d|3[01])\d{3
*/
export function getCellValue(row, column, options = {}) {
if (row == null && column == null) {
- return console.error('Arguments row or column cannot be null or undefined.')
+ return tooltip.info('Arguments row or column cannot be null or undefined.', '')
}
let curSheetOrder = getSheetIndex(Store.currentSheetIndex);
let {
@@ -84,7 +88,7 @@ export function getCellValue(row, column, options = {}) {
*/
// export function setCellValue(row, column, value, options = {}) {
// if (row == null && column == null) {
-// return console.error('Arguments row or column cannot be null or undefined.')
+// return tooltip.info('Arguments row or column cannot be null or undefined.', '')
// }
// let curSheetOrder = getSheetIndex(Store.currentSheetIndex);
// let {
@@ -234,7 +238,7 @@ export function getCellValue(row, column, options = {}) {
// }
export function setCellValue(row, column, value, options = {}) {
if (row == null && column == null) {
- return console.error('Arguments row or column cannot be null or undefined.')
+ return tooltip.info('Arguments row or column cannot be null or undefined.', '')
}
let curSheetOrder = getSheetIndex(Store.currentSheetIndex);
let {
@@ -261,30 +265,33 @@ export function setCellValue(row, column, value, options = {}) {
*/
export function clearCell(row, column, options = {}) {
if (row == null || column == null) {
- return console.error('Arguments row and column cannot be null or undefined.')
+ return tooltip.info('Arguments row and column cannot be null or undefined.', '')
}
+
let curSheetOrder = getSheetIndex(Store.currentSheetIndex);
let {
order = curSheetOrder,
success
} = {...options}
- let targetSheetData = Store.luckysheetfile[order].data;
+
+ let targetSheetData = $.extend(true, [], Store.luckysheetfile[order].data);
let cell = targetSheetData[row][column];
- if(getObjType(targetSheetData[row][column]) == "object"){
- delete targetSheetData[row][column]["m"];
- delete targetSheetData[row][column]["v"];
+ if(getObjType(cell) == "object"){
+ delete cell["m"];
+ delete cell["v"];
- if(targetSheetData[row][column]["f"] != null){
- delete targetSheetData[row][column]["f"];
+ if(cell["f"] != null){
+ delete cell["f"];
formula.delFunctionGroup(row, column, order);
- delete targetSheetData[row][column]["spl"];
+ delete cell["spl"];
}
}
else{
- targetSheetData[row][column] = null;
+ cell = null;
}
+
// 若操作为当前sheet页,则刷新当前sheet页
if (order === curSheetOrder) {
jfrefreshgrid(targetSheetData, [{
@@ -292,6 +299,10 @@ export function clearCell(row, column, options = {}) {
column: [column, column]
}])
}
+ else{
+ Store.luckysheetfile[order].data = targetSheetData;
+ }
+
if (success && typeof success === 'function') {
success(cell)
}
@@ -309,10 +320,11 @@ export function clearCell(row, column, options = {}) {
export function deleteCell(move, row, column, options = {}) {
let moveTypes = ['left', 'up'];
if (!move || moveTypes.indexOf(move) < 0) {
- return console.error('Arguments move cannot be null or undefined and its value must be \'left\' or \'up\'')
+ return tooltip.info('Arguments move cannot be null or undefined and its value must be \'left\' or \'up\'', '')
}
+
if (row == null || column == null) {
- return console.error('Arguments row and column cannot be null or undefined.')
+ return tooltip.info('Arguments row and column cannot be null or undefined.', '')
}
let curSheetOrder = getSheetIndex(Store.currentSheetIndex);
@@ -323,6 +335,7 @@ export function deleteCell(move, row, column, options = {}) {
let moveType = 'move' + move.replace(move[0], move[0].toUpperCase()); // left-moveLeft; up-moveUp
luckysheetDeleteCell(moveType, row, row, column, column, order);
+
if (success && typeof success === 'function') {
success()
}
@@ -340,17 +353,19 @@ export function deleteCell(move, row, column, options = {}) {
*/
export function setCellFormat(row, column, attr, value, options = {}) {
if (row == null && column == null) {
- return console.error('Arguments row or column cannot be null or undefined.')
+ return tooltip.info('Arguments row or column cannot be null or undefined.', '')
}
+
if (!attr) {
- return console.error('Arguments attr cannot be null or undefined.')
+ return tooltip.info('Arguments attr cannot be null or undefined.', '')
}
+
let curSheetOrder = getSheetIndex(Store.currentSheetIndex);
let {
order = curSheetOrder,
success
} = { ...options };
- let targetSheetData = Store.luckysheetfile[order].data;
+ let targetSheetData = $.extend(true, [], Store.luckysheetfile[order].data);
let cellData = targetSheetData[row][column];
// 特殊格式
@@ -365,6 +380,7 @@ export function setCellFormat(row, column, attr, value, options = {}) {
row: [row],
column: [column]
})
+
if (success && typeof success === 'function') {
success(cellData);
}
@@ -381,8 +397,9 @@ export function setCellFormat(row, column, attr, value, options = {}) {
*/
export function find(content, options = {}) {
if (!content && content != 0) {
- return console.error('Search content cannot be null or empty')
+ return tooltip.info('Search content cannot be null or empty', '')
}
+
let curSheetOrder = getSheetIndex(Store.currentSheetIndex);
let {
isRegularExpression = false,
@@ -395,8 +412,10 @@ export function find(content, options = {}) {
let result = [];
for (let i = 0; i < targetSheetData.length; i++) {
const rowArr = targetSheetData[i];
+
for (let j = 0; j < rowArr.length; j++) {
const cell = rowArr[j];
+
if (!cell) {
continue;
}
@@ -439,6 +458,7 @@ export function find(content, options = {}) {
}
}
}
+
return result;
}
@@ -477,12 +497,20 @@ export function frozenFirstRow(order) {
// 冻结为当前sheet页
if (!order || order == getSheetIndex(Store.currentSheetIndex)) {
let scrollTop = $("#luckysheet-cell-main").scrollTop();
+
let row_st = luckysheet_searcharray(Store.visibledatarow, scrollTop);
if(row_st == -1){
row_st = 0;
}
+
let top = Store.visibledatarow[row_st] - 2 - scrollTop + Store.columeHeaderHeight;
- let freezenhorizontaldata = [Store.visibledatarow[row_st], row_st + 1, scrollTop, luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1), top];
+ let freezenhorizontaldata = [
+ Store.visibledatarow[row_st],
+ row_st + 1,
+ scrollTop,
+ luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1),
+ top
+ ];
luckysheetFreezen.saveFreezen(freezenhorizontaldata, top, null, null);
if (luckysheetFreezen.freezenverticaldata != null) {
@@ -509,12 +537,20 @@ export function frozenFirstColumn(order) {
// 冻结为当前sheet页
if (!order || order == getSheetIndex(Store.currentSheetIndex)) {
let scrollLeft = $("#luckysheet-cell-main").scrollLeft();
+
let col_st = luckysheet_searcharray(Store.visibledatacolumn, scrollLeft);
if(col_st == -1){
col_st = 0;
}
+
let left = Store.visibledatacolumn[col_st] - 2 - scrollLeft + Store.rowHeaderWidth;
- let freezenverticaldata = [Store.visibledatacolumn[col_st], col_st + 1, scrollLeft, luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1), left];
+ let freezenverticaldata = [
+ Store.visibledatacolumn[col_st],
+ col_st + 1,
+ scrollLeft,
+ luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1),
+ left
+ ];
luckysheetFreezen.saveFreezen(null, null, freezenverticaldata, left);
if (luckysheetFreezen.freezenhorizontaldata != null) {
@@ -536,6 +572,7 @@ export function frozenFirstColumn(order) {
*/
export function frozenRowRange(range, order) {
const locale_frozen = locale().freezen;
+
if (!range || (!range.hasOwnProperty('row_focus') && !formula.iscelldata(range))) {
if(isEditMode()){
alert(locale_frozen.noSeletionError);
@@ -544,6 +581,7 @@ export function frozenRowRange(range, order) {
}
return
}
+
if (typeof range === 'string' && formula.iscelldata(range)) {
range = formula.getcellrange(range)
range = {
@@ -567,7 +605,13 @@ export function frozenRowRange(range, order) {
}
let top = Store.visibledatarow[row_st] - 2 - scrollTop + Store.columeHeaderHeight;
- let freezenhorizontaldata = [Store.visibledatarow[row_st], row_st + 1, scrollTop, luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1), top];
+ let freezenhorizontaldata = [
+ Store.visibledatarow[row_st],
+ row_st + 1,
+ scrollTop,
+ luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1),
+ top
+ ];
luckysheetFreezen.saveFreezen(freezenhorizontaldata, top, null, null);
if (luckysheetFreezen.freezenverticaldata != null) {
@@ -591,6 +635,7 @@ export function frozenRowRange(range, order) {
export function frozenColumnRange(range, order) {
const locale_frozen = locale().freezen;
let isStringRange = typeof range === 'string' && formula.iscelldata(range);
+
if (!range || (!range.hasOwnProperty('column_focus') && !isStringRange)) {
if(isEditMode()){
alert(locale_frozen.noSeletionError);
@@ -599,6 +644,7 @@ export function frozenColumnRange(range, order) {
}
return
}
+
if (isStringRange) {
range = formula.getcellrange(range)
range = {
@@ -622,7 +668,13 @@ export function frozenColumnRange(range, order) {
}
let left = Store.visibledatacolumn[col_st] - 2 - scrollLeft + Store.rowHeaderWidth;
- let freezenverticaldata = [Store.visibledatacolumn[col_st], col_st + 1, scrollLeft, luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1), left];
+ let freezenverticaldata = [
+ Store.visibledatacolumn[col_st],
+ col_st + 1,
+ scrollLeft,
+ luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1),
+ left
+ ];
luckysheetFreezen.saveFreezen(null, null, freezenverticaldata, left);
if (luckysheetFreezen.freezenhorizontaldata != null) {
@@ -751,7 +803,13 @@ export function setBothFrozen(isRange, options = {}) {
row_st = 0;
}
let top = Store.visibledatarow[row_st] - 2 - scrollTop + Store.columeHeaderHeight;
- let freezenhorizontaldata = [Store.visibledatarow[row_st], row_st + 1, scrollTop, luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1), top];
+ let freezenhorizontaldata = [
+ Store.visibledatarow[row_st],
+ row_st + 1,
+ scrollTop,
+ luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1),
+ top
+ ];
luckysheetFreezen.saveFreezen(freezenhorizontaldata, top, null, null);
luckysheetFreezen.createFreezenHorizontal(freezenhorizontaldata, top);
@@ -762,7 +820,13 @@ export function setBothFrozen(isRange, options = {}) {
col_st = 0;
}
let left = Store.visibledatacolumn[col_st] - 2 - scrollLeft + Store.rowHeaderWidth;
- let freezenverticaldata = [Store.visibledatacolumn[col_st], col_st + 1, scrollLeft, luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1), left];
+ let freezenverticaldata = [
+ Store.visibledatacolumn[col_st],
+ col_st + 1,
+ scrollLeft,
+ luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1),
+ left
+ ];
luckysheetFreezen.saveFreezen(null, null, freezenverticaldata, left);
luckysheetFreezen.createFreezenVertical(freezenverticaldata, left);
@@ -807,7 +871,13 @@ export function setBothFrozen(isRange, options = {}) {
}
let top = Store.visibledatarow[row_st] - 2 - scrollTop + Store.columeHeaderHeight;
- let freezenhorizontaldata = [Store.visibledatarow[row_st], row_st + 1, scrollTop, luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1), top];
+ let freezenhorizontaldata = [
+ Store.visibledatarow[row_st],
+ row_st + 1,
+ scrollTop,
+ luckysheetFreezen.cutVolumn(Store.visibledatarow, row_st + 1),
+ top
+ ];
luckysheetFreezen.saveFreezen(freezenhorizontaldata, top, null, null);
luckysheetFreezen.createFreezenHorizontal(freezenhorizontaldata, top);
@@ -826,7 +896,13 @@ export function setBothFrozen(isRange, options = {}) {
}
let left = Store.visibledatacolumn[col_st] - 2 - scrollLeft + Store.rowHeaderWidth;
- let freezenverticaldata = [Store.visibledatacolumn[col_st], col_st + 1, scrollLeft, luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1), left];
+ let freezenverticaldata = [
+ Store.visibledatacolumn[col_st],
+ col_st + 1,
+ scrollLeft,
+ luckysheetFreezen.cutVolumn(Store.visibledatacolumn, col_st + 1),
+ left
+ ];
luckysheetFreezen.saveFreezen(null, null, freezenverticaldata, left);
luckysheetFreezen.createFreezenVertical(freezenverticaldata, left);
@@ -862,6 +938,7 @@ export function insertRowOrColumn(type, index = 0, options = {}) {
}
return;
}
+
number = parseInt(number);
if (number < 1 || number > 100) {
if(isEditMode()){
@@ -871,6 +948,7 @@ export function insertRowOrColumn(type, index = 0, options = {}) {
}
return;
}
+
// 默认在行上方增加行,列左侧增加列
luckysheetextendtable(type, index, number, "lefttop", order);
@@ -914,13 +992,15 @@ export function insertColumn(column = 0, options = {}) {
*/
export function deleteRowOrColumn(type, startIndex, endIndex, options = {}) {
if (startIndex == null || endIndex == null) {
- return console.error('Please enter the index for deleting rows or columns correctly.')
+ return tooltip.info('Please enter the index for deleting rows or columns correctly.', '')
}
+
let curSheetOrder = getSheetIndex(Store.currentSheetIndex);
let {
order = curSheetOrder,
success
} = {...options}
+
luckysheetdeletetable(type, startIndex, endIndex, order)
if (success && typeof success === 'function') {
@@ -963,8 +1043,9 @@ export function deleteColumn(columnStart, columnEnd, options = {}) {
*/
export function hideRowOrColumn(type, startIndex, endIndex, options = {}) {
if (startIndex == null || endIndex == null) {
- return console.error('Please enter the index for deleting rows or columns correctly.')
+ return tooltip.info('Please enter the index for deleting rows or columns correctly.', '')
}
+
let curSheetOrder = getSheetIndex(Store.currentSheetIndex);
let {
order = curSheetOrder,
@@ -986,7 +1067,7 @@ export function hideRowOrColumn(type, startIndex, endIndex, options = {}) {
if(Store.clearjfundo){
let redo = {};
redo["type"] = type === 'row' ? 'showHidRows' : 'showHidCols';
- redo["sheetIndex"] = order;
+ redo["sheetIndex"] = file.index;
redo["config"] = $.extend(true, {}, file.config);
redo["curconfig"] = cfg;
@@ -995,7 +1076,7 @@ export function hideRowOrColumn(type, startIndex, endIndex, options = {}) {
}
Store.luckysheetfile[order].config = cfg;
- server.saveParam("cg", order, cfg[cfgKey], { "k": cfgKey });
+ server.saveParam("cg", file.index, cfg[cfgKey], { "k": cfgKey });
// 若操作sheet为当前sheet页,行高、列宽 刷新
if (order == curSheetOrder) {
@@ -1020,16 +1101,18 @@ export function hideRowOrColumn(type, startIndex, endIndex, options = {}) {
*/
export function showRowOrColumn(type, startIndex, endIndex, options = {}) {
if (startIndex == null || endIndex == null) {
- return console.error('Please enter the index for deleting rows or columns correctly.')
+ return tooltip.info('Please enter the index for deleting rows or columns correctly.', '')
}
+
let curSheetOrder = getSheetIndex(Store.currentSheetIndex);
let {
order = curSheetOrder,
success
} = {...options}
+ let file = Store.luckysheetfile[order];
let cfgKey = type === 'row' ? 'rowhidden': 'colhidden';
- let cfg = $.extend(true, {}, Store.config);
+ let cfg = $.extend(true, {}, file.config);
if(cfg[cfgKey] == null) {
return;
}
@@ -1042,8 +1125,8 @@ export function showRowOrColumn(type, startIndex, endIndex, options = {}) {
if(Store.clearjfundo){
let redo = {};
redo["type"] = type === 'row' ? 'showHidRows' : 'showHidCols';
- redo["sheetIndex"] = order;
- redo["config"] = $.extend(true, {}, Store.config);
+ redo["sheetIndex"] = file.index;
+ redo["config"] = $.extend(true, {}, file.config);
redo["curconfig"] = cfg;
Store.jfundo = [];
@@ -1051,13 +1134,13 @@ export function showRowOrColumn(type, startIndex, endIndex, options = {}) {
}
//config
- Store.config = cfg;
Store.luckysheetfile[order].config = Store.config;
- server.saveParam("cg", order, cfg[cfgKey], { "k": cfgKey });
+ server.saveParam("cg", file.index, cfg[cfgKey], { "k": cfgKey });
// 若操作sheet为当前sheet页,行高、列宽 刷新
if (order === curSheetOrder) {
+ Store.config = cfg;
jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
}
@@ -1122,6 +1205,7 @@ export function showColumn(startIndex, endIndex, options = {}) {
export function getRange() {
let rangeArr = Store.luckysheet_select_save;
let result = [];
+
for (let i = 0; i < rangeArr.length; i++) {
let rangeItem = rangeArr[i];
let temp = {
@@ -1130,6 +1214,7 @@ export function getRange() {
}
result.push(temp)
}
+
return result;
}
@@ -1140,18 +1225,21 @@ export function getRange() {
* @param {Number} options.order 工作表索引;默认值为当前工作表索引
*/
export function getRangeValue(options = {}) {
+ let curOrder = getSheetIndex(Store.currentSheetIndex);
let {
range,
- order
+ order = curOrder
} = {...options}
+ let file = Store.luckysheetfile[order];
+
if (!range || typeof range === 'object') {
- return getdatabyselection(range, order);
+ return getdatabyselection(range, file.index);
} else if (typeof range === 'string') {
if (formula.iscelldata(range)) {
- return getdatabyselection(formula.getcellrange(range), order)
+ return getdatabyselection(formula.getcellrange(range), file.index)
} else {
- console.error('The range is invalid, please check range parameter.')
+ tooltip.info('The range is invalid, please check range parameter.', '')
}
}
}
@@ -1169,8 +1257,9 @@ export function getRangeValue(options = {}) {
function getRangeArray(dimensional, options = {}) {
let dimensionalArray = ['oneDimensional', 'twoDimensional', 'custom']
if (dimensionalArray.indexOf(dimensional) < 0) {
- return console.error('Argument dimensional is invalid, the value can be \'oneDimensional\', \'twoDimensional\', \'custom\'')
+ return tooltip.info('Argument dimensional is invalid, the value can be \'oneDimensional\', \'twoDimensional\', \'custom\'', '')
}
+
let {
row,
column,
@@ -1184,7 +1273,7 @@ function getRangeArray(dimensional, options = {}) {
if (formula.iscelldata(range)) {
realRange = formula.getcellrange(range)
} else {
- return console.error('The range is invalid, please check range parameter.')
+ return tooltip.info('The range is invalid, please check range parameter.', '')
}
}
@@ -1217,6 +1306,7 @@ export function getRangeJson(isFirstRowTitle, options = {}) {
if (range && typeof range === 'string' && formula.iscelldata(range)) {
range = formula.getcellrange(range)
}
+
if (!range || range.length > 1) {
if(isEditMode()){
alert(locale_drag.noMulti);
@@ -1294,7 +1384,7 @@ export function getRangeJson(isFirstRowTitle, options = {}) {
export function getRangeDiagonal(type, options = {}) {
let typeValues = ['normal', 'anti', 'offset'];
if (typeValues.indexOf(type) < 0) {
- return console.error('The type parameter must be included in [\'normal\', \'anti\', \'offset\']')
+ return tooltip.info('The type parameter must be included in [\'normal\', \'anti\', \'offset\']', '')
}
let curSheetOrder = getSheetIndex(Store.currentSheetIndex);
@@ -1311,6 +1401,7 @@ export function getRangeDiagonal(type, options = {}) {
if (range && typeof range === 'string' && formula.iscelldata(range)) {
range = formula.getcellrange(range)
}
+
if (!range || range.length > 1) {
if(isEditMode()){
alert(locale().drag.noMulti);
@@ -1485,25 +1576,30 @@ export function getRangeBoolean(options = {}) {
*/
export function setRangeValue(data, options = {}) {
let curSheetOrder = getSheetIndex(Store.currentSheetIndex);
- let curRange = Store.luckysheet_select_save;
+ let curRange = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1];
let {
range = curRange,
order = curSheetOrder,
success
} = {...options}
+
if (data == null) {
- return console.error('The data which will be set to range cannot be null.')
+ return tooltip.info('The data which will be set to range cannot be null.', '')
}
+
if (range instanceof Array) {
- return console.error('setRangeValue only supports a single selection.')
+ return tooltip.info('setRangeValue only supports a single selection.', '')
}
+
if (typeof range === 'string' && formula.iscelldata(range)) {
range = formula.getcellrange(range)
}
+
let rowCount = range.row[1] - range.row[0] + 1,
columnCount = range.column[1] - range.column[0] + 1;
+
if (data.length !== rowCount || data[0].length !== columnCount) {
- return console.error('The data to be set does not match the selection.')
+ return tooltip.info('The data to be set does not match the selection.', '')
}
for (let i = 0; i < rowCount; i++) {
@@ -1513,6 +1609,7 @@ export function setRangeValue(data, options = {}) {
setCellValue(row, column, data[i][j], {order: order})
}
}
+
if (success && typeof success === 'function') {
success();
}
@@ -1528,24 +1625,29 @@ export function setRangeValue(data, options = {}) {
*/
export function setSingleRangeFormat(attr, value, options = {}) {
let curSheetOrder = getSheetIndex(Store.currentSheetIndex);
- let curRange = Store.luckysheet_select_save;
+ let curRange = Store.luckysheet_select_save[Store.luckysheet_select_save.length - 1];
let {
range = curRange,
order = curSheetOrder,
} = {...options}
+
if (attr == null) {
- return console.error('Arguments attr cannot be null or undefined.')
+ return tooltip.info('Arguments attr cannot be null or undefined.', '')
}
+
if (range instanceof Array) {
- return console.error('setRangeValue only supports a single selection.')
+ return tooltip.info('setRangeValue only supports a single selection.', '')
}
+
if (typeof range === 'string' && formula.iscelldata(range)) {
range = formula.getcellrange(range)
}
+
let rowCount = range.row[1] - range.row[0] + 1,
columnCount = range.column[1] - range.column[0] + 1;
+
if (data.length !== rowCount || data[0].length !== columnCount) {
- return console.error('The data to be set does not match the selection')
+ return tooltip.info('The data to be set does not match the selection', '')
}
for (let i = 0; i < rowCount; i++) {
@@ -1574,11 +1676,13 @@ export function setRangeFormat(attr, value, options = {}) {
order = curSheetOrder,
success
} = {...options}
+
if (range instanceof Array) {
for (let i = 0; i < range.length; i++) {
setSingleRangeFormat(range[i])
}
}
+
if (success && typeof success === 'function') {
success()
}
@@ -1595,7 +1699,7 @@ export function setRangeFormat(attr, value, options = {}) {
function setRangeFilter(type, options = {}) {
let typeValues = ['open', 'close'];
if (typeValues.indexOf(type) < 0) {
- return console.error('The type parameter must be included in [\'open\', \'close\']')
+ return tooltip.info('The type parameter must be included in [\'open\', \'close\']', '')
}
let curSheetOrder = getSheetIndex(Store.currentSheetIndex),
curRange = Store.luckysheet_select_save;
@@ -1604,7 +1708,8 @@ function setRangeFilter(type, options = {}) {
order = curSheetOrder,
success
} = {...options}
- if(range > 1){
+
+ if(range.length > 1){
const locale_splitText = locale().splitText;
if(isEditMode()){
alert(locale_splitText.tipNoMulti);
@@ -1631,7 +1736,7 @@ function setRangeFilter(type, options = {}) {
export function setRangeMerge(type, options = {}) {
let typeValues = ['all', 'horizontal', 'vertical'];
if (typeValues.indexOf(type) < 0) {
- return console.error('The type parameter must be included in [\'all\', \'horizontal\', \'vertical\']')
+ return tooltip.info('The type parameter must be included in [\'all\', \'horizontal\', \'vertical\']', '')
}
let curSheetOrder = getSheetIndex(Store.currentSheetIndex),
@@ -1641,61 +1746,105 @@ export function setRangeMerge(type, options = {}) {
order = curSheetOrder,
success
} = {...options}
- let file = luckysheetfile[order],
- cfg = file.config,
- data = file.data;
- if (!(range instanceof Array)) {
- range = [range]
+ let file = Store.luckysheetfile[order],
+ cfg = $.extend(true, {}, file.config),
+ data = $.extend(true, [], file.data);
+
+ if(getObjType(range) == 'string'){
+ if(!formula.iscelldata(range)){
+ return tooltip.info('Incorrect selection format', '');
+ }
+
+ let cellrange = formula.getcellrange(range);
+ range = [{
+ "row": cellrange.row,
+ "column": cellrange.column
+ }]
}
+ else if(getObjType(range) == 'object'){
+ if(!range.hasOwnProperty("row") || !range.hasOwnProperty("column")){
+ return tooltip.info('Incorrect selection format', '');
+ }
- let isHasMc = false; //选区是否含有 合并的单元格
- for (let i = 0; i < range.length; i++) {
- let rangeItem = range[i];
- if (rangeItem && typeof rangeItem === 'string' && formula.iscelldata(rangeItem)) {
- rangeItem = formula.getcellrange(rangeItem)
+ range = [{
+ "row": range.row,
+ "column": range.column
+ }]
+ }
+
+ //不能合并重叠区域
+ if(selectIsOverlap(range)){
+ return tooltip.info('Cannot merge overlapping range', '');
+ }
+
+ //选区是否含有 部分合并单元格
+ if(cfg["merge"] != null){
+ let has_PartMC = false;
+
+ for(let s = 0; s < range.length; s++){
+ let r1 = range[s].row[0],
+ r2 = range[s].row[1];
+ let c1 = range[s].column[0],
+ c2 = range[s].column[1];
+
+ has_PartMC = hasPartMC(cfg, r1, r2, c1, c2);
+
+ if(has_PartMC){
+ break;
+ }
+ }
+
+ if(has_PartMC){
+ return tooltip.info('Cannot perform this operation on partially merged cells', '');
}
- let r1 = rangeItem.row[0],
- r2 = rangeItem.row[1],
- c1 = rangeItem.column[0],
- c2 = rangeItem.column[1];
+ }
+
+ //选区是否含有 合并的单元格
+ let isHasMc = false;
+
+ for(let i = 0; i < range.length; i++){
+ let r1 = range[i].row[0],
+ r2 = range[i].row[1];
+ let c1 = range[i].column[0],
+ c2 = range[i].column[1];
for(let r = r1; r <= r2; r++){
for(let c = c1; c <= c2; c++){
let cell = data[r][c];
+
if(getObjType(cell) == "object" && ("mc" in cell)){
isHasMc = true;
break;
}
}
- if (isHasMc) {
+
+ if(isHasMc){
break;
}
}
- if (isHasMc) {
- break;
- }
}
- if (isHasMc) {
+ if(isHasMc){//选区有合并单元格(选区都执行 取消合并)
cancelRangeMerge({
range: range,
order: order
})
- } else {
- for (let i = 0; i < range.length; i++) {
- let rangeItem = range[i];
- if (rangeItem && typeof rangeItem === 'string' && formula.iscelldata(rangeItem)) {
- rangeItem = formula.getcellrange(rangeItem)
+ }
+ else{
+ for(let i = 0; i < range.length; i++){
+ let r1 = range[i].row[0],
+ r2 = range[i].row[1];
+ let c1 = range[i].column[0],
+ c2 = range[i].column[1];
+
+ if(r1 == r2 && c1 == c2){
+ continue;
}
- let r1 = rangeItem.row[0],
- r2 = rangeItem.row[1],
- c1 = rangeItem.column[0],
- c2 = rangeItem.column[1];
-
- if (type === 'all') {
- let fv = {},
- isfirst = false;
+
+ if(type == "all"){
+ let fv = {}, isfirst = false;
+
for(let r = r1; r <= r2; r++){
for(let c = c1; c <= c2; c++){
let cell = data[r][c];
@@ -1713,10 +1862,10 @@ export function setRangeMerge(type, options = {}) {
data[r1][c1].mc = { "r": r1, "c": c1, "rs": r2 - r1 + 1, "cs": c2 - c1 + 1 };
cfg["merge"][r1 + "_" + c1] = { "r": r1, "c": c1, "rs": r2 - r1 + 1, "cs": c2 - c1 + 1 };
- } else if (type === 'vertical') {
+ }
+ else if(type == "vertical"){
for(let c = c1; c <= c2; c++){
- let fv = {},
- isfirst = false;
+ let fv = {}, isfirst = false;
for(let r = r1; r <= r2; r++){
let cell = data[r][c];
@@ -1734,10 +1883,10 @@ export function setRangeMerge(type, options = {}) {
cfg["merge"][r1 + "_" + c] = { "r": r1, "c": c, "rs": r2 - r1 + 1, "cs": 1 };
}
- } else if (type === 'horizontal') {
+ }
+ else if(type == "horizontal"){
for(let r = r1; r <= r2; r++){
- let fv = {},
- isfirst = false;
+ let fv = {}, isfirst = false;
for(let c = c1; c <= c2; c++){
let cell = data[r][c];
@@ -1757,6 +1906,29 @@ export function setRangeMerge(type, options = {}) {
}
}
}
+
+ if(order == curSheetOrder){
+ if (Store.clearjfundo) {
+ Store.jfundo = [];
+ Store.jfredo.push({
+ "type": "mergeChange",
+ "sheetIndex": file.index,
+ "data": $.extend(true, [], file.data),
+ "curData": data,
+ "range": range,
+ "config": $.extend(true, {}, file.config),
+ "curConfig": cfg
+ });
+ }
+
+ Store.clearjfundo = false;
+ jfrefreshgrid(data, range, {"cfg": cfg});
+ Store.clearjfundo = true;
+ }
+ else{
+ file.data = data;
+ file.config = cfg;
+ }
}
if (success && typeof success === 'function') {
@@ -1772,55 +1944,101 @@ export function setRangeMerge(type, options = {}) {
* @param {Object} options.success 操作结束的回调函数
*/
export function cancelRangeMerge(options = {}) {
- let curRange = Store.luckysheet_select_save[0],
+ let curRange = Store.luckysheet_select_save,
curSheetOrder = getSheetIndex(Store.currentSheetIndex);
let {
range = curRange,
order = curSheetOrder,
success
} = {...options}
- let file = luckysheetfile[order],
- cfg = file.config,
- data = file.data;
- if (!(range instanceof Array)) {
- range = [range]
+ let file = Store.luckysheetfile[order],
+ cfg = $.extend(true, {}, file.config),
+ data = $.extend(true, [], file.data);
+
+ if(getObjType(range) == 'string'){
+ if(!formula.iscelldata(range)){
+ return tooltip.info('Incorrect selection format', '');
+ }
+
+ let cellrange = formula.getcellrange(range);
+ range = [{
+ "row": cellrange.row,
+ "column": cellrange.column
+ }]
}
+ else if(getObjType(range) == 'object'){
+ if(!range.hasOwnProperty("row") || !range.hasOwnProperty("column")){
+ return tooltip.info('Incorrect selection format', '');
+ }
- for (let i = 0; i < range.length; i++) {
- let rangeItem = range[i];
- if (rangeItem && typeof rangeItem === 'string' && formula.iscelldata(rangeItem)) {
- rangeItem = formula.getcellrange(rangeItem)
+ range = [{
+ "row": range.row,
+ "column": range.column
+ }]
+ }
+
+ //不能合并重叠区域
+ if(selectIsOverlap(range)){
+ return tooltip.info('Cannot merge overlapping range', '');
+ }
+
+ //选区是否含有 部分合并单元格
+ if(cfg["merge"] != null){
+ let has_PartMC = false;
+
+ for(let s = 0; s < range.length; s++){
+ let r1 = range[s].row[0],
+ r2 = range[s].row[1];
+ let c1 = range[s].column[0],
+ c2 = range[s].column[1];
+
+ has_PartMC = hasPartMC(cfg, r1, r2, c1, c2);
+
+ if(has_PartMC){
+ break;
+ }
+ }
+
+ if(has_PartMC){
+ return tooltip.info('Cannot perform this operation on partially merged cells', '');
}
- let r1 = rangeItem.row[0],
- r2 = rangeItem.row[1],
- c1 = rangeItem.column[0],
- c2 = rangeItem.column[1];
- if (r1 == r2 && c1 == c2) {
+ }
+
+ for(let i = 0; i < range.length; i++){
+ let r1 = range[i].row[0],
+ r2 = range[i].row[1];
+ let c1 = range[i].column[0],
+ c2 = range[i].column[1];
+
+ if(r1 == r2 && c1 == c2){
continue;
}
-
- let fv = {}
+
+ let fv = {};
+
for(let r = r1; r <= r2; r++){
for(let c = c1; c <= c2; c++){
let cell = data[r][c];
-
+
if(cell != null && cell.mc != null){
let mc_r = cell.mc.r, mc_c = cell.mc.c;
-
+
if("rs" in cell.mc){
delete cell.mc;
delete cfg["merge"][mc_r + "_" + mc_c];
-
+
fv[mc_r + "_" + mc_c] = $.extend(true, {}, cell);
}
else{
let cell_clone = fv[mc_r + "_" + mc_c];
+
delete cell_clone.v;
delete cell_clone.m;
delete cell_clone.ct;
delete cell_clone.f;
delete cell_clone.spl;
+
data[r][c] = cell_clone;
}
}
@@ -1828,9 +2046,27 @@ export function cancelRangeMerge(options = {}) {
}
}
- // 当前sheet页合并时刷新
- if (order === curSheetOrder) {
- jfrefreshgrid(data, range, cfg)
+ if(order == curSheetOrder){
+ if (Store.clearjfundo) {
+ Store.jfundo = [];
+ Store.jfredo.push({
+ "type": "mergeChange",
+ "sheetIndex": file.index,
+ "data": $.extend(true, [], file.data),
+ "curData": data,
+ "range": range,
+ "config": $.extend(true, {}, file.config),
+ "curConfig": cfg
+ });
+ }
+
+ Store.clearjfundo = false;
+ jfrefreshgrid(data, range, {"cfg": cfg});
+ Store.clearjfundo = true;
+ }
+ else{
+ file.data = data;
+ file.config = cfg;
}
}
@@ -1845,7 +2081,7 @@ export function cancelRangeMerge(options = {}) {
export function setRangeSort(type, options = {}) {
let typeValues = ['asc', 'desc']
if (typeValues.indexOf(type) < 0) {
- return console.error('The type parameter must be included in [\'asc\', \'desc\'')
+ return tooltip.info('The type parameter must be included in [\'asc\', \'desc\'', '')
}
let curSheetOrder = getSheetIndex(Store.currentSheetIndex),
@@ -1855,22 +2091,20 @@ export function setRangeSort(type, options = {}) {
order = curSheetOrder,
success
} = {...options}
+
let file = Store.luckysheetfile[order],
- cfg = file.config,
- fileData = file.data;
+ cfg = $.extend(true, {}, file.config),
+ fileData = $.extend(true, [], file.data);
if(range instanceof Array && range.length > 1){
- if(isEditMode()){
- alert(locale().sort.noRangeError);
- } else{
- tooltip.info(locale().sort.noRangeError, "");
- }
+ tooltip.info(locale().sort.noRangeError, "");
return;
}
if (range && typeof range === 'string' && formula.iscelldata(range)) {
range = formula.getcellrange(range)
}
+
let r1 = range.row[0],
r2 = range.row[1],
c1 = range.column[0],
@@ -1889,14 +2123,12 @@ export function setRangeSort(type, options = {}) {
}
data.push(data_row);
}
+
if(hasMc){
- if(isEditMode()){
- alert(locale().sort.mergeError);
- } else{
- tooltip.info(locale().sort.mergeError, "");
- }
+ tooltip.info(locale().sort.mergeError, "");
return;
}
+
data = orderbydata([].concat(data), 0, type === 'asc');
for(let r = r1; r <= r2; r++){
@@ -1904,19 +2136,25 @@ export function setRangeSort(type, options = {}) {
fileData[r][c] = data[r - r1][c - c1];
}
}
+
+ let allParam = {};
if(cfg["rowlen"] != null){
- let config = $.extend(true, {}, cfg);
- config = rowlenByRange(fileData, r1, r2, config);
-
- if (order == Store.currentSheetIndex) {
- jfrefreshgrid(fileData, [{ "row": [r1, r2], "column": [c1, c2] }], config, null, true);
- }
- } else{
- if (order == Store.currentSheetIndex) {
- jfrefreshgrid(fileData, [{ "row": [r1, r2], "column": [c1, c2] }]);
+ cfg = rowlenByRange(fileData, r1, r2, cfg);
+
+ allParam = {
+ "cfg": cfg,
+ "RowlChange": true
}
}
+ if (file.index == Store.currentSheetIndex) {
+ jfrefreshgrid(fileData, [{ "row": [r1, r2], "column": [c1, c2] }], allParam);
+ }
+ else{
+ file.data = fileData;
+ file.config = cfg;
+ }
+
if (success && typeof success === 'function') {
success();
}
@@ -1933,7 +2171,7 @@ export function setRangeSort(type, options = {}) {
*/
export function setRangeSortMulti(hasTitle, sort, options = {}) {
if (!sort || !(sort instanceof Array)) {
- return console.error('The sort parameter is invalid.')
+ return tooltip.info('The sort parameter is invalid.', '')
}
let curSheetOrder = getSheetIndex(Store.currentSheetIndex),
@@ -1943,22 +2181,20 @@ export function setRangeSortMulti(hasTitle, sort, options = {}) {
order = curSheetOrder,
success
} = {...options}
+
let file = Store.luckysheetfile[order],
- cfg = file.config,
- fileData = file.data;
+ cfg = $.extend(true, {}, file.config),
+ fileData = $.extend(true, [], file.data);
if(range instanceof Array && range.length > 1){
- if(isEditMode()){
- alert(locale().sort.noRangeError);
- } else{
- tooltip.info(locale().sort.noRangeError, "");
- }
+ tooltip.info(locale().sort.noRangeError, "");
return;
}
if (range && typeof range === 'string' && formula.iscelldata(range)) {
range = formula.getcellrange(range)
}
+
let r1 = range.row[0],
r2 = range.row[1],
c1 = range.column[0],
@@ -1970,6 +2206,7 @@ export function setRangeSortMulti(hasTitle, sort, options = {}) {
} else{
str = r1;
}
+
let hasMc = false; //Whether the sort selection has merged cells
let data = [];
for(let r = str; r <= r2; r++){
@@ -1983,14 +2220,12 @@ export function setRangeSortMulti(hasTitle, sort, options = {}) {
}
data.push(data_row);
}
+
if(hasMc){
- if(isEditMode()){
- alert(locale().sort.mergeError);
- } else{
- tooltip.info(locale().sort.mergeError, "");
- }
+ tooltip.info(locale().sort.mergeError, "");
return;
}
+
sort.forEach(sortItem => {
let i = sortItem.i;
i -= c1;
@@ -2002,19 +2237,25 @@ export function setRangeSortMulti(hasTitle, sort, options = {}) {
fileData[r][c] = data[r - str][c - c1];
}
}
+
+ let allParam = {};
if(cfg["rowlen"] != null){
- let config = $.extend(true, {}, cfg);
- config = rowlenByRange(fileData, str, r2, config);
+ cfg = rowlenByRange(fileData, str, r2, cfg);
- if (order === Store.currentSheetIndex) {
- jfrefreshgrid(fileData, [{ "row": [str, r2], "column": [c1, c2] }], config, null, true);
- }
- } else{
- if (order === Store.currentSheetIndex) {
- jfrefreshgrid(fileData, [{ "row": [str, r2], "column": [c1, c2] }]);
+ allParam = {
+ "cfg": cfg,
+ "RowlChange": true
}
}
+ if (file.index === Store.currentSheetIndex) {
+ jfrefreshgrid(fileData, [{ "row": [str, r2], "column": [c1, c2] }], allParam);
+ }
+ else{
+ file.data = fileData;
+ file.config = cfg;
+ }
+
if (success && typeof success === 'function') {
success();
}
@@ -2049,8 +2290,9 @@ export function matrixOperation(type, options = {}) {
'removeDuplicateByColumn', // 按列删除重复值
'newMatrix' // 生产新矩阵
]
+
if (!type || typeValues.indexOf(type) < 0) {
- return console.error('The type parameter is invalid.')
+ return tooltip.info('The type parameter is invalid.', '')
}
let curRange = Store.luckysheet_select_save[0];
@@ -2060,11 +2302,7 @@ export function matrixOperation(type, options = {}) {
} = {...options}
if(range instanceof Array && range.length > 1){
- if(isEditMode()){
- alert(locale().drag.noMulti);
- } else{
- tooltip.info(locale().drag.noMulti, "");
- }
+ tooltip.info(locale().drag.noMulti, "");
return;
}
@@ -2369,11 +2607,13 @@ export function matrixCalculation(type, number, options = {}) {
'root', // 次方根
'log' // 对数log
]
+
if (!type || typeValues.indexOf(type) < 0) {
- return console.error('The type parameter is invalid.')
+ return tooltip.info('The type parameter is invalid.', '')
}
+
if(number.toString() == "NaN"){
- return console.error('The number parameter is invalid.')
+ return tooltip.info('The number parameter is invalid.', '')
}
let curRange = Store.luckysheet_select_save[0];
@@ -2383,11 +2623,7 @@ export function matrixCalculation(type, number, options = {}) {
} = {...options}
if(range instanceof Array && range.length > 1){
- if(isEditMode()){
- alert(locale().drag.noMulti);
- } else{
- tooltip.info(locale().drag.noMulti, "");
- }
+ tooltip.info(locale().drag.noMulti, "");
return;
}
@@ -2399,6 +2635,7 @@ export function matrixCalculation(type, number, options = {}) {
if (getdata.length == 0) {
return;
}
+
let arr = [];
for (let r = 0; r < getdata.length; r++) {
let a = [];
@@ -2458,6 +2695,116 @@ export function matrixCalculation(type, number, options = {}) {
}
+/**
+ * 新增一个sheet,返回新增的工作表对象
+ * @param {Object} options 可选参数
+ * @param {Object} options.sheetObject 新增的工作表的数据;默认值为空对象
+ * @param {Number} options.order 新增的工作表索引;默认值为最后一个索引位置
+ * @param {Function} options.success 操作结束的回调函数
+ */
+export function setSheetAdd(options = {}) {
+ let lastOrder = Store.luckysheetfile.length - 1;
+ let {
+ sheetObject = {},
+ order = lastOrder,
+ success
+ } = {...options}
+
+ if(!isRealNum(order)){
+ return tooltip.info("Parameter is not a table index", "");
+ }
+
+ order = Number(order);
+
+ let index = sheetmanage.generateRandomSheetIndex();
+
+ let sheetname = sheetmanage.generateRandomSheetName(Store.luckysheetfile, false);
+ if(!!sheetObject.name){
+ let sameName = false;
+
+ for(let i = 0; i < Store.luckysheetfile.length; i++){
+ if(Store.luckysheetfile[i].name == sheetObject.name){
+ sameName = true;
+ break;
+ }
+ }
+
+ if(!sameName){
+ sheetname = sheetObject.name;
+ }
+ }
+
+ $("#luckysheet-sheet-container-c").append(replaceHtml(sheetHTML, {
+ "index": index,
+ "active": "",
+ "name": sheetname,
+ "style": "",
+ "colorset": ""
+ }));
+
+ let sheetconfig = {
+ "name": "",
+ "color": "",
+ "status": "0",
+ "order": "",
+ "index": "",
+ "celldata": [],
+ "row": Store.defaultrowNum,
+ "column": Store.defaultcolumnNum,
+ "config": {},
+ "pivotTable": null,
+ "isPivotTable": false
+ };
+ sheetconfig = $.extend(true, sheetconfig, sheetObject);
+
+ sheetconfig.index = index;
+ sheetconfig.name = sheetname;
+ sheetconfig.order = order;
+
+ if(order <= 0){
+ let beforeIndex = Store.luckysheetfile[0].index;
+ let beforeObj = $("#luckysheet-sheets-item" + beforeIndex);
+ $("#luckysheet-sheets-item" + index).insertBefore(beforeObj);
+
+ Store.luckysheetfile.splice(0, 0, sheetconfig);
+ }
+ else{
+ if(order > Store.luckysheetfile.length){
+ order = Store.luckysheetfile.length;
+ }
+
+ let afterIndex = Store.luckysheetfile[order - 1].index;
+ let afterObj = $("#luckysheet-sheets-item" + afterIndex);
+ $("#luckysheet-sheets-item" + index).insertAfter(afterObj);
+
+ Store.luckysheetfile.splice(order, 0, sheetconfig);
+ }
+
+ Store.luckysheetfile.forEach((item, i, arr) => {
+ arr[i].order = i;
+ })
+
+ $("#luckysheet-sheet-area div.luckysheet-sheets-item").removeClass("luckysheet-sheets-item-active");
+ $("#luckysheet-sheets-item" + index).addClass("luckysheet-sheets-item-active");
+ $("#luckysheet-cell-main").append('');
+ cleargridelement(true);
+
+ server.saveParam("sha", null, $.extend(true, {}, sheetconfig));
+
+ if (Store.clearjfundo) {
+ Store.jfundo = [];
+ let redo = {};
+ redo["type"] = "addSheet";
+ redo["sheetconfig"] = $.extend(true, {}, sheetconfig);
+ redo["index"] = index;
+ redo["currentSheetIndex"] = Store.currentSheetIndex;
+ Store.jfredo.push(redo);
+ }
+
+ sheetmanage.changeSheetExec(index, false, true);
+}
+
+
/**
* 根据窗口大小自动resize画布
*
@@ -2470,6 +2817,7 @@ export function resize(options = {}){
let {
success
} = {...options}
+
if (success && typeof success === 'function') {
success();
}
diff --git a/src/global/cursorPos.js b/src/global/cursorPos.js
index 12eb63e..c01209e 100644
--- a/src/global/cursorPos.js
+++ b/src/global/cursorPos.js
@@ -1,3 +1,5 @@
+import Store from '../store';
+
function luckysheetRangeLast(obj) {
let range;
@@ -45,7 +47,77 @@ function getCursortPosition(textDom){
return cursorPos;
}
+function hideMenuByCancel(event){
+ if (!$(event.target).hasClass("luckysheet-mousedown-cancel") && $(event.target).filter("[class*='sp-palette']").length == 0 && $(event.target).filter("[class*='sp-thumb']").length == 0 && $(event.target).filter("[class*='sp-']").length == 0) {
+ $("#luckysheet-rightclick-menu").hide();
+ $("#luckysheet-cols-h-hover").hide();
+ $("#luckysheet-cols-menu-btn").hide();
+ $("#luckysheet-rightclick-menu").hide();
+ $("#luckysheet-sheet-list, #luckysheet-rightclick-sheet-menu, #luckysheet-user-menu").hide();
+ $("body > .luckysheet-filter-menu, body > .luckysheet-filter-submenu, body > .luckysheet-cols-menu").hide();
+ //$("body > luckysheet-menuButton").hide();
+ Store.luckysheet_cols_menu_status = false;
+ }
+}
+
+function selectTextDom(ele){
+ if (window.getSelection) {
+ let range = document.createRange();
+ range.selectNodeContents(ele);
+ window.getSelection().removeAllRanges();
+ window.getSelection().addRange(range);
+ }
+ else if (document.selection) {
+ let range = document.body.createTextRange();
+ range.moveToElementText(ele);
+ range.select();
+ }
+}
+
+function selectTextContent(ele){
+ if (window.getSelection) {
+ let range = document.createRange();
+ var content=ele.firstChild;
+ range.setStart(content,0);
+ range.setEnd(content,content.length);
+ window.getSelection().removeAllRanges();
+ window.getSelection().addRange(range);
+ }
+ else if (document.selection) {
+ let range = document.body.createTextRange();
+ range.moveToElementText(ele);
+ range.select();
+ }
+}
+
+function selectTextContentCross(sEle, eEle){
+ if (window.getSelection) {
+ let range = document.createRange();
+ var sContent=sEle.firstChild, eContent=eEle.firstChild;
+ range.setStart(sContent,0);
+ range.setEnd(eContent,eContent.length);
+ window.getSelection().removeAllRanges();
+ window.getSelection().addRange(range);
+ }
+}
+
+function selectTextContentCollapse(sEle, index){
+ if (window.getSelection) {
+ let range = document.createRange();
+ var sContent=sEle.firstChild;
+ range.setStart(sContent,index);
+ range.collapse(true);
+ window.getSelection().removeAllRanges();
+ window.getSelection().addRange(range);
+ }
+}
+
export {
luckysheetRangeLast,
getCursortPosition,
+ hideMenuByCancel,
+ selectTextContent,
+ selectTextDom,
+ selectTextContentCross,
+ selectTextContentCollapse
}
\ No newline at end of file
diff --git a/src/global/draw.js b/src/global/draw.js
index 4ea78d3..55443d9 100644
--- a/src/global/draw.js
+++ b/src/global/draw.js
@@ -3,16 +3,18 @@ import conditionformat from '../controllers/conditionformat';
import alternateformat from '../controllers/alternateformat';
import luckysheetSparkline from '../controllers/sparkline';
import menuButton from '../controllers/menuButton';
+import dataVerificationCtrl from '../controllers/dataVerificationCtrl';
import { luckysheetdefaultstyle, luckysheet_CFiconsImg,luckysheetdefaultFont } from '../controllers/constant';
import { luckysheet_searcharray } from '../controllers/sheetSearch';
import { dynamicArrayCompute } from './dynamicArray';
import browser from './browser';
import { isRealNull, isRealNum } from './validate';
import { getCellTextSplitArr,getMeasureText,getCellTextInfo } from './getRowlen';
-import { getcellvalue } from './getdata';
+import { getcellvalue,getRealCellValue } from './getdata';
import { getBorderInfoCompute } from './border';
import { getSheetIndex } from '../methods/get';
import { getObjType, chatatABC, luckysheetfontformat } from '../utils/util';
+import { isInlineStringCell } from '../controllers/inlineString';
import Store from '../store';
import locale from '../locale/locale';
@@ -674,10 +676,7 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of
// continue;
}
else{
- value = getcellvalue(r, c, null, "m");
- if(value == null){
- value = getcellvalue(r, c);
- }
+ value = getRealCellValue(r,c);
}
if(value == null || value.toString().length == 0){
@@ -718,11 +717,13 @@ function luckysheetDrawMain(scrollWidth, scrollHeight, drawWidth, drawHeight, of
let value = null;
let margeMaindata = cell["mc"];
- value = getcellvalue(margeMaindata.r, margeMaindata.c, null, "m");
+ // value = getcellvalue(margeMaindata.r, margeMaindata.c, null, "m");
- if(value == null){
- value = getcellvalue(margeMaindata.r, margeMaindata.c);
- }
+ // if(value == null){
+ // value = getcellvalue(margeMaindata.r, margeMaindata.c);
+ // }
+
+ value = getRealCellValue(margeMaindata.r,margeMaindata.c);
r = margeMaindata.r;
c = margeMaindata.c;
@@ -1180,7 +1181,6 @@ let nullCellRender = function(r, c, start_r, start_c, end_r, end_c,luckysheetTab
let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckysheetTableContent,af_compute, cf_compute,offsetLeft,offsetTop,dynamicArray_compute,cellOverflowMap, dataset_col_st, dataset_col_ed,scrollHeight,scrollWidth,bodrder05,isMerge){
-
let cell = Store.flowdata[r][c];
let cellWidth = end_c - start_c - 2;
let cellHeight = end_r - start_r - 2;
@@ -1219,8 +1219,32 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee
(start_r + offsetTop + borderfix[1]),
(end_c - start_c + borderfix[2]-(!!isMerge?1:0)),
(end_r - start_r + borderfix[3])
- ];
- luckysheetTableContent.fillRect(cellsize[0], cellsize[1], cellsize[2], cellsize[3]);
+ ];
+ luckysheetTableContent.fillRect(cellsize[0], cellsize[1], cellsize[2], cellsize[3]);
+
+ let dataVerification = dataVerificationCtrl.dataVerification;
+
+ if(dataVerification != null && dataVerification[r + '_' + c] != null && !dataVerificationCtrl.validateCellData(value, dataVerification[r + '_' + c])){
+ //单元格左上角红色小三角标示
+ let dv_w = 5 * Store.zoomRatio, dv_h = 5 * Store.zoomRatio; //红色小三角宽高
+
+ luckysheetTableContent.beginPath();
+ luckysheetTableContent.moveTo(
+ (start_c + offsetLeft),
+ (start_r + offsetTop)
+ );
+ luckysheetTableContent.lineTo(
+ (start_c + offsetLeft + dv_w),
+ (start_r + offsetTop)
+ );
+ luckysheetTableContent.lineTo(
+ (start_c + offsetLeft),
+ (start_r + offsetTop + dv_h)
+ );
+ luckysheetTableContent.fillStyle = "#FC6666";
+ luckysheetTableContent.fill();
+ luckysheetTableContent.closePath();
+ }
//若单元格有批注(单元格右上角红色小三角标示)
if(cell.ps != null){
@@ -1266,7 +1290,6 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee
luckysheetTableContent.closePath();
}
-
//溢出单元格
let cellOverflow_bd_r_render = true; //溢出单元格右边框是否需要绘制
let cellOverflow_colInObj = cellOverflow_colIn(cellOverflowMap, r, c, dataset_col_st, dataset_col_ed);
@@ -1288,6 +1311,79 @@ let cellRender = function(r, c, start_r, start_c, end_r, end_c, value, luckyshee
cellOverflow_bd_r_render = false;
}
}
+ //数据验证 复选框
+ else if(dataVerification != null && dataVerification[r + '_' + c] != null && dataVerification[r + '_' + c].type == 'checkbox'){
+ let pos_x = start_c + offsetLeft;
+ let pos_y = start_r + offsetTop + 1;
+
+ luckysheetTableContent.save();
+ luckysheetTableContent.beginPath();
+ luckysheetTableContent.rect(pos_x, pos_y, cellWidth, cellHeight);
+ luckysheetTableContent.clip();
+ luckysheetTableContent.scale(Store.zoomRatio,Store.zoomRatio);
+
+ let measureText = getMeasureText(value, luckysheetTableContent);
+ let textMetrics = measureText.width + 14;
+ let oneLineTextHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent;
+
+ let horizonAlignPos = (pos_x + space_width) ; //默认为1,左对齐
+ if(horizonAlign == "0"){ //居中对齐
+ horizonAlignPos = (pos_x + cellWidth / 2) - (textMetrics / 2);
+ }
+ else if(horizonAlign == "2"){ //右对齐
+ horizonAlignPos = (pos_x + cellWidth - space_width) - textMetrics;
+ }
+
+ let verticalCellHeight = cellHeight > oneLineTextHeight ? cellHeight : oneLineTextHeight;
+
+ let verticalAlignPos_text = (pos_y + verticalCellHeight - space_height) ; //文本垂直方向基准线
+ luckysheetTableContent.textBaseline = "bottom";
+ let verticalAlignPos_checkbox = verticalAlignPos_text - 13;
+
+ if(verticalAlign == "0"){ //居中对齐
+ verticalAlignPos_text = (pos_y + verticalCellHeight / 2);
+ luckysheetTableContent.textBaseline = "middle";
+ verticalAlignPos_checkbox = verticalAlignPos_text - 6;
+ }
+ else if(verticalAlign == "1"){ //上对齐
+ verticalAlignPos_text = (pos_y + space_height);
+ luckysheetTableContent.textBaseline = "top";
+ verticalAlignPos_checkbox = verticalAlignPos_text + 1;
+ }
+
+ horizonAlignPos = horizonAlignPos / Store.zoomRatio;
+ verticalAlignPos_text = verticalAlignPos_text / Store.zoomRatio;
+ verticalAlignPos_checkbox = verticalAlignPos_checkbox / Store.zoomRatio;
+
+ //复选框
+ luckysheetTableContent.lineWidth = 1;
+ luckysheetTableContent.strokeStyle = "#000";
+ luckysheetTableContent.strokeRect(horizonAlignPos, verticalAlignPos_checkbox, 10, 10);
+
+ if(dataVerification[r + '_' + c].checked){
+ luckysheetTableContent.beginPath();
+ luckysheetTableContent.lineTo(
+ horizonAlignPos + 1,
+ verticalAlignPos_checkbox + 6
+ );
+ luckysheetTableContent.lineTo(
+ horizonAlignPos + 4,
+ verticalAlignPos_checkbox + 9
+ );
+ luckysheetTableContent.lineTo(
+ horizonAlignPos + 9,
+ verticalAlignPos_checkbox + 2
+ );
+ luckysheetTableContent.stroke();
+ luckysheetTableContent.closePath();
+ }
+
+ //文本
+ luckysheetTableContent.fillStyle = menuButton.checkstatus(Store.flowdata, r, c , "fc");
+ luckysheetTableContent.fillText(value == null ? "" : value, horizonAlignPos + 14, verticalAlignPos_text);
+
+ luckysheetTableContent.restore();
+ }
else{
//若单元格有条件格式数据条
if(checksCF != null && checksCF["dataBar"] != null){
@@ -1802,7 +1898,7 @@ function getCellOverflowMap(canvas, col_st, col_ed, row_st, row_end){
continue
}
- if(cell != null && !isRealNull(cell.v) && cell.mc == null && cell.tb == '1'){
+ if(cell != null && (!isRealNull(cell.v) || isInlineStringCell(cell) ) && cell.mc == null && cell.tb == '1'){
// let fontset = luckysheetfontformat(cell);
// canvas.font = fontset;
@@ -2052,21 +2148,28 @@ function cellTextRender(textInfo, ctx, option){
// ctx.fillStyle = "rgb(0,0,0)";
for(let i=0;i 5000) {
- jfrefreshgrid(d, st_r, ed_r, st_c, ed_c);
+ jfrefreshgrid(d, [{ "row": [st_r, ed_r], "column": [st_c, ed_c] }]);
}
else {
jfrefreshrange(d, { "row": [st_r, ed_r], "column": [st_c, ed_c] });
diff --git a/src/global/extend.js b/src/global/extend.js
index 2591c65..960ea37 100644
--- a/src/global/extend.js
+++ b/src/global/extend.js
@@ -14,7 +14,7 @@ import Store from '../store';
function luckysheetextendtable(type, index, value, direction, order) {
let curOrder = order || getSheetIndex(Store.currentSheetIndex);
let file = Store.luckysheetfile[curOrder];
- let d = file.data;
+ let d = $.extend(true, [], file.data);
value = Math.floor(value);
let cfg = $.extend(true, {}, file.config);
@@ -457,6 +457,50 @@ function luckysheetextendtable(type, index, value, direction, order) {
newFreezen.freezenverticaldata = luckysheetFreezen.freezenverticaldata;
}
+ //数据验证配置变动
+ let dataVerification = file.dataVerification;
+ let newDataVerification = {};
+ if(dataVerification != null){
+ for(let key in dataVerification){
+ let r = Number(key.split('_')[0]),
+ c = Number(key.split('_')[1]);
+ let item = dataVerification[key];
+
+ if(type == "row"){
+ if(index < r){
+ newDataVerification[(r + value) + "_" + c] = item;
+ }
+ else if(index == r){
+ if(direction == "lefttop"){
+ newDataVerification[(r + value) + "_" + c] = item;
+ }
+ else{
+ newDataVerification[r + "_" + c] = item;
+ }
+ }
+ else{
+ newDataVerification[r + "_" + c] = item;
+ }
+ }
+ else if(type == "column"){
+ if(index < c){
+ newDataVerification[r + "_" + (c + value)] = item;
+ }
+ else if(index == c){
+ if(direction == "lefttop"){
+ newDataVerification[r + "_" + (c + value)] = item;
+ }
+ else{
+ newDataVerification[r + "_" + c] = item;
+ }
+ }
+ else{
+ newDataVerification[r + "_" + c] = item;
+ }
+ }
+ }
+ }
+
let type1;
if (type == "row") {
type1 = "r";
@@ -713,7 +757,7 @@ function luckysheetextendtable(type, index, value, direction, order) {
}
// 修改当前sheet页时刷新
- if (curOrder == Store.currentSheetIndex) {
+ if (file.index == Store.currentSheetIndex) {
jfrefreshgrid_adRC(
d,
cfg,
@@ -723,9 +767,20 @@ function luckysheetextendtable(type, index, value, direction, order) {
newFilterObj,
newCFarr,
newAFarr,
- newFreezen
+ newFreezen,
+ newDataVerification
);
}
+ else{
+ file.data = d;
+ file.config = cfg;
+ file.calcChain = newCalcChain;
+ file.filter = newFilterObj.filter;
+ file.filter_select = newFilterObj.filter_select;
+ file.luckysheet_conditionformat_save = newCFarr;
+ file.luckysheet_alternateformat_save = newAFarr;
+ file.dataVerification = newDataVerification;
+ }
let range = null;
if(type == "row"){
@@ -746,7 +801,7 @@ function luckysheetextendtable(type, index, value, direction, order) {
}
file.luckysheet_select_save = range;
- if (curOrder == Store.currentSheetIndex) {
+ if (file.index == Store.currentSheetIndex) {
Store.luckysheet_select_save = range;
selectHightlightShow();
}
@@ -816,7 +871,7 @@ function luckysheetextendData(rowlen, newData) {
function luckysheetdeletetable(type, st, ed, order) {
let curOrder = order || getSheetIndex(Store.currentSheetIndex);
let file = Store.luckysheetfile[curOrder];
- let d = file.data;
+ let d = $.extend(true, [], file.data);
let slen = ed - st + 1;
let cfg = $.extend(true, {}, file.config);
@@ -1280,6 +1335,34 @@ function luckysheetdeletetable(type, st, ed, order) {
newFreezen.freezenverticaldata = luckysheetFreezen.freezenverticaldata;
}
+ //数据验证配置变动
+ let dataVerification = file.dataVerification;
+ let newDataVerification = {};
+ if(dataVerification != null){
+ for(let key in dataVerification){
+ let r = Number(key.split('_')[0]),
+ c = Number(key.split('_')[1]);
+ let item = dataVerification[key];
+
+ if(type == "row"){
+ if(r < st){
+ newDataVerification[r + "_" + c] = item;
+ }
+ else if(r > ed){
+ newDataVerification[(r - slen) + "_" + c] = item;
+ }
+ }
+ else if(type == "column"){
+ if(c < st){
+ newDataVerification[r + "_" + c] = item;
+ }
+ else if(c > ed){
+ newDataVerification[r + "_" + (c - slen)] = item;
+ }
+ }
+ }
+ }
+
//主逻辑
let type1;
if (type == "row") {
@@ -1471,7 +1554,7 @@ function luckysheetdeletetable(type, st, ed, order) {
}
// 修改当前sheet页时刷新
- if (curOrder == Store.currentSheetIndex) {
+ if (file.index == Store.currentSheetIndex) {
jfrefreshgrid_adRC(
d,
cfg,
@@ -1481,17 +1564,29 @@ function luckysheetdeletetable(type, st, ed, order) {
newFilterObj,
newCFarr,
newAFarr,
- newFreezen
+ newFreezen,
+ newDataVerification
);
}
+ else{
+ file.data = d;
+ file.config = cfg;
+ file.calcChain = newCalcChain;
+ file.filter = newFilterObj.filter;
+ file.filter_select = newFilterObj.filter_select;
+ file.luckysheet_conditionformat_save = newCFarr;
+ file.luckysheet_alternateformat_save = newAFarr;
+ file.dataVerification = newDataVerification;
+ }
}
//删除单元格
function luckysheetDeleteCell(type, str, edr, stc, edc, order) {
- let d = editor.deepCopyFlowData(Store.flowdata);
let curOrder = order || getSheetIndex(Store.currentSheetIndex);
let file = Store.luckysheetfile[curOrder];
+ let d = $.extend(true, [], file.data);
+
let rlen = edr - str + 1;
let clen = edc - stc + 1;
let cfg = $.extend(true, {}, Store.config);
@@ -1835,6 +1930,36 @@ function luckysheetDeleteCell(type, str, edr, stc, edc, order) {
}
}
+ //数据验证配置变动
+ let dataVerification = file.dataVerification;
+ let newDataVerification = {};
+ if(dataVerification != null){
+ for(let key in dataVerification){
+ let r = Number(key.split('_')[0]),
+ c = Number(key.split('_')[1]);
+ let item = dataVerification[key];
+
+ if(r < str || r > edr || c < stc || c > edc){
+ if(type == "moveLeft"){
+ if(c > edc && r >= str && r <= edr){
+ newDataVerification[r + "_" + (c - clen)] = item;
+ }
+ else{
+ newDataVerification[r + "_" + c] = item;
+ }
+ }
+ else if(type == "moveUp"){
+ if(r > edr && c >= stc && c <= edc){
+ newDataVerification[(r - rlen) + "_" + c] = item;
+ }
+ else{
+ newDataVerification[r + "_" + c] = item;
+ }
+ }
+ }
+ }
+ }
+
//边框配置变动
if(cfg["borderInfo"] && cfg["borderInfo"].length > 0){
let borderInfo = [];
@@ -1948,14 +2073,26 @@ function luckysheetDeleteCell(type, str, edr, stc, edc, order) {
}
}
- jfrefreshgrid_deleteCell(
- d,
- cfg,
- { type: type, 'str': str, 'edr': edr, 'stc': stc, 'edc': edc },
- newCalcChain,
- newFilterObj,
- newCFarr
- );
+ if(file.index == Store.currentSheetIndex){
+ jfrefreshgrid_deleteCell(
+ d,
+ cfg,
+ { type: type, 'str': str, 'edr': edr, 'stc': stc, 'edc': edc },
+ newCalcChain,
+ newFilterObj,
+ newCFarr,
+ newDataVerification
+ );
+ }
+ else{
+ file.data = d;
+ file.config = cfg;
+ file.calcChain = newCalcChain;
+ file.filter = newFilterObj.filter;
+ file.filter_select = newFilterObj.filter_select;
+ file.luckysheet_conditionformat_save = newCFarr;
+ file.dataVerification = newDataVerification;
+ }
}
export {
diff --git a/src/global/formula.js b/src/global/formula.js
index c4f0955..ae18fba 100644
--- a/src/global/formula.js
+++ b/src/global/formula.js
@@ -9,8 +9,8 @@ import luckysheetFreezen from '../controllers/freezen';
import { seletedHighlistByindex, luckysheet_count_show } from '../controllers/select';
import { isRealNum, isRealNull, valueIsError, isEditMode } from './validate';
import { isdatetime, isdatatype } from './datecontroll';
-import { getCellTextSplitArr } from '../global/getRowlen';
-import { getcellvalue,getcellFormula } from './getdata';
+import { getCellTextSplitArr,getCellTextInfo } from '../global/getRowlen';
+import { getcellvalue,getcellFormula,getInlineStringNoStyle } from './getdata';
import { setcellvalue } from './setdata';
import { genarate, valueShowEs } from './format';
import editor from './editor';
@@ -18,6 +18,7 @@ import tooltip from './tooltip';
import { rowLocation, colLocation, colLocationByIndex, mouseposition } from './location';
import { luckysheetRangeLast } from './cursorPos';
import { jfrefreshgrid } from './refresh';
+import { isInlineStringCell,convertSpanToShareString } from '../controllers/inlineString';
// import luckysheet_function from '../function/luckysheet_function';
// import functionlist from '../function/functionlist';
import { luckysheet_compareWith, luckysheet_getarraydata, luckysheet_getcelldata, luckysheet_parseData, luckysheet_getValue, luckysheet_indirect_check, luckysheet_indirect_check_return, luckysheet_offset_check } from '../function/func';
@@ -325,7 +326,10 @@ const luckysheetformula = {
if (d[r] != null && d[r][c] != null) {
let cell = d[r][c];
- if(cell.f != null){
+ if(isInlineStringCell(cell)){
+ value = getInlineStringNoStyle(r, c);
+ }
+ else if(cell.f != null){
value = getcellvalue(r, c, d, "f");
}
else{
@@ -1193,41 +1197,70 @@ const luckysheetformula = {
let _this = this;
let $input = $("#luckysheet-rich-text-editor");
-
- // API, we get value from user
- value = value || $input.text();
+ let inputText = $input.text(), inputHtml = $input.html();
+
+
+
if (_this.rangetosheet != null && _this.rangetosheet != Store.currentSheetIndex) {
sheetmanage.changeSheetExec(_this.rangetosheet);
}
let curv = Store.flowdata[r][c];
-
- if(isRealNull(value)){
- if(curv == null || (isRealNull(curv.v) && curv.spl == null)){
- _this.cancelNormalSelected();
- return;
- }
+ let isPrevInline = isInlineStringCell(curv);
+ let isCurInline = (inputText.slice(0, 1) != "=" && inputHtml.indexOf("span")>-1);
+ if(!value && !isCurInline && isPrevInline){
+ delete curv.ct.s;
+ curv.ct.t = "g";
+ curv.ct.fa = "General";
}
- else if(curv!=null && curv.qp != 1){
- if (getObjType(curv) == "object" && (value == curv.f || value == curv.v || value == curv.m)) {
- _this.cancelNormalSelected();
- return;
- }
- else if (value == curv) {
- _this.cancelNormalSelected();
- return;
+ else if(isCurInline){
+ if (getObjType(curv) != "object") {
+ curv = {};
}
- }
+ delete curv.f;
+ delete curv.v;
+ delete curv.m;
- if (getObjType(value) == "string" && value.slice(0, 1) == "=" && value.length > 1) {
+ if(curv.ct==null){
+ curv.ct = {};
+ curv.ct.fa = "General";
+ }
+ curv.ct.t = "inlineStr";
+ curv.ct.s = convertSpanToShareString($input.find("span"));
}
- else if(getObjType(curv) == "object" && curv.ct != null && curv.ct.fa != null && curv.ct.fa != "@" && !isRealNull(value)){
- delete curv.m;//更新时间m处理 , 会实际删除单元格数据的参数(flowdata时已删除)
- if(curv.f != null){ //如果原来是公式,而更新的数据不是公式,则把公式删除
- delete curv.f;
- delete curv.spl; //删除单元格的sparklines的配置串
+
+ // API, we get value from user
+ value = value || $input.text();
+
+ if(!isCurInline){
+ if(isRealNull(value)){
+ if(curv == null || (isRealNull(curv.v) && curv.spl == null)){
+ _this.cancelNormalSelected();
+ return;
+ }
+ }
+ else if(curv!=null && curv.qp != 1){
+ if (getObjType(curv) == "object" && (value == curv.f || value == curv.v || value == curv.m)) {
+ _this.cancelNormalSelected();
+ return;
+ }
+ else if (value == curv) {
+ _this.cancelNormalSelected();
+ return;
+ }
+ }
+
+ if (getObjType(value) == "string" && value.slice(0, 1) == "=" && value.length > 1) {
+
+ }
+ else if(getObjType(curv) == "object" && curv.ct != null && curv.ct.fa != null && curv.ct.fa != "@" && !isRealNull(value)){
+ delete curv.m;//更新时间m处理 , 会实际删除单元格数据的参数(flowdata时已删除)
+ if(curv.f != null){ //如果原来是公式,而更新的数据不是公式,则把公式删除
+ delete curv.f;
+ delete curv.spl; //删除单元格的sparklines的配置串
+ }
}
}
@@ -1236,48 +1269,18 @@ const luckysheetformula = {
let isRunExecFunction = true;
let d = editor.deepCopyFlowData(Store.flowdata);
+ let dynamicArrayItem = null; //动态数组
if (getObjType(curv) == "object") {
- if(getObjType(value) == "string" && value.slice(0, 1) == "=" && value.length > 1){
- let v = _this.execfunction(value, r, c, true);
-
- curv = _this.execFunctionGroupData[r][c];
- curv.f = v[2];
-
- //打进单元格的sparklines的配置串, 报错需要单独处理。
- if(v.length == 4 && v[3].type == "sparklines"){
- delete curv.m;
- delete curv.v;
- let curCalv = v[3].data;
-
- if(getObjType(curCalv) == "array" && getObjType(curCalv[0]) != "object"){
- curv.v = curCalv[0];
- }
- else{
- curv.spl = v[3].data;
- }
- }
- }
- // from API setCellValue,luckysheet.setCellValue(0, 0, {f: "=sum(D1)", bg:"#0188fb"}),value is an object, so get attribute f as value
- else if(getObjType(value) == "object"){
- let valueFunction = value.f;
+ if(!isCurInline){
- if(getObjType(valueFunction) == "string" && valueFunction.slice(0, 1) == "=" && valueFunction.length > 1){
- let v = _this.execfunction(valueFunction, r, c, true);
+ if(getObjType(value) == "string" && value.slice(0, 1) == "=" && value.length > 1){
+ let v = _this.execfunction(value, r, c, true);
- // get v/m/ct
curv = _this.execFunctionGroupData[r][c];
-
- // get f
curv.f = v[2];
- // get other cell style attribute
- delete value.v;
- delete value.m;
- delete value.f;
- Object.assign(curv,value);
-
//打进单元格的sparklines的配置串, 报错需要单独处理。
if(v.length == 4 && v[3].type == "sparklines"){
delete curv.m;
@@ -1292,27 +1295,96 @@ const luckysheetformula = {
curv.spl = v[3].data;
}
}
+ else if(v.length == 4 && v[3].type == "dynamicArrayItem"){
+ dynamicArrayItem = v[3].data;
+ }
}
-
- }
- else{
- _this.delFunctionGroup(r, c);
- _this.execFunctionGroup(r, c, value);
- isRunExecFunction = false;
- curv = _this.execFunctionGroupData[r][c];
+ // from API setCellValue,luckysheet.setCellValue(0, 0, {f: "=sum(D1)", bg:"#0188fb"}),value is an object, so get attribute f as value
+ else if(getObjType(value) == "object"){
+ let valueFunction = value.f;
+
+ if(getObjType(valueFunction) == "string" && valueFunction.slice(0, 1) == "=" && valueFunction.length > 1){
+ let v = _this.execfunction(valueFunction, r, c, true);
- delete curv.f;
- delete curv.spl;
+ // get v/m/ct
- if(curv.qp == 1 && ('' + value).substr(0,1)!="'"){//if quotePrefix is 1, cell is force string, cell clear quotePrefix when it is updated
- curv.qp = 0;
- if(curv.ct!=null){
- curv.ct.fa = "General";
- curv.ct.t = "n";
+ curv = _this.execFunctionGroupData[r][c];
+ curv.f = v[2];
+
+ //打进单元格的sparklines的配置串, 报错需要单独处理。
+ if(v.length == 4 && v[3].type == "sparklines"){
+ delete curv.m;
+ delete curv.v;
+
+ let curCalv = v[3].data;
+
+ if(getObjType(curCalv) == "array" && getObjType(curCalv[0]) != "object"){
+ curv.v = curCalv[0];
+ }
+ else{
+ curv.spl = v[3].data;
+ }
+ }
+ else if(v.length == 4 && v[3].type == "dynamicArrayItem"){
+ dynamicArrayItem = v[3].data;
+ }
+ }
+ // from API setCellValue,luckysheet.setCellValue(0, 0, {f: "=sum(D1)", bg:"#0188fb"}),value is an object, so get attribute f as value
+ else if(getObjType(value) == "object"){
+ let valueFunction = value.f;
+
+ if(getObjType(valueFunction) == "string" && valueFunction.slice(0, 1) == "=" && valueFunction.length > 1){
+ let v = _this.execfunction(valueFunction, r, c, true);
+
+ // get v/m/ct
+ curv = _this.execFunctionGroupData[r][c];
+
+ // get f
+ curv.f = v[2];
+
+ // get other cell style attribute
+ delete value.v;
+ delete value.m;
+ delete value.f;
+ Object.assign(curv,value);
+
+ //打进单元格的sparklines的配置串, 报错需要单独处理。
+ if(v.length == 4 && v[3].type == "sparklines"){
+ delete curv.m;
+ delete curv.v;
+
+ let curCalv = v[3].data;
+
+ if(getObjType(curCalv) == "array" && getObjType(curCalv[0]) != "object"){
+ curv.v = curCalv[0];
+ }
+ else{
+ curv.spl = v[3].data;
+ }
+ }
+ }
+
+ }
+
+ }
+ else {
+ _this.delFunctionGroup(r, c);
+ _this.execFunctionGroup(r, c, value);
+ isRunExecFunction = false;
+ curv = _this.execFunctionGroupData[r][c];
+
+ delete curv.f;
+ delete curv.spl;
+
+ if(curv.qp == 1 && ('' + value).substr(0,1)!="'"){//if quotePrefix is 1, cell is force string, cell clear quotePrefix when it is updated
+ curv.qp = 0;
+ if(curv.ct!=null){
+ curv.ct.fa = "General";
+ curv.ct.t = "n";
+ }
}
}
}
-
value = curv;
}
else {
@@ -1335,6 +1407,9 @@ const luckysheetformula = {
value.spl = v[3].data;
}
}
+ else if(v.length == 4 && v[3].type == "dynamicArrayItem"){
+ dynamicArrayItem = v[3].data;
+ }
}
// from API setCellValue,luckysheet.setCellValue(0, 0, {f: "=sum(D1)", bg:"#0188fb"}),value is an object, so get attribute f as value
else if(getObjType(value) == "object"){
@@ -1363,6 +1438,9 @@ const luckysheetformula = {
value.spl = v[3].data;
}
}
+ else if(v.length == 4 && v[3].type == "dynamicArrayItem"){
+ dynamicArrayItem = v[3].data;
+ }
}
}
@@ -1383,51 +1461,86 @@ const luckysheetformula = {
cfg["rowlen"] = {};
}
- if(d[r][c].tb == "2" && d[r][c].v != null){//自动换行
- let defaultrowlen = 19;
-
- let offlinecanvas = $("#luckysheetTableContentF").get(0).getContext("2d");
- offlinecanvas.textBaseline = 'top'; //textBaseline以top计算
-
- let fontset = luckysheetfontformat(d[r][c]);
- offlinecanvas.font = fontset;
-
- let currentRowLen = defaultrowlen;
- if(cfg["rowlen"][r] != null){
- currentRowLen = cfg["rowlen"][r];
- }
-
- let strValue = getcellvalue(r, c, d).toString();
- let measureText = offlinecanvas.measureText(strValue);
+ if((d[r][c].tb == "2" && d[r][c].v != null) || isInlineStringCell(d[r][c])){//自动换行
+ let defaultrowlen = Store.defaultrowlen;;
- let textMetrics = measureText.width;
- let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 4;
- let oneLineTextHeight = measureText.actualBoundingBoxDescent - measureText.actualBoundingBoxAscent;
+ let canvas = $("#luckysheetTableContent").get(0).getContext("2d");
+ // offlinecanvas.textBaseline = 'top'; //textBaseline以top计算
- if(textMetrics > cellWidth){
- let strArr = [];//文本截断数组
- strArr = getCellTextSplitArr(strValue, strArr, cellWidth, offlinecanvas);
+ // let fontset = luckysheetfontformat(d[r][c]);
+ // offlinecanvas.font = fontset;
- let computeRowlen = oneLineTextHeight * strArr.length + 4;
- //比较计算高度和当前高度取最大高度
- if(computeRowlen > currentRowLen){
- currentRowLen = computeRowlen;
- }
- }
-
- if(currentRowLen != defaultrowlen){
- cfg["rowlen"][r] = currentRowLen;
- RowlChange = true;
+ if(cfg["customHeight"] && cfg["customHeight"][r]==1){
+
}
+ else{
+ // let currentRowLen = defaultrowlen;
+ // if(cfg["rowlen"][r] != null){
+ // currentRowLen = cfg["rowlen"][r];
+ // }
+
+ let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 2;
+
+ let textInfo = getCellTextInfo(d[r][c], canvas,{
+ r:r,
+ c:c,
+ cellWidth:cellWidth
+ });
+
+ let currentRowLen = defaultrowlen;
+ // console.log("rowlen", textInfo);
+ if(textInfo!=null){
+ currentRowLen = textInfo.textHeightAll+2;
+ }
+
+ // let strValue = getcellvalue(r, c, d).toString();
+ // let measureText = offlinecanvas.measureText(strValue);
+
+ // let textMetrics = measureText.width;
+ // let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 4;
+ // let oneLineTextHeight = measureText.actualBoundingBoxDescent - measureText.actualBoundingBoxAscent;
+
+ // if(textMetrics > cellWidth){
+ // let strArr = [];//文本截断数组
+ // strArr = getCellTextSplitArr(strValue, strArr, cellWidth, offlinecanvas);
+
+ // let computeRowlen = oneLineTextHeight * strArr.length + 4;
+ // //比较计算高度和当前高度取最大高度
+ // if(computeRowlen > currentRowLen){
+ // currentRowLen = computeRowlen;
+ // }
+ // }
+
+ if(currentRowLen > defaultrowlen){
+ cfg["rowlen"][r] = currentRowLen;
+ RowlChange = true;
+ }
+ }
+
+ }
+
+ //动态数组
+ let dynamicArray = null;
+ if(!!dynamicArrayItem){
+ let file = Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)];
+ dynamicArray = $.extend(true, [], file["dynamicArray"]);
+ dynamicArray.push(dynamicArrayItem);
+ }
+
+ let allParam = {
+ "dynamicArray": dynamicArray
}
if(RowlChange){
- jfrefreshgrid(d, [{ "row": [r, r], "column": [c, c] }], cfg, null, RowlChange, isRunExecFunction);
- }
- else {
- jfrefreshgrid(d, [{ "row": [r, r], "column": [c, c] }], undefined, undefined, undefined, isRunExecFunction);
+ allParam = {
+ "cfg": cfg,
+ "dynamicArray": dynamicArray,
+ "RowlChange": RowlChange
+ }
}
+ jfrefreshgrid(d, [{ "row": [r, r], "column": [c, c] }], allParam, isRunExecFunction);
+
// Store.luckysheetCellUpdate.length = 0; //clear array
_this.execFunctionGroupData = null; //销毁
},
@@ -3139,13 +3252,14 @@ const luckysheetformula = {
if(kcode != 46){//delete不执行此函数
_this.createRangeHightlight();
}
+
+ $functionbox.html(value);
}
_this.rangestart = false;
_this.rangedrag_column_start = false;
_this.rangedrag_row_start = false;
-
- $functionbox.html(value);
+
_this.rangeHightlightselected($editer, kcode);
}, 1);
},
@@ -4879,7 +4993,7 @@ const luckysheetformula = {
let _locale = locale();
let locale_formulaMore = _locale.formulaMore;
-
+ console.log(txt,r,c)
if(txt.indexOf(_this.error.r) > -1){
return [false, _this.error.r, txt];
}
@@ -4964,6 +5078,8 @@ const luckysheetformula = {
}
//公式结果是数组,分错误值 和 动态数组 两种情况
+ let dynamicArrayItem = null;
+
if(getObjType(result) == "array"){
let isErr = false;
@@ -4976,14 +5092,7 @@ const luckysheetformula = {
result = result[0][0];
}
else{
- let luckysheetfile = getluckysheetfile();
- let file = luckysheetfile[getSheetIndex(Store.currentSheetIndex)];
- let dynamicArray = file["dynamicArray"] == null ? [] : file["dynamicArray"];
- dynamicArray.push({"r": r, "c": c, "f": txt, "data": result});
-
- file["dynamicArray"] = dynamicArray;
- setluckysheetfile(luckysheetfile);
-
+ dynamicArrayItem = {"r": r, "c": c, "f": txt, "data": result};
result = "";
}
}
@@ -5010,6 +5119,10 @@ const luckysheetformula = {
return [true, result, txt, {type: "sparklines", data: sparklines}];
}
+ if(!!dynamicArrayItem){
+ return [true, result, txt, {type: "dynamicArrayItem", data: dynamicArrayItem}];
+ }
+
return [true, result, txt];
},
testFunction: function(txt, fp) {
diff --git a/src/global/getRowlen.js b/src/global/getRowlen.js
index e9df1ac..82aee2c 100644
--- a/src/global/getRowlen.js
+++ b/src/global/getRowlen.js
@@ -1,8 +1,9 @@
import { luckysheetfontformat } from '../utils/util';
import menuButton from '../controllers/menuButton';
-import { getcellvalue } from './getdata';
+import { getcellvalue,checkstatusByCell } from './getdata';
import { colLocationByIndex } from './location';
import { hasChinaword, isRealNull } from './validate';
+import { isInlineStringCell } from '../controllers/inlineString';
import Store from '../store';
//计算范围行高
@@ -12,6 +13,10 @@ function rowlenByRange(d, r1, r2, cfg) {
cfg_clone["rowlen"] = {};
}
+ if(cfg_clone["customHeight"] == null){
+ cfg_clone["customHeight"] = {};
+ }
+
let canvas = $("#luckysheetTableContent").get(0).getContext("2d");
canvas.textBaseline = 'top'; //textBaseline以top计算
@@ -25,6 +30,10 @@ function rowlenByRange(d, r1, r2, cfg) {
// currentRowLen = cfg_clone["rowlen"][r];
// }
+ if(cfg_clone["customHeight"][r]==1){
+ continue;
+ }
+
delete cfg_clone["rowlen"][r];
for(let c = 0; c < d[r].length; c++){
@@ -34,7 +43,7 @@ function rowlenByRange(d, r1, r2, cfg) {
continue;
}
- if(cell != null && cell.v != null){
+ if(cell != null && (cell.v != null || isInlineStringCell(cell)) ){
let cellWidth = colLocationByIndex(c)[1] - colLocationByIndex(c)[0] - 2;
let textInfo = getCellTextInfo(cell, canvas,{
@@ -46,7 +55,7 @@ function rowlenByRange(d, r1, r2, cfg) {
let computeRowlen = 0;
// console.log("rowlen", textInfo);
if(textInfo!=null){
- computeRowlen = textInfo.textHeightAll;
+ computeRowlen = textInfo.textHeightAll+2;
}
// let fontset = luckysheetfontformat(cell);
@@ -196,7 +205,7 @@ function getMeasureText(value, ctx, fontset){
}
if(fontset!=null){
- ctx.font = preFont;
+ ctx.font = fontset;
}
cache.actualBoundingBoxDescent = measureText.actualBoundingBoxDescent;
@@ -269,13 +278,13 @@ function getCellTextInfo(cell , ctx, option){
}
//水平对齐
- let horizonAlign = menuButton.checkstatusByCell(cell, "ht");
+ let horizonAlign = checkstatusByCell(cell, "ht");
//垂直对齐
- let verticalAlign = menuButton.checkstatusByCell(cell, "vt");
+ let verticalAlign = checkstatusByCell(cell, "vt");
- let tb = menuButton.checkstatusByCell(cell ,"tb");//wrap overflow
- let tr = menuButton.checkstatusByCell(cell ,"tr");//rotate
- let rt = menuButton.checkstatusByCell(cell ,"rt");//rotate angle
+ let tb = checkstatusByCell(cell ,"tb");//wrap overflow
+ let tr = checkstatusByCell(cell ,"tr");//rotate
+ let rt = checkstatusByCell(cell ,"rt");//rotate angle
let isRotateUp = 1, isRotateDown=0;
@@ -317,12 +326,65 @@ function getCellTextInfo(cell , ctx, option){
let textContent = {};
textContent.values = [];
- let fontset, cancelLine="0", underLine="0", isInline=false, value;
- if(cell.ct!=null && cell.ct.t=="inlineStr" && cell.ct.sharedStrings!=null && cell.ct.sharedStrings.length>0){
- let strArr = [];
- let sharedStrings = cell.ct.s;
- for(let i=0;i 1){
- vArr = value.split("");
- }
- else{
- vArr.push(value);
- }
let textW_all = 0; //拆分后宽高度合计
let textH_all = 0;
-
- let oneWordWidth = getMeasureText(vArr[0], ctx).width;
let colIndex=0, textH_all_cache=0, textH_all_Column = {}, textH_all_ColumnHeight=[];
+ if(isInline){
+ let preShareCell = null;
+ for(let i = 0; i < inlineStringArr.length; i++){
+ let shareCell = inlineStringArr[i];
+ let value = shareCell.v, showValue=shareCell.v;
+ if(shareCell.wrap===true){
+ value = "M";
+ showValue = "";
+
+
+ if( preShareCell!=null && preShareCell.wrap!==true && (icellHeight && textH_all_Column[colIndex]!=null){
- // textW_all += textW;
- // textH_all = Math.max(textH_all,textH_all_cache);
- textH_all_ColumnHeight.push(textH_all_cache-textH);
- textH_all_cache = textH;
- colIndex +=1;
+ let textW = measureText.width + space_width;
+ let textH = measureText.actualBoundingBoxAscent + measureText.actualBoundingBoxDescent + space_height;
+
+ // textW_all += textW;
+ textH_all_cache += textH;
+
+
+ if(tb=="2" && !shareCell.wrap){
+ if(textH_all_cache>cellHeight && textH_all_Column[colIndex]!=null){
+ // textW_all += textW;
+ // textH_all = Math.max(textH_all,textH_all_cache);
+ // console.log(">",i,colIndex);
+ textH_all_ColumnHeight.push(textH_all_cache-textH);
+ textH_all_cache = textH;
+ colIndex +=1;
+ }
+ }
+
+ if(i== inlineStringArr.length-1){
+ textH_all_ColumnHeight.push(textH_all_cache);
+ }
+
+ if(textH_all_Column[colIndex]==null){
+ textH_all_Column[colIndex]= [];
}
- }
- if(i== vArr.length-1){
- textH_all_ColumnHeight.push(textH_all_cache);
- }
+ let item = {
+ content:showValue,
+ style:shareCell,
+ width:textW,
+ height:textH,
+ left:0,
+ top:0,
+ colIndex:colIndex,
+ asc:measureText.actualBoundingBoxAscent,
+ desc:measureText.actualBoundingBoxDescent,
+ inline:true,
+ }
- if(textH_all_Column[colIndex]==null){
- textH_all_Column[colIndex]= [];
+ if(shareCell.wrap===true){
+ item.wrap=true;
+ }
+
+ textH_all_Column[colIndex].push(item);
+ console.log("normal",i,colIndex,shareCell, preShareCell, textH_all_Column);
+ preShareCell = shareCell;
+
}
+ }
+ else{
+ let measureText = getMeasureText(value, ctx);
+ let textHeight = measureText.actualBoundingBoxDescent + measureText.actualBoundingBoxAscent;
- textH_all_Column[colIndex].push({
- content:vArr[i],
- style:fontset,
- width:textW,
- height:textH,
- left:0,
- top:0,
- colIndex:colIndex,
- asc:measureText.actualBoundingBoxAscent,
- desc:measureText.actualBoundingBoxDescent
- });
+ value = value.toString();
+
+ let vArr = [];
+ if(value.length > 1){
+ vArr = value.split("");
+ }
+ else{
+ vArr.push(value);
+ }
+ let oneWordWidth = getMeasureText(vArr[0], ctx).width;
+ for(let i = 0; i < vArr.length; i++){
+ let textW = oneWordWidth + space_width;
+ let textH = textHeight + space_height;
+
+ // textW_all += textW;
+ textH_all_cache += textH;
+
+
+ if(tb=="2"){
+ if(textH_all_cache>cellHeight && textH_all_Column[colIndex]!=null){
+ // textW_all += textW;
+ // textH_all = Math.max(textH_all,textH_all_cache);
+ textH_all_ColumnHeight.push(textH_all_cache-textH);
+ textH_all_cache = textH;
+ colIndex +=1;
+ }
+ }
+
+ if(i== vArr.length-1){
+ textH_all_ColumnHeight.push(textH_all_cache);
+ }
+
+ if(textH_all_Column[colIndex]==null){
+ textH_all_Column[colIndex]= [];
+ }
+
+ textH_all_Column[colIndex].push({
+ content:vArr[i],
+ style:fontset,
+ width:textW,
+ height:textH,
+ left:0,
+ top:0,
+ colIndex:colIndex,
+ asc:measureText.actualBoundingBoxAscent,
+ desc:measureText.actualBoundingBoxDescent
+ });
+
+ }
}
let textH_all_ColumWidth = [];
@@ -474,9 +611,10 @@ function getCellTextInfo(cell , ctx, option){
width:columnWidth,
height:word.height,
left:left,
- top:top+word.height/2,
- asc:word.asc,
- desc:word.desc
+ top:top+word.height-space_height,
+ asc:word.height,
+ desc:0,
+ fs:fontSize
});
textContent.values.push(word);
@@ -496,7 +634,6 @@ function getCellTextInfo(cell , ctx, option){
}
if(tb=="2" || isInline){//wrap
- value = value.toString();
let textW_all = 0; //拆分后宽高度合计
let textH_all = 0;
@@ -508,119 +645,313 @@ function getCellTextInfo(cell , ctx, option){
textContent.rotate = rt;
rt = Math.abs(rt);
- let anchor = 0, preHeight = 0, preWidth=0, preStr, preTextHeight, preTextWidth, i=0;
- while(i <= value.length){
- let str = value.substring(anchor, i);
- let measureText = getMeasureText(str, ctx);
- let textWidth = measureText.width;
- let textHeight = measureText.actualBoundingBoxAscent+measureText.actualBoundingBoxDescent;
+ let anchor = 0, preHeight = 0, preWidth=0, preStr, preTextHeight, preTextWidth, i=1, wrapStyle={};
+ if(isInline){
+ while(i <= inlineStringArr.length){
+ let shareCells = inlineStringArr.slice(anchor, i);
+ if(shareCells[shareCells.length-1].wrap===true){
- let width = textWidth * Math.cos(rt*Math.PI/180) + textHeight * Math.sin(rt*Math.PI/180);//consider text box wdith and line height
+ anchor = i;
+
+ if(shareCells.length>1){
+ for(let s=0;scellHeight && text_all_split[splitIndex]!=null){
- // console.log("cut",anchor, i , str);
- anchor = i-1;
-
- text_all_split[splitIndex].push({
- content:preStr,
- style:fontset,
- width:preWidth,
- height:preHeight,
- left:0,
- top:0,
- splitIndex:splitIndex,
- textHeight:preTextHeight,
- textWidth:preTextWidth,
- asc:measureText.actualBoundingBoxAscent,
- desc:measureText.actualBoundingBoxDescent
- });
splitIndex +=1;
+
+ i++;
+
+ continue;
}
- else if(i== value.length){
- // console.log("last",anchor, i , str);
- if(text_all_split[splitIndex]==null){
- text_all_split[splitIndex]= [];
+
+ let textWidth=0, textHeight=0;
+ for(let s=0;scellHeight && text_all_split[splitIndex]!=null && tb=="2"){
+ // console.log("cut",anchor, i , str);
+ anchor = i-1;
+
+ for(let s=0;scellWidth && text_all_split[splitIndex]!=null){
-
- anchor = i-1;
-
- text_all_split[splitIndex].push({
- content:preStr,
- style:fontset,
- width:preWidth,
- height:preHeight,
- left:0,
- top:0,
- splitIndex:splitIndex,
- asc:measureText.actualBoundingBoxAscent,
- desc:measureText.actualBoundingBoxDescent
- });
+ else{//plain
+ if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null && tb=="2"){
+
+ anchor = i-1;
+
+ for(let s=0;scellHeight && text_all_split[splitIndex]!=null){
+ // console.log("cut",anchor, i , str);
+ anchor = i-1;
+
+ text_all_split[splitIndex].push({
+ content:preStr,
+ style:fontset,
+ left:0,
+ top:0,
+ splitIndex:splitIndex,
+ height:preTextHeight,
+ width:preTextWidth,
+ asc:measureText.actualBoundingBoxAscent,
+ desc:measureText.actualBoundingBoxDescent,
+ fs:fontSize,
+ });
+
+ splitIndex +=1;
+ }
+ else if(i== value.length){
+ // console.log("last",anchor, i , str);
+ if(text_all_split[splitIndex]==null){
+ text_all_split[splitIndex]= [];
+ }
+ text_all_split[splitIndex].push({
+ content:str,
+ style:fontset,
+ left:0,
+ top:0,
+ splitIndex:splitIndex,
+ height:textHeight,
+ width:textWidth,
+ asc:measureText.actualBoundingBoxAscent,
+ desc:measureText.actualBoundingBoxDescent,
+ fs:fontSize,
+ });
+ break;
+ }
+ else{
+ if(text_all_split[splitIndex]==null){
+ text_all_split[splitIndex]= [];
+ }
+ i++;
+ }
}
- else{
- if(text_all_split[splitIndex]==null){
- text_all_split[splitIndex]= [];
+ else{//plain
+ if((width+space_width)>cellWidth && text_all_split[splitIndex]!=null){
+
+ anchor = i-1;
+
+ text_all_split[splitIndex].push({
+ content:preStr,
+ style:fontset,
+ width:preTextWidth,
+ height:preTextHeight,
+ left:0,
+ top:0,
+ splitIndex:splitIndex,
+ asc:measureText.actualBoundingBoxAscent,
+ desc:measureText.actualBoundingBoxDescent,
+ fs:fontSize,
+ });
+
+ splitIndex +=1;
+ }
+ else if(i== value.length){
+ if(text_all_split[splitIndex]==null){
+ text_all_split[splitIndex]= [];
+ }
+ text_all_split[splitIndex].push({
+ content:str,
+ style:fontset,
+ width:textWidth,
+ height:textHeight,
+ left:0,
+ top:0,
+ splitIndex:splitIndex,
+ asc:measureText.actualBoundingBoxAscent,
+ desc:measureText.actualBoundingBoxDescent,
+ fs:fontSize,
+ });
+
+ break;
+ }
+ else{
+ if(text_all_split[splitIndex]==null){
+ text_all_split[splitIndex]= [];
+ }
+ i++;
}
- i++;
}
+
+ preStr = str;
+ preTextHeight = textHeight;
+ preTextWidth = textWidth;
+
}
-
- preWidth = width;
- preHeight = height;
- preStr = str;
- preTextHeight = textHeight;
- preTextWidth = textWidth;
-
}
let split_all_size = [], oneLinemaxWordCount=0;
@@ -635,8 +966,8 @@ function getCellTextInfo(cell , ctx, option){
for(let s=0;s1?(wordGroup.textHeight/1.5):0);
- // if(verticalAlign == "0"){
- // top = y + cellHeight/2 - topOffset - textH_all/2 + wordGroup.asc+(splitLen>1?(wordGroup.textHeight/3):0);
- // }
- // else if(verticalAlign == "1"){
- // top = y - topOffset + wordGroup.asc;
- // }
-
- // cumColumnWidth += wordGroup.textWidth;
-
- // if(c==0 && i==0 && isRotateUp=="1"){
- // textContent.textLeftAll = left;
- // textContent.textTopAll = top-wordGroup.asc;
- // }
- // else if(c==0 && i==(splitLen-1) && isRotateUp=="0"){
- // textContent.textLeftAll = left;
- // textContent.textTopAll = top+wordGroup.desc;
- // }
-
- // console.log("plainWrap" ,left , top);
}
else{//plain
left = space_width + cumColumnWidth;
@@ -942,7 +1217,7 @@ function getCellTextInfo(cell , ctx, option){
top = space_height + cumWordHeight+ size.asc;
}
- cumColumnWidth += wordGroup.width;
+
drawLineInfo(wordGroup, cancelLine, underLine,{
width:wordGroup.width,
@@ -950,7 +1225,8 @@ function getCellTextInfo(cell , ctx, option){
left:left,
top:top,
asc:size.asc,
- desc:size.desc
+ desc:size.desc,
+ fs:wordGroup.fs
});
}
@@ -959,6 +1235,8 @@ function getCellTextInfo(cell , ctx, option){
wordGroup.top = top;
textContent.values.push(wordGroup);
+
+ cumColumnWidth += wordGroup.width;
}
@@ -1096,7 +1374,8 @@ function getCellTextInfo(cell , ctx, option){
left:left,
top:top,
asc:measureText.actualBoundingBoxAscent,
- desc:measureText.actualBoundingBoxDescent
+ desc:measureText.actualBoundingBoxDescent,
+ fs:fontSize,
});
textContent.values.push(wordGroup);
@@ -1116,7 +1395,17 @@ function getCellTextInfo(cell , ctx, option){
function drawLineInfo(wordGroup, cancelLine,underLine,option){
- let left = option.left, top = option.top, width=option.width, height = option.height, asc = option.asc,desc = option.desc;
+ let left = option.left, top = option.top, width=option.width, height = option.height, asc = option.asc,desc = option.desc,fs = option.fs;
+
+ if(wordGroup.wrap===true){
+ return;
+ }
+
+ if(wordGroup.inline==true && wordGroup.style!=null){
+ cancelLine = wordGroup.style.cl;
+ underLine = wordGroup.style.un;
+ }
+
if(cancelLine!="0"){
wordGroup.cancelLine = {};
wordGroup.cancelLine.startX = left;
@@ -1125,6 +1414,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
wordGroup.cancelLine.endX = left + width;
wordGroup.cancelLine.endY = top-asc/2+1;
+ wordGroup.cancelLine.fs = fs;
+
}
if(underLine!="0"){
@@ -1137,6 +1428,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
item.endX = left + width;
item.endY = top;
+ item.fs = fs;
+
wordGroup.underLine.push(item);
}
@@ -1148,6 +1441,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
item.endX = left + width;
item.endY = top+desc;
+ item.fs = fs;
+
wordGroup.underLine.push(item);
}
@@ -1159,6 +1454,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
item.endX = left + width;
item.endY = top+desc;
+ item.fs = fs;
+
wordGroup.underLine.push(item);
}
@@ -1170,6 +1467,8 @@ function drawLineInfo(wordGroup, cancelLine,underLine,option){
item.endX = left + width;
item.endY = top+desc+2;
+ item.fs = fs;
+
wordGroup.underLine.push(item);
}
}
diff --git a/src/global/getdata.js b/src/global/getdata.js
index 5fa8401..9c1029d 100644
--- a/src/global/getdata.js
+++ b/src/global/getdata.js
@@ -1,10 +1,12 @@
-import { getObjType } from '../utils/util';
+import { getObjType,rgbTohex } from '../utils/util';
import { getSheetIndex } from '../methods/get';
import server from '../controllers/server';
import formula from './formula';
import editor from './editor';
import { dynamicArrayCompute } from './dynamicArray';
import sheetmanage from '../controllers/sheetmanage';
+import { isInlineStringCT,isInlineStringCell,convertCssToStyleList } from '../controllers/inlineString';
+import locale from '../locale/locale';
import Store from '../store';
//Get selection range value
@@ -261,4 +263,307 @@ export function getOrigincell(r, c, i) {
return data[r][c];
+}
+
+export function getRealCellValue(r, c){
+ let value = getcellvalue(r, c, null, "m");
+ if(value == null){
+ value = getcellvalue(r, c);
+ if(value==null){
+ let ct = getcellvalue(r, c, null, "ct");
+ if(isInlineStringCT(ct)){
+ value = ct.s;
+ }
+ }
+ }
+
+ return value;
+}
+
+export function getInlineStringNoStyle(r, c){
+ let ct = getcellvalue(r, c, null, "ct");
+ if(isInlineStringCT(ct)){
+ let strings = ct.s, value="";
+ for(let i=0;i" + strObj.v + "";
+ }
+ }
+ return value;
+ }
+
+ return "";
+}
+
+export function getFontStyleByCell(cell,checksAF,checksCF, isCheck=true){
+ if(cell==null){
+ return;
+ }
+ let style = "";
+ const _locale = locale();
+ const locale_fontarray = _locale.fontarray;
+ for(let key in cell){
+ let value = cell[key];
+ if(isCheck){
+ value = checkstatusByCell(cell, key);
+ }
+ if(key == "bl" && value != "0"){
+ style += "font-weight: bold;";
+ }
+
+ if(key == "it" && value != "0"){
+ style += "font-style:italic;";
+ }
+
+ if(key == "ff"){
+ let f = value;
+ if(!isNaN(parseInt(value))){
+ f = locale_fontarray[parseInt(value)];
+ }
+ else{
+ f = value;
+ }
+ style += "font-family: " + f + ";";
+ }
+
+ if(key == "fs" && value != "10"){
+ style += "font-size: "+ value + "pt;";
+ }
+
+ if((key == "fc" && value != "#000000") || checksAF != null || (checksCF != null && checksCF["textColor"] != null)){
+ if(checksCF != null && checksCF["textColor"] != null){
+ style += "color: " + checksCF["textColor"] + ";";
+ }
+ else if(checksAF != null){
+ style += "color: " + checksAF[0] + ";";
+ }
+ else{
+ style += "color: " + value + ";";
+ }
+ }
+
+ if(key == "cl" && value != "0"){
+ style += "text-decoration: line-through;";
+ }
+
+ if(key == "un" && (value == "1" || value == "3")){
+ let color = cell["_color"];
+ if(color==null){
+ color = cell["fc"];
+ }
+ let fs = cell["_fontSize"];
+ if(fs==null){
+ fs = cell["fs"];
+ }
+ style += "border-bottom: "+ Math.floor(fs/9) +"px solid "+ color +";";
+ }
+
+ }
+ return style;
+}
+
+export function checkstatusByCell(cell, a){
+ let foucsStatus =cell;
+ let tf = {"bl":1, "it":1 , "ff":1, "cl":1, "un":1};
+
+ if(a in tf || (a=="fs" && isInlineStringCell(cell)) ){
+ if(foucsStatus == null){
+ foucsStatus = "0";
+ }
+ else{
+ var w = window.getSelection(), isInlineEdit=false;
+ if(w.type!="None"){
+ var range = w.getRangeAt(0);
+ let startContainer = range.startContainer;
+ if (parseInt($("#luckysheet-input-box").css("top")) > 0 && startContainer.parentNode.tagName=="SPAN" && !range.collapsed) {
+ let span = startContainer.parentNode;
+ let styleList = convertCssToStyleList(span.style.cssText);
+ foucsStatus = styleList[a];
+ isInlineEdit = true;
+ }
+ }
+
+ if(!isInlineEdit){
+ if(isInlineStringCell(cell)){
+ foucsStatus = cell.ct.s[0][a];
+ }
+ else{
+ foucsStatus = foucsStatus[a];
+ }
+ }
+
+ if(foucsStatus == null){
+ foucsStatus = "0";
+ }
+ }
+ }
+ else if(a == "fc"){
+ if(foucsStatus == null){
+ foucsStatus = "#000000";
+ }
+ else{
+ foucsStatus = foucsStatus[a];
+
+ if(foucsStatus == null){
+ foucsStatus = "#000000";
+ }
+
+ if(foucsStatus.indexOf("rgba") > -1){
+ foucsStatus = rgbTohex(foucsStatus);
+ }
+ }
+ }
+ else if(a == "bg"){
+ if(foucsStatus == null){
+ foucsStatus = null;
+ }
+ else{
+ foucsStatus = foucsStatus[a];
+
+ if(foucsStatus == null){
+ foucsStatus = null;
+ }
+ else if(foucsStatus.toString().indexOf("rgba") > -1){
+ foucsStatus = rgbTohex(foucsStatus);
+ }
+ }
+ }
+ else if(a.substr(0, 2) == "bs"){
+ if(foucsStatus == null){
+ foucsStatus = "none";
+ }
+ else{
+ foucsStatus = foucsStatus[a];
+ if(foucsStatus == null){
+ foucsStatus = "none";
+ }
+ }
+ }
+ else if(a.substr(0, 2) == "bc"){
+ if(foucsStatus == null){
+ foucsStatus = "#000000";
+ }
+ else{
+ foucsStatus = foucsStatus[a];
+ if(foucsStatus == null){
+ foucsStatus = "#000000";
+ }
+ }
+ }
+ else if(a == "ht"){
+ if(foucsStatus == null){
+ foucsStatus = "1";
+ }
+ else{
+ foucsStatus = foucsStatus[a];
+ if(foucsStatus == null){
+ foucsStatus = "1";
+ }
+ }
+
+ if(["0", "1", "2"].indexOf(foucsStatus.toString()) == -1){
+ foucsStatus = "1";
+ }
+ }
+ else if(a == "vt"){
+ if(foucsStatus == null){
+ foucsStatus = "2";
+ }
+ else{
+ foucsStatus = foucsStatus[a];
+ if(foucsStatus == null){
+ foucsStatus = "2";
+ }
+ }
+
+ if(["0", "1", "2"].indexOf(foucsStatus.toString()) == -1){
+ foucsStatus = "2";
+ }
+ }
+ else if(a == "ct"){
+ if(foucsStatus == null){
+ foucsStatus = null;
+ }
+ else{
+ foucsStatus = foucsStatus[a];
+ if(foucsStatus == null){
+ foucsStatus = null;
+ }
+ }
+ }
+ else if(a == "fs"){
+ if(foucsStatus == null){
+ foucsStatus = "10";
+ }
+ else{
+ foucsStatus = foucsStatus[a];
+ if(foucsStatus == null){
+ foucsStatus = "10";
+ }
+ }
+ }
+ else if(a == "tb"){
+ if(foucsStatus == null){
+ foucsStatus = "0";
+ }
+ else{
+ foucsStatus = foucsStatus[a];
+ if(foucsStatus == null){
+ foucsStatus = "0";
+ }
+ }
+ }
+ else if(a == "tr"){
+ if(foucsStatus == null){
+ foucsStatus = "0";
+ }
+ else{
+ foucsStatus = foucsStatus[a];
+ if(foucsStatus == null){
+ foucsStatus = "0";
+ }
+ }
+ }
+ else if(a == "rt"){
+ if(foucsStatus == null){
+ foucsStatus = null;
+ }
+ else{
+ foucsStatus = foucsStatus[a];
+ if(foucsStatus == null){
+ foucsStatus = null;
+ }
+ }
+ }
+
+ return foucsStatus;
+}
+
+export function textTrim(x) {
+ if(x==null || x.length==0){
+ return x;
+ }
+ return x.replace(/^\s+|\s+$/gm,'');
}
\ No newline at end of file
diff --git a/src/global/refresh.js b/src/global/refresh.js
index 512448e..53d831e 100644
--- a/src/global/refresh.js
+++ b/src/global/refresh.js
@@ -13,18 +13,21 @@ import luckysheetFreezen from '../controllers/freezen';
import server from '../controllers/server';
import sheetmanage from '../controllers/sheetmanage';
import luckysheetPostil from '../controllers/postil';
+import dataVerificationCtrl from '../controllers/dataVerificationCtrl';
import { selectHightlightShow, selectionCopyShow } from '../controllers/select';
import { createFilterOptions } from '../controllers/filter';
import { getSheetIndex } from '../methods/get';
import Store from '../store';
-function jfrefreshgrid(data, range, cfg, cdformat, RowlChange, isRunExecFunction=true, isRefreshCanvas=true) {
+function jfrefreshgrid(data, range, allParam, isRunExecFunction = true, isRefreshCanvas = true) {
if(data == null){
data = Store.flowdata;
}
+
if(range == null){
range = Store.luckysheet_select_save;
}
+
//单元格数据更新联动
if (isRunExecFunction) {
formula.execFunctionExist = [];
@@ -40,6 +43,19 @@ function jfrefreshgrid(data, range, cfg, cdformat, RowlChange, isRunExecFunction
formula.execFunctionGroupData = null;
}
+ //关联参数
+ if(allParam == null){
+ allParam = {};
+ }
+
+ let cfg = allParam["cfg"]; //config
+ let RowlChange = allParam["RowlChange"]; //行高改变
+ let cdformat = allParam["cdformat"]; //条件格式
+ let dataVerification = allParam["dataVerification"]; //数据验证
+ let dynamicArray = allParam["dynamicArray"]; //动态数组
+
+ let file = Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)];
+
if (Store.clearjfundo) {
Store.jfundo = [];
@@ -53,11 +69,27 @@ function jfrefreshgrid(data, range, cfg, cdformat, RowlChange, isRunExecFunction
let curCdformat;
if(cdformat == null){
- curCdformat = $.extend(true, [], Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["luckysheet_conditionformat_save"]);
+ curCdformat = $.extend(true, [], file["luckysheet_conditionformat_save"]);
}
else{
curCdformat = cdformat;
}
+
+ let curDataVerification;
+ if(dataVerification == null){
+ curDataVerification = $.extend(true, {}, file["dataVerification"])
+ }
+ else{
+ curDataVerification = dataVerification;
+ }
+
+ let curDynamicArray;
+ if(dynamicArray == null){
+ curDynamicArray = $.extend(true, [], file["dynamicArray"]);
+ }
+ else{
+ curDynamicArray = dynamicArray;
+ }
Store.jfredo.push({
"type": "datachange",
@@ -67,21 +99,25 @@ function jfrefreshgrid(data, range, cfg, cdformat, RowlChange, isRunExecFunction
"range": range,
"config": $.extend(true, {}, Store.config),
"curConfig": curConfig,
- "cdformat": $.extend(true, [], Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["luckysheet_conditionformat_save"]),
+ "cdformat": $.extend(true, [], file["luckysheet_conditionformat_save"]),
"curCdformat": curCdformat,
- "RowlChange": RowlChange
+ "RowlChange": RowlChange,
+ "dataVerification": $.extend(true, [], file["dataVerification"]),
+ "curDataVerification": curDataVerification,
+ "dynamicArray": $.extend(true, [], file["dynamicArray"]),
+ "curDynamicArray": curDynamicArray
});
}
//Store.flowdata
Store.flowdata = data;
editor.webWorkerFlowDataCache(Store.flowdata);//worker存数据
- Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].data = Store.flowdata;
+ file.data = Store.flowdata;
//config
if(cfg != null){
Store.config = cfg;
- Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)].config = Store.config;
+ file.config = Store.config;
server.saveParam("all", Store.currentSheetIndex, cfg, { "k": "config" });
@@ -92,11 +128,25 @@ function jfrefreshgrid(data, range, cfg, cdformat, RowlChange, isRunExecFunction
//条件格式
if(cdformat != null){
- Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)]["luckysheet_conditionformat_save"] = cdformat;
+ file["luckysheet_conditionformat_save"] = cdformat;
server.saveParam("all", Store.currentSheetIndex, cdformat, { "k": "luckysheet_conditionformat_save" });
}
+ //数据验证
+ if(dataVerification != null){
+ dataVerificationCtrl.dataVerification = dataVerification;
+ file["dataVerification"] = dataVerification;
+ server.saveParam("all", Store.currentSheetIndex, dataVerification, { "k": "dataVerification" });
+ }
+
+ //动态数组
+ if(dynamicArray != null){
+ file["dynamicArray"] = dynamicArray;
+
+ server.saveParam("all", Store.currentSheetIndex, dynamicArray, { "k": "dynamicArray" });
+ }
+
//更新数据的范围
for(let s = 0; s < range.length; s++){
let r1 = range[s].row[0];
@@ -127,7 +177,6 @@ function jfrefreshgrid(data, range, cfg, cdformat, RowlChange, isRunExecFunction
luckysheetrefreshgrid();
}, 1);
}
-
window.luckysheet_getcelldata_cache = null;
}
@@ -331,7 +380,7 @@ function jfrefreshrange(data, range, cdformat) {
}
//删除、增加行列 刷新表格
-function jfrefreshgrid_adRC(data, cfg, ctrlType, ctrlValue, calc, filterObj, cf, af, freezen){
+function jfrefreshgrid_adRC(data, cfg, ctrlType, ctrlValue, calc, filterObj, cf, af, freezen, dataVerification){
let file = Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)];
//merge改变对应的单元格值改变
@@ -364,7 +413,7 @@ function jfrefreshgrid_adRC(data, cfg, ctrlType, ctrlValue, calc, filterObj, cf,
for(let i = 0; i < calc.length; i++){
let clc = calc[i];
- let clc_r = clc.r, clc_c = clc.c, clc_i = clc.index, clc_funcStr = getcellFormula(clc_r, clc_c, clc_i);
+ let clc_r = clc.r, clc_c = clc.c, clc_i = clc.index, clc_funcStr = getcellFormula(clc_r, clc_c, clc_i, data);
let clc_result = formula.execfunction(clc_funcStr, clc_r, clc_c, null, true);
clc.func = clc_result;
@@ -397,7 +446,9 @@ function jfrefreshgrid_adRC(data, cfg, ctrlType, ctrlValue, calc, filterObj, cf,
"af": $.extend(true, [], file.luckysheet_alternateformat_save),
"curAf": af,
"freezen": { "freezenhorizontaldata": luckysheetFreezen.freezenhorizontaldata, "freezenverticaldata": luckysheetFreezen.freezenverticaldata },
- "curFreezen": freezen
+ "curFreezen": freezen,
+ "dataVerification": $.extend(true, {}, file.dataVerification),
+ "curDataVerification": dataVerification
});
}
@@ -516,12 +567,17 @@ function jfrefreshgrid_adRC(data, cfg, ctrlType, ctrlValue, calc, filterObj, cf,
luckysheetFreezen.freezenverticaldata = null;
}
+ //数据验证
+ dataVerificationCtrl.dataVerification = dataVerification;
+ file.dataVerification = dataVerification;
+ server.saveParam("all", Store.currentSheetIndex, file.dataVerification, { "k": "dataVerification" });
+
//行高、列宽刷新
jfrefreshgrid_rhcw(Store.flowdata.length, Store.flowdata[0].length);
}
//删除单元格 刷新表格
-function jfrefreshgrid_deleteCell(data, cfg, ctrl, calc, filterObj, cf){
+function jfrefreshgrid_deleteCell(data, cfg, ctrl, calc, filterObj, cf, dataVerification){
let file = Store.luckysheetfile[getSheetIndex(Store.currentSheetIndex)];
//merge改变对应的单元格值改变
@@ -568,7 +624,7 @@ function jfrefreshgrid_deleteCell(data, cfg, ctrl, calc, filterObj, cf){
for(let i = 0; i < calc.length; i++){
let clc = calc[i];
- let clc_r = clc.r, clc_c = clc.c, clc_i = clc.index, clc_funcStr = getcellFormula(clc_r, clc_c, clc_i);
+ let clc_r = clc.r, clc_c = clc.c, clc_i = clc.index, clc_funcStr = getcellFormula(clc_r, clc_c, clc_i, data);
let clc_result = formula.execfunction(clc_funcStr, clc_r, clc_c, null, true);
clc.func = clc_result;
@@ -598,6 +654,8 @@ function jfrefreshgrid_deleteCell(data, cfg, ctrl, calc, filterObj, cf){
"curFilterObj": filterObj,
"cf": $.extend(true, [], file.luckysheet_conditionformat_save),
"curCf": cf,
+ "dataVerification": $.extend(true, {}, file.dataVerification),
+ "curDataVerification": dataVerification
});
}
@@ -671,6 +729,11 @@ function jfrefreshgrid_deleteCell(data, cfg, ctrl, calc, filterObj, cf){
file.luckysheet_conditionformat_save = cf;
server.saveParam("all", Store.currentSheetIndex, file.luckysheet_conditionformat_save, { "k": "luckysheet_conditionformat_save" });
+ //数据验证
+ dataVerificationCtrl.dataVerification = dataVerification;
+ file.dataVerification = dataVerification;
+ server.saveParam("all", Store.currentSheetIndex, file.dataVerification, { "k": "dataVerification" });
+
setTimeout(function () {
luckysheetrefreshgrid();
}, 1);
@@ -795,6 +858,16 @@ function jfrefreshgrid_pastcut(source, target, RowlChange){
Store.luckysheetfile[getSheetIndex(source["sheetIndex"])].luckysheet_conditionformat_save = source["curCdformat"];
Store.luckysheetfile[getSheetIndex(target["sheetIndex"])].luckysheet_conditionformat_save = target["curCdformat"];
+ //数据验证
+ if(Store.currentSheetIndex == source["sheetIndex"]){
+ dataVerificationCtrl.dataVerification = source["curDataVerification"];
+ }
+ else if(Store.currentSheetIndex == target["sheetIndex"]){
+ dataVerificationCtrl.dataVerification = target["curDataVerification"]
+ }
+ Store.luckysheetfile[getSheetIndex(source["sheetIndex"])].dataVerification = source["curDataVerification"];
+ Store.luckysheetfile[getSheetIndex(target["sheetIndex"])].dataVerification = target["curDataVerification"];
+
setTimeout(function () {
luckysheetrefreshgrid();
}, 1);
@@ -811,6 +884,16 @@ function jfrefreshgrid_pastcut(source, target, RowlChange){
server.historyParam(source["curData"], source["sheetIndex"], {"row": source["range"]["row"], "column": source["range"]["column"]});
//目的表
server.historyParam(target["curData"], target["sheetIndex"], {"row": target["range"]["row"], "column": target["range"]["column"]});
+
+ //来源表
+ server.saveParam("all", source["sheetIndex"], source["curCdformat"], { "k": "luckysheet_conditionformat_save" });
+ //目的表
+ server.saveParam("all", target["sheetIndex"], target["curCdformat"], { "k": "luckysheet_conditionformat_save" });
+
+ //来源表
+ server.saveParam("all", source["sheetIndex"], source["curDataVerification"], { "k": "dataVerification" });
+ //目的表
+ server.saveParam("all", target["sheetIndex"], target["curDataVerification"], { "k": "dataVerification" });
}
//行高、列宽改变 刷新表格
diff --git a/src/global/sort.js b/src/global/sort.js
index 0383468..c80735e 100644
--- a/src/global/sort.js
+++ b/src/global/sort.js
@@ -267,15 +267,18 @@ function sortSelection(isAsc) {
}
}
+ let allParam = {};
if(Store.config["rowlen"] != null){
let cfg = $.extend(true, {}, Store.config);
cfg = rowlenByRange(d, str, edr, cfg);
- jfrefreshgrid(d, [{ "row": [str, edr], "column": [c1, c2] }], cfg, null, true);
- }
- else{
- jfrefreshgrid(d, [{ "row": [str, edr], "column": [c1, c2] }]);
+ allParam = {
+ "cfg": cfg,
+ "RowlChange": true
+ }
}
+
+ jfrefreshgrid(d, [{ "row": [str, edr], "column": [c1, c2] }], allParam);
}
//排序一列数据
@@ -352,15 +355,18 @@ function sortColumnSeletion(colIndex, isAsc) {
}
}
+ let allParam = {};
if(Store.config["rowlen"] != null){
let cfg = $.extend(true, {}, Store.config);
cfg = rowlenByRange(d, str, edr, cfg);
- jfrefreshgrid(d, [{ "row": [str, edr], "column": [c1, c2] }], cfg, null, true);
- }
- else{
- jfrefreshgrid(d, [{ "row": [str, edr], "column": [c1, c2] }]);
+ allParam = {
+ "cfg": cfg,
+ "RowlChange": true
+ }
}
+
+ jfrefreshgrid(d, [{ "row": [str, edr], "column": [c1, c2] }], allParam);
}
export {
diff --git a/src/index.html b/src/index.html
index 3aa78bc..d935a35 100644
--- a/src/index.html
+++ b/src/index.html
@@ -38,7 +38,7 @@
// "ct":{
// "fa":"General",
// "t":"inlineStr",
- // "sharedStrings":[
+ // "s":[
// {
// "ff":"等线", //font family
// "fc":"#fff000",//font color
@@ -80,6 +80,45 @@
plugins: ['chart'],
data:
[sheetCell,sheetFormula,sheetConditionFormat,sheetSparkline,sheetTable,sheetComment,sheetPivotTableData,sheetPivotTable,sheetChart]
+ // [{"name":"Sheet1","config":{"columnlen":{"0":241},"rowlen":{"0":81}},"index":"1","status":"1","order":"0","luckysheet_select_save":[{"row":[0,0],"column":[4,4],"sheetIndex":1}],"zoomRatio":1,"showGridLines":"1","defaultColWidth":72,"defaultRowHeight":18,"celldata":[
+ // {"r":0,"c":0,
+ // "v":{
+ // "ct":{
+ // "fa":"General",
+ // "t":"inlineStr",
+ // "s":[
+ // {
+ // "ff":"Arial", //font family
+ // "fc":"#fff000",//font color
+ // "fs":12,//font size
+ // "cl":0,//strike
+ // "un":0,//underline
+ // "bl":0,//blod
+ // "it":0,//italic
+ // v:"我在马路\r\n边捡到\r\n\r\n一分钱"
+ // },
+ // {
+ // "ff":"Arial", //font family
+ // "fc":"#ff0000",//font color
+ // "fs":14,//font size
+ // "cl":"1",//strike
+ // "un":"1",//underline
+ // "bl":"1",//blod
+ // "it":"0",//italic
+ // v:"交给警\r\n察叔叔\r\n"
+ // },
+ // ]
+ // },
+ // "fs":11,
+ // "ff":"等线",
+ // "vt":0,
+ // "tb":2,
+ // "v":"",
+ // "qp":1,
+ // }
+ // },
+ // {"r":17,"c":2,"v":{"v":"Luckysheet","ct":{"fa":"General","t":"g"},"bg":null,"bl":0,"it":0,"ff":0,"fs":"11","fc":"rgb(51, 51, 51)","ht":1,"vt":1,"m":"Luckysheet"}}
+ // ],"calcChain":[]}]
})
})
diff --git a/src/locale/en.js b/src/locale/en.js
index baa3200..30b4f48 100644
--- a/src/locale/en.js
+++ b/src/locale/en.js
@@ -46,6 +46,7 @@ export default {
screenshot: 'Screenshot',
splitColumn: 'Split text',
insertImage: 'Insert image',
+ dataVerification: 'Data verification',
clearText:"Clear color",
noColorSelectedText:"No color is selected",
@@ -609,7 +610,6 @@ export default {
"space":"space",
},
-
findAndReplace:{
find:"Find",
replace:"Replace",
@@ -640,6 +640,7 @@ export default {
findBtn:"Find next",
noFindTip:"The content was not found",
+ modeTip:"This operation is not available in this mode",
searchTargetSheet:"Sheet",
searchTargetCell:"Cell",
@@ -867,6 +868,55 @@ export default {
fiveQuadrantDiagram: 'Five-quadrant diagram',
fiveBoxes: '5 Boxes',
},
+ dataVerification: {
+ cellRange: 'Cell range',
+ selectCellRange: 'Click to select cell range',
+ selectCellRange2: 'Please select a range of cells',
+ verificationCondition: 'Verification condition',
+ dropdown: 'drop-down list',
+ checkbox: 'Checkbox',
+ number: 'Number',
+ number_integer: 'Number-integer',
+ number_decimal: 'Number-decimal',
+ text_content: 'Text-content',
+ text_length: 'Text-length',
+ date: 'Date',
+ validity: 'Effectiveness',
+ placeholder1: 'Please enter the options, separated by commas, such as 1,2,3,4,5',
+ placeholder2: 'Please enter content',
+ placeholder3: 'Numeric value, such as 10',
+ placeholder4: 'Please enter the specified text',
+ placeholder5: 'Please enter the prompt displayed when the cell is selected',
+ selected: 'Selected',
+ notSelected: 'Not selected',
+ between: 'Between',
+ notBetween: 'Not between',
+ equal: 'Equal',
+ notEqualTo: 'Not equal to',
+ moreThanThe: 'More than the',
+ lessThan: 'Less than',
+ greaterOrEqualTo: 'Greater or equal to',
+ lessThanOrEqualTo: 'Less than or equal to',
+ include: 'Include',
+ exclude: 'Exclude',
+ earlierThan: 'Earlier than',
+ noEarlierThan: 'No earlier than',
+ laterThan: 'Later than',
+ noLaterThan: 'No later than',
+ identificationNumber: 'Identification number',
+ phoneNumber: 'Phone number',
+ remote: 'Automatic remote acquisition option',
+ prohibitInput: 'Prohibit input when input data is invalid',
+ hintShow: 'Show prompt when cell is selected',
+ deleteVerification: 'Delete verification',
+ tooltipInfo1: 'The drop-down list option cannot be empty',
+ tooltipInfo2: 'Checkbox content cannot be empty',
+ tooltipInfo3: 'The value entered is not a numeric type',
+ tooltipInfo4: 'The value 2 cannot be less than the value 1',
+ tooltipInfo5: 'The text content cannot be empty',
+ tooltipInfo6: 'The value entered is not a date type',
+ tooltipInfo7: 'Date 2 cannot be less than date 1',
+ },
formula:{
sum:"Sum",
average:"Average",
diff --git a/src/locale/zh.js b/src/locale/zh.js
index 3806ef1..6b330c5 100644
--- a/src/locale/zh.js
+++ b/src/locale/zh.js
@@ -46,6 +46,7 @@ export default {
screenshot: '截图',
splitColumn: '分列',
insertImage: '插入图片',
+ dataVerification: '数据验证',
clearText:"清除颜色选择",
noColorSelectedText:"没有颜色被选择",
@@ -655,6 +656,7 @@ export default {
findBtn:"查找下一个",
noFindTip:"没有查找到该内容",
+ modeTip:"该模式下不可进行此操作",
searchTargetSheet:"工作表",
searchTargetCell:"单元格",
@@ -884,6 +886,55 @@ export default {
fiveQuadrantDiagram: '五象限图',
fiveBoxes: '5个框',
},
+ dataVerification: {
+ cellRange: '单元格范围',
+ selectCellRange: '点击选择单元格范围',
+ selectCellRange2: '请选择单元格范围',
+ verificationCondition: '验证条件',
+ dropdown: '下拉列表',
+ checkbox: '复选框',
+ number: '数字',
+ number_integer: '数字-整数',
+ number_decimal: '数字-小数',
+ text_content: '文本-内容',
+ text_length: '文本-长度',
+ date: '日期',
+ validity: '有效性',
+ placeholder1: '请输入选项,以英文逗号分隔,如1,2,3,4,5',
+ placeholder2: '请输入内容',
+ placeholder3: '数值,如10',
+ placeholder4: '请输入指定的文本',
+ placeholder5: '请输入选中单元格时显示的提示语',
+ selected: '选择时',
+ notSelected: '未选择',
+ between: '介于',
+ notBetween: '不介于',
+ equal: '等于',
+ notEqualTo: '不等于',
+ moreThanThe: '大于',
+ lessThan: '小于',
+ greaterOrEqualTo: '大于等于',
+ lessThanOrEqualTo: '小于等于',
+ include: '包括',
+ exclude: '不包括',
+ earlierThan: '早于',
+ noEarlierThan: '不早于',
+ laterThan: '晚于',
+ noLaterThan: '不晚于',
+ identificationNumber: '身份证号码',
+ phoneNumber: '手机号',
+ remote: '自动远程获取选项',
+ prohibitInput: '输入数据无效时禁止输入',
+ hintShow: '选中单元格时显示提示语',
+ deleteVerification: '删除验证',
+ tooltipInfo1: '下拉列表选项不可为空',
+ tooltipInfo2: '复选框内容不可为空',
+ tooltipInfo3: '输入的值不是数值类型',
+ tooltipInfo4: '数值2不能小于数值1',
+ tooltipInfo5: '文本内容不能为空',
+ tooltipInfo6: '输入的值不是日期类型',
+ tooltipInfo7: '日期2不能小于日期1',
+ },
formula:{
sum:"求和",
average:"平均值",
diff --git a/src/store/index.js b/src/store/index.js
index 220638d..e851409 100644
--- a/src/store/index.js
+++ b/src/store/index.js
@@ -127,6 +127,8 @@ const Store = {
showGridLines:true,
toobarObject: {}, //toolbar constant
+ inlineStringEditCache:null,
+ inlineStringEditRange:null,
}