Browse Source

Merge pull request #165810 in DEC/fineui from master to feature/x

* commit '549b0b95a124a773895334294b24f5b0e0c1ef91':
  KERNEL-12705 feat: bi.number_editor 功能优化, 自定义输入的format, debounce移除
master
superman 2 years ago
parent
commit
3f803eb000
  1. 49
      demo/js/widget/numbereditor/demo.number_editor.js
  2. 5
      src/base/single/button/button.basic.js
  3. 11
      src/widget/numbereditor/number.editor.js

49
demo/js/widget/numbereditor/demo.number_editor.js

@ -7,7 +7,7 @@ Demo.FileManager = BI.inherit(BI.Widget, {
}, },
render: function () { render: function () {
var editor = BI.createWidget({ var editor1 = BI.createWidget({
type: "bi.number_editor", type: "bi.number_editor",
validationChecker: function (v) { validationChecker: function (v) {
return BI.parseFloat(v) <= 100 && BI.parseFloat(v) >= 0; return BI.parseFloat(v) <= 100 && BI.parseFloat(v) >= 0;
@ -16,21 +16,50 @@ Demo.FileManager = BI.inherit(BI.Widget, {
width: 150, width: 150,
errorText: "hahah" errorText: "hahah"
}); });
editor.on(BI.NumberEditor.EVENT_CHANGE, function () { editor1.on(BI.NumberEditor.EVENT_CHANGE, function () {
if (BI.parseFloat(this.getValue()) < 1) { if (BI.parseFloat(this.getValue()) < 1) {
editor.setDownEnable(false); editor1.setDownEnable(false);
} else { } else {
editor.setDownEnable(true); editor1.setDownEnable(true);
} }
BI.Msg.toast(editor.getValue()); BI.Msg.toast(editor1.getValue());
}); });
var editor2 = BI.createWidget({
type: "bi.number_editor",
validationChecker: function (v) {
return BI.parseFloat(v) <= 100 && BI.parseFloat(v) >= 0;
},
valueFormatter: (v) => `${v}$`,
valueParser: (v) => v.replace(/\$\s?|(,*)/g, ''),
height: 24,
width: 150,
errorText: "hahah"
});
editor2.on(BI.NumberEditor.EVENT_CHANGE, function () {
if (BI.parseFloat(this.getValue()) < 1) {
editor2.setDownEnable(false);
} else {
editor2.setDownEnable(true);
}
BI.Msg.toast(editor2.getValue());
});
return { return {
type: "bi.vertical", type: "bi.vertical",
items: [{ hgap: 20,
el: editor, vgap: 20,
height: 24 items: [
}] {
el: editor1,
height: 24
}, {
el: editor2,
height: 24
}
]
}; };
} }
}); });
BI.shortcut("demo.number_editor", Demo.FileManager); BI.shortcut("demo.number_editor", Demo.FileManager);

5
src/base/single/button/button.basic.js

@ -26,6 +26,7 @@ BI.BasicButton = BI.inherit(BI.Single, {
trigger: null, trigger: null,
handler: BI.emptyFn, handler: BI.emptyFn,
bubble: null, bubble: null,
debounce: true
}); });
}, },
@ -222,10 +223,10 @@ BI.BasicButton = BI.inherit(BI.Single, {
}); });
// 之后的300ms点击无效 // 之后的300ms点击无效
var onClick = BI.debounce(this._doClick, BI.EVENT_RESPONSE_TIME, { var onClick = o.debounce ? BI.debounce(this._doClick, BI.EVENT_RESPONSE_TIME, {
"leading": true, "leading": true,
"trailing": false, "trailing": false,
}); }) : this._doClick;
function ev(e) { function ev(e) {
if (o.stopEvent) { if (o.stopEvent) {

11
src/widget/numbereditor/number.editor.js

@ -10,6 +10,9 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
valueFormatter: function (v) { valueFormatter: function (v) {
return v; return v;
}, },
valueParser: function (v) {
return v;
},
value: 0, value: 0,
allowBlank: false, allowBlank: false,
errorText: "", errorText: "",
@ -38,6 +41,10 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
errorText: o.errorText errorText: o.errorText
}); });
this.editor.on(BI.TextEditor.EVENT_CHANGE, function () { this.editor.on(BI.TextEditor.EVENT_CHANGE, function () {
// 大多数时候valueFormatter往往需要配合valueParser一起使用
var value = this.getValue();
var parsedValue = o.valueParser(value);
this.setValue(o.valueFormatter(parsedValue));
self.fireEvent(BI.NumberEditor.EVENT_CHANGE); self.fireEvent(BI.NumberEditor.EVENT_CHANGE);
}); });
this.editor.on(BI.TextEditor.EVENT_ERROR, function () { this.editor.on(BI.TextEditor.EVENT_ERROR, function () {
@ -57,6 +64,7 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
type: "bi.icon_button", type: "bi.icon_button",
forceNotSelected: true, forceNotSelected: true,
trigger: "lclick,", trigger: "lclick,",
debounce: false,
cls: (o.simple ? "solid-triangle-top-font " : "add-up-font bi-border-left ") + "top-button bi-list-item-active2 icon-size-12" cls: (o.simple ? "solid-triangle-top-font " : "add-up-font bi-border-left ") + "top-button bi-list-item-active2 icon-size-12"
}); });
this.topBtn.on(BI.IconButton.EVENT_CHANGE, function () { this.topBtn.on(BI.IconButton.EVENT_CHANGE, function () {
@ -68,6 +76,7 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
type: "bi.icon_button", type: "bi.icon_button",
trigger: "lclick,", trigger: "lclick,",
forceNotSelected: true, forceNotSelected: true,
debounce: false,
cls: (o.simple ? "solid-triangle-bottom-font " : "minus-down-font bi-border-left ") + "bottom-button bi-list-item-active2 icon-size-12" cls: (o.simple ? "solid-triangle-bottom-font " : "minus-down-font bi-border-left ") + "bottom-button bi-list-item-active2 icon-size-12"
}); });
this.bottomBtn.on(BI.IconButton.EVENT_CHANGE, function () { this.bottomBtn.on(BI.IconButton.EVENT_CHANGE, function () {
@ -154,4 +163,4 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
}); });
BI.NumberEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; BI.NumberEditor.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.NumberEditor.EVENT_CHANGE = "EVENT_CHANGE"; BI.NumberEditor.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.number_editor", BI.NumberEditor); BI.shortcut("bi.number_editor", BI.NumberEditor);

Loading…
Cancel
Save