Browse Source

update

master
iapyang 7 years ago
parent
commit
5ceea134de
  1. 6
      dist/base.css
  2. 31
      dist/base.js
  3. 6
      dist/bundle.css
  4. 31
      dist/bundle.js
  5. 2
      dist/bundle.min.css
  6. 70
      dist/bundle.min.js
  7. 6
      dist/fineui.css
  8. 31
      dist/fineui.js
  9. 2
      dist/fineui.min.css
  10. 31
      dist/fineui.min.js
  11. 31
      src/base/formula/formulaeditor.js
  12. 6
      src/css/base/formula/formulaeditor.css
  13. 10
      src/less/base/formula/formulaeditor.less

6
dist/base.css vendored

@ -700,6 +700,12 @@ li.CodeMirror-hint-active {
background: #08f; background: #08f;
color: white; color: white;
} }
.bi-formula-editor .error-field {
color: #ff4949;
padding: 0 5px;
margin: 1px 1px;
display: inline-block;
}
.bi-message-title { .bi-message-title {
font-size: 14px; font-size: 14px;
cursor: pointer; cursor: pointer;

31
dist/base.js vendored

@ -14534,7 +14534,10 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
value: "", value: "",
fieldTextValueMap: {}, fieldTextValueMap: {},
showHint: true, showHint: true,
lineHeight: 2 lineHeight: 2,
paramFormatter: function (v) {
return v;
}
}); });
}, },
_init: function () { _init: function () {
@ -14568,10 +14571,6 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
self.fireEvent(BI.FormulaEditor.EVENT_BLUR); self.fireEvent(BI.FormulaEditor.EVENT_BLUR);
}); });
this.editor.on("keyup", function (cm, keyboard) {
self.fireEvent(BI.FormulaEditor.EVENT_KEY_UP, keyboard.key);
});
if (BI.isKey(this.options.watermark)) { if (BI.isKey(this.options.watermark)) {
var self = this; var self = this;
this.watermark = BI.createWidget({ this.watermark = BI.createWidget({
@ -14643,11 +14642,21 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
* @param field * @param field
*/ */
insertField: function (field) { insertField: function (field) {
var value = this.options.fieldTextValueMap[field];
var fieldId = this.options.paramFormatter(field);
var from = this.editor.getCursor(); var from = this.editor.getCursor();
// 解决插入字段由括号或其他特殊字符包围时分裂的bug,在两端以不可见字符包裹一下 // 解决插入字段由括号或其他特殊字符包围时分裂的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(); 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(); this.editor.focus();
}, },
@ -14695,8 +14704,9 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
_.forEach(line.markedSpans, function (i, ms) { _.forEach(line.markedSpans, function (i, ms) {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": 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)) { if (!fields.contains(dId)) {
fields.push(dId); fields.push(dId);
} }
@ -14715,6 +14725,7 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": case "fieldName":
case "error-field":
var fieldNameLength = i.to - i.from; var fieldNameLength = i.to - i.from;
value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length); value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length);
num = num + 2 - fieldNameLength; num = num + 2 - fieldNameLength;
@ -14734,10 +14745,11 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
_.forEach(line.markedSpans, function (i, ms) { _.forEach(line.markedSpans, function (i, ms) {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": case "fieldName":
case "error-field":
var fieldNameLength = i.to - i.from; var fieldNameLength = i.to - i.from;
var start = i.from + num + 1; var start = i.from + num + 1;
var end = fieldNameLength - 2; 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); value = value.substr(0, i.from + num) + "$\{" + fieldId + "\}" + value.substr(i.to + num, value.length);
num += fieldId.length - fieldNameLength + 3; num += fieldId.length - fieldNameLength + 3;
break; break;
@ -14767,7 +14779,6 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
BI.FormulaEditor.EVENT_CHANGE = "EVENT_CHANGE"; BI.FormulaEditor.EVENT_CHANGE = "EVENT_CHANGE";
BI.FormulaEditor.EVENT_BLUR = "EVENT_BLUR"; BI.FormulaEditor.EVENT_BLUR = "EVENT_BLUR";
BI.FormulaEditor.EVENT_FOCUS = "EVENT_FOCUS"; BI.FormulaEditor.EVENT_FOCUS = "EVENT_FOCUS";
BI.FormulaEditor.EVENT_KEY_UP = "EVENT_KEY_UP";
BI.shortcut("bi.formula_editor", BI.FormulaEditor); BI.shortcut("bi.formula_editor", BI.FormulaEditor);
/** /**
* z-index在1亿层级 * z-index在1亿层级

6
dist/bundle.css vendored

@ -2407,6 +2407,12 @@ li.CodeMirror-hint-active {
background: #08f; background: #08f;
color: white; color: white;
} }
.bi-formula-editor .error-field {
color: #ff4949;
padding: 0 5px;
margin: 1px 1px;
display: inline-block;
}
.bi-message-title { .bi-message-title {
font-size: 14px; font-size: 14px;
cursor: pointer; cursor: pointer;

31
dist/bundle.js vendored

@ -50304,7 +50304,10 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
value: "", value: "",
fieldTextValueMap: {}, fieldTextValueMap: {},
showHint: true, showHint: true,
lineHeight: 2 lineHeight: 2,
paramFormatter: function (v) {
return v;
}
}); });
}, },
_init: function () { _init: function () {
@ -50338,10 +50341,6 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
self.fireEvent(BI.FormulaEditor.EVENT_BLUR); self.fireEvent(BI.FormulaEditor.EVENT_BLUR);
}); });
this.editor.on("keyup", function (cm, keyboard) {
self.fireEvent(BI.FormulaEditor.EVENT_KEY_UP, keyboard.key);
});
if (BI.isKey(this.options.watermark)) { if (BI.isKey(this.options.watermark)) {
var self = this; var self = this;
this.watermark = BI.createWidget({ this.watermark = BI.createWidget({
@ -50413,11 +50412,21 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
* @param field * @param field
*/ */
insertField: function (field) { insertField: function (field) {
var value = this.options.fieldTextValueMap[field];
var fieldId = this.options.paramFormatter(field);
var from = this.editor.getCursor(); var from = this.editor.getCursor();
// 解决插入字段由括号或其他特殊字符包围时分裂的bug,在两端以不可见字符包裹一下 // 解决插入字段由括号或其他特殊字符包围时分裂的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(); 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(); this.editor.focus();
}, },
@ -50465,8 +50474,9 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
_.forEach(line.markedSpans, function (i, ms) { _.forEach(line.markedSpans, function (i, ms) {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": 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)) { if (!fields.contains(dId)) {
fields.push(dId); fields.push(dId);
} }
@ -50485,6 +50495,7 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": case "fieldName":
case "error-field":
var fieldNameLength = i.to - i.from; var fieldNameLength = i.to - i.from;
value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length); value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length);
num = num + 2 - fieldNameLength; num = num + 2 - fieldNameLength;
@ -50504,10 +50515,11 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
_.forEach(line.markedSpans, function (i, ms) { _.forEach(line.markedSpans, function (i, ms) {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": case "fieldName":
case "error-field":
var fieldNameLength = i.to - i.from; var fieldNameLength = i.to - i.from;
var start = i.from + num + 1; var start = i.from + num + 1;
var end = fieldNameLength - 2; 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); value = value.substr(0, i.from + num) + "$\{" + fieldId + "\}" + value.substr(i.to + num, value.length);
num += fieldId.length - fieldNameLength + 3; num += fieldId.length - fieldNameLength + 3;
break; break;
@ -50537,7 +50549,6 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
BI.FormulaEditor.EVENT_CHANGE = "EVENT_CHANGE"; BI.FormulaEditor.EVENT_CHANGE = "EVENT_CHANGE";
BI.FormulaEditor.EVENT_BLUR = "EVENT_BLUR"; BI.FormulaEditor.EVENT_BLUR = "EVENT_BLUR";
BI.FormulaEditor.EVENT_FOCUS = "EVENT_FOCUS"; BI.FormulaEditor.EVENT_FOCUS = "EVENT_FOCUS";
BI.FormulaEditor.EVENT_KEY_UP = "EVENT_KEY_UP";
BI.shortcut("bi.formula_editor", BI.FormulaEditor); BI.shortcut("bi.formula_editor", BI.FormulaEditor);
/** /**
* z-index在1亿层级 * z-index在1亿层级

2
dist/bundle.min.css vendored

File diff suppressed because one or more lines are too long

70
dist/bundle.min.js vendored

File diff suppressed because one or more lines are too long

6
dist/fineui.css vendored

@ -2407,6 +2407,12 @@ li.CodeMirror-hint-active {
background: #08f; background: #08f;
color: white; color: white;
} }
.bi-formula-editor .error-field {
color: #ff4949;
padding: 0 5px;
margin: 1px 1px;
display: inline-block;
}
.bi-message-title { .bi-message-title {
font-size: 14px; font-size: 14px;
cursor: pointer; cursor: pointer;

31
dist/fineui.js vendored

@ -50547,7 +50547,10 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
value: "", value: "",
fieldTextValueMap: {}, fieldTextValueMap: {},
showHint: true, showHint: true,
lineHeight: 2 lineHeight: 2,
paramFormatter: function (v) {
return v;
}
}); });
}, },
_init: function () { _init: function () {
@ -50581,10 +50584,6 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
self.fireEvent(BI.FormulaEditor.EVENT_BLUR); self.fireEvent(BI.FormulaEditor.EVENT_BLUR);
}); });
this.editor.on("keyup", function (cm, keyboard) {
self.fireEvent(BI.FormulaEditor.EVENT_KEY_UP, keyboard.key);
});
if (BI.isKey(this.options.watermark)) { if (BI.isKey(this.options.watermark)) {
var self = this; var self = this;
this.watermark = BI.createWidget({ this.watermark = BI.createWidget({
@ -50656,11 +50655,21 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
* @param field * @param field
*/ */
insertField: function (field) { insertField: function (field) {
var value = this.options.fieldTextValueMap[field];
var fieldId = this.options.paramFormatter(field);
var from = this.editor.getCursor(); var from = this.editor.getCursor();
// 解决插入字段由括号或其他特殊字符包围时分裂的bug,在两端以不可见字符包裹一下 // 解决插入字段由括号或其他特殊字符包围时分裂的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(); 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(); this.editor.focus();
}, },
@ -50708,8 +50717,9 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
_.forEach(line.markedSpans, function (i, ms) { _.forEach(line.markedSpans, function (i, ms) {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": 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)) { if (!fields.contains(dId)) {
fields.push(dId); fields.push(dId);
} }
@ -50728,6 +50738,7 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": case "fieldName":
case "error-field":
var fieldNameLength = i.to - i.from; var fieldNameLength = i.to - i.from;
value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length); value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length);
num = num + 2 - fieldNameLength; num = num + 2 - fieldNameLength;
@ -50747,10 +50758,11 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
_.forEach(line.markedSpans, function (i, ms) { _.forEach(line.markedSpans, function (i, ms) {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": case "fieldName":
case "error-field":
var fieldNameLength = i.to - i.from; var fieldNameLength = i.to - i.from;
var start = i.from + num + 1; var start = i.from + num + 1;
var end = fieldNameLength - 2; 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); value = value.substr(0, i.from + num) + "$\{" + fieldId + "\}" + value.substr(i.to + num, value.length);
num += fieldId.length - fieldNameLength + 3; num += fieldId.length - fieldNameLength + 3;
break; break;
@ -50780,7 +50792,6 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
BI.FormulaEditor.EVENT_CHANGE = "EVENT_CHANGE"; BI.FormulaEditor.EVENT_CHANGE = "EVENT_CHANGE";
BI.FormulaEditor.EVENT_BLUR = "EVENT_BLUR"; BI.FormulaEditor.EVENT_BLUR = "EVENT_BLUR";
BI.FormulaEditor.EVENT_FOCUS = "EVENT_FOCUS"; BI.FormulaEditor.EVENT_FOCUS = "EVENT_FOCUS";
BI.FormulaEditor.EVENT_KEY_UP = "EVENT_KEY_UP";
BI.shortcut("bi.formula_editor", BI.FormulaEditor); BI.shortcut("bi.formula_editor", BI.FormulaEditor);
/** /**
* z-index在1亿层级 * z-index在1亿层级

2
dist/fineui.min.css vendored

File diff suppressed because one or more lines are too long

31
dist/fineui.min.js vendored

@ -65,7 +65,10 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
value: "", value: "",
fieldTextValueMap: {}, fieldTextValueMap: {},
showHint: true, showHint: true,
lineHeight: 2 lineHeight: 2,
paramFormatter: function (v) {
return v;
}
}); });
}, },
_init: function () { _init: function () {
@ -99,10 +102,6 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
self.fireEvent(BI.FormulaEditor.EVENT_BLUR); self.fireEvent(BI.FormulaEditor.EVENT_BLUR);
}); });
this.editor.on("keyup", function (cm, keyboard) {
self.fireEvent(BI.FormulaEditor.EVENT_KEY_UP, keyboard.key);
});
if (BI.isKey(this.options.watermark)) { if (BI.isKey(this.options.watermark)) {
var self = this; var self = this;
this.watermark = BI.createWidget({ this.watermark = BI.createWidget({
@ -174,11 +173,21 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
* @param field * @param field
*/ */
insertField: function (field) { insertField: function (field) {
var value = this.options.fieldTextValueMap[field];
var fieldId = this.options.paramFormatter(field);
var from = this.editor.getCursor(); var from = this.editor.getCursor();
// 解决插入字段由括号或其他特殊字符包围时分裂的bug,在两端以不可见字符包裹一下 // 解决插入字段由括号或其他特殊字符包围时分裂的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(); 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(); this.editor.focus();
}, },
@ -226,8 +235,9 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
_.forEach(line.markedSpans, function (i, ms) { _.forEach(line.markedSpans, function (i, ms) {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": 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)) { if (!fields.contains(dId)) {
fields.push(dId); fields.push(dId);
} }
@ -246,6 +256,7 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": case "fieldName":
case "error-field":
var fieldNameLength = i.to - i.from; var fieldNameLength = i.to - i.from;
value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length); value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length);
num = num + 2 - fieldNameLength; num = num + 2 - fieldNameLength;
@ -265,10 +276,11 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
_.forEach(line.markedSpans, function (i, ms) { _.forEach(line.markedSpans, function (i, ms) {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": case "fieldName":
case "error-field":
var fieldNameLength = i.to - i.from; var fieldNameLength = i.to - i.from;
var start = i.from + num + 1; var start = i.from + num + 1;
var end = fieldNameLength - 2; 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); value = value.substr(0, i.from + num) + "$\{" + fieldId + "\}" + value.substr(i.to + num, value.length);
num += fieldId.length - fieldNameLength + 3; num += fieldId.length - fieldNameLength + 3;
break; break;
@ -298,5 +310,4 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
BI.FormulaEditor.EVENT_CHANGE = "EVENT_CHANGE"; BI.FormulaEditor.EVENT_CHANGE = "EVENT_CHANGE";
BI.FormulaEditor.EVENT_BLUR = "EVENT_BLUR"; BI.FormulaEditor.EVENT_BLUR = "EVENT_BLUR";
BI.FormulaEditor.EVENT_FOCUS = "EVENT_FOCUS"; BI.FormulaEditor.EVENT_FOCUS = "EVENT_FOCUS";
BI.FormulaEditor.EVENT_KEY_UP = "EVENT_KEY_UP";
BI.shortcut("bi.formula_editor", BI.FormulaEditor); BI.shortcut("bi.formula_editor", BI.FormulaEditor);

31
src/base/formula/formulaeditor.js

@ -11,7 +11,10 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
value: "", value: "",
fieldTextValueMap: {}, fieldTextValueMap: {},
showHint: true, showHint: true,
lineHeight: 2 lineHeight: 2,
paramFormatter: function (v) {
return v;
}
}); });
}, },
_init: function () { _init: function () {
@ -45,10 +48,6 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
self.fireEvent(BI.FormulaEditor.EVENT_BLUR); self.fireEvent(BI.FormulaEditor.EVENT_BLUR);
}); });
this.editor.on("keyup", function (cm, keyboard) {
self.fireEvent(BI.FormulaEditor.EVENT_KEY_UP, keyboard.key);
});
if (BI.isKey(this.options.watermark)) { if (BI.isKey(this.options.watermark)) {
var self = this; var self = this;
this.watermark = BI.createWidget({ this.watermark = BI.createWidget({
@ -120,11 +119,21 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
* @param field * @param field
*/ */
insertField: function (field) { insertField: function (field) {
var value = this.options.fieldTextValueMap[field];
var fieldId = this.options.paramFormatter(field);
var from = this.editor.getCursor(); var from = this.editor.getCursor();
// 解决插入字段由括号或其他特殊字符包围时分裂的bug,在两端以不可见字符包裹一下 // 解决插入字段由括号或其他特殊字符包围时分裂的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(); 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(); this.editor.focus();
}, },
@ -172,8 +181,9 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
_.forEach(line.markedSpans, function (i, ms) { _.forEach(line.markedSpans, function (i, ms) {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": 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)) { if (!fields.contains(dId)) {
fields.push(dId); fields.push(dId);
} }
@ -192,6 +202,7 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": case "fieldName":
case "error-field":
var fieldNameLength = i.to - i.from; var fieldNameLength = i.to - i.from;
value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length); value = value.substr(0, i.from + num) + "$a" + value.substr(i.to + num, value.length);
num = num + 2 - fieldNameLength; num = num + 2 - fieldNameLength;
@ -211,10 +222,11 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
_.forEach(line.markedSpans, function (i, ms) { _.forEach(line.markedSpans, function (i, ms) {
switch (i.marker.className) { switch (i.marker.className) {
case "fieldName": case "fieldName":
case "error-field":
var fieldNameLength = i.to - i.from; var fieldNameLength = i.to - i.from;
var start = i.from + num + 1; var start = i.from + num + 1;
var end = fieldNameLength - 2; 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); value = value.substr(0, i.from + num) + "$\{" + fieldId + "\}" + value.substr(i.to + num, value.length);
num += fieldId.length - fieldNameLength + 3; num += fieldId.length - fieldNameLength + 3;
break; break;
@ -244,5 +256,4 @@ BI.FormulaEditor = BI.inherit(BI.Single, {
BI.FormulaEditor.EVENT_CHANGE = "EVENT_CHANGE"; BI.FormulaEditor.EVENT_CHANGE = "EVENT_CHANGE";
BI.FormulaEditor.EVENT_BLUR = "EVENT_BLUR"; BI.FormulaEditor.EVENT_BLUR = "EVENT_BLUR";
BI.FormulaEditor.EVENT_FOCUS = "EVENT_FOCUS"; BI.FormulaEditor.EVENT_FOCUS = "EVENT_FOCUS";
BI.FormulaEditor.EVENT_KEY_UP = "EVENT_KEY_UP";
BI.shortcut("bi.formula_editor", BI.FormulaEditor); BI.shortcut("bi.formula_editor", BI.FormulaEditor);

6
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;
}

10
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;
}
}
Loading…
Cancel
Save