Browse Source

feature: 选中数据支持分页

es6
guy 2 years ago
parent
commit
f2a57ad403
  1. 25
      src/widget/multiselect/multiselect.loader.js
  2. 23
      src/widget/multiselect/multiselect.loader.nobar.js

25
src/widget/multiselect/multiselect.loader.js

@ -18,7 +18,7 @@ BI.MultiSelectLoader = BI.inherit(BI.Widget, {
valueFormatter: BI.emptyFn, valueFormatter: BI.emptyFn,
itemsCreator: BI.emptyFn, itemsCreator: BI.emptyFn,
onLoaded: BI.emptyFn, onLoaded: BI.emptyFn,
itemHeight: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, itemHeight: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT
}); });
}, },
@ -64,15 +64,13 @@ BI.MultiSelectLoader = BI.inherit(BI.Widget, {
}, opts.el), }, opts.el),
itemsCreator: function (op, callback) { itemsCreator: function (op, callback) {
var startValue = self._startValue; var startValue = self._startValue;
var firstItems = [];
self.storeValue && (op = BI.extend(op || {}, { self.storeValue && (op = BI.extend(op || {}, {
selectedValues: BI.isKey(startValue) && self.storeValue.type === BI.Selection.Multi selectedValues: BI.isKey(startValue) && self.storeValue.type === BI.Selection.Multi
? self.storeValue.value.concat(startValue) : self.storeValue.value ? self.storeValue.value.concat(startValue) : self.storeValue.value
})); }));
opts.itemsCreator(op, function (ob) { if (self.storeValue) {
hasNext = ob.hasNext; var json = BI.map(self.storeValue.value.slice((op.times - 1) * 10, op.times * 10), function (i, v) {
var firstItems = [];
if (op.times === 1 && self.storeValue) {
var json = BI.map(self.storeValue.value, function (i, v) {
var txt = opts.valueFormatter(v) || v; var txt = opts.valueFormatter(v) || v;
return { return {
text: txt, text: txt,
@ -81,6 +79,7 @@ BI.MultiSelectLoader = BI.inherit(BI.Widget, {
selected: self.storeValue.type === BI.Selection.Multi selected: self.storeValue.type === BI.Selection.Multi
}; };
}); });
if (op.times === 1) {
if (BI.isKey(self._startValue) && !BI.contains(self.storeValue.value, self._startValue)) { if (BI.isKey(self._startValue) && !BI.contains(self.storeValue.value, self._startValue)) {
var txt = opts.valueFormatter(startValue) || startValue; var txt = opts.valueFormatter(startValue) || startValue;
json.unshift({ json.unshift({
@ -90,10 +89,22 @@ BI.MultiSelectLoader = BI.inherit(BI.Widget, {
selected: true selected: true
}); });
} }
}
if (op.times < Math.floor((self.storeValue.value.length - 1) / 10)) {
hasNext = true;
callback(self._createItems(json), op.keyword || "");
(op.times === 1) && self._scrollToTop();
return;
}
firstItems = self._createItems(json); firstItems = self._createItems(json);
} }
var times = op.times - Math.max(0, Math.floor((self.storeValue.value.length - 1) / 10));
opts.itemsCreator(BI.extend({}, op, {
times: times
}), function (ob) {
hasNext = ob.hasNext;
callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || ""); callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || "");
if (op.times === 1 && self.storeValue) { if (times === 1 && self.storeValue) {
BI.isKey(startValue) && (self.storeValue.type === BI.Selection.All ? BI.remove(self.storeValue.value, startValue) : BI.pushDistinct(self.storeValue.value, startValue)); BI.isKey(startValue) && (self.storeValue.type === BI.Selection.All ? BI.remove(self.storeValue.value, startValue) : BI.pushDistinct(self.storeValue.value, startValue));
self.setValue(self.storeValue); self.setValue(self.storeValue);
} }

23
src/widget/multiselect/multiselect.loader.nobar.js

@ -55,15 +55,13 @@ BI.MultiSelectNoBarLoader = BI.inherit(BI.Widget, {
}, },
itemsCreator: function (op, callback) { itemsCreator: function (op, callback) {
var startValue = self._startValue; var startValue = self._startValue;
var firstItems = [];
self.storeValue && (op = BI.extend(op || {}, { self.storeValue && (op = BI.extend(op || {}, {
selectedValues: BI.isKey(startValue) && self.storeValue.type === BI.Selection.Multi selectedValues: BI.isKey(startValue) && self.storeValue.type === BI.Selection.Multi
? self.storeValue.value.concat(startValue) : self.storeValue.value ? self.storeValue.value.concat(startValue) : self.storeValue.value
})); }));
opts.itemsCreator(op, function (ob) { if (self.storeValue) {
hasNext = ob.hasNext; var json = BI.map(self.storeValue.value.slice((op.times - 1) * 100, op.times * 100), function (i, v) {
var firstItems = [];
if (op.times === 1 && self.storeValue) {
var json = BI.map(self.storeValue.value, function (i, v) {
var txt = opts.valueFormatter(v) || v; var txt = opts.valueFormatter(v) || v;
return { return {
text: txt, text: txt,
@ -72,6 +70,7 @@ BI.MultiSelectNoBarLoader = BI.inherit(BI.Widget, {
selected: self.storeValue.type === BI.Selection.Multi selected: self.storeValue.type === BI.Selection.Multi
}; };
}); });
if (op.times === 1) {
if (BI.isKey(self._startValue) && !BI.contains(self.storeValue.value, self._startValue)) { if (BI.isKey(self._startValue) && !BI.contains(self.storeValue.value, self._startValue)) {
var txt = opts.valueFormatter(startValue) || startValue; var txt = opts.valueFormatter(startValue) || startValue;
json.unshift({ json.unshift({
@ -81,10 +80,22 @@ BI.MultiSelectNoBarLoader = BI.inherit(BI.Widget, {
selected: true selected: true
}); });
} }
}
if (op.times < Math.floor((self.storeValue.value.length - 1) / 100)) {
hasNext = true;
callback(self._createItems(json), op.keyword || "");
(op.times === 1) && self._scrollToTop();
return;
}
firstItems = self._createItems(json); firstItems = self._createItems(json);
} }
var times = op.times - Math.max(0, Math.floor((self.storeValue.value.length - 1) / 100));
opts.itemsCreator(BI.extend({}, op, {
times: times
}), function (ob) {
hasNext = ob.hasNext;
callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || ""); callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || "");
if (op.times === 1 && self.storeValue) { if (times === 1 && self.storeValue) {
BI.isKey(startValue) && (self.storeValue.type === BI.Selection.All ? BI.remove(self.storeValue.value, startValue) : BI.pushDistinct(self.storeValue.value, startValue)); BI.isKey(startValue) && (self.storeValue.type === BI.Selection.All ? BI.remove(self.storeValue.value, startValue) : BI.pushDistinct(self.storeValue.value, startValue));
self.setValue(self.storeValue); self.setValue(self.storeValue);
} }

Loading…
Cancel
Save