149 lines
6.0 KiB
JavaScript
149 lines
6.0 KiB
JavaScript
![]() |
"use strict";
|
||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||
|
var tslib_1 = require("tslib");
|
||
|
var dayjs_1 = tslib_1.__importDefault(require("dayjs"));
|
||
|
var props_1 = require("./props");
|
||
|
var manager_1 = tslib_1.__importStar(require("./manager"));
|
||
|
Component({
|
||
|
props: props_1.CalendarDefaultProps,
|
||
|
data: {
|
||
|
renderTimes: 0,
|
||
|
checkTimes: 0,
|
||
|
buttonDisabled: true
|
||
|
},
|
||
|
didMount: function () {
|
||
|
var _a = this.props, min = _a.min, max = _a.max, disableDates = _a.disableDates, selectionMode = _a.selectionMode, customDateList = _a.customDateList, defaultValue = _a.defaultValue, defaultRange = _a.defaultRange, showlunar = _a.showlunar;
|
||
|
this.timer = null;
|
||
|
this.calendarManager = new manager_1.default({
|
||
|
min: min,
|
||
|
max: max,
|
||
|
disableDates: disableDates,
|
||
|
selectionMode: selectionMode,
|
||
|
customDateList: customDateList,
|
||
|
defaultValue: defaultValue,
|
||
|
defaultRange: defaultRange,
|
||
|
showlunar: showlunar
|
||
|
});
|
||
|
this.render();
|
||
|
this.getConfirmButtonState();
|
||
|
},
|
||
|
didUpdate: function (prev) {
|
||
|
if (!(0, dayjs_1.default)(this.props.min).isSame(prev.min) || !(0, dayjs_1.default)(this.props.max).isSame(prev.max)) {
|
||
|
this.calendarManager.updateStartEndDate(this.props.min, this.props.max);
|
||
|
this.render();
|
||
|
}
|
||
|
else if (prev.disableDates !== this.props.disableDates) {
|
||
|
this.calendarManager.updateDisableDates(this.props.disableDates);
|
||
|
this.render();
|
||
|
}
|
||
|
else if (prev.customDateList !== this.props.customDateList) {
|
||
|
this.calendarManager.updateCustomDateList(this.props.customDateList);
|
||
|
this.render();
|
||
|
}
|
||
|
},
|
||
|
methods: {
|
||
|
console: function () {
|
||
|
var args = [];
|
||
|
for (var _i = 0; _i < arguments.length; _i++) {
|
||
|
args[_i] = arguments[_i];
|
||
|
}
|
||
|
console.log.apply(console, args);
|
||
|
},
|
||
|
checkScroll: function () {
|
||
|
var _this = this;
|
||
|
clearInterval(this.timer);
|
||
|
this.timer = setInterval(function () {
|
||
|
console.log('checkscroll');
|
||
|
_this.setData({ checkTimes: _this.data.checkTimes + 1 });
|
||
|
}, 50);
|
||
|
},
|
||
|
clearCheckScroll: function () {
|
||
|
console.log('clearCheckScroll');
|
||
|
clearInterval(this.timer);
|
||
|
},
|
||
|
render: function () {
|
||
|
this.calendarManager.calculateCalendarList();
|
||
|
this.setData({
|
||
|
calendarList: this.calendarManager.calendarList,
|
||
|
renderTimes: this.data.renderTimes + 1
|
||
|
});
|
||
|
},
|
||
|
onDateChange: function (dataItem) {
|
||
|
var _a;
|
||
|
var selectionMode = this.props.selectionMode;
|
||
|
var date = dataItem.fullDate, disable = dataItem.disable;
|
||
|
if (disable || !selectionMode)
|
||
|
return;
|
||
|
var _b = this.calendarManager, selectStartDate = _b.selectStartDate, selectEndDate = _b.selectEndDate;
|
||
|
if (this.props.selectionMode === manager_1.ECalendarSelectMode.range) {
|
||
|
if (selectStartDate && !selectEndDate) {
|
||
|
selectEndDate = date;
|
||
|
}
|
||
|
else if (!selectStartDate && !selectEndDate) {
|
||
|
selectStartDate = date;
|
||
|
}
|
||
|
else if (selectStartDate && selectEndDate) {
|
||
|
selectStartDate = date;
|
||
|
selectEndDate = null;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
selectStartDate = date;
|
||
|
selectEndDate = null;
|
||
|
}
|
||
|
if ((0, dayjs_1.default)(selectEndDate).isBefore(selectStartDate)) {
|
||
|
_a = [selectStartDate, selectEndDate], selectEndDate = _a[0], selectStartDate = _a[1];
|
||
|
}
|
||
|
this.updateSelectDate(selectStartDate, selectEndDate);
|
||
|
if (!this.props.showConfirmButton) {
|
||
|
this.onCheck();
|
||
|
}
|
||
|
else {
|
||
|
this.getConfirmButtonState();
|
||
|
}
|
||
|
},
|
||
|
updateSelectDate: function (start, end) {
|
||
|
this.calendarManager.updateSelectDate(start, end);
|
||
|
this.render();
|
||
|
},
|
||
|
getConfirmButtonState: function () {
|
||
|
if (this.props.selectionMode === manager_1.ECalendarSelectMode.range) {
|
||
|
if (this.calendarManager.selectStartDate && this.calendarManager.selectEndDate) {
|
||
|
return this.setData({
|
||
|
buttonDisabled: false
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
if (this.calendarManager.selectStartDate) {
|
||
|
return this.setData({
|
||
|
buttonDisabled: false
|
||
|
});
|
||
|
}
|
||
|
}
|
||
|
this.setData({
|
||
|
buttonDisabled: true
|
||
|
});
|
||
|
},
|
||
|
onCheck: function () {
|
||
|
var _a, _b, _c, _d;
|
||
|
if (this.props.selectionMode === manager_1.ECalendarSelectMode.range) {
|
||
|
if (this.calendarManager.selectStartDate && this.calendarManager.selectEndDate) {
|
||
|
(_b = (_a = this.props).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, [(0, dayjs_1.default)(this.calendarManager.selectStartDate).toDate(), (0, dayjs_1.default)(this.calendarManager.selectEndDate).toDate()]);
|
||
|
}
|
||
|
}
|
||
|
else if (this.props.selectionMode === manager_1.ECalendarSelectMode.single) {
|
||
|
if (this.calendarManager.selectStartDate) {
|
||
|
(_d = (_c = this.props).onChange) === null || _d === void 0 ? void 0 : _d.call(_c, (0, dayjs_1.default)(this.calendarManager.selectStartDate).toDate());
|
||
|
}
|
||
|
}
|
||
|
},
|
||
|
onCancel: function () {
|
||
|
this.updateSelectDate(null, null);
|
||
|
},
|
||
|
onClose: function () {
|
||
|
var _a;
|
||
|
(_a = this.props) === null || _a === void 0 ? void 0 : _a.onClose();
|
||
|
},
|
||
|
}
|
||
|
});
|