diff --git a/dist/base.css b/dist/base.css index 6882fab0c..b27789f6b 100644 --- a/dist/base.css +++ b/dist/base.css @@ -700,6 +700,12 @@ li.CodeMirror-hint-active { background: #08f; color: white; } +.bi-formula-editor .error-field { + color: #ff4949; + padding: 0 5px; + margin: 1px 1px; + display: inline-block; +} .bi-message-title { font-size: 14px; cursor: pointer; diff --git a/dist/base.js b/dist/base.js index 97da35a6e..22751e404 100644 --- a/dist/base.js +++ b/dist/base.js @@ -14534,7 +14534,10 @@ BI.FormulaEditor = BI.inherit(BI.Single, { value: "", fieldTextValueMap: {}, showHint: true, - lineHeight: 2 + lineHeight: 2, + paramFormatter: function (v) { + return v; + } }); }, _init: function () { @@ -14643,11 +14646,21 @@ BI.FormulaEditor = BI.inherit(BI.Single, { * @param field */ insertField: function (field) { + var value = this.options.fieldTextValueMap[field]; + var fieldId = this.options.paramFormatter(field); var from = this.editor.getCursor(); // 解决插入字段由括号或其他特殊字符包围时分裂的bug,在两端以不可见字符包裹一下 - this.editor.replaceSelection("\u200b" + field + "\u200b"); + var showName = fieldId.replaceAll(/^$/, function (str) { + return str.substring(2, str.length - 2); + }); + this.editor.replaceSelection("\u200b" + showName + "\u200b"); var to = this.editor.getCursor(); - this.editor.markText(from, to, {className: "fieldName", atomic: true, startStyle: "start", endStyle: "end"}); + var className = "fieldName"; + if (BI.isNotNull(fieldId.match(/^$/))) { + className = "error-field"; + } + this.editor.markText(from, to, {className: className, atomic: true, startStyle: "start", endStyle: "end", value: value}); + this.editor.replaceSelection(" "); this.editor.focus(); }, @@ -14695,8 +14708,9 @@ BI.FormulaEditor = BI.inherit(BI.Single, { _.forEach(line.markedSpans, function (i, ms) { switch (i.marker.className) { case "fieldName": + case "error-field": // 因为插入字段的时候首尾加了不可见字符,所以首尾缩进一个字符 - var dId = fieldMap[value.substr(i.from + 1, i.to - i.from - 2)]; + var dId = i.marker.value; if (!fields.contains(dId)) { fields.push(dId); } @@ -14715,6 +14729,7 @@ BI.FormulaEditor = BI.inherit(BI.Single, { switch (i.marker.className) { case "fieldName": + case "error-field": var fieldNameLength = i.to - i.from; value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length); num = num + 2 - fieldNameLength; @@ -14734,10 +14749,11 @@ BI.FormulaEditor = BI.inherit(BI.Single, { _.forEach(line.markedSpans, function (i, ms) { switch (i.marker.className) { case "fieldName": + case "error-field": var fieldNameLength = i.to - i.from; var start = i.from + num + 1; var end = fieldNameLength - 2; - var fieldId = fieldMap[value.substr(start, end)]; + var fieldId = i.marker.value; value = value.substr(0, i.from + num) + "$\{" + fieldId + "\}" + value.substr(i.to + num, value.length); num += fieldId.length - fieldNameLength + 3; break; diff --git a/dist/bundle.css b/dist/bundle.css index 2961214ff..addb772a7 100644 --- a/dist/bundle.css +++ b/dist/bundle.css @@ -2456,6 +2456,12 @@ li.CodeMirror-hint-active { background: #08f; color: white; } +.bi-formula-editor .error-field { + color: #ff4949; + padding: 0 5px; + margin: 1px 1px; + display: inline-block; +} .bi-message-title { font-size: 14px; cursor: pointer; diff --git a/dist/bundle.js b/dist/bundle.js index 4b133714d..d7f1bf7be 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -50304,7 +50304,10 @@ BI.FormulaEditor = BI.inherit(BI.Single, { value: "", fieldTextValueMap: {}, showHint: true, - lineHeight: 2 + lineHeight: 2, + paramFormatter: function (v) { + return v; + } }); }, _init: function () { @@ -50413,11 +50416,21 @@ BI.FormulaEditor = BI.inherit(BI.Single, { * @param field */ insertField: function (field) { + var value = this.options.fieldTextValueMap[field]; + var fieldId = this.options.paramFormatter(field); var from = this.editor.getCursor(); // 解决插入字段由括号或其他特殊字符包围时分裂的bug,在两端以不可见字符包裹一下 - this.editor.replaceSelection("\u200b" + field + "\u200b"); + var showName = fieldId.replaceAll(/^$/, function (str) { + return str.substring(2, str.length - 2); + }); + this.editor.replaceSelection("\u200b" + showName + "\u200b"); var to = this.editor.getCursor(); - this.editor.markText(from, to, {className: "fieldName", atomic: true, startStyle: "start", endStyle: "end"}); + var className = "fieldName"; + if (BI.isNotNull(fieldId.match(/^$/))) { + className = "error-field"; + } + this.editor.markText(from, to, {className: className, atomic: true, startStyle: "start", endStyle: "end", value: value}); + this.editor.replaceSelection(" "); this.editor.focus(); }, @@ -50465,8 +50478,9 @@ BI.FormulaEditor = BI.inherit(BI.Single, { _.forEach(line.markedSpans, function (i, ms) { switch (i.marker.className) { case "fieldName": + case "error-field": // 因为插入字段的时候首尾加了不可见字符,所以首尾缩进一个字符 - var dId = fieldMap[value.substr(i.from + 1, i.to - i.from - 2)]; + var dId = i.marker.value; if (!fields.contains(dId)) { fields.push(dId); } @@ -50485,6 +50499,7 @@ BI.FormulaEditor = BI.inherit(BI.Single, { switch (i.marker.className) { case "fieldName": + case "error-field": var fieldNameLength = i.to - i.from; value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length); num = num + 2 - fieldNameLength; @@ -50504,10 +50519,11 @@ BI.FormulaEditor = BI.inherit(BI.Single, { _.forEach(line.markedSpans, function (i, ms) { switch (i.marker.className) { case "fieldName": + case "error-field": var fieldNameLength = i.to - i.from; var start = i.from + num + 1; var end = fieldNameLength - 2; - var fieldId = fieldMap[value.substr(start, end)]; + var fieldId = i.marker.value; value = value.substr(0, i.from + num) + "$\{" + fieldId + "\}" + value.substr(i.to + num, value.length); num += fieldId.length - fieldNameLength + 3; break; diff --git a/dist/fineui.css b/dist/fineui.css index 1f0bd1e92..2e44640ec 100644 --- a/dist/fineui.css +++ b/dist/fineui.css @@ -2456,6 +2456,12 @@ li.CodeMirror-hint-active { background: #08f; color: white; } +.bi-formula-editor .error-field { + color: #ff4949; + padding: 0 5px; + margin: 1px 1px; + display: inline-block; +} .bi-message-title { font-size: 14px; cursor: pointer; diff --git a/dist/fineui.js b/dist/fineui.js index 9d3ed469b..6c59e5fb8 100644 --- a/dist/fineui.js +++ b/dist/fineui.js @@ -50547,7 +50547,10 @@ BI.FormulaEditor = BI.inherit(BI.Single, { value: "", fieldTextValueMap: {}, showHint: true, - lineHeight: 2 + lineHeight: 2, + paramFormatter: function (v) { + return v; + } }); }, _init: function () { @@ -50656,11 +50659,21 @@ BI.FormulaEditor = BI.inherit(BI.Single, { * @param field */ insertField: function (field) { + var value = this.options.fieldTextValueMap[field]; + var fieldId = this.options.paramFormatter(field); var from = this.editor.getCursor(); // 解决插入字段由括号或其他特殊字符包围时分裂的bug,在两端以不可见字符包裹一下 - this.editor.replaceSelection("\u200b" + field + "\u200b"); + var showName = fieldId.replaceAll(/^$/, function (str) { + return str.substring(2, str.length - 2); + }); + this.editor.replaceSelection("\u200b" + showName + "\u200b"); var to = this.editor.getCursor(); - this.editor.markText(from, to, {className: "fieldName", atomic: true, startStyle: "start", endStyle: "end"}); + var className = "fieldName"; + if (BI.isNotNull(fieldId.match(/^$/))) { + className = "error-field"; + } + this.editor.markText(from, to, {className: className, atomic: true, startStyle: "start", endStyle: "end", value: value}); + this.editor.replaceSelection(" "); this.editor.focus(); }, @@ -50708,8 +50721,9 @@ BI.FormulaEditor = BI.inherit(BI.Single, { _.forEach(line.markedSpans, function (i, ms) { switch (i.marker.className) { case "fieldName": + case "error-field": // 因为插入字段的时候首尾加了不可见字符,所以首尾缩进一个字符 - var dId = fieldMap[value.substr(i.from + 1, i.to - i.from - 2)]; + var dId = i.marker.value; if (!fields.contains(dId)) { fields.push(dId); } @@ -50728,6 +50742,7 @@ BI.FormulaEditor = BI.inherit(BI.Single, { switch (i.marker.className) { case "fieldName": + case "error-field": var fieldNameLength = i.to - i.from; value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length); num = num + 2 - fieldNameLength; @@ -50747,10 +50762,11 @@ BI.FormulaEditor = BI.inherit(BI.Single, { _.forEach(line.markedSpans, function (i, ms) { switch (i.marker.className) { case "fieldName": + case "error-field": var fieldNameLength = i.to - i.from; var start = i.from + num + 1; var end = fieldNameLength - 2; - var fieldId = fieldMap[value.substr(start, end)]; + var fieldId = i.marker.value; value = value.substr(0, i.from + num) + "$\{" + fieldId + "\}" + value.substr(i.to + num, value.length); num += fieldId.length - fieldNameLength + 3; break; diff --git a/dist/fineui.min.js b/dist/fineui.min.js index 0792d22e6..9f41e346b 100644 --- a/dist/fineui.min.js +++ b/dist/fineui.min.js @@ -65,7 +65,10 @@ BI.FormulaEditor = BI.inherit(BI.Single, { value: "", fieldTextValueMap: {}, showHint: true, - lineHeight: 2 + lineHeight: 2, + paramFormatter: function (v) { + return v; + } }); }, _init: function () { @@ -174,11 +177,21 @@ BI.FormulaEditor = BI.inherit(BI.Single, { * @param field */ insertField: function (field) { + var value = this.options.fieldTextValueMap[field]; + var fieldId = this.options.paramFormatter(field); var from = this.editor.getCursor(); // 解决插入字段由括号或其他特殊字符包围时分裂的bug,在两端以不可见字符包裹一下 - this.editor.replaceSelection("\u200b" + field + "\u200b"); + var showName = fieldId.replaceAll(/^$/, function (str) { + return str.substring(2, str.length - 2); + }); + this.editor.replaceSelection("\u200b" + showName + "\u200b"); var to = this.editor.getCursor(); - this.editor.markText(from, to, {className: "fieldName", atomic: true, startStyle: "start", endStyle: "end"}); + var className = "fieldName"; + if (BI.isNotNull(fieldId.match(/^$/))) { + className = "error-field"; + } + this.editor.markText(from, to, {className: className, atomic: true, startStyle: "start", endStyle: "end", value: value}); + this.editor.replaceSelection(" "); this.editor.focus(); }, @@ -226,8 +239,9 @@ BI.FormulaEditor = BI.inherit(BI.Single, { _.forEach(line.markedSpans, function (i, ms) { switch (i.marker.className) { case "fieldName": + case "error-field": // 因为插入字段的时候首尾加了不可见字符,所以首尾缩进一个字符 - var dId = fieldMap[value.substr(i.from + 1, i.to - i.from - 2)]; + var dId = i.marker.value; if (!fields.contains(dId)) { fields.push(dId); } @@ -246,6 +260,7 @@ BI.FormulaEditor = BI.inherit(BI.Single, { switch (i.marker.className) { case "fieldName": + case "error-field": var fieldNameLength = i.to - i.from; value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length); num = num + 2 - fieldNameLength; @@ -265,10 +280,11 @@ BI.FormulaEditor = BI.inherit(BI.Single, { _.forEach(line.markedSpans, function (i, ms) { switch (i.marker.className) { case "fieldName": + case "error-field": var fieldNameLength = i.to - i.from; var start = i.from + num + 1; var end = fieldNameLength - 2; - var fieldId = fieldMap[value.substr(start, end)]; + var fieldId = i.marker.value; value = value.substr(0, i.from + num) + "$\{" + fieldId + "\}" + value.substr(i.to + num, value.length); num += fieldId.length - fieldNameLength + 3; break; diff --git a/src/base/formula/formulaeditor.js b/src/base/formula/formulaeditor.js index 1c26f6e4c..0c71e2874 100644 --- a/src/base/formula/formulaeditor.js +++ b/src/base/formula/formulaeditor.js @@ -11,7 +11,10 @@ BI.FormulaEditor = BI.inherit(BI.Single, { value: "", fieldTextValueMap: {}, showHint: true, - lineHeight: 2 + lineHeight: 2, + paramFormatter: function (v) { + return v; + } }); }, _init: function () { @@ -120,11 +123,21 @@ BI.FormulaEditor = BI.inherit(BI.Single, { * @param field */ insertField: function (field) { + var value = this.options.fieldTextValueMap[field]; + var fieldId = this.options.paramFormatter(field); var from = this.editor.getCursor(); // 解决插入字段由括号或其他特殊字符包围时分裂的bug,在两端以不可见字符包裹一下 - this.editor.replaceSelection("\u200b" + field + "\u200b"); + var showName = fieldId.replaceAll(/^$/, function (str) { + return str.substring(2, str.length - 2); + }); + this.editor.replaceSelection("\u200b" + showName + "\u200b"); var to = this.editor.getCursor(); - this.editor.markText(from, to, {className: "fieldName", atomic: true, startStyle: "start", endStyle: "end"}); + var className = "fieldName"; + if (BI.isNotNull(fieldId.match(/^$/))) { + className = "error-field"; + } + this.editor.markText(from, to, {className: className, atomic: true, startStyle: "start", endStyle: "end", value: value}); + this.editor.replaceSelection(" "); this.editor.focus(); }, @@ -172,8 +185,9 @@ BI.FormulaEditor = BI.inherit(BI.Single, { _.forEach(line.markedSpans, function (i, ms) { switch (i.marker.className) { case "fieldName": + case "error-field": // 因为插入字段的时候首尾加了不可见字符,所以首尾缩进一个字符 - var dId = fieldMap[value.substr(i.from + 1, i.to - i.from - 2)]; + var dId = i.marker.value; if (!fields.contains(dId)) { fields.push(dId); } @@ -192,6 +206,7 @@ BI.FormulaEditor = BI.inherit(BI.Single, { switch (i.marker.className) { case "fieldName": + case "error-field": var fieldNameLength = i.to - i.from; value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length); num = num + 2 - fieldNameLength; @@ -211,10 +226,11 @@ BI.FormulaEditor = BI.inherit(BI.Single, { _.forEach(line.markedSpans, function (i, ms) { switch (i.marker.className) { case "fieldName": + case "error-field": var fieldNameLength = i.to - i.from; var start = i.from + num + 1; var end = fieldNameLength - 2; - var fieldId = fieldMap[value.substr(start, end)]; + var fieldId = i.marker.value; value = value.substr(0, i.from + num) + "$\{" + fieldId + "\}" + value.substr(i.to + num, value.length); num += fieldId.length - fieldNameLength + 3; break; diff --git a/src/css/base/formula/formulaeditor.css b/src/css/base/formula/formulaeditor.css new file mode 100644 index 000000000..6dfe219ff --- /dev/null +++ b/src/css/base/formula/formulaeditor.css @@ -0,0 +1,6 @@ +.bi-formula-editor .error-field { + color: #ff4949; + padding: 0 5px; + margin: 1px 1px; + display: inline-block; +} diff --git a/src/less/base/formula/formulaeditor.less b/src/less/base/formula/formulaeditor.less new file mode 100644 index 000000000..34f0f6793 --- /dev/null +++ b/src/less/base/formula/formulaeditor.less @@ -0,0 +1,10 @@ +@import "../../index"; + +.bi-formula-editor { + & .error-field { + color: @color-bi-text-failure; + padding: 0 5px; + margin: 1px 1px; + display: inline-block; + } +}