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. 45
      demo/js/widget/numbereditor/demo.number_editor.js
  2. 5
      src/base/single/button/button.basic.js
  3. 9
      src/widget/numbereditor/number.editor.js

45
demo/js/widget/numbereditor/demo.number_editor.js

@ -7,7 +7,7 @@ Demo.FileManager = BI.inherit(BI.Widget, {
},
render: function () {
var editor = BI.createWidget({
var editor1 = BI.createWidget({
type: "bi.number_editor",
validationChecker: function (v) {
return BI.parseFloat(v) <= 100 && BI.parseFloat(v) >= 0;
@ -16,20 +16,49 @@ Demo.FileManager = BI.inherit(BI.Widget, {
width: 150,
errorText: "hahah"
});
editor.on(BI.NumberEditor.EVENT_CHANGE, function () {
editor1.on(BI.NumberEditor.EVENT_CHANGE, function () {
if (BI.parseFloat(this.getValue()) < 1) {
editor.setDownEnable(false);
editor1.setDownEnable(false);
} 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 {
type: "bi.vertical",
items: [{
el: editor,
hgap: 20,
vgap: 20,
items: [
{
el: editor1,
height: 24
}]
}, {
el: editor2,
height: 24
}
]
};
}
});

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

@ -26,6 +26,7 @@ BI.BasicButton = BI.inherit(BI.Single, {
trigger: null,
handler: BI.emptyFn,
bubble: null,
debounce: true
});
},
@ -222,10 +223,10 @@ BI.BasicButton = BI.inherit(BI.Single, {
});
// 之后的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,
"trailing": false,
});
}) : this._doClick;
function ev(e) {
if (o.stopEvent) {

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

@ -10,6 +10,9 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
valueFormatter: function (v) {
return v;
},
valueParser: function (v) {
return v;
},
value: 0,
allowBlank: false,
errorText: "",
@ -38,6 +41,10 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
errorText: o.errorText
});
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);
});
this.editor.on(BI.TextEditor.EVENT_ERROR, function () {
@ -57,6 +64,7 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
type: "bi.icon_button",
forceNotSelected: true,
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"
});
this.topBtn.on(BI.IconButton.EVENT_CHANGE, function () {
@ -68,6 +76,7 @@ BI.NumberEditor = BI.inherit(BI.Widget, {
type: "bi.icon_button",
trigger: "lclick,",
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"
});
this.bottomBtn.on(BI.IconButton.EVENT_CHANGE, function () {

Loading…
Cancel
Save