Browse Source

待解决 formatter

es6
刘荣歆 7 years ago
parent
commit
ded7298afb
  1. 111
      bi/widget.js
  2. 8
      demo/js/config/widget.js
  3. 73
      docs/demo.js
  4. 111
      docs/widget.js

111
bi/widget.js

@ -14523,6 +14523,117 @@ BI.SwitchTree.SelectType = {
};
BI.shortcut('bi.switch_tree', BI.SwitchTree);
/**
* Created by dailer on 2017/7/18.
* 数值微调器练习
*/
BI.FineTuningNumberEditor = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.FineTuningNumberEditor.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-fine-tuning-number-editor bi-border",
value: 0,
disabled: false,
min: 0,
max: 100,
step: 1,
formatter: BI.emptyFn,
parser: BI.emptyFn
})
},
_init: function () {
BI.FineTuningNumberEditor.superclass._init.apply(this, arguments);
var self = this,
o = this.options;
this.formatter = o.formatter;
this.step = this.options.step;
console.log(this.options.value);
this.editor = BI.createWidget({
type: "bi.sign_editor",
value: o.value,
errorText: BI.i18nText("BI-Please_Input_Natural_Number"),
// validationChecker: function (v) {
// // return BI.isNaturalNumber(v);
// }
});
this.editor.on(BI.TextEditor.EVENT_CONFIRM, function () {
self._finetuning(1);
self.fireEvent(BI.FineTuningNumberEditor.EVENT_CONFIRM);
});
this.topBtn = BI.createWidget({
type: "bi.icon_button",
trigger: "lclick,",
cls: "column-pre-page-h-font top-button bi-border-left bi-border-bottom",
handler: function () {
self._finetuning(1);
self.fireEvent(BI.FineTuningNumberEditor.EVENT_CONFIRM);
}
});
this.bottomBtn = BI.createWidget({
type: "bi.icon_button",
trigger: "lclick,",
cls: "column-next-page-h-font bottom-button bi-border-left bi-border-top",
handler: function () {
self._finetuning(-1);
self.fireEvent(BI.FineTuningNumberEditor.EVENT_CONFIRM);
}
});
this._finetuning(0);
BI.createWidget({
type: "bi.htape",
element: this,
items: [this.editor, {
el: {
type: "bi.grid",
columns: 1,
rows: 2,
items: [{
column: 0,
row: 0,
el: this.topBtn
}, {
column: 0,
row: 1,
el: this.bottomBtn
}]
},
width: 30
}]
});
},
//微调
_finetuning: function (add) {
//窝是在不值该如何处理精度损失问题,所以迫不得已采取了这个方法
var v = BI.parseFloat(this.editor.getValue()) * 1000000000000;
var addend = add * this.step * 1000000000000;
var result = (v + addend) / 1000000000000;
console.log(this.options.formatter.toString());
this.editor.setValue(this.formatter(result));
},
getMinAndMax: function () {},
getStep: function () {},
getValue: function () {},
setStep: function (step) {
this.step = step || this.step;
},
setValue: function (v) {}
});
BI.FineTuningNumberEditor.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.shortcut("bi.test_editor", BI.FineTuningNumberEditor);/**
* 年份下拉框
*
* Created by GUY on 2015/8/28.

8
demo/js/config/widget.js

@ -181,11 +181,11 @@ Demo.WIDGET_CONFIG = [{
pId: 412,
text: "bi.year_month_combo",
value: "demo.year_month_combo"
},{
}, {
pId: 412,
text: "bi.year_quarter_combo",
value: "demo.year_quarter_combo"
},{
}, {
pId: 4,
id: 413,
text: "简单下拉树"
@ -249,5 +249,9 @@ Demo.WIDGET_CONFIG = [{
pId: 418,
text: "bi.dialog",
value: "demo.dialog"
}, {
id: 7,
text: '数值微调器',
value: "demo.test_editor"
}
];

73
docs/demo.js

@ -3520,11 +3520,11 @@ Demo.COMPONENT_CONFIG = [{
pId: 412,
text: "bi.year_month_combo",
value: "demo.year_month_combo"
},{
}, {
pId: 412,
text: "bi.year_quarter_combo",
value: "demo.year_quarter_combo"
},{
}, {
pId: 4,
id: 413,
text: "简单下拉树"
@ -3588,6 +3588,10 @@ Demo.COMPONENT_CONFIG = [{
pId: 418,
text: "bi.dialog",
value: "demo.dialog"
}, {
id: 7,
text: '数值微调器',
value: "demo.test_editor"
}
];Demo.Func = BI.inherit(BI.Widget, {
props: {
@ -9299,6 +9303,71 @@ BI.shortcut("demo.responsive_table", Demo.Func);Demo.Func = BI.inherit(BI.Widget
}
});
BI.shortcut("demo.sequence_table", Demo.Func);/**
* Created by Dailer on 2017/7/18.
*/
Demo.TestEditor = BI.inherit(BI.Widget, {
props: {
baseCls: ""
},
render: function () {
var editor = BI.createWidget({
type: "bi.sign_editor",
cls: "bi-border",
formatter: function (v) {
return 20;
},
width: 90,
height: 28,
});
var test = BI.createWidget({
type: "bi.test_editor",
value: 12,
width: 90,
height: 28,
step: 0.1
});
var enable = 1;
return {
type: "bi.vertical",
items: [{
el: test
}, {
type: "bi.left",
items: [{
el: editor
}, {
type: "bi.button",
text: "设置step",
width: 90,
height: 28,
handler: function () {
test.setStep(editor.getValue());
BI.Msg.toast("设置成功")
}
}, {
type: "bi.button",
text: "toggle disabled",
height: 28,
handler: function () {
enable *= -1;
test.setEnable(Boolean(1 + enable));
BI.Msg.toast("设置成功")
},
lgap: 20
}]
},
],
vgap: 20,
hgap: 10
}
}
})
BI.shortcut("demo.test_editor", Demo.TestEditor);/**
* Created by Dailer on 2017/7/13.
*/
Demo.TimeInterval = BI.inherit(BI.Widget, {

111
docs/widget.js

@ -14523,6 +14523,117 @@ BI.SwitchTree.SelectType = {
};
BI.shortcut('bi.switch_tree', BI.SwitchTree);
/**
* Created by dailer on 2017/7/18.
* 数值微调器练习
*/
BI.FineTuningNumberEditor = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.FineTuningNumberEditor.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-fine-tuning-number-editor bi-border",
value: 0,
disabled: false,
min: 0,
max: 100,
step: 1,
formatter: BI.emptyFn,
parser: BI.emptyFn
})
},
_init: function () {
BI.FineTuningNumberEditor.superclass._init.apply(this, arguments);
var self = this,
o = this.options;
this.formatter = o.formatter;
this.step = this.options.step;
console.log(this.options.value);
this.editor = BI.createWidget({
type: "bi.sign_editor",
value: o.value,
errorText: BI.i18nText("BI-Please_Input_Natural_Number"),
// validationChecker: function (v) {
// // return BI.isNaturalNumber(v);
// }
});
this.editor.on(BI.TextEditor.EVENT_CONFIRM, function () {
self._finetuning(1);
self.fireEvent(BI.FineTuningNumberEditor.EVENT_CONFIRM);
});
this.topBtn = BI.createWidget({
type: "bi.icon_button",
trigger: "lclick,",
cls: "column-pre-page-h-font top-button bi-border-left bi-border-bottom",
handler: function () {
self._finetuning(1);
self.fireEvent(BI.FineTuningNumberEditor.EVENT_CONFIRM);
}
});
this.bottomBtn = BI.createWidget({
type: "bi.icon_button",
trigger: "lclick,",
cls: "column-next-page-h-font bottom-button bi-border-left bi-border-top",
handler: function () {
self._finetuning(-1);
self.fireEvent(BI.FineTuningNumberEditor.EVENT_CONFIRM);
}
});
this._finetuning(0);
BI.createWidget({
type: "bi.htape",
element: this,
items: [this.editor, {
el: {
type: "bi.grid",
columns: 1,
rows: 2,
items: [{
column: 0,
row: 0,
el: this.topBtn
}, {
column: 0,
row: 1,
el: this.bottomBtn
}]
},
width: 30
}]
});
},
//微调
_finetuning: function (add) {
//窝是在不值该如何处理精度损失问题,所以迫不得已采取了这个方法
var v = BI.parseFloat(this.editor.getValue()) * 1000000000000;
var addend = add * this.step * 1000000000000;
var result = (v + addend) / 1000000000000;
console.log(this.options.formatter.toString());
this.editor.setValue(this.formatter(result));
},
getMinAndMax: function () {},
getStep: function () {},
getValue: function () {},
setStep: function (step) {
this.step = step || this.step;
},
setValue: function (v) {}
});
BI.FineTuningNumberEditor.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.shortcut("bi.test_editor", BI.FineTuningNumberEditor);/**
* 年份下拉框
*
* Created by GUY on 2015/8/28.

Loading…
Cancel
Save