Browse Source

给codeeditor添加paramformatter接口,是的可以自定义参数显示值

es6
windy 7 years ago
parent
commit
e86a53bbf1
  1. 14
      bi/base.js
  2. 14
      docs/base.js
  3. 14
      src/base/single/editor/editor.code.js

14
bi/base.js

@ -17727,7 +17727,11 @@ BI.CodeEditor = BI.inherit(BI.Single, {
value: '', value: '',
watermark: "", watermark: "",
lineHeight: 2, lineHeight: 2,
readOnly: false readOnly: false,
//参数显示值构造函数
paramFormatter: function (v) {
return v;
}
}); });
}, },
_init: function () { _init: function () {
@ -17811,6 +17815,8 @@ BI.CodeEditor = BI.inherit(BI.Single, {
}, },
insertParam: function (param) { insertParam: function (param) {
var value = param;
param = this.options.paramFormatter(param);
var from = this.editor.getCursor(); var from = this.editor.getCursor();
this.editor.replaceSelection(param); this.editor.replaceSelection(param);
var to = this.editor.getCursor(); var to = this.editor.getCursor();
@ -17818,6 +17824,7 @@ BI.CodeEditor = BI.inherit(BI.Single, {
if (BI.isNotNull(param.match(/^<!.*!>$/))) { if (BI.isNotNull(param.match(/^<!.*!>$/))) {
options.className = 'error-param'; options.className = 'error-param';
} }
options.value = value;
this.editor.markText(from, to, options); this.editor.markText(from, to, options);
this.editor.replaceSelection(" "); this.editor.replaceSelection(" ");
this.editor.focus(); this.editor.focus();
@ -17837,8 +17844,11 @@ BI.CodeEditor = BI.inherit(BI.Single, {
case "param": case "param":
case "error-param": case "error-param":
var fieldNameLength = i.to - i.from; var fieldNameLength = i.to - i.from;
value = value.substr(0, i.from + num) + "$\{" + value.substr(i.from + num, fieldNameLength) + "\}" + value.substr(i.to + num, value.length); value = value.substr(0, i.from + num) + "$\{" + i.marker.value + "\}" + value.substr(i.to + num, value.length);
//加上${}的偏移
num += 3; num += 3;
//加上实际值和显示值的长度差的偏移
num += (i.marker.value.length - fieldNameLength);
break; break;
} }
}); });

14
docs/base.js

@ -17727,7 +17727,11 @@ BI.CodeEditor = BI.inherit(BI.Single, {
value: '', value: '',
watermark: "", watermark: "",
lineHeight: 2, lineHeight: 2,
readOnly: false readOnly: false,
//参数显示值构造函数
paramFormatter: function (v) {
return v;
}
}); });
}, },
_init: function () { _init: function () {
@ -17811,6 +17815,8 @@ BI.CodeEditor = BI.inherit(BI.Single, {
}, },
insertParam: function (param) { insertParam: function (param) {
var value = param;
param = this.options.paramFormatter(param);
var from = this.editor.getCursor(); var from = this.editor.getCursor();
this.editor.replaceSelection(param); this.editor.replaceSelection(param);
var to = this.editor.getCursor(); var to = this.editor.getCursor();
@ -17818,6 +17824,7 @@ BI.CodeEditor = BI.inherit(BI.Single, {
if (BI.isNotNull(param.match(/^<!.*!>$/))) { if (BI.isNotNull(param.match(/^<!.*!>$/))) {
options.className = 'error-param'; options.className = 'error-param';
} }
options.value = value;
this.editor.markText(from, to, options); this.editor.markText(from, to, options);
this.editor.replaceSelection(" "); this.editor.replaceSelection(" ");
this.editor.focus(); this.editor.focus();
@ -17837,8 +17844,11 @@ BI.CodeEditor = BI.inherit(BI.Single, {
case "param": case "param":
case "error-param": case "error-param":
var fieldNameLength = i.to - i.from; var fieldNameLength = i.to - i.from;
value = value.substr(0, i.from + num) + "$\{" + value.substr(i.from + num, fieldNameLength) + "\}" + value.substr(i.to + num, value.length); value = value.substr(0, i.from + num) + "$\{" + i.marker.value + "\}" + value.substr(i.to + num, value.length);
//加上${}的偏移
num += 3; num += 3;
//加上实际值和显示值的长度差的偏移
num += (i.marker.value.length - fieldNameLength);
break; break;
} }
}); });

14
src/base/single/editor/editor.code.js

@ -11,7 +11,11 @@ BI.CodeEditor = BI.inherit(BI.Single, {
value: '', value: '',
watermark: "", watermark: "",
lineHeight: 2, lineHeight: 2,
readOnly: false readOnly: false,
//参数显示值构造函数
paramFormatter: function (v) {
return v;
}
}); });
}, },
_init: function () { _init: function () {
@ -95,6 +99,8 @@ BI.CodeEditor = BI.inherit(BI.Single, {
}, },
insertParam: function (param) { insertParam: function (param) {
var value = param;
param = this.options.paramFormatter(param);
var from = this.editor.getCursor(); var from = this.editor.getCursor();
this.editor.replaceSelection(param); this.editor.replaceSelection(param);
var to = this.editor.getCursor(); var to = this.editor.getCursor();
@ -102,6 +108,7 @@ BI.CodeEditor = BI.inherit(BI.Single, {
if (BI.isNotNull(param.match(/^<!.*!>$/))) { if (BI.isNotNull(param.match(/^<!.*!>$/))) {
options.className = 'error-param'; options.className = 'error-param';
} }
options.value = value;
this.editor.markText(from, to, options); this.editor.markText(from, to, options);
this.editor.replaceSelection(" "); this.editor.replaceSelection(" ");
this.editor.focus(); this.editor.focus();
@ -121,8 +128,11 @@ BI.CodeEditor = BI.inherit(BI.Single, {
case "param": case "param":
case "error-param": case "error-param":
var fieldNameLength = i.to - i.from; var fieldNameLength = i.to - i.from;
value = value.substr(0, i.from + num) + "$\{" + value.substr(i.from + num, fieldNameLength) + "\}" + value.substr(i.to + num, value.length); value = value.substr(0, i.from + num) + "$\{" + i.marker.value + "\}" + value.substr(i.to + num, value.length);
//加上${}的偏移
num += 3; num += 3;
//加上实际值和显示值的长度差的偏移
num += (i.marker.value.length - fieldNameLength);
break; break;
} }
}); });

Loading…
Cancel
Save