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