Zhenfei.Li
2 years ago
12 changed files with 598 additions and 541 deletions
@ -0,0 +1,3 @@ |
|||||||
|
export { LazyLoader } from "./loader.lazy"; |
||||||
|
export { ListLoader } from "./loader.list"; |
||||||
|
export { SortList } from "./sort.list"; |
@ -1,103 +1,106 @@ |
|||||||
/** |
import { shortcut, Widget, extend, createWidget, takeRight, take } from "@/core"; |
||||||
* Created by roy on 15/11/6. |
import { Loader } from "@/base"; |
||||||
*/ |
|
||||||
BI.LazyLoader = BI.inherit(BI.Widget, { |
@shortcut() |
||||||
_const: { |
export class LazyLoader extends Widget { |
||||||
PAGE: 100 |
static xtype = "bi.lazy_loader" |
||||||
}, |
|
||||||
_defaultConfig: function () { |
_const = { |
||||||
return BI.extend(BI.LazyLoader.superclass._defaultConfig.apply(this, arguments), { |
PAGE: 100, |
||||||
|
}; |
||||||
|
|
||||||
|
static EVENT_CHANGE = "EVENT_CHANGE" |
||||||
|
|
||||||
|
_defaultConfig() { |
||||||
|
return extend(super._defaultConfig(...arguments), { |
||||||
baseCls: "bi-lazy-loader", |
baseCls: "bi-lazy-loader", |
||||||
el: {}, |
el: {}, |
||||||
items: [] |
items: [], |
||||||
}); |
}); |
||||||
}, |
} |
||||||
|
|
||||||
_init: function () { |
_init() { |
||||||
var self = this, o = this.options; |
const o = this.options; |
||||||
BI.LazyLoader.superclass._init.apply(this, arguments); |
super._init(...arguments); |
||||||
var all = o.items.length; |
const all = o.items.length; |
||||||
this.loader = BI.createWidget({ |
this.loader = createWidget({ |
||||||
type: "bi.loader", |
type: "bi.loader", |
||||||
element: this, |
element: this, |
||||||
// 下面是button_group的属性
|
// 下面是button_group的属性
|
||||||
el: o.el, |
el: o.el, |
||||||
|
itemsCreator: (options, populate) => { |
||||||
itemsCreator: function (options, populate) { |
populate(this._getNextItems(options)); |
||||||
populate(self._getNextItems(options)); |
|
||||||
}, |
}, |
||||||
hasNext: function (option) { |
hasNext: option => option.count < all, |
||||||
return option.count < all; |
|
||||||
} |
|
||||||
}); |
}); |
||||||
|
|
||||||
this.loader.on(BI.Loader.EVENT_CHANGE, function (obj) { |
this.loader.on(Loader.EVENT_CHANGE, obj => { |
||||||
self.fireEvent(BI.LazyLoader.EVENT_CHANGE, obj); |
this.fireEvent(LazyLoader.EVENT_CHANGE, obj); |
||||||
}); |
}); |
||||||
}, |
} |
||||||
_getNextItems: function (options) { |
|
||||||
var self = this, o = this.options; |
_getNextItems(options) { |
||||||
var lastNum = o.items.length - this._const.PAGE * (options.times - 1); |
const o = this.options; |
||||||
var lastItems = BI.takeRight(o.items, lastNum); |
const lastNum = o.items.length - this._const.PAGE * (options.times - 1); |
||||||
var nextItems = BI.take(lastItems, this._const.PAGE); |
const lastItems = takeRight(o.items, lastNum); |
||||||
|
const nextItems = take(lastItems, this._const.PAGE); |
||||||
|
|
||||||
return nextItems; |
return nextItems; |
||||||
}, |
} |
||||||
|
|
||||||
populate: function (items) { |
populate(items) { |
||||||
this.loader.populate(items); |
this.loader.populate(items); |
||||||
}, |
} |
||||||
|
|
||||||
addItems: function (items) { |
addItems(items) { |
||||||
this.loader.addItems(items); |
this.loader.addItems(items); |
||||||
}, |
} |
||||||
|
|
||||||
empty: function () { |
empty() { |
||||||
this.loader.empty(); |
this.loader.empty(); |
||||||
}, |
} |
||||||
|
|
||||||
setNotSelectedValue: function () { |
setNotSelectedValue() { |
||||||
this.loader.setNotSelectedValue.apply(this.loader, arguments); |
this.loader.setNotSelectedValue(...arguments); |
||||||
}, |
} |
||||||
|
|
||||||
getNotSelectedValue: function () { |
getNotSelectedValue() { |
||||||
return this.loader.getNotSelectedValue(); |
return this.loader.getNotSelectedValue(); |
||||||
}, |
} |
||||||
|
|
||||||
setValue: function () { |
setValue() { |
||||||
this.loader.setValue.apply(this.loader, arguments); |
this.loader.setValue(...arguments); |
||||||
}, |
} |
||||||
|
|
||||||
getValue: function () { |
getValue() { |
||||||
return this.loader.getValue.apply(this.loader, arguments); |
return this.loader.getValue(...arguments); |
||||||
}, |
} |
||||||
|
|
||||||
getAllButtons: function () { |
getAllButtons() { |
||||||
return this.loader.getAllButtons(); |
return this.loader.getAllButtons(); |
||||||
}, |
} |
||||||
|
|
||||||
getAllLeaves: function () { |
getAllLeaves() { |
||||||
return this.loader.getAllLeaves(); |
return this.loader.getAllLeaves(); |
||||||
}, |
} |
||||||
|
|
||||||
getSelectedButtons: function () { |
getSelectedButtons() { |
||||||
return this.loader.getSelectedButtons(); |
return this.loader.getSelectedButtons(); |
||||||
}, |
} |
||||||
|
|
||||||
getNotSelectedButtons: function () { |
getNotSelectedButtons() { |
||||||
return this.loader.getNotSelectedButtons(); |
return this.loader.getNotSelectedButtons(); |
||||||
}, |
} |
||||||
|
|
||||||
getIndexByValue: function (value) { |
getIndexByValue(value) { |
||||||
return this.loader.getIndexByValue(value); |
return this.loader.getIndexByValue(value); |
||||||
}, |
} |
||||||
|
|
||||||
getNodeById: function (id) { |
getNodeById(id) { |
||||||
return this.loader.getNodeById(id); |
return this.loader.getNodeById(id); |
||||||
}, |
} |
||||||
|
|
||||||
getNodeByValue: function (value) { |
getNodeByValue(value) { |
||||||
return this.loader.getNodeByValue(value); |
return this.loader.getNodeByValue(value); |
||||||
} |
} |
||||||
}); |
} |
||||||
BI.LazyLoader.EVENT_CHANGE = "EVENT_CHANGE"; |
|
||||||
BI.shortcut("bi.lazy_loader", BI.LazyLoader); |
|
||||||
|
@ -1,43 +1,48 @@ |
|||||||
|
import { shortcut, extend, createWidget } from "@/core"; |
||||||
|
import { BasicButton } from "@/base"; |
||||||
|
|
||||||
/** |
/** |
||||||
* 分段控件使用的button |
* 分段控件使用的button |
||||||
* |
* |
||||||
* Created by GUY on 2015/9/7. |
* Created by GUY on 2015/9/7. |
||||||
* @class BI.SegmentButton |
* @class SegmentButton |
||||||
* @extends BI.BasicButton |
* @extends BasicButton |
||||||
*/ |
*/ |
||||||
BI.SegmentButton = BI.inherit(BI.BasicButton, { |
@shortcut() |
||||||
|
export class SegmentButton extends BasicButton { |
||||||
|
static xtype = "bi.segment_button" |
||||||
|
|
||||||
|
_defaultConfig() { |
||||||
|
const conf = super._defaultConfig(...arguments); |
||||||
|
|
||||||
_defaultConfig: function () { |
return extend(conf, { |
||||||
var conf = BI.SegmentButton.superclass._defaultConfig.apply(this, arguments); |
baseCls: `${conf.baseCls || ""} bi-segment-button bi-list-item-select bi-card`, |
||||||
return BI.extend(conf, { |
|
||||||
baseCls: (conf.baseCls || "") + " bi-segment-button bi-list-item-select bi-card", |
|
||||||
shadow: true, |
shadow: true, |
||||||
readonly: true, |
readonly: true, |
||||||
hgap: 5 |
hgap: 5, |
||||||
}); |
}); |
||||||
}, |
} |
||||||
|
|
||||||
_init: function () { |
_init() { |
||||||
BI.SegmentButton.superclass._init.apply(this, arguments); |
super._init(...arguments); |
||||||
var opts = this.options, self = this; |
const opts = this.options; |
||||||
this.text = BI.createWidget({ |
this.text = createWidget({ |
||||||
type: "bi.label", |
type: "bi.label", |
||||||
element: this, |
element: this, |
||||||
textHeight: opts.height, |
textHeight: opts.height, |
||||||
whiteSpace: opts.whiteSpace, |
whiteSpace: opts.whiteSpace, |
||||||
text: opts.text, |
text: opts.text, |
||||||
value: opts.value, |
value: opts.value, |
||||||
hgap: opts.hgap |
hgap: opts.hgap, |
||||||
}); |
}); |
||||||
}, |
} |
||||||
|
|
||||||
setSelected: function () { |
setSelected() { |
||||||
BI.SegmentButton.superclass.setSelected.apply(this, arguments); |
super.setSelected(...arguments); |
||||||
}, |
} |
||||||
|
|
||||||
setText: function (text) { |
setText(text) { |
||||||
BI.SegmentButton.superclass.setText.apply(this, arguments); |
super.setText(...arguments); |
||||||
this.text.setText(text); |
this.text.setText(text); |
||||||
} |
} |
||||||
}); |
} |
||||||
BI.shortcut("bi.segment_button", BI.SegmentButton); |
|
||||||
|
@ -0,0 +1,2 @@ |
|||||||
|
export { SegmentButton } from "./button.segment"; |
||||||
|
export { Segment } from "./segment"; |
@ -1,72 +1,79 @@ |
|||||||
|
import { shortcut, Widget, extend, toPix, Controller, createWidget, createItems, makeArrayByArray } from "@/core"; |
||||||
|
import { ButtonGroup } from "@/base"; |
||||||
|
|
||||||
/** |
/** |
||||||
* 单选按钮组 |
* 单选按钮组 |
||||||
* |
* |
||||||
* Created by GUY on 2015/9/7. |
* Created by GUY on 2015/9/7. |
||||||
* @class BI.Segment |
* @class Segment |
||||||
* @extends BI.Widget |
* @extends Widget |
||||||
*/ |
*/ |
||||||
BI.Segment = BI.inherit(BI.Widget, { |
@shortcut() |
||||||
_defaultConfig: function () { |
export class Segment extends Widget { |
||||||
return BI.extend(BI.Segment.superclass._defaultConfig.apply(this, arguments), { |
static xtype = "bi.segment" |
||||||
|
|
||||||
|
static EVENT_CHANGE = "EVENT_CHANGE" |
||||||
|
|
||||||
|
_defaultConfig() { |
||||||
|
return extend(super._defaultConfig(...arguments), { |
||||||
baseCls: "bi-segment", |
baseCls: "bi-segment", |
||||||
items: [], |
items: [], |
||||||
height: 24, |
height: 24, |
||||||
}); |
}); |
||||||
}, |
} |
||||||
_init: function () { |
|
||||||
BI.Segment.superclass._init.apply(this, arguments); |
_init() { |
||||||
var self = this, o = this.options; |
super._init(...arguments); |
||||||
this.buttonGroup = BI.createWidget({ |
const o = this.options; |
||||||
|
this.buttonGroup = createWidget({ |
||||||
element: this, |
element: this, |
||||||
type: "bi.button_group", |
type: "bi.button_group", |
||||||
value: o.value, |
value: o.value, |
||||||
items: [BI.createItems(o.items, { |
items: [createItems(o.items, { |
||||||
type: "bi.segment_button", |
type: "bi.segment_button", |
||||||
height: BI.toPix(o.height, 2), |
height: toPix(o.height, 2), |
||||||
whiteSpace: o.whiteSpace, |
whiteSpace: o.whiteSpace, |
||||||
})], |
})], |
||||||
layouts: [{ |
layouts: [{ |
||||||
type: "bi.table", |
type: "bi.table", |
||||||
columnSize: BI.makeArrayByArray(o.items, "fill"), |
columnSize: makeArrayByArray(o.items, "fill"), |
||||||
}], |
}], |
||||||
}); |
}); |
||||||
this.buttonGroup.on(BI.Controller.EVENT_CHANGE, function () { |
this.buttonGroup.on(Controller.EVENT_CHANGE, (...args) => { |
||||||
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); |
this.fireEvent(Controller.EVENT_CHANGE, ...args); |
||||||
}); |
}); |
||||||
this.buttonGroup.on(BI.ButtonGroup.EVENT_CHANGE, function (value, obj) { |
this.buttonGroup.on(ButtonGroup.EVENT_CHANGE, (value, obj) => { |
||||||
self.fireEvent(BI.Segment.EVENT_CHANGE, value, obj); |
this.fireEvent(Segment.EVENT_CHANGE, value, obj); |
||||||
}); |
}); |
||||||
}, |
} |
||||||
|
|
||||||
_setEnable: function (enable) { |
_setEnable(enable) { |
||||||
BI.Segment.superclass._setEnable.apply(this, arguments); |
super._setEnable(...arguments); |
||||||
if (enable === true) { |
if (enable === true) { |
||||||
this.element.removeClass("base-disabled disabled"); |
this.element.removeClass("base-disabled disabled"); |
||||||
} else if (enable === false) { |
} else if (enable === false) { |
||||||
this.element.addClass("base-disabled disabled"); |
this.element.addClass("base-disabled disabled"); |
||||||
} |
} |
||||||
}, |
} |
||||||
|
|
||||||
setValue: function (v) { |
setValue(v) { |
||||||
this.buttonGroup.setValue(v); |
this.buttonGroup.setValue(v); |
||||||
}, |
} |
||||||
|
|
||||||
setEnabledValue: function (v) { |
setEnabledValue(v) { |
||||||
this.buttonGroup.setEnabledValue(v); |
this.buttonGroup.setEnabledValue(v); |
||||||
}, |
} |
||||||
|
|
||||||
getValue: function () { |
getValue() { |
||||||
return this.buttonGroup.getValue(); |
return this.buttonGroup.getValue(); |
||||||
}, |
} |
||||||
|
|
||||||
populate: function (buttons) { |
populate(buttons) { |
||||||
var o = this.options; |
const o = this.options; |
||||||
this.buttonGroup.populate([BI.createItems(buttons, { |
this.buttonGroup.populate([createItems(buttons, { |
||||||
type: "bi.segment_button", |
type: "bi.segment_button", |
||||||
height: BI.toPix(o.height, 2), |
height: toPix(o.height, 2), |
||||||
whiteSpace: o.whiteSpace, |
whiteSpace: o.whiteSpace, |
||||||
})]); |
})]); |
||||||
}, |
} |
||||||
}); |
} |
||||||
BI.Segment.EVENT_CHANGE = "EVENT_CHANGE"; |
|
||||||
BI.shortcut("bi.segment", BI.Segment); |
|
||||||
|
Loading…
Reference in new issue