Browse Source

slider 添加显示位数

master
Urthur 7 years ago
parent
commit
5f3c505fd0
  1. 15
      bi/slider.js
  2. 5
      demo/js/widget/slider/demo.slider.js
  3. 5
      dist/demo.js
  4. 15
      dist/slider.js
  5. 15
      src/addons/slider/singleslider/singleslider.js

15
bi/slider.js

@ -45,13 +45,14 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
}, },
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.SingleSlider.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.SingleSlider.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-single-slider bi-slider-track" baseCls: "bi-single-slider bi-slider-track",
digit: 3
}); });
}, },
_init: function () { _init: function () {
BI.SingleSlider.superclass._init.apply(this, arguments); BI.SingleSlider.superclass._init.apply(this, arguments);
var self = this; var self = this, o = this.options;
var c = this._constant; var c = this._constant;
this.enable = false; this.enable = false;
this.value = ""; this.value = "";
@ -80,9 +81,10 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
var significantPercent = BI.parseFloat(percent.toFixed(1));//直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 var significantPercent = BI.parseFloat(percent.toFixed(1));//直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。
self._setBlueTrack(significantPercent); self._setBlueTrack(significantPercent);
self._setLabelPosition(significantPercent); self._setLabelPosition(significantPercent);
var v = self._getValueByPercent(significantPercent); var v = self._getValueByPercent(significantPercent).toFixed(o.digit);
self.label.setValue(v); self.label.setValue(v);
self.value = v; self.value = v;
self.fireEvent(BI.SingleSlider.EVENT_CHANGE);
}, },
stop: function (e, ui) { stop: function (e, ui) {
var percent = (ui.position.left) * 100 / (self._getGrayTrackLength()); var percent = (ui.position.left) * 100 / (self._getGrayTrackLength());
@ -116,7 +118,7 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
} }
var significantPercent = BI.parseFloat(percent.toFixed(1)); var significantPercent = BI.parseFloat(percent.toFixed(1));
self._setAllPosition(significantPercent); self._setAllPosition(significantPercent);
var v = self._getValueByPercent(significantPercent); var v = self._getValueByPercent(significantPercent).toFixed(o.digit);
self.label.setValue(v); self.label.setValue(v);
self.value = v; self.value = v;
self.fireEvent(BI.SingleSlider.EVENT_CHANGE); self.fireEvent(BI.SingleSlider.EVENT_CHANGE);
@ -138,7 +140,8 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
}); });
this.label.on(BI.SignEditor.EVENT_CONFIRM, function () { this.label.on(BI.SignEditor.EVENT_CONFIRM, function () {
var v = BI.parseFloat(this.getValue()); var v = BI.parseFloat(this.getValue());
self.value = v; this.setValue(v.toFixed(o.digit));
self.value = v.toFixed(o.digit);
var percent = self._getPercentByValue(v); var percent = self._getPercentByValue(v);
var significantPercent = BI.parseFloat(percent.toFixed(1)); var significantPercent = BI.parseFloat(percent.toFixed(1));
self._setAllPosition(significantPercent); self._setAllPosition(significantPercent);
@ -262,7 +265,9 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
}, },
setValue: function (v) { setValue: function (v) {
var o = this.options;
var value = BI.parseFloat(v); var value = BI.parseFloat(v);
value = value.toFixed(o.digit);
if ((!isNaN(value))) { if ((!isNaN(value))) {
if (this._checkValidation(value)) { if (this._checkValidation(value)) {
this.value = value; this.value = value;

5
demo/js/widget/slider/demo.slider.js

@ -14,6 +14,7 @@ Demo.Slider = BI.inherit(BI.Widget, {
var singleSlider = BI.createWidget({ var singleSlider = BI.createWidget({
type: "bi.single_slider", type: "bi.single_slider",
digit: 0,
width: 300, width: 300,
height: 50 height: 50
}); });
@ -23,7 +24,11 @@ Demo.Slider = BI.inherit(BI.Widget, {
max: 100 max: 100
}); });
singleSlider.setValue(30);
singleSlider.populate(); singleSlider.populate();
singleSlider.on(BI.SingleSlider.EVENT_CHANGE, function () {
console.log(this.getValue());
});
var normalSingleSlider = BI.createWidget({ var normalSingleSlider = BI.createWidget({
type: "bi.single_slider_normal", type: "bi.single_slider_normal",

5
dist/demo.js vendored

@ -8448,6 +8448,7 @@ Demo.Slider = BI.inherit(BI.Widget, {
var singleSlider = BI.createWidget({ var singleSlider = BI.createWidget({
type: "bi.single_slider", type: "bi.single_slider",
digit: 0,
width: 300, width: 300,
height: 50 height: 50
}); });
@ -8457,7 +8458,11 @@ Demo.Slider = BI.inherit(BI.Widget, {
max: 100 max: 100
}); });
singleSlider.setValue(30);
singleSlider.populate(); singleSlider.populate();
singleSlider.on(BI.SingleSlider.EVENT_CHANGE, function () {
console.log(this.getValue());
});
var normalSingleSlider = BI.createWidget({ var normalSingleSlider = BI.createWidget({
type: "bi.single_slider_normal", type: "bi.single_slider_normal",

15
dist/slider.js vendored

@ -45,13 +45,14 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
}, },
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.SingleSlider.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.SingleSlider.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-single-slider bi-slider-track" baseCls: "bi-single-slider bi-slider-track",
digit: 3
}); });
}, },
_init: function () { _init: function () {
BI.SingleSlider.superclass._init.apply(this, arguments); BI.SingleSlider.superclass._init.apply(this, arguments);
var self = this; var self = this, o = this.options;
var c = this._constant; var c = this._constant;
this.enable = false; this.enable = false;
this.value = ""; this.value = "";
@ -80,9 +81,10 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
var significantPercent = BI.parseFloat(percent.toFixed(1));//直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 var significantPercent = BI.parseFloat(percent.toFixed(1));//直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。
self._setBlueTrack(significantPercent); self._setBlueTrack(significantPercent);
self._setLabelPosition(significantPercent); self._setLabelPosition(significantPercent);
var v = self._getValueByPercent(significantPercent); var v = self._getValueByPercent(significantPercent).toFixed(o.digit);
self.label.setValue(v); self.label.setValue(v);
self.value = v; self.value = v;
self.fireEvent(BI.SingleSlider.EVENT_CHANGE);
}, },
stop: function (e, ui) { stop: function (e, ui) {
var percent = (ui.position.left) * 100 / (self._getGrayTrackLength()); var percent = (ui.position.left) * 100 / (self._getGrayTrackLength());
@ -116,7 +118,7 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
} }
var significantPercent = BI.parseFloat(percent.toFixed(1)); var significantPercent = BI.parseFloat(percent.toFixed(1));
self._setAllPosition(significantPercent); self._setAllPosition(significantPercent);
var v = self._getValueByPercent(significantPercent); var v = self._getValueByPercent(significantPercent).toFixed(o.digit);
self.label.setValue(v); self.label.setValue(v);
self.value = v; self.value = v;
self.fireEvent(BI.SingleSlider.EVENT_CHANGE); self.fireEvent(BI.SingleSlider.EVENT_CHANGE);
@ -138,7 +140,8 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
}); });
this.label.on(BI.SignEditor.EVENT_CONFIRM, function () { this.label.on(BI.SignEditor.EVENT_CONFIRM, function () {
var v = BI.parseFloat(this.getValue()); var v = BI.parseFloat(this.getValue());
self.value = v; this.setValue(v.toFixed(o.digit));
self.value = v.toFixed(o.digit);
var percent = self._getPercentByValue(v); var percent = self._getPercentByValue(v);
var significantPercent = BI.parseFloat(percent.toFixed(1)); var significantPercent = BI.parseFloat(percent.toFixed(1));
self._setAllPosition(significantPercent); self._setAllPosition(significantPercent);
@ -262,7 +265,9 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
}, },
setValue: function (v) { setValue: function (v) {
var o = this.options;
var value = BI.parseFloat(v); var value = BI.parseFloat(v);
value = value.toFixed(o.digit);
if ((!isNaN(value))) { if ((!isNaN(value))) {
if (this._checkValidation(value)) { if (this._checkValidation(value)) {
this.value = value; this.value = value;

15
src/addons/slider/singleslider/singleslider.js

@ -13,13 +13,14 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
}, },
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.SingleSlider.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.SingleSlider.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-single-slider bi-slider-track" baseCls: "bi-single-slider bi-slider-track",
digit: 3
}); });
}, },
_init: function () { _init: function () {
BI.SingleSlider.superclass._init.apply(this, arguments); BI.SingleSlider.superclass._init.apply(this, arguments);
var self = this; var self = this, o = this.options;
var c = this._constant; var c = this._constant;
this.enable = false; this.enable = false;
this.value = ""; this.value = "";
@ -48,9 +49,10 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
var significantPercent = BI.parseFloat(percent.toFixed(1));//直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 var significantPercent = BI.parseFloat(percent.toFixed(1));//直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。
self._setBlueTrack(significantPercent); self._setBlueTrack(significantPercent);
self._setLabelPosition(significantPercent); self._setLabelPosition(significantPercent);
var v = self._getValueByPercent(significantPercent); var v = self._getValueByPercent(significantPercent).toFixed(o.digit);
self.label.setValue(v); self.label.setValue(v);
self.value = v; self.value = v;
self.fireEvent(BI.SingleSlider.EVENT_CHANGE);
}, },
stop: function (e, ui) { stop: function (e, ui) {
var percent = (ui.position.left) * 100 / (self._getGrayTrackLength()); var percent = (ui.position.left) * 100 / (self._getGrayTrackLength());
@ -84,7 +86,7 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
} }
var significantPercent = BI.parseFloat(percent.toFixed(1)); var significantPercent = BI.parseFloat(percent.toFixed(1));
self._setAllPosition(significantPercent); self._setAllPosition(significantPercent);
var v = self._getValueByPercent(significantPercent); var v = self._getValueByPercent(significantPercent).toFixed(o.digit);
self.label.setValue(v); self.label.setValue(v);
self.value = v; self.value = v;
self.fireEvent(BI.SingleSlider.EVENT_CHANGE); self.fireEvent(BI.SingleSlider.EVENT_CHANGE);
@ -106,7 +108,8 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
}); });
this.label.on(BI.SignEditor.EVENT_CONFIRM, function () { this.label.on(BI.SignEditor.EVENT_CONFIRM, function () {
var v = BI.parseFloat(this.getValue()); var v = BI.parseFloat(this.getValue());
self.value = v; this.setValue(v.toFixed(o.digit));
self.value = v.toFixed(o.digit);
var percent = self._getPercentByValue(v); var percent = self._getPercentByValue(v);
var significantPercent = BI.parseFloat(percent.toFixed(1)); var significantPercent = BI.parseFloat(percent.toFixed(1));
self._setAllPosition(significantPercent); self._setAllPosition(significantPercent);
@ -230,7 +233,9 @@ BI.SingleSlider = BI.inherit(BI.Widget, {
}, },
setValue: function (v) { setValue: function (v) {
var o = this.options;
var value = BI.parseFloat(v); var value = BI.parseFloat(v);
value = value.toFixed(o.digit);
if ((!isNaN(value))) { if ((!isNaN(value))) {
if (this._checkValidation(value)) { if (this._checkValidation(value)) {
this.value = value; this.value = value;

Loading…
Cancel
Save