@d.blizen/datepicker-nash-travel
Version:
A vue component of datepicker, includes DatePicker, DatetimePicker, DateRangePicker, TimePicker
1,582 lines (1,367 loc) • 332 kB
JavaScript
/**
* Bundle of @livelybone/vue-datepicker
* Generated: 2021-02-04
* Version: 4.0.2
* License: MIT
* Author: 2631541504@qq.com
*/
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
typeof define === 'function' && define.amd ? define(['exports'], factory) :
(global = global || self, factory(global.VueDatepicker = {}));
}(this, (function (exports) { 'use strict';
function _typeof(obj) {
"@babel/helpers - typeof";
if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
_typeof = function (obj) {
return typeof obj;
};
} else {
_typeof = function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
}
return _typeof(obj);
}
function _defineProperty(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys(Object(source), true).forEach(function (key) {
_defineProperty(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
function _objectWithoutPropertiesLoose(source, excluded) {
if (source == null) return {};
var target = {};
var sourceKeys = Object.keys(source);
var key, i;
for (i = 0; i < sourceKeys.length; i++) {
key = sourceKeys[i];
if (excluded.indexOf(key) >= 0) continue;
target[key] = source[key];
}
return target;
}
function _objectWithoutProperties(source, excluded) {
if (source == null) return {};
var target = _objectWithoutPropertiesLoose(source, excluded);
var key, i;
if (Object.getOwnPropertySymbols) {
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
for (i = 0; i < sourceSymbolKeys.length; i++) {
key = sourceSymbolKeys[i];
if (excluded.indexOf(key) >= 0) continue;
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
target[key] = source[key];
}
}
return target;
}
function _slicedToArray(arr, i) {
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
}
function _toConsumableArray(arr) {
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
}
function _arrayWithoutHoles(arr) {
if (Array.isArray(arr)) return _arrayLikeToArray(arr);
}
function _arrayWithHoles(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArray(iter) {
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
}
function _iterableToArrayLimit(arr, i) {
if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return;
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _unsupportedIterableToArray(o, minLen) {
if (!o) return;
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
var n = Object.prototype.toString.call(o).slice(8, -1);
if (n === "Object" && o.constructor) n = o.constructor.name;
if (n === "Map" || n === "Set") return Array.from(o);
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
}
function _arrayLikeToArray(arr, len) {
if (len == null || len > arr.length) len = arr.length;
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
return arr2;
}
function _nonIterableSpread() {
throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
function _nonIterableRest() {
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
}
/**
* Bundle of @livelybone/date-generator
* Generated: 2020-05-17
* Version: 4.2.1
* License: MIT
* Author: 2631541504@qq.com
*/
function _defineProperty$1(obj, key, value) {
if (key in obj) {
Object.defineProperty(obj, key, {
value: value,
enumerable: true,
configurable: true,
writable: true
});
} else {
obj[key] = value;
}
return obj;
}
function ownKeys$1(object, enumerableOnly) {
var keys = Object.keys(object);
if (Object.getOwnPropertySymbols) {
var symbols = Object.getOwnPropertySymbols(object);
if (enumerableOnly) symbols = symbols.filter(function (sym) {
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
});
keys.push.apply(keys, symbols);
}
return keys;
}
function _objectSpread2$1(target) {
for (var i = 1; i < arguments.length; i++) {
var source = arguments[i] != null ? arguments[i] : {};
if (i % 2) {
ownKeys$1(Object(source), true).forEach(function (key) {
_defineProperty$1(target, key, source[key]);
});
} else if (Object.getOwnPropertyDescriptors) {
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
} else {
ownKeys$1(Object(source)).forEach(function (key) {
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
});
}
}
return target;
}
function fillTo(width, num) {
var pad = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '0';
if (pad === undefined) pad = '0';
num = num.toString();
width -= num.length;
if (width > 0) {
return new Array(width + (/\./.test(num) ? 2 : 1)).join(pad) + num;
}
return num;
}
function isNonNegInt(num) {
num = +num;
return num === Math.floor(num) && num >= 0;
}
function positiveMod(val, div) {
return (val % div + div) % div;
}
function isLeapYear(year) {
year = +year;
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
}
function getMonthLen(year, month) {
year = +year;
month = +month;
if (month === 2) {
return isLeapYear(year) ? 29 : 28;
}
return Math.ceil(Math.abs(month - 7.5)) % 2 === 1 ? 31 : 30;
}
function getIntervalVal(defaultMax) {
return function (options) {
var interval = Math.ceil(Math.abs(options && options.interval || 1));
var min = Math.ceil(Math.abs(options && options.min || 0));
var max = Math.ceil(Math.abs(options && options.max || defaultMax - 1));
var arr = [];
for (var i = 0; i <= defaultMax; i += interval) {
arr.push({
value: fillTo(2, i),
max: defaultMax,
canBeChose: i >= min && i <= max
});
}
return arr;
};
}
function parseDate(date) {
if (!date) return null;
var reg = /^(\d{4})-?(\d{1,2})?-?(\d{1,2})?$/;
if (!reg.test(date)) {
console.warn(new Error("Param date `".concat(date, "` is invalid. The right example: 2018[-02][-01]")));
return null;
}
var arr = date.match(reg);
var dateObj = {
year: fillTo(4, arr[1]),
month: fillTo(2, positiveMod(+arr[2] || 1, 12) || 12)
};
var monthLen = getMonthLen(dateObj.year, dateObj.month);
dateObj.date = fillTo(2, positiveMod(+arr[3] || 1, monthLen) || monthLen);
return dateObj;
}
function parseTime(time) {
if (!time) return null;
var reg = /^(\d{1,2}):?(\d{1,2})?:?(\d{1,2})?$/;
if (!reg.test(time)) {
console.warn(new Error("Param time `".concat(time, "` is invalid. The right example: 18[:02][:01]")));
return null;
}
var arr = time.match(reg);
return {
hour: fillTo(2, positiveMod(+arr[1], 24)),
minute: fillTo(2, positiveMod(+arr[2] || 0, 60)),
second: fillTo(2, positiveMod(+arr[3] || 0, 60))
};
}
function nowDate() {
var now = new Date();
return {
year: fillTo(4, now.getFullYear()),
month: fillTo(2, now.getMonth() + 1),
date: fillTo(2, now.getDate())
};
}
function gntMonth(year, options) {
year = +year;
options = options || {};
var splitLen = options.splitLen || 3;
var min = typeof options.min === 'string' ? parseDate(options.min) : options.min;
var max = typeof options.max === 'string' ? parseDate(options.max) : options.max;
var arr = [];
var line = Math.ceil(12 / splitLen);
var now = nowDate();
for (var i = 0; i < line; i += 1) {
arr[i] = [];
for (var j = 0; j < splitLen; j += 1) {
var month = i * splitLen + j + 1;
if (month > 12) break;
arr[i].push({
year: fillTo(4, year),
month: fillTo(2, month),
canBeChose: !min && !max || !!min && !!max && (year > +min.year || year === +min.year && month >= +min.month) && (year < +max.year || year === +max.year && month <= +max.month) || !max && !!min && (year > +min.year || year === +min.year && month >= +min.month) || !min && !!max && (year < +max.year || year === +max.year && month <= +max.month),
isNow: +now.year === year && +now.month === month
});
}
}
return arr;
}
function getMonthByStep(currMonth, step) {
var $currMonth = typeof currMonth === 'string' ? parseDate(currMonth) : currMonth;
if (!$currMonth) return null;
var $month = +$currMonth.month + step;
var mod = positiveMod($month, 12);
var times = Math.floor($month / 12);
if (mod === 0) times -= 1;
return {
year: fillTo(4, +$currMonth.year + times),
month: fillTo(2, mod || 12)
};
}
/**
* Integer number
* */
/**
* Format: /^\d\d$/
* */
var DefaultMax;
/**
* Format: /^(\d{4})-?(\d{1,2})?-?(\d{1,2})?$/
* */
(function (DefaultMax) {
DefaultMax[DefaultMax["Hour"] = 23] = "Hour";
DefaultMax[DefaultMax["Minute"] = 59] = "Minute";
DefaultMax[DefaultMax["Second"] = 59] = "Second";
})(DefaultMax || (DefaultMax = {}));
var DateCompare;
(function (DateCompare) {
DateCompare[DateCompare["GreatThanYear"] = 100] = "GreatThanYear";
DateCompare[DateCompare["GreatThanMonth"] = 10] = "GreatThanMonth";
DateCompare[DateCompare["GreatThanDate"] = 1] = "GreatThanDate";
DateCompare[DateCompare["Equal"] = 0] = "Equal";
DateCompare[DateCompare["LessThanDate"] = -1] = "LessThanDate";
DateCompare[DateCompare["LessThanMonth"] = -10] = "LessThanMonth";
DateCompare[DateCompare["LessThanYear"] = -100] = "LessThanYear";
})(DateCompare || (DateCompare = {}));
function getDay(year, month, date) {
year = +year;
month = +month;
date = +date;
var c;
var y;
var m;
if (month === 1 || month === 2) {
c = Math.floor((year - 1) / 100);
y = (year - 1) % 100;
m = month + 12;
} else {
c = Math.floor(year / 100);
y = year % 100;
m = month;
}
return positiveMod(y + Math.floor(y / 4) + Math.floor(c / 4) - 2 * c + Math.floor(26 * (m + 1) / 10) + date - 1, 7);
}
function compareDates(date1, date2) {
var $date1 = typeof date1 === 'string' ? parseDate(date1) : date1;
var $date2 = typeof date2 === 'string' ? parseDate(date2) : date2;
if (!$date1 || !$date2) return DateCompare.Equal;
var diff = +$date1.year - +$date2.year;
if (diff) return diff > 0 ? DateCompare.GreatThanYear : DateCompare.LessThanYear;
diff = +$date1.month - +$date2.month;
if (diff) return diff > 0 ? DateCompare.GreatThanMonth : DateCompare.LessThanMonth;
diff = +$date1.date - +$date2.date;
if (diff) return diff > 0 ? DateCompare.GreatThanDate : DateCompare.LessThanDate;
return DateCompare.Equal;
}
function calcStepBetweenDates(date, targetDate) {
var $date = typeof date === 'string' ? parseDate(date) : date;
var $targetDate = typeof targetDate === 'string' ? parseDate(targetDate) : targetDate;
if (!$date || !$targetDate) return 0;
var compare = compareDates($date, $targetDate);
if (compare === 0) return 0;
var small = compare > 0 ? $targetDate : $date;
var big = compare > 0 ? $date : $targetDate;
var flag = compare > 0 ? 1 : -1;
var yearStep = +big.year - +small.year;
if (yearStep > 1) {
return (new Array(yearStep).join(',').split('').reduce(function (pre, v, i) {
var year = +small.year + i + 1;
return pre + (isLeapYear(year) ? 366 : 365);
}, 0) + calcStepBetweenDates(_objectSpread2$1({}, small, {
month: 12,
date: 31
}), small) + calcStepBetweenDates(big, _objectSpread2$1({}, big, {
month: 1,
date: 1
})) + 1) * flag;
}
if (yearStep === 1) {
return (calcStepBetweenDates(_objectSpread2$1({}, small, {
month: 12,
date: 31
}), small) + calcStepBetweenDates(big, _objectSpread2$1({}, big, {
month: 1,
date: 1
})) + 1) * flag;
}
var monthStep = +big.month - +small.month;
if (monthStep > 1) {
return (new Array(monthStep).join(',').split('').reduce(function (pre, v, i) {
var month = +small.month + i + 1;
return pre + getMonthLen(small.year, month);
}, 0) + calcStepBetweenDates(_objectSpread2$1({}, small, {
date: getMonthLen(small.year, small.month)
}), small) + calcStepBetweenDates(big, _objectSpread2$1({}, big, {
date: 1
})) + 1) * flag;
}
if (monthStep === 1) {
return (calcStepBetweenDates(_objectSpread2$1({}, small, {
date: getMonthLen(small.year, small.month)
}), small) + calcStepBetweenDates(big, _objectSpread2$1({}, big, {
date: 1
})) + 1) * flag;
}
return (+big.date - +small.date) * flag;
}
function gntCalendar(monthInfo, options) {
var $monthInfo = typeof monthInfo === 'string' ? parseDate(monthInfo) : monthInfo;
if (!$monthInfo) return null;
var year = +$monthInfo.year;
var month = +$monthInfo.month;
options = options || {};
if (!isNonNegInt(year) || !isNonNegInt(month)) {
throw new Error('Prop year and month must be a non-negative number');
}
var minD = typeof options.min === 'string' ? parseDate(options.min) : options.min;
var maxD = typeof options.max === 'string' ? parseDate(options.max) : options.max;
var firstDayOfWeek = options.firstDayOfWeek || 0;
var prevMonth = getMonthByStep({
year: year,
month: month
}, -1);
var prevMonthLen = getMonthLen(prevMonth.year, prevMonth.month);
var monthLen = getMonthLen(year, month);
var nextMonth = getMonthByStep({
year: year,
month: month
}, 1);
var lineLen = Math.ceil(31 / 7) + 1;
var calendar = [];
var canChose = function canChose($year, $month, date) {
var compare = function compare(t, flag) {
if (!t) return true;
flag = flag || 1;
var y = +t.year;
var m = +t.month;
var d = +t.date;
return ($year - y) * flag > 0 || $year === y && ($month - m) * flag > 0 || $year === y && $month === m && (date - d) * flag >= 0;
};
return compare(minD) && compare(maxD, -1);
};
var incrementDate = 1;
var nextIncrementDate = 1;
var firstDay = getDay(year, month, 1);
var fillDateLen = (firstDay - firstDayOfWeek + 7) % 7;
var now = nowDate();
for (var i = 0; i < lineLen; i += 1) {
calendar[i] = [];
for (var j = 0; j < 7; j += 1) {
if (i === 0 && j < fillDateLen) {
var d = prevMonthLen - fillDateLen + 1 + j;
calendar[i][j] = {
year: fillTo(4, prevMonth.year),
month: fillTo(2, prevMonth.month),
date: fillTo(2, d),
isInThisMonth: false,
canBeChose: canChose(+prevMonth.year, +prevMonth.month, d),
isNow: false
};
calendar[i][j].isNow = calcStepBetweenDates(now, calendar[i][j]) === 0; // eslint-disable-next-line no-continue
continue;
}
if (incrementDate <= monthLen) {
calendar[i][j] = {
year: fillTo(4, year),
month: fillTo(2, month),
date: fillTo(2, incrementDate),
isInThisMonth: true,
canBeChose: canChose(year, month, incrementDate),
isNow: false
};
calendar[i][j].isNow = calcStepBetweenDates(now, calendar[i][j]) === 0;
incrementDate += 1;
} else {
calendar[i][j] = {
year: fillTo(4, nextMonth.year),
month: fillTo(2, nextMonth.month),
date: fillTo(2, nextIncrementDate),
isInThisMonth: false,
canBeChose: canChose(+nextMonth.year, +nextMonth.month, nextIncrementDate),
isNow: false
};
calendar[i][j].isNow = calcStepBetweenDates(now, calendar[i][j]) === 0;
nextIncrementDate += 1;
}
}
}
return calendar;
}
function getDateByStep(currDate, step) {
var $currDate = typeof currDate === 'string' ? parseDate(currDate) : currDate;
if (!$currDate) return null;
var len = getMonthLen($currDate.year, $currDate.month);
var date = +$currDate.date + step;
if (date <= 0) {
var prevMonth = getMonthByStep($currDate, -1);
return getDateByStep(_objectSpread2$1({}, prevMonth, {
date: getMonthLen(prevMonth.year, prevMonth.month)
}), date);
}
if (date > len) {
var nextMonth = getMonthByStep($currDate, 1);
return getDateByStep(_objectSpread2$1({}, nextMonth, {
date: 1
}), date - len);
}
return {
year: fillTo(4, $currDate.year),
month: fillTo(2, $currDate.month),
date: fillTo(2, date)
};
}
var getHour = getIntervalVal(DefaultMax.Hour);
var getMinute = getIntervalVal(DefaultMax.Minute);
var getSecond = getIntervalVal(DefaultMax.Second);
function gntYear(start, len, options) {
start = +start;
options = options || {};
if (!isNonNegInt(+start) || !isNonNegInt(+len)) {
throw new Error('Prop start and len must be a non-negative number');
}
var splitLen = options.splitLen || 3;
var min = options.min || null;
var max = options.max || null;
var arr = [];
var line = Math.ceil(len / splitLen);
var now = nowDate();
for (var i = 0; i < line; i += 1) {
arr[i] = [];
for (var j = 0; j < splitLen; j += 1) {
var year = start + i * splitLen + j;
if (year - start + 1 > len) break;
arr[i].push({
year: fillTo(4, year),
canBeChose: !min && !max || !!min && !!max && year >= min && year <= max || !min && !!max && year <= max || !max && !!min && year >= min,
isNow: +now.year === year
});
}
}
return arr;
}
var dateReg = /^((\d{4})-?(\d{1,2})?-?(\d{1,2})?)/;
var timeReg = /^((\d{1,2}):?(\d{1,2})?:?(\d{1,2})?)/;
var AllTypes = ['year', 'month', 'date', 'time'];
var AllTimeTypes = ['hour', 'minute', 'second'];
function sliceUtilEqual(arr, val) {
var index = Object.keys(arr).find(function (i) {
return arr[+i] === val;
});
if (!index) return arr;
return arr.slice(0, +index + 1);
} // flag:
// -1 - 如果 d1 小于等于 d2,返回 true
// 1 - 如果 d1 大于等于 d2,返回 true
// 0 - 如果 d1 等于 d2,返回 true
function dateCompare(date, targetDate) {
var flag = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
var type = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'date';
var $date = typeof date === 'string' ? parseDate(date) : date ? _objectSpread2({}, date) : undefined;
var $targetDate = typeof targetDate === 'string' ? parseDate(targetDate) : targetDate ? _objectSpread2({}, targetDate) : undefined;
if (!$date) return false;
if (!$targetDate) return true;
if (type === 'year') {
$date.month = '01';
$date.date = '01';
$targetDate.month = '01';
$targetDate.date = '01';
} else if (type === 'month') {
$date.date = '01';
$targetDate.date = '01';
}
var compare = compareDates($date, $targetDate);
return flag === 0 ? compare === 0 : compare * flag >= 0;
} // flag:
// -1 - 如果 t1 小于等于 t2,返回 true
// 1 - 如果 t1 大于等于 t2,返回 true
// 0 - 如果 t1 等于 t2,返回 true
function timeCompare(time, targetTime) {
var flag = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
var type = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'second';
var $time = typeof time === 'string' ? parseTime(time) : time ? _objectSpread2({}, time) : undefined;
var $targetTime = typeof targetTime === 'string' ? parseTime(targetTime) : targetTime ? _objectSpread2({}, targetTime) : undefined;
if (!$time) return false;
if (!$targetTime) return true;
if (type === 'hour') {
$time.minute = '00';
$time.second = '00';
$targetTime.minute = '00';
$targetTime.second = '00';
} else if (type === 'minute') {
$time.second = '00';
$targetTime.second = '00';
}
var get = function get(t) {
return +"".concat(fillTo(2, t.hour)).concat(fillTo(2, t.minute)).concat(fillTo(2, t.second));
};
var compare = get($time) - get($targetTime);
return flag === 0 ? compare === 0 : compare * flag >= 0;
}
function datetimeCompare(datetime, targetDatetime) {
var flag = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 1;
var type = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 'second';
if (!datetime) return false;
if (!targetDatetime) return true;
if (flag === 0) return dateCompare(datetime, targetDatetime, flag) && (datetime.hour === undefined || timeCompare(datetime, targetDatetime, flag));
var compare = dateCompare(datetime, targetDatetime, flag);
if (!compare) return false;
var compareReverse = dateCompare(datetime, targetDatetime, -flag);
if (compareReverse) return datetime.hour === undefined || timeCompare(datetime, targetDatetime, flag, type);
return true;
}
function $fillTo(width, num) {
return num !== undefined ? fillTo(width, num) : '';
}
function getTenYears(val) {
if (!val) return '';
var tenYear = Math.floor(+val.year / 10 - 0.5);
return "".concat(tenYear * 10 + 1, " - ").concat((tenYear + 1) * 10);
}
function createNowTimeObj() {
var now = new Date();
return {
year: now.getFullYear(),
month: now.getMonth() + 1,
date: now.getDate(),
hour: now.getHours(),
minute: now.getMinutes(),
second: now.getSeconds()
};
}
function formatDateObj(val) {
return {
year: val.year && fillTo(4, val.year) || '',
month: val.month && fillTo(2, val.month) || '',
date: val.date && fillTo(2, val.date) || ''
};
}
function formatTimeObj(val) {
return {
hour: val.hour && fillTo(2, val.hour) || '',
minute: val.minute && fillTo(2, val.minute) || '',
second: val.second && fillTo(2, val.second) || ''
};
}
function formatDate(d) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'date';
if (!d) return '';
var arr = [];
var year = d.year && $fillTo(4, d.year);
if (year) {
arr.push(year);
var month = d.month && $fillTo(2, d.month);
if (month) {
arr.push(month);
var date = d.date && $fillTo(2, d.date);
if (date) arr.push(date);
}
}
return arr.slice(0, sliceUtilEqual(AllTypes, type).length).join('-');
}
function formatTime(t) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'second';
if (!t) return '';
var arr = [];
var hour = t.hour && $fillTo(2, t.hour);
if (hour) {
arr.push(hour);
var minute = t.minute && $fillTo(2, t.minute);
if (minute) {
arr.push(minute);
var second = t.second && $fillTo(2, t.second);
if (second) arr.push(second);
}
}
return arr.slice(0, sliceUtilEqual(AllTimeTypes, type).length).join(':');
}
function mergePropExceptEmpty(o1, o2) {
return Object.keys(_objectSpread2(_objectSpread2({}, o1), o2)).reduce(function (pre, k) {
return _objectSpread2(_objectSpread2({}, pre), {}, _defineProperty({}, k, o2 && o2[k] || o1 && o1[k]));
}, o1);
}
function dealDateLimit(min, max) {
var error = [];
var minDate = min && parseDate(min) || undefined;
if (min && !minDate) error.push("Prop min(".concat(min, ") is invalid"));
var maxDate = max && parseDate(max) || undefined;
if (max && !maxDate) error.push("Prop max(".concat(max, ") is invalid"));
return {
minDate: formatDateObj(mergePropExceptEmpty({
year: '0000',
month: '01',
date: '01'
}, minDate)),
maxDate: formatDateObj(mergePropExceptEmpty({
year: '9999',
month: '12',
date: '31'
}, maxDate)),
error: error.join(';')
};
}
function dealTimeLimit(min, max) {
var error = [];
var minTime = min && parseTime(min) || undefined;
if (min && !minTime) error.push("Prop min(".concat(min, ") is invalid"));
var maxTime = max && parseTime(max) || undefined;
if (max && !maxTime) error.push("Prop max(".concat(max, ") is invalid"));
return {
minTime: formatTimeObj(mergePropExceptEmpty({
hour: '00',
minute: '00',
second: '00'
}, minTime)),
maxTime: formatTimeObj(mergePropExceptEmpty({
hour: '23',
minute: '59',
second: '59'
}, maxTime)),
error: error.join(';')
};
}
function dealDatetimeLimit(min, max, selectedDate) {
var minArr = (min || '').trim().split(/\s+/);
var maxArr = (max || '').trim().split(/\s+/);
var _dealDateLimit = dealDateLimit(minArr[0], maxArr[0]),
minDate = _dealDateLimit.minDate,
maxDate = _dealDateLimit.maxDate;
var compare = {
toMin: minDate && selectedDate ? compareDates(selectedDate, minDate) : 1,
toMax: maxDate && selectedDate ? compareDates(selectedDate, maxDate) : -1
};
var _dealTimeLimit = dealTimeLimit(minArr[1], maxArr[1]),
$minTime = _dealTimeLimit.minTime,
$maxTime = _dealTimeLimit.maxTime;
var error = [];
var minDatetime = minDate ? _objectSpread2(_objectSpread2({}, minDate), $minTime) : undefined;
if (min && !minDatetime) error.push("Prop min(".concat(min, ") is invalid"));
var maxDatetime = maxDate ? _objectSpread2(_objectSpread2({}, maxDate), $maxTime) : undefined;
if (max && !maxDatetime) error.push("Prop min(".concat(max, ") is invalid"));
var minTime = function () {
if (compare.toMin === 0) return $minTime;
if (compare.toMin < 0) return {
hour: '23',
minute: '59',
second: '59'
};
return {
hour: '00',
minute: '00',
second: '00'
};
}();
var maxTime = function () {
if (compare.toMax === 0) return $maxTime;
if (compare.toMax > 0) return {
hour: '00',
minute: '00',
second: '00'
};
return {
hour: '23',
minute: '59',
second: '59'
};
}();
return {
minArr: minArr,
maxArr: maxArr,
minDate: minDate,
maxDate: maxDate,
minTime: minTime,
maxTime: maxTime,
minDatetime: minDatetime,
maxDatetime: maxDatetime,
error: error.join(';')
};
}
function getNextMonthFirstDate(dateInfo) {
if (!dateInfo) return undefined;
var month = getMonthByStep(dateInfo, 1);
return _objectSpread2(_objectSpread2({}, month), {}, {
date: fillTo(2, 1)
});
}
function getPrevMonthLastDate(dateInfo) {
if (!dateInfo) return undefined;
var month = getMonthByStep(dateInfo, -1);
return _objectSpread2(_objectSpread2({}, month), {}, {
date: fillTo(2, getMonthLen(month.year, month.month))
});
}
function getPrevYearLastDate(year) {
if (!year) return undefined;
return {
year: fillTo(4, +year - 1),
month: '12',
date: '31'
};
}
function getPrevTenYearLastDate(year) {
if (!year) return undefined;
return {
year: fillTo(4, (Math.ceil(+year / 10) - 1) * 10),
month: '12',
date: '31'
};
}
function getNextYearFirstDate(year) {
if (!year) return undefined;
return {
year: fillTo(4, +year + 1),
month: '01',
date: '01'
};
}
function getNextTenYearFirstDate(year) {
if (!year) return undefined;
return {
year: fillTo(4, Math.ceil(+year / 10) * 10 + 1),
month: '01',
date: '01'
};
}
function getFirstMaxDate(val) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'date';
if (!val) return undefined;
if (type === 'year') return getPrevTenYearLastDate(val.year);
if (type === 'month') return getPrevYearLastDate(val.year);
return getPrevMonthLastDate(val);
}
function getLastMinDate(val) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'date';
if (!val) return undefined;
if (type === 'year') return getNextTenYearFirstDate(val.year);
if (type === 'month') return getNextYearFirstDate(val.year);
return getNextMonthFirstDate(val);
}
function dateValidator(val) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'date';
var min = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
var max = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
if (!val) return '';
var date = typeof val === 'string' ? parseDate(val) : val;
var checkProps = sliceUtilEqual(AllTypes, type);
if (!date || !checkProps.every(function (k) {
return date[k];
})) return "Value(".concat(val, ") is invalid");
if (!((!min || dateCompare(date, min, 1, type)) && (!max || dateCompare(date, max, -1, type)))) {
return "Value".concat(val, " is out of range");
}
return '';
}
function timeValidator(val) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'second';
var min = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
var max = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
if (!val) return '';
var time = typeof val === 'string' ? parseTime(val) : val;
var checkProps = sliceUtilEqual(AllTimeTypes, type);
if (!time || !checkProps.every(function (k) {
return time[k];
})) return "Value(".concat(val, ") is invalid");
if (!((!min || timeCompare(time, min, 1, type)) && (!max || timeCompare(time, max, -1, type)))) {
return "Value".concat(val, " is out of range");
}
return '';
}
function parseDatetime(val) {
var $val = val || '';
if (!$val.trim()) return null;
var arr = $val.trim().split(/\s+/);
return _objectSpread2(_objectSpread2({}, parseDate(arr[0])), parseTime(arr[1]));
}
function datetimeValidator(val) {
var type = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'second';
var min = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
var max = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
if (!val) return '';
var time = typeof val === 'string' ? parseDatetime(val) : val;
var checkProps = AllTypes.slice(0, 3).concat(sliceUtilEqual(AllTimeTypes, type));
if (!time || !checkProps.every(function (k) {
return time[k];
})) return "Value(".concat(val, ") is invalid");
if (!((!min || datetimeCompare(time, min, 1, type)) && (!max || datetimeCompare(time, max, -1, type)))) {
return "Value".concat(val, " is out of range");
}
return '';
}
function isInSameTenYear(v1, v2) {
return dateCompare(v1, v2, 0, 'year');
}
function isInSameYear(v1, v2) {
return dateCompare(v1, v2, 0, 'year');
}
function isInSameMonth(v1, v2) {
return dateCompare(v1, v2, 0, 'month');
}
function isInSamePage(_ref, type) {
var _ref2 = _slicedToArray(_ref, 2),
v1 = _ref2[0],
v2 = _ref2[1];
if (type === 'year') return isInSameTenYear(v1, v2);
if (type === 'month') return isInSameYear(v1, v2);
return isInSameMonth(v1, v2);
}
function formatDatetime(val, type) {
var str = '';
var d = formatDate(val);
str += d;
if (!str) return '';
var t = formatTime(val, type);
return t ? "".concat(str, " ").concat(t) : '';
}
var script = {
name: 'Date',
props: {
type: String,
minDate: Object,
maxDate: Object,
dayStr: Array,
selectedDates: Array,
isRange: Boolean,
firstDayOfWeek: {
type: Number,
default: 0
}
},
data: function data() {
return {
dateObj: formatDateObj(createNowTimeObj())
};
},
computed: {
$dayStr: function $dayStr() {
var dayStr = !this.dayStr || this.dayStr.length < 7 || this.dayStr.some(function (day) {
return typeof day !== 'string';
}) ? ['日', '一', '二', '三', '四', '五', '六'] : this.dayStr.slice(0, 7);
return dayStr.slice(this.firstDayOfWeek).concat(dayStr.slice(0, this.firstDayOfWeek));
},
years: function years() {
if (!this.dateObj.year) return [];
return gntYear(Math.floor(this.dateObj.year / 10 - 0.5) * 10 + 1, 10, {
splitLen: 3,
min: this.minDate.year,
max: this.maxDate.year
});
},
months: function months() {
return gntMonth(this.dateObj.year, {
splitLen: 3,
min: this.minDate,
max: this.maxDate
});
},
dates: function dates() {
return gntCalendar(this.dateObj, {
min: this.minDate,
max: this.maxDate,
firstDayOfWeek: this.firstDayOfWeek
});
},
pickerItems: function pickerItems() {
if (this.type === 'year') return this.years;
if (this.type === 'month') return this.months;
return this.dates;
}
},
watch: {
pickerItems: function pickerItems(val) {
var showBtn = null;
if (this.type === 'time') {
showBtn = {
prev: dateCompare(getDateByStep(this.dateObj, -1), this.minDate, 1),
next: dateCompare(getDateByStep(this.dateObj, 1), this.maxDate, -1)
};
} else {
var _date$month$year$this = {
date: {
prev: function prev(v) {
return getPrevMonthLastDate(v);
},
next: function next(v) {
return getNextMonthFirstDate(v);
}
},
month: {
prev: function prev(v) {
return getPrevYearLastDate(v.year);
},
next: function next(v) {
return getNextYearFirstDate(v.year);
}
},
year: {
prev: function prev(v) {
return getPrevTenYearLastDate(v.year);
},
next: function next(v) {
return getNextTenYearFirstDate(v.year);
}
}
}[this.type],
prev = _date$month$year$this.prev,
next = _date$month$year$this.next;
showBtn = {
prev: dateCompare(prev(this.dateObj), this.minDate, 1, this.type),
next: dateCompare(next(this.dateObj), this.maxDate, -1, this.type)
};
}
this.$emit('emitData', {
showBtn: showBtn,
items: val
});
},
dateObj: {
immediate: true,
handler: function handler(val) {
// This event is used to trigger the interaction of another comp
this.$emit('pageChange', {
currObj: val
});
}
}
},
methods: {
chose: function chose(item) {
if (item.canBeChose) {
this.dateObj[this.type] = item[this.type];
this.$emit('chose', _objectSpread2({
type: this.type
}, item));
this.$forceUpdate();
}
},
isSelected: function isSelected(item) {
if (!this.selectedDates) return false;
var checkProps = sliceUtilEqual(AllTypes, this.type);
return this.selectedDates.filter(Boolean).some(function (it) {
return checkProps.every(function (k) {
return item[k] === it[k];
});
});
},
isInRange: function isInRange(item) {
if (this.isRange && this.selectedDates && this.selectedDates.filter(Boolean).length > 1) {
var date = _objectSpread2(_objectSpread2({}, item), {}, {
month: this.type !== 'year' && item.month || '01',
date: this.type === 'date' && item.date || '01'
});
return dateCompare(date, this.selectedDates[0], 1, this.type) && dateCompare(date, this.selectedDates[1], -1, this.type);
}
return false;
},
to: function to() {
var step = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
if (this.type === 'year') {
this.dateObj = formatDateObj(_objectSpread2(_objectSpread2({}, this.dateObj), {}, {
year: +this.dateObj.year + 10 * step
}));
this.$emit('to', _objectSpread2({
type: 'ten-year'
}, this.dateObj));
} else if (this.type === 'month') {
this.dateObj = formatDateObj(_objectSpread2(_objectSpread2({}, this.dateObj), {}, {
year: +this.dateObj.year + step
}));
if (this.dateObj.canBeChose) this.$emit('to', _objectSpread2({
type: 'year'
}, this.dateObj));
} else if (this.type === 'date') {
this.dateObj = getMonthByStep(this.dateObj, step);
if (this.dateObj.canBeChose) this.$emit('to', _objectSpread2({
type: 'month'
}, this.dateObj));
} else {
this.dateObj = getDateByStep(this.dateObj, step);
if (this.dateObj.canBeChose) this.$emit('to', _objectSpread2({
type: 'date'
}, this.dateObj));
}
}
}
};
function normalizeComponent(template, style, script, scopeId, isFunctionalTemplate, moduleIdentifier
/* server only */
, shadowMode, createInjector, createInjectorSSR, createInjectorShadow) {
if (typeof shadowMode !== 'boolean') {
createInjectorSSR = createInjector;
createInjector = shadowMode;
shadowMode = false;
} // Vue.extend constructor export interop.
var options = typeof script === 'function' ? script.options : script; // render functions
if (template && template.render) {
options.render = template.render;
options.staticRenderFns = template.staticRenderFns;
options._compiled = true; // functional template
if (isFunctionalTemplate) {
options.functional = true;
}
} // scopedId
if (scopeId) {
options._scopeId = scopeId;
}
var hook;
if (moduleIdentifier) {
// server build
hook = function hook(context) {
// 2.3 injection
context = context || // cached call
this.$vnode && this.$vnode.ssrContext || // stateful
this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext; // functional
// 2.2 with runInNewContext: true
if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
context = __VUE_SSR_CONTEXT__;
} // inject component styles
if (style) {
style.call(this, createInjectorSSR(context));
} // register component module identifier for async chunk inference
if (context && context._registeredComponents) {
context._registeredComponents.add(moduleIdentifier);
}
}; // used by ssr in case component is cached and beforeCreate
// never gets called
options._ssrRegister = hook;
} else if (style) {
hook = shadowMode ? function (context) {
style.call(this, createInjectorShadow(context, this.$root.$options.shadowRoot));
} : function (context) {
style.call(this, createInjector(context));
};
}
if (hook) {
if (options.functional) {
// register for functional component in vue file
var originalRender = options.render;
options.render = function renderWithStyleInjection(h, context) {
hook.call(context);
return originalRender(h, context);
};
} else {
// inject component registration as beforeCreate hook
var existing = options.beforeCreate;
options.beforeCreate = existing ? [].concat(existing, hook) : [hook];
}
}
return script;
}
/* script */
var __vue_script__ = script;
/* template */
var __vue_render__ = function __vue_render__() {
var _vm = this;
var _h = _vm.$createElement;
var _c = _vm._self._c || _h;
return _c('div', {
staticClass: "picker-items dates"
}, [_vm.type === 'date' ? _c('div', {
staticClass: "row-item h"
}, _vm._l(_vm.$dayStr, function (item, i) {
return _c('span', {
key: i,
staticClass: "item date"
}, [_vm._v(_vm._s(item))]);
}), 0) : _vm._e(), _vm._v(" "), _vm._l(_vm.pickerItems, function (rowItems, i) {
return _c('div', {
key: i,
staticClass: "row-item"
}, _vm._l(rowItems, function (item, j) {
var _obj;
return _c('span', {
key: i + '' + j,
staticClass: "item",
class: (_obj = {
'not-in-month': _vm.type === 'date' && !item.isInThisMonth,
disabled: !item.canBeChose
}, _obj[_vm.type] = true, _obj.selected = _vm.isSelected(item), _obj['is-now'] = item.isNow, _obj['is-in-range'] = _vm.isInRange(item), _obj),
on: {
"click": function click($event) {
return _vm.chose(item);
},
"mouseover": function mouseover($event) {
item.canBeChose && _vm.$emit('mouseover', item);
}
}
}, [_vm._v(_vm._s(item[_vm.type]))]);
}), 0);
})], 2);
};
var __vue_staticRenderFns__ = [];
/* style */
var __vue_inject_styles__ = undefined;
/* scoped */
var __vue_scope_id__ = undefined;
/* module identifier */
var __vue_module_identifier__ = undefined;
/* functional template */
var __vue_is_functional_template__ = false;
/* style inject */
/* style inject SSR */
/* style inject shadow dom */
var __vue_component__ = /*#__PURE__*/normalizeComponent({
render: __vue_render__,
staticRenderFns: __vue_staticRenderFns__
}, __vue_inject_styles__, __vue_script__, __vue_scope_id__, __vue_is_functional_template__, __vue_module_identifier__, false, undefined, undefined, undefined);
function _typeof$1(obj) {
if (typeof Symbol === "function" && _typeof(Symbol.iterator) === "symbol") {
_typeof$1 = function _typeof$1(obj) {
return _typeof(obj);
};
} else {
_typeof$1 = function _typeof$1(obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : _typeof(obj);
};
}
return _typeof$1(obj);
}
function _slicedToArray$1(arr, i) {
return _arrayWithHoles$1(arr) || _iterableToArrayLimit$1(arr, i) || _nonIterableRest$1();
}
function _toConsumableArray$1(arr) {
return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _nonIterableSpread$1();
}
function _arrayWithoutHoles$1(arr) {
if (Array.isArray(arr)) {
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) {
arr2[i] = arr[i];
}
return arr2;
}
}
function _arrayWithHoles$1(arr) {
if (Array.isArray(arr)) return arr;
}
function _iterableToArray$1(iter) {
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
}
function _iterableToArrayLimit$1(arr, i) {
var _arr = [];
var _n = true;
var _d = false;
var _e = undefined;
try {
for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
_arr.push(_s.value);
if (i && _arr.length === i) break;
}
} catch (err) {
_d = true;
_e = err;
} finally {
try {
if (!_n && _i["return"] != null) _i["return"]();
} finally {
if (_d) throw _e;
}
}
return _arr;
}
function _nonIterableSpread$1() {
throw new TypeError("Invalid attempt to spread non-iterable instance");
}
function _nonIterableRest$1() {
throw new TypeError("Invalid attempt to destructure non-iterable instance");
}
/**
* @description If param obj is expected that can be copied
* */
var ExpectedObjType;
(function (ExpectedObjType) {
ExpectedObjType["NormalObj"] = "object";
ExpectedObjType["Array"] = "Array";
})(ExpectedObjType || (ExpectedObjType = {}));
function expectedObjType(obj) {
return _typeof$1(obj) === 'object' && !(obj === null || obj instanceof Promise || obj instanceof Date || obj instanceof Error || obj instanceof RegExp) && !(typeof window !== 'undefined' && (obj instanceof FileList || obj instanceof File || obj instanceof Element || obj instanceof Window || obj instanceof Document)) ? obj instanceof Array ? ExpectedObjType.Array : ExpectedObjType.NormalObj : false;
}
/**
* @description Returns the start dimension of the nested loop
* @param {Object} obj
* @param {Array} tParents - Target parents
* */
function circularStructureIndex(obj, tParents) {
var index = Object.keys(tParents).find(function (i) {
return tParents[+i] === obj;
});
return index !== undefined ? {
index: +index
} : undefined;
}
/**
* @description Returns the start dimension of the nested loop
* */
function isCircularStructure(obj) {
var paths = ['', ''];
var isCircular = function isCircular(object) {
var path = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['Object'];
var oParents = arguments.length > 2 ? arguments[2] : undefined;
if (_typeof$1(object) !== 'object' || object === null) return false;
var parents = oParents ? [].concat(_toConsumableArray$1(oParents), [object]) : [object];
return Object.entries(object).some(function (_ref) {
var _ref2 = _slicedToArray$1(_ref, 2),
key = _ref2[0],
value = _ref2[1];
var cPath = [].concat(_toConsumableArray$1(path), [key]);
var circularIndex = circularStructureIndex(value, parents);
if (circularIndex) {
paths[0] = cPath.slice(0, circularIndex.index + 1).reduce(function (pre, p) {
return "".concat(pre, ".").concat(p);
}, '').replace(/^\./, '');
paths[1] = cPath.reduce(function (pre, p) {
return "".concat(pre, ".").concat(p);
}, '').replace(/^\./, '');
return true;
}
return isCircular(value, cPath, parents);
});
};
return isCircular(obj) ? paths : null;
}
/**
* @description Deep copy, cannot deal nested loop
* */
function objectSimpleCopy(obj) {
return JSON.parse(JSON.stringify(obj));
}
function merge(target) {
for (var _len = arguments.length, rest = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
rest[_key - 1] = arguments[_key];
}
rest.forEach(function (obj) {
Object.entries(obj).forEach(function (_ref) {
var _ref2 = _slicedToArray$1(_ref, 2),
key = _ref2[0],
val = _ref2[1];
var obj1 = target[key];
if (expectedObjType(val) && expectedObjType(obj1)) {
merge(obj1, val);
} else {
target[key] = _typeof$1(val) === 'object' ? objectSimpleCopy(val) : val;
}
});
});
return target;
}
/**
* @description Deep merge, cannot deal nested loop
* @return The first parameter object which has been merged
* */
function objectDeepMerge(target) {
var allTypeIs = 'same';
for (var _len2 = arguments.length, rest = new Array(_len