|
|
@ -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); |
|
|
|
|
|
|
|