Browse Source

Pull request #3354: KERNEL-14045 refactor: calendar和pager文件es6化

Merge in VISUAL/fineui from ~JOKER.WANG/fineui:es6 to es6

* commit '7fd4fd7218fc28f00356b7f8dcc325a2c7304f74':
  KERNEL-14045 refactor: 补充别名修改路径
  KERNEL-14045 refactor: 使用别名修改路径
  KERNEL-14045 refactor: 修改引用路径
  KERNEL-14045 refactor: calendar和pager文件es6化
es6
Joker.Wang-王顺 2 years ago
parent
commit
e9bc394a01
  1. 70
      src/case/calendar/calendar.date.item.js
  2. 255
      src/case/calendar/calendar.js
  3. 198
      src/case/calendar/calendar.year.js
  4. 3
      src/case/calendar/index.js
  5. 7
      src/case/index.js
  6. 3
      src/case/pager/index.js
  7. 206
      src/case/pager/pager.all.count.js
  8. 260
      src/case/pager/pager.detail.js
  9. 167
      src/case/pager/pager.direction.js

70
src/case/calendar/calendar.date.item.js

@ -1,16 +1,23 @@
/** /**
* 专门为calendar的视觉加的button作为私有button,不能配置任何属性也不要用这个玩意 * 专门为calendar的视觉加的button作为私有button,不能配置任何属性也不要用这个玩意
*/ */
BI.CalendarDateItem = BI.inherit(BI.BasicButton, {
props: function() { import { shortcut } from "@/core";
import { BasicButton } from "@/base";
@shortcut()
export class CalendarDateItem extends BasicButton {
props() {
return { return {
baseCls: "bi-calendar-date-item", baseCls: "bi-calendar-date-item",
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT + 8, height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT + 8,
} };
}, }
static xtype = "bi.calendar_date_item";
render: function () { render () {
var self = this, o = this.options; const { text, value, lgap, rgap, tgap, bgap } = this.options;
return { return {
type: "bi.absolute", type: "bi.absolute",
items: [{ items: [{
@ -18,41 +25,40 @@ BI.CalendarDateItem = BI.inherit(BI.BasicButton, {
type: "bi.text_item", type: "bi.text_item",
cls: "bi-border-radius bi-list-item-select", cls: "bi-border-radius bi-list-item-select",
textAlign: "center", textAlign: "center",
text: o.text, text,
value: o.value, value,
ref: function () { ref: _ref => {
self.text = this; this.text = _ref;
} },
}, },
left: o.lgap, left: lgap,
right: o.rgap, right: rgap,
top: o.tgap, top: tgap,
bottom: o.bgap bottom: bgap,
}] }],
}; };
}, }
doHighLight: function () { doHighLight () {
this.text.doHighLight.apply(this.text, arguments); this.text.doHighLight(...arguments);
}, }
unHighLight: function () { unHighLight () {
this.text.unHighLight.apply(this.text, arguments); this.text.unHighLight(...arguments);
}, }
setValue: function () { setValue () {
if (!this.isReadOnly()) { if (!this.isReadOnly()) {
this.text.setValue.apply(this.text, arguments); this.text.setValue(...arguments);
} }
}, }
setSelected: function (b) { setSelected (b) {
BI.CalendarDateItem.superclass.setSelected.apply(this, arguments); super.setSelected(...arguments);
this.text.setSelected(b); this.text.setSelected(b);
}, }
getValue: function () { getValue () {
return this.text.getValue(); return this.text.getValue();
} }
}); }
BI.shortcut("bi.calendar_date_item", BI.CalendarDateItem);

255
src/case/calendar/calendar.js

@ -3,32 +3,36 @@
* @class BI.Calendar * @class BI.Calendar
* @extends BI.Widget * @extends BI.Widget
*/ */
BI.Calendar = BI.inherit(BI.Widget, { import { shortcut, Widget, getDate, each, range, extend, isLeapYear, Date, StartOfWeek, checkDateVoid, map, createWidget, createItems, LogicFactory, Controller, getShortDayName, getOffsetDate, isNotEmptyString, parseInt } from "@/core";
_defaultConfig: function () { @shortcut()
var conf = BI.Calendar.superclass._defaultConfig.apply(this, arguments); export class Calendar extends Widget {
return BI.extend(conf, { static xtype = "bi.calendar";
_defaultConfig () {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
baseCls: "bi-calendar", baseCls: "bi-calendar",
logic: { logic: {
dynamic: false dynamic: false,
}, },
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
year: 2015, year: 2015,
month: 8, month: 8,
day: 25 day: 25,
}); });
}, }
_dateCreator (Y, M, D) {
_dateCreator: function (Y, M, D) { const { min, max } = this.options, log = {}, De = getDate();
var self = this, o = this.options, log = {}, De = BI.getDate(); const mins = min.match(/\d+/g);
var mins = o.min.match(/\d+/g); const maxs = max.match(/\d+/g);
var maxs = o.max.match(/\d+/g);
De.setFullYear(Y, M, D); De.setFullYear(Y, M, D);
log.ymd = [De.getFullYear(), De.getMonth(), De.getDate()]; log.ymd = [De.getFullYear(), De.getMonth(), De.getDate()];
var MD = BI.Date._MD.slice(0); const MD = Date._MD.slice(0);
MD[1] = BI.isLeapYear(log.ymd[0]) ? 29 : 28; MD[1] = isLeapYear(log.ymd[0]) ? 29 : 28;
// 日期所在月第一天 // 日期所在月第一天
De.setFullYear(log.ymd[0], log.ymd[1], 1); De.setFullYear(log.ymd[0], log.ymd[1], 1);
@ -36,15 +40,16 @@ BI.Calendar = BI.inherit(BI.Widget, {
log.FDay = De.getDay(); log.FDay = De.getDay();
// 当前BI.StartOfWeek与周日对齐后的FDay是周几 // 当前BI.StartOfWeek与周日对齐后的FDay是周几
var offSetFDay = (7 - BI.StartOfWeek + log.FDay) % 7; const offSetFDay = (7 - StartOfWeek + log.FDay) % 7;
// 当前月页第一天是几号 // 当前月页第一天是几号
log.PDay = MD[M === 0 ? 11 : M - 1] - offSetFDay + 1; log.PDay = MD[M === 0 ? 11 : M - 1] - offSetFDay + 1;
log.NDay = 1; log.NDay = 1;
var items = []; const items = [];
BI.each(BI.range(42), function (i) { each(range(42), i => {
var td = {}, YY = log.ymd[0], MM = log.ymd[1] + 1, DD; const td = {};
let YY = log.ymd[0], MM = log.ymd[1] + 1, DD;
// 上个月的日期 // 上个月的日期
if (i < offSetFDay) { if (i < offSetFDay) {
td.lastMonth = true; td.lastMonth = true;
@ -63,89 +68,92 @@ BI.Calendar = BI.inherit(BI.Widget, {
MM === 12 && (YY += 1); MM === 12 && (YY += 1);
MM = MM === 12 ? 1 : MM + 1; MM = MM === 12 ? 1 : MM + 1;
} }
if (BI.checkDateVoid(YY, MM, DD, mins, maxs)[0]) { if (checkDateVoid(YY, MM, DD, mins, maxs)[0]) {
td.disabled = true; td.disabled = true;
} }
td.text = DD; td.text = DD;
items.push(td); items.push(td);
}); });
return items; return items;
}, }
_init: function () { _init () {
BI.Calendar.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const { year, month, day, logic } = this.options;
var items = BI.map(this._getWeekLabel(), function (i, value) { const items = map(this._getWeekLabel(), (i, value) => {
return { return {
type: "bi.label", type: "bi.label",
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
text: value text: value,
}; };
}); });
var title = BI.createWidget({ const title = createWidget({
type: "bi.button_group", type: "bi.button_group",
height: 44, height: 44,
items: items, items,
layouts: [{ layouts: [{
type: "bi.center", type: "bi.center",
hgap: 5, hgap: 5,
vgap: 10 vgap: 10,
}] }],
}); });
this.days = BI.createWidget({ this.days = createWidget({
type: "bi.button_group", type: "bi.button_group",
items: BI.createItems(this._getItems(), {}), items: createItems(this._getItems(), {}),
value: o.year + "-" + o.month + "-" + o.day, value: `${year}-${month}-${day}`,
layouts: [BI.LogicFactory.createLogic("table", BI.extend({}, o.logic, { layouts: [LogicFactory.createLogic("table", extend({}, logic, {
columns: 7, columns: 7,
rows: 6, rows: 6,
columnSize: [1 / 7, 1 / 7, 1 / 7, 1 / 7, 1 / 7, 1 / 7, 1 / 7], columnSize: [1 / 7, 1 / 7, 1 / 7, 1 / 7, 1 / 7, 1 / 7, 1 / 7],
rowSize: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT + 8 rowSize: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT + 8,
}))] }))],
}); });
this.days.on(BI.Controller.EVENT_CHANGE, function () { this.days.on(Controller.EVENT_CHANGE, () => {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); this.fireEvent(Controller.EVENT_CHANGE, arguments);
}); });
BI.createWidget(BI.extend({ createWidget(extend({
element: this element: this,
}, BI.LogicFactory.createLogic("vertical", BI.extend({}, o.logic, { }, LogicFactory.createLogic("vertical", extend({}, logic, {
items: BI.LogicFactory.createLogicItemsByDirection("top", title, { items: LogicFactory.createLogicItemsByDirection("top", title, {
el: this.days, el: this.days,
tgap: -5 tgap: -5,
}) }),
})))); }))));
}, }
_getWeekLabel: function () { _getWeekLabel () {
return BI.map(BI.range(0, 7), function (idx, v) { return map(range(0, 7), (idx, v) => getShortDayName((v + StartOfWeek) % 7));
return BI.getShortDayName((v + BI.StartOfWeek) % 7); }
});
},
isFrontDate: function () { isFrontDate () {
var o = this.options, c = this._const; const { year, month, min, max } = this.options;
var Y = o.year, M = o.month, De = BI.getDate(), day = De.getDay(); let Y = year;
const M = month, De = getDate(), day = De.getDay();
Y = Y | 0; Y = Y | 0;
De.setFullYear(Y, M, 1); De.setFullYear(Y, M, 1);
var newDate = BI.getOffsetDate(De, -1 * (day + 1)); const newDate = getOffsetDate(De, -1 * (day + 1));
return !!BI.checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0];
}, return !!checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), min, max)[0];
}
isFinalDate: function () { isFinalDate () {
var o = this.options, c = this._const; const { year, month, min, max } = this.options;
var Y = o.year, M = o.month, De = BI.getDate(), day = De.getDay(); let Y = year;
const M = month, De = getDate(), day = De.getDay();
Y = Y | 0; Y = Y | 0;
De.setFullYear(Y, M, 1); De.setFullYear(Y, M, 1);
var newDate = BI.getOffsetDate(De, 42 - day); const newDate = getOffsetDate(De, 42 - day);
return !!BI.checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), o.min, o.max)[0];
}, return !!checkDateVoid(newDate.getFullYear(), newDate.getMonth(), newDate.getDate(), min, max)[0];
}
_getItems: function () { _getItems () {
var o = this.options; const o = this.options;
var days = this._dateCreator(o.year, o.month - 1, o.day); const days = this._dateCreator(o.year, o.month - 1, o.day);
var items = []; const items = [];
items.push(days.slice(0, 7)); items.push(days.slice(0, 7));
items.push(days.slice(7, 14)); items.push(days.slice(7, 14));
items.push(days.slice(14, 21)); items.push(days.slice(14, 21));
@ -153,93 +161,94 @@ BI.Calendar = BI.inherit(BI.Widget, {
items.push(days.slice(28, 35)); items.push(days.slice(28, 35));
items.push(days.slice(35, 42)); items.push(days.slice(35, 42));
return BI.map(items, function (i, item) { return map(items, (i, item) => map(item, (j, td) => {
return BI.map(item, function (j, td) { let month = td.lastMonth ? o.month - 1 : (td.nextMonth ? o.month + 1 : o.month);
var month = td.lastMonth ? o.month - 1 : (td.nextMonth ? o.month + 1 : o.month); let year = o.year;
var year = o.year; if (month > 12) {
if (month > 12) { month = 1;
month = 1; year++;
year++; } else if (month < 1) {
} else if (month < 1) { month = 12;
month = 12; year--;
year--; }
}
return BI.extend(td, { return extend(td, {
type: "bi.calendar_date_item", type: "bi.calendar_date_item",
once: false, once: false,
forceSelected: true, forceSelected: true,
value: year + "-" + month + "-" + td.text, value: `${year}-${month}-${td.text}`,
disabled: td.disabled, disabled: td.disabled,
cls: td.lastMonth || td.nextMonth ? "bi-tips" : "", cls: td.lastMonth || td.nextMonth ? "bi-tips" : "",
lgap: 2, lgap: 2,
rgap: 2, rgap: 2,
tgap: 4, tgap: 4,
bgap: 4 bgap: 4,
// selected: td.currentDay // selected: td.currentDay
});
}); });
}); }));
}, }
_populate: function() { _populate() {
this.days.populate(this._getItems()); this.days.populate(this._getItems());
}, }
setMinDate: function (minDate) { setMinDate (minDate) {
var o = this.options; const o = this.options;
if (BI.isNotEmptyString(o.min)) { if (isNotEmptyString(o.min)) {
o.min = minDate; o.min = minDate;
this._populate(); this._populate();
} }
}, }
setMaxDate: function (maxDate) { setMaxDate (maxDate) {
var o = this.options; const o = this.options;
if (BI.isNotEmptyString(o.max)) { if (isNotEmptyString(o.max)) {
o.max = maxDate; o.max = maxDate;
this._populate(); this._populate();
} }
}, }
setValue: function (ob) { setValue (ob) {
this.days.setValue([ob.year + "-" + ob.month + "-" + ob.day]); this.days.setValue([`${ob.year}-${ob.month}-${ob.day}`]);
}, }
getValue: function () { getValue () {
var date = this.days.getValue()[0].match(/\d+/g); const date = this.days.getValue()[0].match(/\d+/g);
return { return {
year: date[0] | 0, year: date[0] | 0,
month: date[1] | 0, month: date[1] | 0,
day: date[2] | 0 day: date[2] | 0,
}; };
} }
}); }
BI.extend(BI.Calendar, { extend(Calendar, {
getPageByDateJSON: function (json) { getPageByDateJSON (json) {
var year = BI.getDate().getFullYear(); const year = getDate().getFullYear();
var month = BI.getDate().getMonth(); const month = getDate().getMonth();
var page = (json.year - year) * 12; let page = (json.year - year) * 12;
page += json.month - 1 - month; page += json.month - 1 - month;
return page; return page;
}, },
getDateJSONByPage: function (v) { getDateJSONByPage (v) {
var months = BI.getDate().getMonth(); const months = getDate().getMonth();
var page = v; let page = v;
// 对当前page做偏移,使到当前年初 // 对当前page做偏移,使到当前年初
page = page + months; page = page + months;
var year = BI.parseInt(page / 12); let year = parseInt(page / 12);
if(page < 0 && page % 12 !== 0) { if (page < 0 && page % 12 !== 0) {
year--; year--;
} }
var month = page >= 0 ? (page % 12) : ((12 + page % 12) % 12); const month = page >= 0 ? (page % 12) : ((12 + page % 12) % 12);
return { return {
year: BI.getDate().getFullYear() + year, year: getDate().getFullYear() + year,
month: month + 1 month: month + 1,
}; };
} },
}); });
BI.shortcut("bi.calendar", BI.Calendar);

198
src/case/calendar/calendar.year.js

@ -3,99 +3,104 @@
* @class BI.YearCalendar * @class BI.YearCalendar
* @extends BI.Widget * @extends BI.Widget
*/ */
BI.YearCalendar = BI.inherit(BI.Widget, { import { shortcut, Widget, extend, parseDateTime, range, checkDateVoid, print, getDate, each, createWidget, createItems, LogicFactory, Controller, makeArray, map, isNotEmptyString } from "@/core";
@shortcut()
_defaultConfig: function () { export class YearCalendar extends Widget {
var conf = BI.YearCalendar.superclass._defaultConfig.apply(this, arguments); static xtype = "bi.year_calendar";
return BI.extend(conf, { _defaultConfig () {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
baseCls: "bi-year-calendar", baseCls: "bi-year-calendar",
behaviors: {}, behaviors: {},
logic: { logic: {
dynamic: false dynamic: false,
}, },
min: "1900-01-01", // 最小日期 min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期 max: "2099-12-31", // 最大日期
year: null year: null,
}); });
}, }
_yearCreator: function (Y) { _yearCreator (Y) {
var o = this.options; const { min, max } = this.options;
Y = Y | 0; Y = Y | 0;
var start = BI.YearCalendar.getStartYear(Y); const start = YearCalendar.getStartYear(Y);
var items = []; const items = [];
// 对于年控件来说,只要传入的minDate和maxDate的year区间包含v就是合法的 // 对于年控件来说,只要传入的minDate和maxDate的year区间包含v就是合法的
var startDate = BI.parseDateTime(o.min, "%Y-%X-%d"); const startDate = parseDateTime(min, "%Y-%X-%d");
var endDate = BI.parseDateTime(o.max, "%Y-%X-%d"); const endDate = parseDateTime(max, "%Y-%X-%d");
BI.each(BI.range(BI.YearCalendar.INTERVAL), function (i) { each(range(YearCalendar.INTERVAL), i => {
var td = {}; const td = {};
if (BI.checkDateVoid(start + i, 1, 1, BI.print(BI.getDate(startDate.getFullYear(), 0, 1), "%Y-%X-%d"), BI.print(BI.getDate(endDate.getFullYear(), 0, 1), "%Y-%X-%d"))[0]) { if (checkDateVoid(start + i, 1, 1, print(getDate(startDate.getFullYear(), 0, 1), "%Y-%X-%d"), print(getDate(endDate.getFullYear(), 0, 1), "%Y-%X-%d"))[0]) {
td.disabled = true; td.disabled = true;
} }
td.text = start + i; td.text = start + i;
items.push(td); items.push(td);
}); });
return items; return items;
}, }
_init () {
_init: function () { super._init(...arguments);
BI.YearCalendar.superclass._init.apply(this, arguments); const { behaviors, logic } = this.options;
var self = this, o = this.options; this.currentYear = getDate().getFullYear();
this.currentYear = BI.getDate().getFullYear();
this.years = BI.createWidget({ this.years = createWidget({
type: "bi.button_group", type: "bi.button_group",
behaviors: o.behaviors, behaviors,
items: BI.createItems(this._getItems(), {}), items: createItems(this._getItems(), {}),
layouts: [BI.LogicFactory.createLogic("table", BI.extend({}, o.logic, { layouts: [LogicFactory.createLogic("table", extend({}, logic, {
columns: 2, columns: 2,
rows: 6, rows: 6,
columnSize: [1 / 2, 1 / 2], columnSize: [1 / 2, 1 / 2],
rowSize: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, rowSize: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
})), { })), {
type: "bi.center_adapt", type: "bi.center_adapt",
vgap: 2 vgap: 2,
}] }],
}); });
this.years.on(BI.Controller.EVENT_CHANGE, function () { this.years.on(Controller.EVENT_CHANGE, (...args) => {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); this.fireEvent(Controller.EVENT_CHANGE, ...args);
}); });
BI.createWidget(BI.extend({ createWidget(extend({
element: this element: this,
}, BI.LogicFactory.createLogic("vertical", BI.extend({}, o.logic, { }, LogicFactory.createLogic("vertical", extend({}, logic, {
scrolly: true, scrolly: true,
vgap: 5, vgap: 5,
hgap: 6, hgap: 6,
items: BI.LogicFactory.createLogicItemsByDirection("top", this.years) items: LogicFactory.createLogicItemsByDirection("top", this.years),
})))); }))));
}, }
isFrontYear: function () { isFrontYear () {
var o = this.options; const { min, max } = this.options;
var Y = o.year; let Y = this.options.year;
Y = Y | 0; Y = Y | 0;
return !!BI.checkDateVoid(BI.YearCalendar.getStartYear(Y) - 1, 1, 1, o.min, o.max)[0];
}, return !!checkDateVoid(YearCalendar.getStartYear(Y) - 1, 1, 1, min, max)[0];
}
isFinalYear: function () { isFinalYear () {
var o = this.options, c = this._const; const { min, max } = this.options;
var Y = o.year; let Y = this.options.year;
Y = Y | 0; Y = Y | 0;
return !!BI.checkDateVoid(BI.YearCalendar.getEndYear(Y) + 1, 1, 1, o.min, o.max)[0];
}, return !!checkDateVoid(YearCalendar.getEndYear(Y) + 1, 1, 1, min, max)[0];
}
_getItems: function () { _getItems () {
var o = this.options; const { year } = this.options;
var years = this._yearCreator(o.year || this.currentYear); const years = this._yearCreator(year || this.currentYear);
// 纵向排列年 // 纵向排列年
var len = years.length, tyears = BI.makeArray(len, ""); const len = years.length, tyears = makeArray(len, "");
var map = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11]; const mapArr = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11];
BI.each(years, function (i, y) { each(years, (i, y) => {
tyears[i] = years[map[i]]; tyears[i] = years[mapArr[i]];
}); });
var items = []; const items = [];
items.push(tyears.slice(0, 2)); items.push(tyears.slice(0, 2));
items.push(tyears.slice(2, 4)); items.push(tyears.slice(2, 4));
items.push(tyears.slice(4, 6)); items.push(tyears.slice(4, 6));
@ -103,71 +108,70 @@ BI.YearCalendar = BI.inherit(BI.Widget, {
items.push(tyears.slice(8, 10)); items.push(tyears.slice(8, 10));
items.push(tyears.slice(10, 12)); items.push(tyears.slice(10, 12));
return BI.map(items, function (i, item) { return map(items, (i, item) => map(item, (j, td) => extend(td, {
return BI.map(item, function (j, td) { type: "bi.text_item",
return BI.extend(td, { cls: "bi-list-item-select bi-border-radius",
type: "bi.text_item", textAlign: "center",
cls: "bi-list-item-select bi-border-radius", whiteSpace: "normal",
textAlign: "center", once: false,
whiteSpace: "normal", forceSelected: true,
once: false, height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
forceSelected: true, width: 45,
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, value: td.text,
width: 45, disabled: td.disabled,
value: td.text, })));
disabled: td.disabled }
});
});
});
},
_populate: function () { _populate () {
this.years.populate(this._getItems()); this.years.populate(this._getItems());
}, }
setMinDate: function (minDate) { setMinDate (minDate) {
var o = this.options; const o = this.options;
if (BI.isNotEmptyString(o.min)) { if (isNotEmptyString(o.min)) {
o.min = minDate; o.min = minDate;
this._populate(); this._populate();
} }
}, }
setMaxDate: function (maxDate) { setMaxDate (maxDate) {
var o = this.options; const o = this.options;
if (BI.isNotEmptyString(this.options.max)) { if (isNotEmptyString(this.options.max)) {
o.max = maxDate; o.max = maxDate;
this._populate(); this._populate();
} }
}, }
setValue: function (val) { setValue (val) {
this.years.setValue([val]); this.years.setValue([val]);
}, }
getValue: function () { getValue () {
return this.years.getValue()[0]; return this.years.getValue()[0];
} }
}); }
// 类方法 // 类方法
BI.extend(BI.YearCalendar, { extend(YearCalendar, {
INTERVAL: 12, INTERVAL: 12,
// 获取显示的第一年 // 获取显示的第一年
getStartYear: function (year) { getStartYear (year) {
var cur = BI.getDate().getFullYear(); const cur = getDate().getFullYear();
return year - ((year - cur + 3) % BI.YearCalendar.INTERVAL + 12) % BI.YearCalendar.INTERVAL;
return year - ((year - cur + 3) % YearCalendar.INTERVAL + 12) % YearCalendar.INTERVAL;
}, },
getEndYear: function (year) { getEndYear (year) {
return BI.YearCalendar.getStartYear(year) + BI.YearCalendar.INTERVAL - 1; return YearCalendar.getStartYear(year) + YearCalendar.INTERVAL - 1;
}, },
getPageByYear: function (year) { getPageByYear (year) {
var cur = BI.getDate().getFullYear(); const cur = getDate().getFullYear();
year = BI.YearCalendar.getStartYear(year); year = YearCalendar.getStartYear(year);
return (year - cur + 3) / BI.YearCalendar.INTERVAL;
} return (year - cur + 3) / YearCalendar.INTERVAL;
},
}); });
BI.shortcut("bi.year_calendar", BI.YearCalendar);

3
src/case/calendar/index.js

@ -0,0 +1,3 @@
export { CalendarDateItem } from "./calendar.date.item";
export { Calendar } from "./calendar";
export { YearCalendar } from "./calendar.year";

7
src/case/index.js

@ -1,10 +1,17 @@
import * as button from "./button"; import * as button from "./button";
import * as calendarItem from "./calendar";
import * as pager from "./pager";
import * as editor from "./editor"; import * as editor from "./editor";
Object.assign(BI, { Object.assign(BI, {
...button, ...button,
...calendarItem,
...pager,
...editor, ...editor,
}); });
export * from "./button"; export * from "./button";
export * from "./calendar";
export * from "./pager";
export * from "./editor"; export * from "./editor";

3
src/case/pager/index.js

@ -0,0 +1,3 @@
export { AllCountPager } from "./pager.all.count";
export { DetailPager } from "./pager.detail";
export { DirectionPager } from "./pager.direction";

206
src/case/pager/pager.all.count.js

@ -2,10 +2,15 @@
* 有总页数和总行数的分页控件 * 有总页数和总行数的分页控件
* Created by Young's on 2016/10/13. * Created by Young's on 2016/10/13.
*/ */
BI.AllCountPager = BI.inherit(BI.Widget, { import { shortcut, Widget, extend, isPositiveInteger, createWidget, parseInt, HorizontalAlign, isNotEmptyObject } from "@/core";
// import { TextEditor } from "@/widget/editor/editor.text";
_defaultConfig: function () { import { Pager } from "@/base";
return BI.extend(BI.AllCountPager.superclass._defaultConfig.apply(this, arguments), { @shortcut()
export class AllCountPager extends Widget {
static xtype = "bi.all_count_pager";
static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig () {
return extend(super._defaultConfig(...arguments), {
extraCls: "bi-all-count-pager", extraCls: "bi-all-count-pager",
pagerDirection: "vertical", // 翻页按钮方向,可选值:vertical/horizontal pagerDirection: "vertical", // 翻页按钮方向,可选值:vertical/horizontal
height: 24, height: 24,
@ -16,36 +21,36 @@ BI.AllCountPager = BI.inherit(BI.Widget, {
showRowCount: true, showRowCount: true,
showRowInfo: true, showRowInfo: true,
}); });
}, }
_init: function () { _init () {
BI.AllCountPager.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options, pagerIconCls = this._getPagerIconCls(); const { pages, curr, hasPrev, hasNext, firstPage, lastPage, height, showRowCount } = this.options, pagerIconCls = this._getPagerIconCls();
this.editor = BI.createWidget({ this.editor = createWidget({
type: "bi.small_text_editor", type: "bi.small_text_editor",
cls: "pager-editor bi-border-radius", cls: "pager-editor bi-border-radius",
validationChecker: function (v) { validationChecker (v) {
return (o.pages === 0 && v === "0") || BI.isPositiveInteger(v); return (pages === 0 && v === "0") || isPositiveInteger(v);
}, },
hgap: 4, hgap: 4,
vgap: 0, vgap: 0,
value: o.curr, value: curr,
errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), errorText: BI.i18nText("BI-Please_Input_Positive_Integer"),
width: 40, width: 40,
height: 24, height: 24,
invisible: o.pages <= 1 invisible: pages <= 1,
}); });
this.pager = BI.createWidget({ this.pager = createWidget({
type: "bi.pager", type: "bi.pager",
width: 58, width: 58,
layouts: [{ layouts: [{
type: "bi.horizontal", type: "bi.horizontal",
lgap: 5 lgap: 5,
}], }],
dynamicShow: false, dynamicShow: false,
pages: o.pages, pages,
curr: o.curr, curr,
groups: 0, groups: 0,
first: false, first: false,
@ -57,7 +62,7 @@ BI.AllCountPager = BI.inherit(BI.Widget, {
warningTitle: BI.i18nText("BI-Current_Is_First_Page"), warningTitle: BI.i18nText("BI-Current_Is_First_Page"),
height: 22, height: 22,
width: 22, width: 22,
cls: "bi-border bi-border-radius all-pager-prev bi-list-item-select2 " + pagerIconCls.preCls cls: `bi-border bi-border-radius all-pager-prev bi-list-item-select2 ${pagerIconCls.preCls}`,
}, },
next: { next: {
type: "bi.icon_button", type: "bi.icon_button",
@ -66,42 +71,43 @@ BI.AllCountPager = BI.inherit(BI.Widget, {
warningTitle: BI.i18nText("BI-Current_Is_Last_Page"), warningTitle: BI.i18nText("BI-Current_Is_Last_Page"),
height: 22, height: 22,
width: 22, width: 22,
cls: "bi-border bi-border-radius all-pager-next bi-list-item-select2 " + pagerIconCls.nextCls cls: `bi-border bi-border-radius all-pager-next bi-list-item-select2 ${pagerIconCls.nextCls}`,
}, },
hasPrev: o.hasPrev, hasPrev,
hasNext: o.hasNext, hasNext,
firstPage: o.firstPage, firstPage,
lastPage: o.lastPage, lastPage,
invisible: o.pages <= 1 invisible: pages <= 1,
}); });
this.editor.on(BI.TextEditor.EVENT_CONFIRM, function () { // TODO:需等到TextEditor 完成es6化后才可替换BI.TextEditor
self.pager.setValue(BI.parseInt(self.editor.getValue())); this.editor.on(BI.TextEditor.EVENT_CONFIRM, () => {
self.fireEvent(BI.AllCountPager.EVENT_CHANGE); this.pager.setValue(parseInt(this.editor.getValue()));
this.fireEvent(AllCountPager.EVENT_CHANGE);
}); });
this.pager.on(BI.Pager.EVENT_CHANGE, function () { this.pager.on(Pager.EVENT_CHANGE, () => {
self.fireEvent(BI.AllCountPager.EVENT_CHANGE); this.fireEvent(AllCountPager.EVENT_CHANGE);
}); });
this.pager.on(BI.Pager.EVENT_AFTER_POPULATE, function () { this.pager.on(Pager.EVENT_AFTER_POPULATE, () => {
self.editor.setValue(self.pager.getCurrentPage()); this.editor.setValue(this.pager.getCurrentPage());
}); });
this.allPages = BI.createWidget({ this.allPages = createWidget({
type: "bi.label", type: "bi.label",
title: o.pages, title: pages,
height: o.height, height,
text: "/" + o.pages, text: `/${pages}`,
lgap: 5, lgap: 5,
invisible: o.pages <= 1 invisible: pages <= 1,
}); });
BI.createWidget(o.showRowCount ? { createWidget(showRowCount ? {
type: "bi.vertical_adapt", type: "bi.vertical_adapt",
element: this, element: this,
scrollx: false, scrollx: false,
columnSize: ["fill", ""], columnSize: ["fill", ""],
horizontalAlign: BI.HorizontalAlign.Right, horizontalAlign: HorizontalAlign.Right,
items: [ items: [
this._getRowCountObject(), this._getRowCountObject(),
this.editor, this.allPages, this.pager this.editor, this.allPages, this.pager
@ -109,126 +115,124 @@ BI.AllCountPager = BI.inherit(BI.Widget, {
} : { } : {
type: "bi.vertical_adapt", type: "bi.vertical_adapt",
element: this, element: this,
items: [this.editor, this.allPages, this.pager] items: [this.editor, this.allPages, this.pager],
}); });
}, }
_getPagerIconCls: function () { _getPagerIconCls () {
var o = this.options; const { pagerDirection } = this.options;
switch (o.pagerDirection) { switch (pagerDirection) {
case "horizontal": case "horizontal":
return { return {
preCls: "row-pre-page-h-font ", preCls: "row-pre-page-h-font ",
nextCls: "row-next-page-h-font " nextCls: "row-next-page-h-font ",
}; };
case "vertical": case "vertical":
default: default:
return { return {
preCls: "column-pre-page-h-font ", preCls: "column-pre-page-h-font ",
nextCls: "column-next-page-h-font " nextCls: "column-next-page-h-font ",
}; };
} }
}, }
_getRowCountObject: function() { _getRowCountObject() {
var self = this, o = this.options; const { height, count, rowInfoObject } = this.options;
return { return {
type: "bi.left", type: "bi.left",
height: o.height, height,
scrollable: false, scrollable: false,
ref: function (_ref) { ref: _ref => {
self.rowCountObject = _ref; this.rowCountObject = _ref;
}, },
items: [{ items: [{
type: "bi.label", type: "bi.label",
height: o.height, height,
text: BI.i18nText("BI-Basic_Total"), text: BI.i18nText("BI-Basic_Total"),
ref: function (_ref) { ref: _ref => {
self.prevText = _ref; this.prevText = _ref;
} },
}, { }, {
el: { el: {
type: "bi.label", type: "bi.label",
ref: function (_ref) { ref: _ref => {
self.rowCount = _ref; this.rowCount = _ref;
}, },
cls: "row-count", cls: "row-count",
height: o.height, height,
text: o.count, text: count,
title: o.count title: count,
}, },
hgap: 5, hgap: 5,
}, { }, {
type: "bi.label", type: "bi.label",
height: o.height, height,
text: BI.i18nText("BI-Tiao_Data"), text: BI.i18nText("BI-Tiao_Data"),
textAlign: "left" textAlign: "left",
}, BI.isNotEmptyObject(o.rowInfoObject) ? o.rowInfoObject : null] }, isNotEmptyObject(rowInfoObject) ? rowInfoObject : null],
}; };
}, }
setAllPages: function (v) { setAllPages (v) {
this.allPages.setText("/" + v); this.allPages.setText(`/${v}`);
this.allPages.setTitle(v); this.allPages.setTitle(v);
this.options.pages = v; this.options.pages = v;
this.pager.setAllPages(v); this.pager.setAllPages(v);
this.editor.setEnable(v >= 1); this.editor.setEnable(v >= 1);
this.setPagerVisible(v > 1); this.setPagerVisible(v > 1);
}, }
setShowRowInfo: function (b) { setShowRowInfo (b) {
this.options.showRowInfo = b; this.options.showRowInfo = b;
this.rowCountObject.setVisible(b); this.rowCountObject.setVisible(b);
}, }
setValue: function (v) { setValue (v) {
this.pager.setValue(v); this.pager.setValue(v);
}, }
setVPage: function (v) { setVPage (v) {
this.pager.setValue(v); this.pager.setValue(v);
}, }
setCount: function (count) { setCount (count) {
if (this.options.showRowCount) { if (this.options.showRowCount) {
this.rowCount.setText(count); this.rowCount.setText(count);
this.rowCount.setTitle(count); this.rowCount.setTitle(count);
} }
}, }
setCountPrevText: function (text) { setCountPrevText (text) {
if (this.options.showRowCount) { if (this.options.showRowCount) {
this.prevText.setText(text); this.prevText.setText(text);
} }
}, }
getCurrentPage: function () { getCurrentPage () {
return this.pager.getCurrentPage(); return this.pager.getCurrentPage();
}, }
hasPrev: function () { hasPrev () {
return this.pager.hasPrev(); return this.pager.hasPrev();
}, }
hasNext: function () { hasNext () {
return this.pager.hasNext(); return this.pager.hasNext();
}, }
isShowPager: function () { isShowPager () {
return this.options.showRowInfo || this.options.pages > 1; return this.options.showRowInfo || this.options.pages > 1;
}, }
setPagerVisible: function (b) { setPagerVisible (b) {
this.editor.setVisible(b); this.editor.setVisible(b);
this.allPages.setVisible(b); this.allPages.setVisible(b);
this.pager.setVisible(b); this.pager.setVisible(b);
}, }
populate: function () { populate () {
this.pager.populate(); this.pager.populate();
this.setPagerVisible(this.options.pages > 1); this.setPagerVisible(this.options.pages > 1);
} }
}); }
BI.AllCountPager.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.all_count_pager", BI.AllCountPager);

260
src/case/pager/pager.detail.js

@ -5,9 +5,15 @@
* @class BI.DetailPager * @class BI.DetailPager
* @extends BI.Widget * @extends BI.Widget
*/ */
BI.DetailPager = BI.inherit(BI.Widget, {
_defaultConfig: function () { import { shortcut, Widget, extend, emptyFn, result, debounce, isKey, createWidget, createItems, Controller, Events, MIN, MAX } from "@/core";
return BI.extend(BI.DetailPager.superclass._defaultConfig.apply(this, arguments), { @shortcut()
export class DetailPager extends Widget {
static xtype = "bi.detail_pager";
static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_AFTER_POPULATE = "EVENT_AFTER_POPULATE";
_defaultConfig () {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-detail-pager", baseCls: "bi-detail-pager",
behaviors: {}, behaviors: {},
layouts: [{ layouts: [{
@ -19,11 +25,11 @@ BI.DetailPager = BI.inherit(BI.Widget, {
dynamicShowFirstLast: false, // 是否动态显示首页、尾页 dynamicShowFirstLast: false, // 是否动态显示首页、尾页
dynamicShowPrevNext: false, // 是否动态显示上一页、下一页 dynamicShowPrevNext: false, // 是否动态显示上一页、下一页
pages: false, // 总页数 pages: false, // 总页数
curr: function () { curr () {
return 1; return 1;
}, // 初始化当前页 }, // 初始化当前页
groups: 0, // 连续显示分页数 groups: 0, // 连续显示分页数
jump: BI.emptyFn, // 分页的回调函数 jump: emptyFn, // 分页的回调函数
first: false, // 是否显示首页 first: false, // 是否显示首页
last: false, // 是否显示尾页 last: false, // 是否显示尾页
@ -31,35 +37,34 @@ BI.DetailPager = BI.inherit(BI.Widget, {
next: "下一页", next: "下一页",
firstPage: 1, firstPage: 1,
lastPage: function () { // 在万不得已时才会调用这个函数获取最后一页的页码, 主要作用于setValue方法 lastPage () { // 在万不得已时才会调用这个函数获取最后一页的页码, 主要作用于setValue方法
return 1; return 1;
}, },
hasPrev: BI.emptyFn, // pages不可用时有效 hasPrev: emptyFn, // pages不可用时有效
hasNext: BI.emptyFn // pages不可用时有效 hasNext: emptyFn, // pages不可用时有效
}); });
}, }
_init: function () { _init () {
BI.DetailPager.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this; this.currPage = result(this.options, "curr");
this.currPage = BI.result(this.options, "curr");
// 翻页太灵敏 // 翻页太灵敏
this._lock = false; this._lock = false;
this._debouce = BI.debounce(function () { this._debouce = debounce(() => {
self._lock = false; this._lock = false;
}, 300); }, 300);
this._populate(); this._populate();
}, }
_populate () {
_populate: function () { const o = this.options, view = [], dict = {};
var self = this, o = this.options, view = [], dict = {}; const { dynamicShow, dynamicShowPrevNext, hasPrev, dynamicShowFirstLast, hasNext, behaviors, layouts, jump } = this.options;
this.empty(); this.empty();
var pages = BI.result(o, "pages"); const pages = result(o, "pages");
var curr = BI.result(this, "currPage"); const curr = result(this, "currPage");
var groups = BI.result(o, "groups"); let groups = result(o, "groups");
var first = BI.result(o, "first"); let first = result(o, "first");
var last = BI.result(o, "last"); let last = result(o, "last");
var prev = BI.result(o, "prev"); const prev = result(o, "prev");
var next = BI.result(o, "next"); const next = result(o, "next");
if (pages === false) { if (pages === false) {
groups = 0; groups = 0;
@ -73,32 +78,32 @@ BI.DetailPager = BI.inherit(BI.Widget, {
dict.index = Math.ceil((curr + ((groups > 1 && groups !== pages) ? 1 : 0)) / (groups === 0 ? 1 : groups)); dict.index = Math.ceil((curr + ((groups > 1 && groups !== pages) ? 1 : 0)) / (groups === 0 ? 1 : groups));
// 当前页非首页,则输出上一页 // 当前页非首页,则输出上一页
if (((!o.dynamicShow && !o.dynamicShowPrevNext) || curr > 1) && prev !== false) { if (((!dynamicShow && !dynamicShowPrevNext) || curr > 1) && prev !== false) {
if (BI.isKey(prev)) { if (isKey(prev)) {
view.push({ view.push({
text: prev, text: prev,
value: "prev", value: "prev",
disabled: pages === false ? o.hasPrev(curr) === false : !(curr > 1 && prev !== false) disabled: pages === false ? hasPrev(curr) === false : !(curr > 1 && prev !== false),
}); });
} else { } else {
view.push(BI.extend({ view.push(extend({
disabled: pages === false ? o.hasPrev(curr) === false : !(curr > 1 && prev !== false) disabled: pages === false ? hasPrev(curr) === false : !(curr > 1 && prev !== false),
}, prev)); }, prev));
} }
} }
// 当前组非首组,则输出首页 // 当前组非首组,则输出首页
if (((!o.dynamicShow && !o.dynamicShowFirstLast) || (dict.index > 1 && groups !== 0)) && first) { if (((!dynamicShow && !dynamicShowFirstLast) || (dict.index > 1 && groups !== 0)) && first) {
view.push({ view.push({
text: first, text: first,
value: "first", value: "first",
disabled: !(dict.index > 1 && groups !== 0) disabled: !(dict.index > 1 && groups !== 0),
}); });
if (dict.index > 1 && groups !== 0) { if (dict.index > 1 && groups !== 0) {
view.push({ view.push({
type: "bi.label", type: "bi.label",
cls: "page-ellipsis", cls: "page-ellipsis",
text: "\u2026" text: "\u2026",
}); });
} }
} }
@ -107,13 +112,14 @@ BI.DetailPager = BI.inherit(BI.Widget, {
dict.poor = Math.floor((groups - 1) / 2); dict.poor = Math.floor((groups - 1) / 2);
dict.start = dict.index > 1 ? curr - dict.poor : 1; dict.start = dict.index > 1 ? curr - dict.poor : 1;
dict.end = dict.index > 1 ? (function () { dict.end = dict.index > 1 ? (function () {
var max = curr + (groups - dict.poor - 1); const max = curr + (groups - dict.poor - 1);
return max > pages ? pages : max; return max > pages ? pages : max;
}()) : groups; }()) : groups;
if (dict.end - dict.start < groups - 1) { // 最后一组状态 if (dict.end - dict.start < groups - 1) { // 最后一组状态
dict.start = dict.end - groups + 1; dict.start = dict.end - groups + 1;
} }
var s = dict.start, e = dict.end; let s = dict.start, e = dict.end;
if (first && last && (dict.index > 1 && groups !== 0) && (pages > groups && dict.end < pages && groups !== 0)) { if (first && last && (dict.index > 1 && groups !== 0) && (pages > groups && dict.end < pages && groups !== 0)) {
s++; s++;
e--; e--;
@ -123,164 +129,166 @@ BI.DetailPager = BI.inherit(BI.Widget, {
view.push({ view.push({
text: s, text: s,
value: s, value: s,
selected: true selected: true,
}); });
} else { } else {
view.push({ view.push({
text: s, text: s,
value: s value: s,
}); });
} }
} }
// 总页数大于连续分页数,且当前组最大页小于总页,输出尾页 // 总页数大于连续分页数,且当前组最大页小于总页,输出尾页
if (((!o.dynamicShow && !o.dynamicShowFirstLast) || (pages > groups && dict.end < pages && groups !== 0)) && last) { if (((!dynamicShow && !dynamicShowFirstLast) || (pages > groups && dict.end < pages && groups !== 0)) && last) {
if (pages > groups && dict.end < pages && groups !== 0) { if (pages > groups && dict.end < pages && groups !== 0) {
view.push({ view.push({
type: "bi.label", type: "bi.label",
cls: "page-ellipsis", cls: "page-ellipsis",
text: "\u2026" text: "\u2026",
}); });
} }
view.push({ view.push({
text: last, text: last,
value: "last", value: "last",
disabled: !(pages > groups && dict.end < pages && groups !== 0) disabled: !(pages > groups && dict.end < pages && groups !== 0),
}); });
} }
// 当前页不为尾页时,输出下一页 // 当前页不为尾页时,输出下一页
dict.flow = !prev && groups === 0; dict.flow = !prev && groups === 0;
if (((!o.dynamicShow && !o.dynamicShowPrevNext) && next) || (curr !== pages && next || dict.flow)) { if (((!dynamicShow && !dynamicShowPrevNext) && next) || (curr !== pages && next || dict.flow)) {
view.push((function () { view.push((function () {
if (BI.isKey(next)) { if (isKey(next)) {
if (pages === false) { if (pages === false) {
return {text: next, value: "next", disabled: o.hasNext(curr) === false}; return { text: next, value: "next", disabled: hasNext(curr) === false };
} }
return (dict.flow && curr === pages) return (dict.flow && curr === pages)
? ?
{text: next, value: "next", disabled: true} { text: next, value: "next", disabled: true }
: :
{text: next, value: "next", disabled: !(curr !== pages && next || dict.flow)}; { text: next, value: "next", disabled: !(curr !== pages && next || dict.flow) };
} }
return BI.extend({
disabled: pages === false ? o.hasNext(curr) === false : !(curr !== pages && next || dict.flow) return extend({
disabled: pages === false ? hasNext(curr) === false : !(curr !== pages && next || dict.flow),
}, next); }, next);
}())); }()));
} }
this.button_group = BI.createWidget({ this.button_group = createWidget({
type: "bi.button_group", type: "bi.button_group",
element: this, element: this,
items: BI.createItems(view, { items: createItems(view, {
cls: "page-item bi-border bi-list-item-active", cls: "page-item bi-border bi-list-item-active",
height: 23 height: 23,
}), }),
behaviors: o.behaviors, behaviors,
layouts: o.layouts layouts,
}); });
this.button_group.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { this.button_group.on(Controller.EVENT_CHANGE, (type, value, obj, ...args) => {
if (self._lock === true) { if (this._lock === true) {
return; return;
} }
self._lock = true; this._lock = true;
self._debouce(); this._debouce();
if (type === BI.Events.CLICK) { if (type === Events.CLICK) {
var v = self.button_group.getValue()[0]; const v = this.button_group.getValue()[0];
switch (v) { switch (v) {
case "first": case "first":
self.currPage = 1; this.currPage = 1;
break; break;
case "last": case "last":
self.currPage = pages; this.currPage = pages;
break; break;
case "prev": case "prev":
self.currPage--; this.currPage--;
break; break;
case "next": case "next":
self.currPage++; this.currPage++;
break; break;
default: default:
self.currPage = v; this.currPage = v;
break; break;
} }
o.jump.apply(self, [{ jump.apply(this, [{
pages: pages, pages,
curr: self.currPage curr: this.currPage,
}]); }]);
self._populate(); this._populate();
self.fireEvent(BI.DetailPager.EVENT_CHANGE, obj); this.fireEvent(DetailPager.EVENT_CHANGE, obj);
} }
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); this.fireEvent(Controller.EVENT_CHANGE, type, value, obj, ...args);
}); });
this.fireEvent(BI.DetailPager.EVENT_AFTER_POPULATE); this.fireEvent(DetailPager.EVENT_AFTER_POPULATE);
}, }
getCurrentPage: function () { getCurrentPage () {
return this.currPage; return this.currPage;
}, }
setAllPages: function (pages) { setAllPages (pages) {
this.options.pages = pages; this.options.pages = pages;
this._populate(); this._populate();
}, }
hasPrev: function (v) { hasPrev (v) {
v || (v = 1); v || (v = 1);
var o = this.options; const { hasPrev } = this.options;
var pages = this.options.pages; const pages = this.options.pages;
return pages === false ? o.hasPrev(v) : v > 1;
}, return pages === false ? hasPrev(v) : v > 1;
}
hasNext: function (v) { hasNext (v) {
v || (v = 1); v || (v = 1);
var o = this.options; const { hasNext } = this.options;
var pages = this.options.pages; const pages = this.options.pages;
return pages === false ? o.hasNext(v) : v < pages;
}, return pages === false ? hasNext(v) : v < pages;
}
setValue: function (v) { setValue (v) {
var o = this.options; const o = this.options;
const { pages } = this.options;
v = v || 0; v = v || 0;
v = v < 1 ? 1 : v; v = v < 1 ? 1 : v;
if (o.pages === false) { if (pages === false) {
var lastPage = BI.result(o, "lastPage"), firstPage = 1; const lastPage = result(o, "lastPage");
this.currPage = v > lastPage ? lastPage : ((firstPage = BI.result(o, "firstPage")), (v < firstPage ? firstPage : v)); let firstPage = 1;
this.currPage = v > lastPage ? lastPage : ((firstPage = result(o, "firstPage")), (v < firstPage ? firstPage : v));
} else { } else {
v = v > o.pages ? o.pages : v; v = v > pages ? pages : v;
this.currPage = v; this.currPage = v;
} }
this._populate(); this._populate();
}, }
getValue: function () { getValue () {
var val = this.button_group.getValue()[0]; const val = this.button_group.getValue()[0];
switch (val) { switch (val) {
case "prev": case "prev":
return -1; return -1;
case "next": case "next":
return 1; return 1;
case "first": case "first":
return BI.MIN; return MIN;
case "last": case "last":
return BI.MAX; return MAX;
default : default :
return val; return val;
} }
}, }
attr: function (key, value) { attr (key, value) {
BI.DetailPager.superclass.attr.apply(this, arguments); super.attr(...arguments);
if (key === "curr") { if (key === "curr") {
this.currPage = BI.result(this.options, "curr"); this.currPage = result(this.options, "curr");
} }
}, }
populate: function () { populate () {
this._populate(); this._populate();
} }
}); }
BI.DetailPager.EVENT_CHANGE = "EVENT_CHANGE";
BI.DetailPager.EVENT_AFTER_POPULATE = "EVENT_AFTER_POPULATE";
BI.shortcut("bi.detail_pager", BI.DetailPager);

167
src/case/pager/pager.direction.js

@ -5,80 +5,83 @@
* @class BI.DirectionPager * @class BI.DirectionPager
* @extends BI.Widget * @extends BI.Widget
*/ */
BI.DirectionPager = BI.inherit(BI.Widget, {
_defaultConfig: function () { import { shortcut, Widget, extend, emptyFn, createWidget } from "@/core";
return BI.extend(BI.DirectionPager.superclass._defaultConfig.apply(this, arguments), { import { Pager } from "@/base";
@shortcut()
export class DirectionPager extends Widget {
static EVENT_CHANGE = "EVENT_CHANGE";
static xtype = "bi.direction_pager";
_defaultConfig () {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-direction-pager", baseCls: "bi-direction-pager",
height: 24, height: 24,
horizontal: { horizontal: {
pages: false, // 总页数 pages: false, // 总页数
curr: 1, // 初始化当前页, pages为数字时可用 curr: 1, // 初始化当前页, pages为数字时可用
hasPrev: BI.emptyFn, hasPrev: emptyFn,
hasNext: BI.emptyFn, hasNext: emptyFn,
firstPage: 1, firstPage: 1,
lastPage: BI.emptyFn lastPage: emptyFn,
}, },
vertical: { vertical: {
pages: false, // 总页数 pages: false, // 总页数
curr: 1, // 初始化当前页, pages为数字时可用 curr: 1, // 初始化当前页, pages为数字时可用
hasPrev: BI.emptyFn, hasPrev: emptyFn,
hasNext: BI.emptyFn, hasNext: emptyFn,
firstPage: 1, firstPage: 1,
lastPage: BI.emptyFn lastPage: emptyFn,
} },
}); });
}, }
_init: function () { _init () {
BI.DirectionPager.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options;
var v = o.vertical, h = o.horizontal;
this._createVPager(); this._createVPager();
this._createHPager(); this._createHPager();
this.layout = BI.createWidget({ this.layout = createWidget({
type: "bi.absolute", type: "bi.absolute",
scrollable: false, scrollable: false,
element: this, element: this,
items: [{ items: [{
el: this.vpager, el: this.vpager,
top: 0, top: 0,
right: 86 right: 86,
}, { }, {
el: this.vlabel, el: this.vlabel,
top: 0, top: 0,
right: 110 right: 110,
}, { }, {
el: this.hpager, el: this.hpager,
top: 0, top: 0,
right: 0 right: 0,
}, { }, {
el: this.hlabel, el: this.hlabel,
top: 0, top: 0,
right: 24 right: 24,
}] }],
}); });
}, }
_createVPager: function () { _createVPager () {
var self = this, o = this.options; const v = this.options.vertical;
var v = o.vertical; this.vlabel = createWidget({
this.vlabel = BI.createWidget({
type: "bi.label", type: "bi.label",
width: 24, width: 24,
height: 24, height: 24,
value: v.curr, value: v.curr,
title: v.curr, title: v.curr,
invisible: true invisible: true,
}); });
this.vpager = BI.createWidget({ this.vpager = createWidget({
type: "bi.pager", type: "bi.pager",
width: 72, width: 72,
layouts: [{ layouts: [{
type: "bi.horizontal", type: "bi.horizontal",
scrollx: false, scrollx: false,
rgap: 24 rgap: 24,
}], }],
invisible: true, invisible: true,
@ -96,7 +99,7 @@ BI.DirectionPager = BI.inherit(BI.Widget, {
warningTitle: BI.i18nText("BI-Current_Is_First_Page"), warningTitle: BI.i18nText("BI-Current_Is_First_Page"),
height: 22, height: 22,
width: 22, width: 22,
cls: "bi-border bi-border-radius direction-pager-prev column-pre-page-h-font bi-list-item-select2" cls: "bi-border bi-border-radius direction-pager-prev column-pre-page-h-font bi-list-item-select2",
}, },
next: { next: {
type: "bi.icon_button", type: "bi.icon_button",
@ -105,42 +108,40 @@ BI.DirectionPager = BI.inherit(BI.Widget, {
warningTitle: BI.i18nText("BI-Current_Is_Last_Page"), warningTitle: BI.i18nText("BI-Current_Is_Last_Page"),
height: 22, height: 22,
width: 22, width: 22,
cls: "bi-border bi-border-radius direction-pager-next column-next-page-h-font bi-list-item-select2" cls: "bi-border bi-border-radius direction-pager-next column-next-page-h-font bi-list-item-select2",
}, },
hasPrev: v.hasPrev, hasPrev: v.hasPrev,
hasNext: v.hasNext, hasNext: v.hasNext,
firstPage: v.firstPage, firstPage: v.firstPage,
lastPage: v.lastPage lastPage: v.lastPage,
}); });
this.vpager.on(BI.Pager.EVENT_CHANGE, function () { this.vpager.on(Pager.EVENT_CHANGE, () => {
self.fireEvent(BI.DirectionPager.EVENT_CHANGE); this.fireEvent(DirectionPager.EVENT_CHANGE);
}); });
this.vpager.on(BI.Pager.EVENT_AFTER_POPULATE, function () { this.vpager.on(Pager.EVENT_AFTER_POPULATE, () => {
self.vlabel.setValue(this.getCurrentPage()); this.vlabel.setValue(this.vpager.getCurrentPage());
self.vlabel.setTitle(this.getCurrentPage()); this.vlabel.setTitle(this.vpager.getCurrentPage());
}); });
}, }
_createHPager () {
_createHPager: function () { const h = this.options.horizontal;
var self = this, o = this.options; this.hlabel = createWidget({
var h = o.horizontal;
this.hlabel = BI.createWidget({
type: "bi.label", type: "bi.label",
width: 24, width: 24,
height: 24, height: 24,
value: h.curr, value: h.curr,
title: h.curr, title: h.curr,
invisible: true invisible: true,
}); });
this.hpager = BI.createWidget({ this.hpager = createWidget({
type: "bi.pager", type: "bi.pager",
width: 72, width: 72,
layouts: [{ layouts: [{
type: "bi.horizontal", type: "bi.horizontal",
scrollx: false, scrollx: false,
rgap: 24 rgap: 24,
}], }],
invisible: true, invisible: true,
@ -158,7 +159,7 @@ BI.DirectionPager = BI.inherit(BI.Widget, {
warningTitle: BI.i18nText("BI-Current_Is_First_Page"), warningTitle: BI.i18nText("BI-Current_Is_First_Page"),
height: 22, height: 22,
width: 22, width: 22,
cls: "bi-border bi-border-radius direction-pager-prev row-pre-page-h-font bi-list-item-select2" cls: "bi-border bi-border-radius direction-pager-prev row-pre-page-h-font bi-list-item-select2",
}, },
next: { next: {
type: "bi.icon_button", type: "bi.icon_button",
@ -167,74 +168,74 @@ BI.DirectionPager = BI.inherit(BI.Widget, {
warningTitle: BI.i18nText("BI-Current_Is_Last_Page"), warningTitle: BI.i18nText("BI-Current_Is_Last_Page"),
height: 22, height: 22,
width: 22, width: 22,
cls: "bi-border bi-border-radius direction-pager-next row-next-page-h-font bi-list-item-select2" cls: "bi-border bi-border-radius direction-pager-next row-next-page-h-font bi-list-item-select2",
}, },
hasPrev: h.hasPrev, hasPrev: h.hasPrev,
hasNext: h.hasNext, hasNext: h.hasNext,
firstPage: h.firstPage, firstPage: h.firstPage,
lastPage: h.lastPage lastPage: h.lastPage,
}); });
this.hpager.on(BI.Pager.EVENT_CHANGE, function () { this.hpager.on(Pager.EVENT_CHANGE, () => {
self.fireEvent(BI.DirectionPager.EVENT_CHANGE); this.fireEvent(DirectionPager.EVENT_CHANGE);
}); });
this.hpager.on(BI.Pager.EVENT_AFTER_POPULATE, function () { this.hpager.on(Pager.EVENT_AFTER_POPULATE, () => {
self.hlabel.setValue(this.getCurrentPage()); this.hlabel.setValue(this.hpager.getCurrentPage());
self.hlabel.setTitle(this.getCurrentPage()); this.hlabel.setTitle(this.hpager.getCurrentPage());
}); });
}, }
getVPage: function () { getVPage () {
return this.vpager.getCurrentPage(); return this.vpager.getCurrentPage();
}, }
getHPage: function () { getHPage () {
return this.hpager.getCurrentPage(); return this.hpager.getCurrentPage();
}, }
setVPage: function (v) { setVPage (v) {
this.vpager.setValue(v); this.vpager.setValue(v);
this.vlabel.setValue(v); this.vlabel.setValue(v);
this.vlabel.setTitle(v); this.vlabel.setTitle(v);
}, }
setHPage: function (v) { setHPage (v) {
this.hpager.setValue(v); this.hpager.setValue(v);
this.hlabel.setValue(v); this.hlabel.setValue(v);
this.hlabel.setTitle(v); this.hlabel.setTitle(v);
}, }
hasVNext: function () { hasVNext () {
return this.vpager.hasNext(); return this.vpager.hasNext();
}, }
hasHNext: function () { hasHNext () {
return this.hpager.hasNext(); return this.hpager.hasNext();
}, }
hasVPrev: function () { hasVPrev () {
return this.vpager.hasPrev(); return this.vpager.hasPrev();
}, }
hasHPrev: function () { hasHPrev () {
return this.hpager.hasPrev(); return this.hpager.hasPrev();
}, }
setHPagerVisible: function (b) { setHPagerVisible (b) {
this.hpager.setVisible(b); this.hpager.setVisible(b);
this.hlabel.setVisible(b); this.hlabel.setVisible(b);
}, }
setVPagerVisible: function (b) { setVPagerVisible (b) {
this.vpager.setVisible(b); this.vpager.setVisible(b);
this.vlabel.setVisible(b); this.vlabel.setVisible(b);
}, }
populate: function () { populate () {
this.vpager.populate(); this.vpager.populate();
this.hpager.populate(); this.hpager.populate();
var vShow = false, hShow = false; let vShow = false, hShow = false;
if (!this.hasHNext() && !this.hasHPrev()) { if (!this.hasHNext() && !this.hasHPrev()) {
this.setHPagerVisible(false); this.setHPagerVisible(false);
} else { } else {
@ -248,8 +249,8 @@ BI.DirectionPager = BI.inherit(BI.Widget, {
vShow = true; vShow = true;
} }
this.setVisible(hShow || vShow); this.setVisible(hShow || vShow);
var num = [86, 110, 0, 24]; const num = [86, 110, 0, 24];
var items = this.layout.attr("items"); const items = this.layout.attr("items");
if (vShow === true && hShow === true) { if (vShow === true && hShow === true) {
items[0].right = num[0]; items[0].right = num[0];
@ -265,12 +266,10 @@ BI.DirectionPager = BI.inherit(BI.Widget, {
} }
this.layout.attr("items", items); this.layout.attr("items", items);
this.layout.resize(); this.layout.resize();
}, }
clear: function () { clear () {
this.vpager.attr("curr", 1); this.vpager.attr("curr", 1);
this.hpager.attr("curr", 1); this.hpager.attr("curr", 1);
} }
}); }
BI.DirectionPager.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.direction_pager", BI.DirectionPager);

Loading…
Cancel
Save