Browse Source

feat(condition format): formula condition

formula condition

fix #186
master
wpxp123456 5 years ago
parent
commit
6c98bded8d
  1. 133
      src/controllers/conditionformat.js
  2. 4
      src/global/formula.js
  3. 2
      src/locale/en.js
  4. 2
      src/locale/es.js
  5. 2
      src/locale/zh.js
  6. 2
      src/locale/zh_tw.js

133
src/controllers/conditionformat.js

@ -43,6 +43,10 @@ const conditionformat = {
<span class="icon iconfont luckysheet-iconfont-youjiantou"></span>
<span>${conditionformat_Text.ruleTypeItem5}</span>
</div>
<div class="ruleTypeItem">
<span class="icon iconfont luckysheet-iconfont-youjiantou"></span>
<span>${conditionformat_Text.ruleTypeItem6}</span>
</div>
</div>`;
},
textCellColorHtml: function(){
@ -510,6 +514,19 @@ const conditionformat = {
conditionName = "duplicateValue";
conditionValue.push(type1);
}
else if(index == 5){ //公式
conditionName = "formula";
//条件值
let v = $("#luckysheet-newConditionRule-dialog #formulaConditionVal input").val().trim();
if(v == ""){
_this.infoDialog("Condition value cannot be empty!", "");
return;
}
conditionValue.push(v);
}
//格式颜色
let textcolor;
@ -882,6 +899,19 @@ const conditionformat = {
conditionName = "duplicateValue";
conditionValue.push(type1);
}
else if(index == 5){ //公式
conditionName = "formula";
//条件值
let v = $("#luckysheet-editorConditionRule-dialog #formulaConditionVal input").val().trim();
console.log(v)
if(v == ""){
_this.infoDialog("Condition value cannot be empty!", "");
return;
}
conditionValue.push(v);
}
//格式颜色
let textcolor;
@ -1232,8 +1262,11 @@ const conditionformat = {
$("#" + id).hide();
//入口
let source;
if(id == "luckysheet-conditionformat-dialog"){
if($(this).siblings("input").attr("id") == "conditionVal"){
let $id = $(this).siblings("input").attr("id");
if($id == "conditionVal"){
source = "0_1";
}
else{
@ -1241,7 +1274,12 @@ const conditionformat = {
}
}
else if(id == "luckysheet-newConditionRule-dialog"){
if($(this).parents(".range").attr("id") == "conditionVal"){
let $id = $(this).parents(".range").attr("id");
if($id == "formulaConditionVal"){
source = "1_0";
}
else if($id == "conditionVal"){
source = "1_1";
}
else{
@ -1249,7 +1287,12 @@ const conditionformat = {
}
}
else if(id == "luckysheet-editorConditionRule-dialog"){
if($(this).parents(".range").attr("id") == "conditionVal"){
let $id = $(this).parents(".range").attr("id");
if($id == "formulaConditionVal"){
source = "2_0";
}
else if($id == "conditionVal"){
source = "2_1";
}
else{
@ -1277,6 +1320,10 @@ const conditionformat = {
$("#luckysheet-conditionformat-dialog").show();
$("#luckysheet-conditionformat-dialog #conditionVal2").val(v);
}
else if(source == "1_0"){
$("#luckysheet-newConditionRule-dialog").show();
$("#luckysheet-newConditionRule-dialog #formulaConditionVal input").val(v);
}
else if(source == "1_1"){
$("#luckysheet-newConditionRule-dialog").show();
$("#luckysheet-newConditionRule-dialog #conditionVal input").val(v);
@ -1285,6 +1332,10 @@ const conditionformat = {
$("#luckysheet-newConditionRule-dialog").show();
$("#luckysheet-newConditionRule-dialog #conditionVal2 input").val(v);
}
else if(source == "2_0"){
$("#luckysheet-editorConditionRule-dialog").show();
$("#luckysheet-editorConditionRule-dialog #formulaConditionVal input").val(v);
}
else if(source == "2_1"){
$("#luckysheet-editorConditionRule-dialog").show();
$("#luckysheet-editorConditionRule-dialog #conditionVal input").val(v);
@ -1305,10 +1356,10 @@ const conditionformat = {
if(source == "0_1" || source == "0_2"){
$("#luckysheet-conditionformat-dialog").show();
}
else if(source == "1_1" || source == "1_2"){
else if(source == "1_0" || source == "1_1" || source == "1_2"){
$("#luckysheet-newConditionRule-dialog").show();
}
else if(source == "2_1" || source == "2_2"){
else if(source == "2_0" || source == "2_1" || source == "2_2"){
$("#luckysheet-editorConditionRule-dialog").show();
}
@ -1909,6 +1960,13 @@ const conditionformat = {
else if(conditionName == "SubAverage"){
return conditionformat_Text.belowAverage;
}
else if(conditionName == "formula"){
if(v.slice(0, 1) != '='){
v = '=' + v;
}
return conditionformat_Text.formula + ': ' + v;
}
},
newConditionRuleDialog: function(source){
let _this = this;
@ -2011,6 +2069,9 @@ const conditionformat = {
index = 4;
type1 = rule["conditionValue"];
}
else if(conditionName == "formula"){
index = 5;
}
}
//规则说明
@ -2174,6 +2235,12 @@ const conditionformat = {
$("#luckysheet-editorConditionRule-dialog #isPercent").attr("checked", "checked");
}
}
else{
if(conditionName == "formula"){
let val1 = rule.conditionValue[0];
$("#luckysheet-editorConditionRule-dialog #formulaConditionVal input").val(val1);
}
}
$("#luckysheet-editorConditionRule-dialog #textcolorshow").spectrum("set", ruleFormat.textColor);
$("#luckysheet-editorConditionRule-dialog #cellcolorshow").spectrum("set", ruleFormat.cellColor);
@ -2367,6 +2434,16 @@ const conditionformat = {
</div>
<div class="title">${conditionformat_Text.setFormat}</div>${textCellColorHtml}`;
break;
case 5: //使用公式确定要设置格式的单元格
ruleExplainHtml = `<div class="title">${conditionformat_Text.ruleTypeItem2_title}:</div>
<div style="height: 30px;margin-bottom: 10px;">
<div class="inpbox range" id="formulaConditionVal" style="width: 250px;">
<input class="formulaInputFocus" style="width: 200px;"/>
<i class="fa fa-table" aria-hidden="true" title="${conditionformat_Text.selectCell}"></i>
</div>
</div>
<div class="title">${conditionformat_Text.setFormat}: </div>${textCellColorHtml}`;
break;
}
return ruleExplainHtml;
@ -3640,6 +3717,52 @@ const conditionformat = {
}
}
}
else if(conditionName == "formula"){
let str = cellrange[s].row[0],
edr = cellrange[s].row[1],
stc = cellrange[s].column[0],
edc = cellrange[s].column[1];
let formulaTxt = conditionValue0;
if(conditionValue0.toString().slice(0, 1) != '='){
formulaTxt = '=' + conditionValue0;
}
for(let r = str; r <= edr; r++){
for(let c = stc; c <= edc; c++){
let func = formulaTxt;
let offsetRow = r - str;
let offsetCol = c - stc;
if(offsetRow > 0){
func = "=" + formula.functionCopy(func, "down", offsetRow);
}
if(offsetCol > 0){
func = "=" + formula.functionCopy(func, "right", offsetCol);
}
let funcV = formula.execfunction(func);
let v = funcV[1];
if(typeof v != 'boolean'){
v = !!Number(v);
}
if(!v){
continue;
}
if((r + "_" + c) in computeMap){
computeMap[r + "_" + c]["textColor"] = textColor;
computeMap[r + "_" + c]["cellColor"] = cellColor;
}
else{
computeMap[r + "_" + c] = { "textColor": textColor, "cellColor": cellColor };
}
}
}
}
}
}
}

4
src/global/formula.js

@ -1214,7 +1214,7 @@ const luckysheetformula = {
$("#luckysheet-formula-search-c, #luckysheet-formula-help-c").hide();
_this.helpFunctionExe($editer, currSelection);
console.log(currSelection, $(currSelection).closest(".luckysheet-formula-functionrange-cell").length);
// console.log(currSelection, $(currSelection).closest(".luckysheet-formula-functionrange-cell").length);
if ($(currSelection).closest(".luckysheet-formula-functionrange-cell").length == 0) {
_this.searchFunction($editer);
return;
@ -5619,7 +5619,7 @@ const luckysheetformula = {
Store.calculateSheetIndex = index;
let fp = $.trim(_this.functionParserExe(txt));
console.log(fp)
if ((fp.substr(0, 20) == "luckysheet_function." || fp.substr(0, 22) == "luckysheet_compareWith") ) {
_this.functionHTMLIndex = 0;
}

2
src/locale/en.js

@ -9591,6 +9591,8 @@ export default {
ruleTypeItem4: 'Format only values above or below the average',
ruleTypeItem4_title: 'Is a value that satisfies the following conditions',
ruleTypeItem5: 'Format only unique or repeated values',
ruleTypeItem6: 'Use formulas to determine which cells to format',
formula: 'Formula',
textColor: 'Text color',
cellColor: 'Cell color',
confirm: 'Confirm',

2
src/locale/es.js

@ -9589,6 +9589,8 @@ export default {
ruleTypeItem4: 'Aplicar formato solo a los valores superiores o inferiores al promedio',
ruleTypeItem4_title: 'Es un valor que cumple las siguientes condiciones',
ruleTypeItem5: 'Aplicar formato solo a valores únicos o repetidos',
ruleTypeItem6: 'Use fórmulas para determinar qué celdas formatear',
formula: 'fórmula',
textColor: 'Color Texto',
cellColor: 'Color Celda',
confirm: 'Confirma',

2
src/locale/zh.js

@ -9833,6 +9833,8 @@ export default {
ruleTypeItem4: '仅对高于或低于平均值的数值设置格式',
ruleTypeItem4_title: '为满足以下条件的值',
ruleTypeItem5: '仅对唯一值或重复值设置格式',
ruleTypeItem6: '使用公式确定要设置格式的单元格',
formula: '公式',
textColor: '文本颜色',
cellColor: '单元格颜色',
confirm: '确定',

2
src/locale/zh_tw.js

@ -9826,6 +9826,8 @@ export default {
ruleTypeItem4 : '僅對高於或低於平均值的數值設定格式',
ruleTypeItem4_title : '為滿足以下條件的值',
ruleTypeItem5 : '僅對唯一值或重複值設定格式',
ruleTypeItem6 : '使用公式確定要設置格式的單元格',
formula : '公式',
textColor : '文字顏色',
cellColor : '儲存格顏色',
confirm : '確定',

Loading…
Cancel
Save