UNPKG

@prettyy/ui

Version:

vue2 UI

1,815 lines (1,643 loc) 226 kB
module.exports = /******/ (function(modules) { // webpackBootstrap /******/ // The module cache /******/ var installedModules = {}; /******/ /******/ // The require function /******/ function __webpack_require__(moduleId) { /******/ /******/ // Check if module is in cache /******/ if(installedModules[moduleId]) { /******/ return installedModules[moduleId].exports; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = installedModules[moduleId] = { /******/ i: moduleId, /******/ l: false, /******/ exports: {} /******/ }; /******/ /******/ // Execute the module function /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); /******/ /******/ // Flag the module as loaded /******/ module.l = true; /******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /******/ /******/ // expose the modules object (__webpack_modules__) /******/ __webpack_require__.m = modules; /******/ /******/ // expose the module cache /******/ __webpack_require__.c = installedModules; /******/ /******/ // define getter function for harmony exports /******/ __webpack_require__.d = function(exports, name, getter) { /******/ if(!__webpack_require__.o(exports, name)) { /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); /******/ } /******/ }; /******/ /******/ // define __esModule on exports /******/ __webpack_require__.r = function(exports) { /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); /******/ } /******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; /******/ /******/ // create a fake namespace object /******/ // mode & 1: value is a module id, require it /******/ // mode & 2: merge all properties of value into the ns /******/ // mode & 4: return value when already ns object /******/ // mode & 8|1: behave like require /******/ __webpack_require__.t = function(value, mode) { /******/ if(mode & 1) value = __webpack_require__(value); /******/ if(mode & 8) return value; /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value; /******/ var ns = Object.create(null); /******/ __webpack_require__.r(ns); /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value }); /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key)); /******/ return ns; /******/ }; /******/ /******/ // getDefaultExport function for compatibility with non-harmony modules /******/ __webpack_require__.n = function(module) { /******/ var getter = module && module.__esModule ? /******/ function getDefault() { return module['default']; } : /******/ function getModuleExports() { return module; }; /******/ __webpack_require__.d(getter, 'a', getter); /******/ return getter; /******/ }; /******/ /******/ // Object.prototype.hasOwnProperty.call /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); }; /******/ /******/ // __webpack_public_path__ /******/ __webpack_require__.p = ""; /******/ /******/ /******/ // Load entry module and return exports /******/ return __webpack_require__(__webpack_require__.s = 19); /******/ }) /************************************************************************/ /******/ ([ /* 0 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; // EXTERNAL MODULE: ./components/utils/date-util/fixedDate.js var fixedDate = __webpack_require__(3); // CONCATENATED MODULE: ./components/utils/date-util/date.js /* Modified from https://github.com/taylorhakes/fecha * * the mit license (mit) * * copyright (c) 2015 taylor hakes * * permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "software"), to deal * in the software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the software, and to permit persons to whom the software is * furnished to do so, subject to the following conditions: * * the above copyright notice and this permission notice shall be included in all * copies or substantial portions of the software. * * the software is provided "as is", without warranty of any kind, express or * implied, including but not limited to the warranties of merchantability, * fitness for a particular purpose and noninfringement. in no event shall the * authors or copyright holders be liable for any claim, damages or other * liability, whether in an action of contract, tort or otherwise, arising from, * out of or in connection with the software or the use or other dealings in the * software. */ /*eslint-disable*/ // 把 YYYY-MM-DD 改成了 yyyy-MM-dd /** * Parse or format dates * @class fecha */ var fecha = {} var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g var twoDigits = '\\d\\d?' var threeDigits = '\\d{3}' var fourDigits = '\\d{4}' var word = '[^\\s]+' var literal = /\[([^]*?)\]/gm var noop = function () { } function regexEscape (str) { return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&') } function shorten (arr, sLen) { var newArr = [] for (var i = 0, len = arr.length; i < len; i++) { newArr.push(arr[i].substr(0, sLen)) } return newArr } function monthUpdate (arrName) { return function (d, v, i18n) { var index = i18n[arrName].indexOf(v.charAt(0).toUpperCase() + v.substr(1).toLowerCase()) if (~index) { d.month = index } } } function pad (val, len) { val = String(val) len = len || 2 while (val.length < len) { val = '0' + val } return val } var dayNames = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] var monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] var monthNamesShort = shorten(monthNames, 3) var dayNamesShort = shorten(dayNames, 3) fecha.i18n = { dayNamesShort: dayNamesShort, dayNames: dayNames, monthNamesShort: monthNamesShort, monthNames: monthNames, amPm: ['am', 'pm'], DoFn: function DoFn (D) { return D + ['th', 'st', 'nd', 'rd'][D % 10 > 3 ? 0 : (D - D % 10 !== 10) * D % 10] } } var formatFlags = { D: function (dateObj) { return dateObj.getDay() }, DD: function (dateObj) { return pad(dateObj.getDay()) }, Do: function (dateObj, i18n) { return i18n.DoFn(dateObj.getDate()) }, d: function (dateObj) { return dateObj.getDate() }, dd: function (dateObj) { return pad(dateObj.getDate()) }, ddd: function (dateObj, i18n) { return i18n.dayNamesShort[dateObj.getDay()] }, dddd: function (dateObj, i18n) { return i18n.dayNames[dateObj.getDay()] }, M: function (dateObj) { return dateObj.getMonth() + 1 }, MM: function (dateObj) { return pad(dateObj.getMonth() + 1) }, MMM: function (dateObj, i18n) { return i18n.monthNamesShort[dateObj.getMonth()] }, MMMM: function (dateObj, i18n) { return i18n.monthNames[dateObj.getMonth()] }, yy: function (dateObj) { return pad(String(dateObj.getFullYear()), 4).substr(2) }, yyyy: function (dateObj) { return pad(dateObj.getFullYear(), 4) }, h: function (dateObj) { return dateObj.getHours() % 12 || 12 }, hh: function (dateObj) { return pad(dateObj.getHours() % 12 || 12) }, H: function (dateObj) { return dateObj.getHours() }, HH: function (dateObj) { return pad(dateObj.getHours()) }, m: function (dateObj) { return dateObj.getMinutes() }, mm: function (dateObj) { return pad(dateObj.getMinutes()) }, s: function (dateObj) { return dateObj.getSeconds() }, ss: function (dateObj) { return pad(dateObj.getSeconds()) }, S: function (dateObj) { return Math.round(dateObj.getMilliseconds() / 100) }, SS: function (dateObj) { return pad(Math.round(dateObj.getMilliseconds() / 10), 2) }, SSS: function (dateObj) { return pad(dateObj.getMilliseconds(), 3) }, a: function (dateObj, i18n) { return dateObj.getHours() < 12 ? i18n.amPm[0] : i18n.amPm[1] }, A: function (dateObj, i18n) { return dateObj.getHours() < 12 ? i18n.amPm[0].toUpperCase() : i18n.amPm[1].toUpperCase() }, ZZ: function (dateObj) { var o = dateObj.getTimezoneOffset() return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4) } } var parseFlags = { d: [twoDigits, function (d, v) { d.day = v }], Do: [twoDigits + word, function (d, v) { d.day = parseInt(v, 10) }], M: [twoDigits, function (d, v) { d.month = v - 1 }], yy: [twoDigits, function (d, v) { var da = fixedDate["a" /* default */].getDate(), cent = +('' + da.getFullYear()).substr(0, 2) d.year = '' + (v > 68 ? cent - 1 : cent) + v }], h: [twoDigits, function (d, v) { d.hour = v }], m: [twoDigits, function (d, v) { d.minute = v }], s: [twoDigits, function (d, v) { d.second = v }], yyyy: [fourDigits, function (d, v) { d.year = v }], S: ['\\d', function (d, v) { d.millisecond = v * 100 }], SS: ['\\d{2}', function (d, v) { d.millisecond = v * 10 }], SSS: [threeDigits, function (d, v) { d.millisecond = v }], D: [twoDigits, noop], ddd: [word, noop], MMM: [word, monthUpdate('monthNamesShort')], MMMM: [word, monthUpdate('monthNames')], a: [word, function (d, v, i18n) { var val = v.toLowerCase() if (val === i18n.amPm[0]) { d.isPm = false } else if (val === i18n.amPm[1]) { d.isPm = true } }], ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) { var parts = (v + '').match(/([+-]|\d\d)/gi), minutes if (parts) { minutes = +(parts[1] * 60) + parseInt(parts[2], 10) d.timezoneOffset = parts[0] === '+' ? minutes : -minutes } }] } parseFlags.dd = parseFlags.d parseFlags.dddd = parseFlags.ddd parseFlags.DD = parseFlags.D parseFlags.mm = parseFlags.m parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h parseFlags.MM = parseFlags.M parseFlags.ss = parseFlags.s parseFlags.A = parseFlags.a // Some common format strings fecha.masks = { default: 'ddd MMM dd yyyy HH:mm:ss', shortDate: 'M/D/yy', mediumDate: 'MMM d, yyyy', longDate: 'MMMM d, yyyy', fullDate: 'dddd, MMMM d, yyyy', shortTime: 'HH:mm', mediumTime: 'HH:mm:ss', longTime: 'HH:mm:ss.SSS' } /*** * Format a date * @method format * @param {Date|number} dateObj * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate' */ fecha.format = function (dateObj, mask, i18nSettings) { var i18n = i18nSettings || fecha.i18n if (typeof dateObj === 'number') { dateObj = new Date(dateObj) } if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) { throw new Error(`Invalid Date "${dateObj} in fecha.format`) } mask = fecha.masks[mask] || mask || fecha.masks['default'] var literals = [] // Make literals inactive by replacing them with ?? mask = mask.replace(literal, function ($0, $1) { literals.push($1) return '@@@' }) // Apply formatting rules mask = mask.replace(token, function ($0) { return $0 in formatFlags ? formatFlags[$0](dateObj, i18n) : $0.slice(1, $0.length - 1) }) // Inline literal values back into the formatted value return mask.replace(/@@@/g, function () { return literals.shift() }) } /** * Parse a date string into an object, changes - into / * @method parse * @param {string} dateStr Date string * @param {string} format Date parse format * @returns {Date|boolean} */ fecha.parse = function (dateStr, format, i18nSettings) { var i18n = i18nSettings || fecha.i18n if (typeof format !== 'string') { throw new Error(`Invalid format "${format}" in fecha.parse`) } format = fecha.masks[format] || format // Avoid regular expression denial of service, fail early for really long strings // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS if (dateStr.length > 1000) { return null } var dateInfo = {} var parseInfo = [] var literals = [] format = format.replace(literal, function ($0, $1) { literals.push($1) return '@@@' }) var newFormat = regexEscape(format).replace(token, function ($0) { if (parseFlags[$0]) { var info = parseFlags[$0] parseInfo.push(info[1]) return '(' + info[0] + ')' } return $0 }) newFormat = newFormat.replace(/@@@/g, function () { return literals.shift() }) var matches = dateStr.match(new RegExp(newFormat, 'i')) if (!matches) { return null } for (var i = 1; i < matches.length; i++) { parseInfo[i - 1](dateInfo, matches[i], i18n) } var today = fixedDate["a" /* default */].getDate() if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) { dateInfo.hour = +dateInfo.hour + 12 } else if (dateInfo.isPm === false && +dateInfo.hour === 12) { dateInfo.hour = 0 } var date if (dateInfo.timezoneOffset != null) { dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1, dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0)) } else { date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1, dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0) } return date } /* harmony default export */ var date_util_date = (fecha); // CONCATENATED MODULE: ./components/utils/date-util/index.js /** * 获取上个月剩下的天数(距离这个月一周内) * @param {Date} date * @param {Number} weekStart 星期开始量 * @return {Array} */ function getPrevMonthDays(date, weekStart) { date = new Date(date.getTime()) date.setDate(1) // 本月1号是星期几 const weekDay = date.getDay() // 临界条件: 正好本月的第一天是【设置的一周的起始量】 // 不需要数据 if (weekDay === weekStart) { return [] } // 上月需要计入的天数 let lastDays if (weekStart === 0) { lastDays = weekDay } else if (weekDay === 0) { lastDays = 7 - weekStart } else if (weekDay < weekStart) { // 如果当前星期量小于起始量 lastDays = (7 + weekDay - weekStart) % 7 } else { // 当前的星期量大于起始量 // 使用差值就行了 lastDays = weekDay - weekStart } // 将时间跳转到上月的最后一天 date.setDate(0) // 上月的最后一天是几号 const day = date.getDate() // 年 const year = date.getFullYear() // 月 const month = date.getMonth() + 1 // 天数集合 const days = [] // 上月的最后一天不是星期六(星期天是一周第一天) // 那就要在这月显示 for (let i = 1; i <= lastDays; i++) { const value = day - lastDays + i date.setDate(value) days.push({ overflow: true, date: value, value: date, year, month, day: date.getDay() }) } return days } /** * 获取当月的天数 * @param {Date} date * @return {Array} */ function getCurrentMonthDays(date) { date = new Date(date.getTime()) // 设置日期到下个月 // 将时间跳转到本月的最后一天 date.setMonth(date.getMonth() + 1, 0) // 本月的最后一天是几号 const day = date.getDate() // 年 const year = date.getFullYear() // 月 const month = date.getMonth() + 1 // 天数集合 const days = [] for (let i = 1; i <= day; i++) { date.setDate(i) days.push({ date: i, value: date, year, month, day: date.getDay() }) } return days } /** * 获取这个月底到下个月的天数(距离这个月最后一天的一周内) * @param {Date} date * @param {number} remain 剩下的空余数量 * @return {Array} */ function getNextMonthDays(date, remain) { date = new Date(date.getTime()) // 设置日期到下个月 date.setMonth(date.getMonth() + 1) // 年 const year = date.getFullYear() // 月 const month = date.getMonth() + 1 // 天数集合 const days = [] // 多显示7天 for (let i = 1; i <= remain + 7; i++) { date.setDate(i) days.push({ overflow: true, date: i, value: date, year, month, day: date.getDay() }) } return days } /** * 解析日期偏移串 * @param {Object|string} offset * @return {{year: number, month: number, date: number}} */ function resolveDateOffset(offset) { if (!offset) { return { year: 0, month: 0, date: 0 } } // 值是偏移对象 if (typeof offset === 'object') { return offset } // 不是字符串,数据无效 if (typeof offset !== 'string') { throw Error(`[datepicker] Invalid offset type: ${typeof offset}`) } // 值是偏移串 const matches = /^((?<year>-?(\d+)?)y)?((?<month>-?(\d+)?)m)?((?<date>-?(\d+)?)d)?$/i.exec(offset) if (!matches) { throw Error(`[datepicker] Invalid offset value: ${offset}`) } return { year: parseInt(matches.groups.year) || 0, month: parseInt(matches.groups.month) || 0, date: parseInt(matches.groups.date) || 0 } } const util = { /** * 获取当前日期是一年中的第几天 * @param date * @param includeCurrentMonth * @return {number} */ getDayOfYear(date, includeCurrentMonth) { date = date ? this.parse(date) : fixedDate["a" /* default */].getDate() let days = 0 if (includeCurrentMonth !== false) { days += date.getDate() } // 前面的月份 let month = date.getMonth() for (let i = 0; i < month; i++) { date.setMonth(i + 1, 0) days += date.getDate() } return days }, /** * 获取传入日期处于一年中的第多少周 * @param {Date|Date[]} date * @param {object} [option] * @param {number} [option.start=0] 周的偏移值 * @return {{year: Number, week: Number}} */ getWeekOfYear(date, option) { option = { start: 0, ...option } const [start] = Array.isArray(date) ? date.map(d => this.parse(d)) : this.getWeekRange(date, { start: option.start }) // 当传入的是日期范围时,date + 3 ,表示一周中间的那一天 // 得到周所在的日期 const weekDate = Array.isArray(date) ? this.offsetDate(start, { date: 3 }) : date // 当年的第一天是星期几 const weekDayOfFirstDay = this.setDate(weekDate, { month: 0, date: 1 }).getDay() // 周日期所在年的第一天的星期数 + 周日期所在其年的天数 - 起始日期 / 7 // 得到周数 const offset = weekDayOfFirstDay > option.start ? option.start : option.start - 7 const days = weekDayOfFirstDay + this.getDayOfYear(weekDate) - offset return { year: weekDate.getFullYear(), week: Math.ceil(Math.abs(days) / 7) } }, /** * 获取传入日期处于一月中的第多少周 * @param {Date|Date[]} date * @param {object} [option] * @param {number} [option.start=0] 周的偏移值 * @return {{year: Number, month: Number, week: Number}} */ getWeekOfMonth(date, option) { option = { start: 0, ...option } const [start] = Array.isArray(date) ? date.map(d => this.parse(d)) : this.getWeekRange(date, { start: option.start }) // 当传入的是日期范围时,date + 3 ,表示一周中间的那一天 // 得到周所在的日期 const weekDate = Array.isArray(date) ? this.offsetDate(start, { date: 3 }) : date // 当月的第一天是星期几 const weekDayOfFirstDay = this.setDate(weekDate, { date: 1 }).getDay() // 周日期所在月的第一天的星期数 + 周日期所在其月的天数 - 起始日期 / 7 // 得到周数 const offset = weekDayOfFirstDay > option.start ? option.start : option.start - 7 const days = weekDayOfFirstDay + weekDate.getDate() - offset return { year: weekDate.getFullYear(), month: weekDate.getMonth(), week: Math.ceil(Math.abs(days) / 7) } }, /** * 根据传入日期生成日期所在月的日历视图 * @param {Date|String|Number} date * @param {Number} [weekStart=0] * @return {*[]} */ makeDateView(date, weekStart) { date = date ? this.parse(date) : fixedDate["a" /* default */].getDate() // 一共是7列5行 const size = 7 * 5 const prevMonthDays = getPrevMonthDays(date, weekStart || 0) const currentMonthDays = getCurrentMonthDays(date) const nextMonthDays = getNextMonthDays(date, size - prevMonthDays.length - currentMonthDays.length) return [...prevMonthDays, ...currentMonthDays, ...nextMonthDays] }, /** * 给指定的起始日期设置时间范围 00:00:00 和 23:59:59 * @param {Date} begin * @param {Date} end * @private */ appendTime(begin, end) { begin.setHours(0, 0, 0) end.setHours(23, 59, 59) }, /** * 按指定规则对日期进行偏移 * @param {Date} date * @param {Object|string} offset 日期的偏移量 * @return {Date} 偏移后的日期对象(新对象) */ offsetDate(date, offset) { offset = resolveDateOffset(offset) const newValue = { year: date.getFullYear() + (parseInt(offset.year) || 0), month: date.getMonth() + (parseInt(offset.month) || 0), date: 1 } const newDate = new Date(newValue.year, newValue.month, newValue.date) const newLastDate = date.getDate() + (parseInt(offset.date) || 0) if (offset.date) { newDate.setDate(newLastDate) return newDate } // 当未指定日期偏移时 // 使用原日期的 date // 此处的逻辑是为了防止日期大于本月的最后一天 const lastDate = this.getLastDayOfMonth(newDate) if (newLastDate <= lastDate) { newDate.setDate(newLastDate) return newDate } newDate.setDate(lastDate) return newDate }, /** * 获取指定月份的最后一天是几号 * @param {Date} date * @param {number} [month] 不指定时,使用当前日期的月份 * @return {number} */ getLastDayOfMonth(date, month) { month = arguments.length > 1 ? month : date.getMonth() // 获取当月最后一天 const temp = this.setDate(date, { month: month + 1, date: 0 }) return temp.getDate() }, /** * 根据一个日期以及偏移参数获取日期范围 * @param {Date} date * @param {Object|string} [beginOffset] 开始日期的偏移量 * @param {Object|string} [endOffset] 结束日期的偏移量 * @param {object} [option] * @param {string} [option.format] 格式化串,不指定时返回 Date 类型 * @param {boolean} [option.time=false] 是否附带时间串 * @return {Date[]|String[]} */ getDateRange(date, beginOffset, endOffset, option) { const { time, format } = option || {} const begin = this.offsetDate(date, beginOffset) const end = this.offsetDate(date, endOffset) if (time) { this.appendTime(begin, end) } const range = [begin, end] return format ? range.map(d => this.format(d, format)) : range }, /** * 根据一个日期,谋算出其所在周的起止日期 * @param {Date} date * @param {Object} [option] * @param {number} [option.start=0] 周起始量,0-6分别表示星期天到星期六 * @param {number} [option.offset=0] 周偏移量,可以是任意整数 * @param {boolean} [option.time=false] 是否附带时间串 * @param {string} [option.format] 格式化串,不指定时返回 Date 类型 * @return {Date[]|String[]} */ getWeekRange(date, option) { const { start, offset, time, format } = { start: 0, offset: 0, ...option } const weekDay = date.getDay() const begin = new Date(date.getTime()) // 先找出星期天为第一天的日期 begin.setDate(begin.getDate() - weekDay) // ----判断 start 的位置 与传入日期的位置差---- // 如果 start 大于 传入日期,则直接使用 start 对应的日期为起始 // 否则,将开始日期 - 7(跳转到上一周) // 再移动 start 的天数,就是正确的起始日期 if (start > weekDay) { begin.setDate(begin.getDate() - 7) } // ----判断 结束---- if (start) { // 再移动 start 的天数,就是正确的起始日期 begin.setDate(begin.getDate() + start) } const end = new Date(begin.getFullYear(), begin.getMonth(), begin.getDate() + 6) if (offset) { begin.setDate(begin.getDate() + Math.round(offset) * 7) end.setFullYear(begin.getFullYear(), begin.getMonth(), begin.getDate() + 6) } if (time) { this.appendTime(begin, end) } const range = [begin, end] return format ? range.map(d => this.format(d, format)) : range }, /** * 根据一个日期,谋算出其所在月的起止日期 (月的第一天和最后一天) * @param {Date} date * @param {Object} [option] * @param {number} [option.offset=0] 月偏移量,可以是任意整数 * @param {boolean} [option.time=false] 是否附带时间串 * @param {string} [option.format] 格式化串,不指定时返回 Date 类型 * @return {Date[]|String[]} */ getMonthRange(date, option) { const { offset, time, format } = { offset: 0, ...option } const begin = new Date(date.getTime()) const end = new Date(date.getTime()) begin.setMonth(begin.getMonth() + Math.round(offset), 1) end.setMonth(end.getMonth() + Math.round(offset) + 1, 0) if (time) { this.appendTime(begin, end) } const range = [begin, end] return format ? range.map(d => this.format(d, format)) : range }, /** * 根据一个日期,谋算出其所在季度的起止日期 * @param {Date} date * @param {Object} [option] * @param {number} [option.offset=0] 季度偏移量,可以是任意整数 * @param {boolean} [option.time=false] 是否附带时间串 * @param {string} [option.format] 格式化串,不指定时返回 Date 类型 * @return {Date[]|String[]} */ getQuarterRange(date, option) { const { offset, time, format } = { offset: 0, ...option } const month = date.getMonth() const beginMonth = Math.floor(month / 3) * 3 const begin = new Date(date.getTime()) begin.setMonth(beginMonth, 1) const end = new Date(date.getTime()) // 设置为月底 end.setMonth(begin.getMonth() + 3, 0) if (offset) { begin.setMonth(begin.getMonth() + Math.round(offset) * 3, 1) end.setFullYear(begin.getFullYear(), end.getMonth() + Math.round(offset) * 3 + 1, 0) } if (time) { this.appendTime(begin, end) } const range = [begin, end] return format ? range.map(d => this.format(d, format)) : range }, /** * 按照指定的值设置 Date 对象 * @param {Date|String|Number} date * @param {Object} [option] * @param {Number} [option.year] * @param {Number} [option.month] * @param {Number} [option.date] * @param {Number} [option.hour] * @param {Number} [option.minute] * @param {Number} [option.second] * @param {Boolean} [option.copy=true] * @return {Date} */ setDate(date, option) { const { year, month, date: day, hour, minute, second, copy } = { copy: true, ...option } const temp = copy ? new Date(date.getTime()) : date if (year !== undefined && year !== null) { temp.setFullYear(year) } if (month !== undefined && month !== null) { temp.setMonth(month, 1) } if (day !== undefined && day !== null) { temp.setDate(day) } if (hour !== undefined && hour !== null) { temp.setHours(hour, 0, 0) } if (minute !== undefined && minute !== null) { temp.setMinutes(minute, 0) } if (second !== undefined && second !== null) { temp.setSeconds(second) } return temp }, /** * 将任意类型的日期格式转换成 Date 类型 * @param {Date|String|Number} date * @param {String} [format] 当 date 是字符串时,通过此参数指定格式 * @return {Date} */ parse(date, format) { if (date instanceof Date) { return new Date(date.getTime()) } if (date instanceof Number) { return new Date(date) } if (typeof date === 'string') { const now = fixedDate["a" /* default */].getDate() let today = this.format(now, 'yyyy-MM-dd') if (/^\d{4}$/.test(date)) { // 2018 -> 2018-01-01 date = `${date}-01-01` if (!format) { format = 'yyyy-MM-dd' } } else if (/^\d{2}:\d{2}$/.test(date)) { // 10:10 -> 20xx-01-01 10:10:00 date = `${today} ${date}:00` if (!format) { format = 'yyyy-MM-dd HH:mm:ss' } } else if (/^\d{4}-\d{2}$/.test(date)) { // 2018-10 -> 2018-10-01 date = `${date}-01` if (!format) { format = 'yyyy-MM-dd' } } else if (/^\d{2}:\d{2}:\d{2}$/.test(date)) { // 10:10:10 -> 20xx-01-01 10:10:10 date = `${today} ${date}` if (!format) { format = 'yyyy-MM-dd HH:mm:ss' } } else if (/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/.test(date)) { // 2018-10-10 10:10 -> 2018-10-10 10:10:00 date = `${date}:00` if (!format) { format = 'yyyy-MM-dd HH:mm:ss' } } else if (!format) { format = 'yyyy-MM-dd' } } return date_util_date.parse(date, format) || new Date(date) }, /** * 将任意格式的日期格式化成指定的格式 * @param {Date|String|Number} date * @param {String} format 输出格式 * @param {String} [inputFormat] 当 date 是字符串时,通过此参数指定格式,不指定时使用 format 的值 * @return {string} */ format(date, format, inputFormat) { if (!date) { return '' } const value = this.parse(date, inputFormat || format) return date_util_date.format(value, format) }, /** * * @param {Date|String|Number} date1 * @param {Date|String|Number} date2 * @param {String} format 日期格式 * @return {boolean} */ equals(date1, date2, format) { if (!date1 && !date2) { return true } if (!date1 || !date2) { return false } return this.format(date1, format) === this.format(date2, format) }, pad(val, len, fill) { val = String(val) len = len || 2 fill = fill || '0' while (val.length < len) { val = fill + val } return val }, /** * * @param {HTMLElement} element * @param {HTMLElement} test */ isParent(element, test) { if (!element || !test) { return false } if (element === test) { return true } if (element === document.body) { return false } const parentElement = element.parentElement if (parentElement === test) { return true } if (parentElement === document.body) { return false } return this.isParent(parentElement, test) } } /* harmony default export */ var date_util = __webpack_exports__["a"] = (util); /***/ }), /* 1 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; }); /* globals __VUE_SSR_CONTEXT__ */ // IMPORTANT: Do NOT use ES2015 features in this file (except for modules). // This module is a runtime utility for cleaner component module output and will // be included in the final webpack user bundle. function normalizeComponent ( scriptExports, render, staticRenderFns, functionalTemplate, injectStyles, scopeId, moduleIdentifier, /* server only */ shadowMode /* vue-cli only */ ) { // Vue.extend constructor export interop var options = typeof scriptExports === 'function' ? scriptExports.options : scriptExports // render functions if (render) { options.render = render options.staticRenderFns = staticRenderFns options._compiled = true } // functional template if (functionalTemplate) { options.functional = true } // scopedId if (scopeId) { options._scopeId = 'data-v-' + scopeId } var hook if (moduleIdentifier) { // server build hook = function (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 (injectStyles) { injectStyles.call(this, context) } // register component module identifier for async chunk inferrence 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 (injectStyles) { hook = shadowMode ? function () { injectStyles.call(this, this.$root.$options.shadowRoot) } : injectStyles } if (hook) { if (options.functional) { // for template-only hot-reload because in that case the render fn doesn't // go through the normalizer options._injectStyles = hook // register for functioal 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 { exports: scriptExports, options: options } } /***/ }), /* 2 */, /* 3 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; /** * 修正日期支持类,用于修正客户端与服务器时间不一致的问题 */ class FixedDate { constructor() { const now = new Date() this.timestamp = now.getTime() this.updateTime = now } /** * 指定当前时间戳 * @param {Number} timestamp 单位为秒或毫秒,传入 0 表示使用系统时间 * @return {Date} 新的日期对象 */ setDate(timestamp) { if (this.timestamp === 0) { this.timestamp = new Date().getTime() } if (!timestamp) { throw new Error(`Invalid timestamp of date: ${timestamp}`) } if (timestamp.toString().length < 13) { this.timestamp = timestamp * 1000 } else { this.timestamp = timestamp } this.updateTime = new Date() return this.getDate() } /** * 获取当前的时间 * @returns {Date} */ getDate() { const now = new Date() // 将设置的时间戳 // 与差值 (当前时间与时间戳更新时间的差值)相加 // 加上后得到新的时间戳,那么就是修正的当前时间 const fixedTimestamp = this.timestamp + (now.getTime() - this.updateTime.getTime()) return new Date(fixedTimestamp) } } const fixedDate = new FixedDate() /* Example: // 设置时间,以作为当前的时间 fixedDate.setDate(1635479224587) // 获取时间,返回值为被修正后的时间 */ /* harmony default export */ __webpack_exports__["a"] = (fixedDate); /***/ }), /* 4 */, /* 5 */, /* 6 */, /* 7 */, /* 8 */, /* 9 */, /* 10 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; /* harmony default export */ __webpack_exports__["a"] = ({ get DATETIME () { return 'datetime' }, get DATE () { return 'date' }, get TIME () { return 'time' }, get WEEK () { return 'week' }, get MONTH () { return 'month' }, get QUARTER () { return 'quarter' }, get YEAR () { return 'year' } }); /***/ }), /* 11 */ /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./components/lib/picker/src/main.vue?vue&type=template&id=f5fec1a0 var render = function() { var _vm = this var _h = _vm.$createElement var _c = _vm._self._c || _h return _c( "div", { staticClass: "vl-date-picker--box" }, [ _vm.renderTimePanel ? _c("time-panel", { directives: [ { name: "show", rawName: "v-show", value: _vm.showTimePanel, expression: "showTimePanel" } ], on: { "pick-date": _vm.onPickDate, pick: _vm.onTimePicked }, scopedSlots: _vm._u( [ { key: "title", fn: function() { return [_vm._t("title")] }, proxy: true } ], null, true ) }) : _vm._e(), _vm._v(" "), _vm.renderDatePanel ? _c("date-panel", { directives: [ { name: "show", rawName: "v-show", value: _vm.showDatePanel, expression: "showDatePanel" } ], on: { "pick-year": _vm.onPickYear, "pick-month": _vm.onPickMonth, pick: _vm.onDatePicked }, scopedSlots: _vm._u( [ { key: "title", fn: function() { return [_vm._t("title")] }, proxy: true }, { key: "append", fn: function() { return [ _c("time-panel", { directives: [ { name: "show", rawName: "v-show", value: _vm.renderDateTimePanel, expression: "renderDateTimePanel" } ], on: { "pick-date": _vm.onPickDate, pick: _vm.onTimePicked }, scopedSlots: _vm._u( [ { key: "title", fn: function() { return [_vm._t("title")] }, proxy: true } ], null, true ) }) ] }, proxy: true } ], null, true ) }) : _vm._e(), _vm._v(" "), _vm.renderDatePanel || _vm.renderMonthPanel ? _c("month-panel", { directives: [ { name: "show", rawName: "v-show", value: _vm.showMonthPanel, expression: "showMonthPanel" } ], on: { "pick-year": _vm.onPickYear, pick: _vm.onMonthPicked }, scopedSlots: _vm._u( [ { key: "title", fn: function() { return [_vm._t("title")] }, proxy: true } ], null, true ) }) : _vm._e(), _vm._v(" "), _c("year-panel", { directives: [ { name: "show", rawName: "v-show", value: _vm.currentType === _vm.types.YEAR, expression: "currentType === types.YEAR" } ], on: { pick: _vm.onYearPicked }, scopedSlots: _vm._u( [ { key: "title", fn: function() { return [_vm._t("title")] }, proxy: true } ], null, true ) }) ], 1 ) } var staticRenderFns = [] render._withStripped = true // CONCATENATED MODULE: ./components/lib/picker/src/main.vue?vue&type=template&id=f5fec1a0 // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./components/lib/date-picker/src/YearPanel.vue?vue&type=template&id=7f3becd1 var YearPanelvue_type_template_id_7f3becd1_render = function() { var _vm = this var _h = _vm.$createElement var _c = _vm._self._c || _h return _c("base-panel", { attrs: { "extra-class": "vl-date-picker--panel-year", view: _vm.data }, on: { prev: _vm.onPrevDecades, next: _vm.onNextDecades, "pick-cell": _vm.onPick }, scopedSlots: _vm._u( [ { key: "panelTitle", fn: function() { return [_vm._t("title")] }, proxy: true }, { key: "header", fn: function() { return [ _c("span", [ _vm._v( _vm._s(_vm.startYear) + "年 - " + _vm._s(_vm.stopYear) + "年" ) ]) ] }, proxy: true } ], null, true ) }) } var YearPanelvue_type_template_id_7f3becd1_staticRenderFns = [] YearPanelvue_type_template_id_7f3becd1_render._withStripped = true // CONCATENATED MODULE: ./components/lib/date-picker/src/YearPanel.vue?vue&type=template&id=7f3becd1 // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./components/lib/date-picker/src/BasePanel.vue?vue&type=template&id=030994bd var BasePanelvue_type_template_id_030994bd_render = function() { var _vm = this var _h = _vm.$createElement var _c = _vm._self._c || _h return _c( "div", { staticClass: "vl-date-picker--panel", class: _vm.extraClass || "" }, [ _c( "div", { staticClass: "vl-date-picker--panel-title" }, [_vm._t("panelTitle")], 2 ), _vm._v(" "), _c("div", { staticClass: "vl-date-picker--panel-header" }, [ _c("div", { staticClass: "vl-date-picker--panel-header-prev" }, [ _c("span", { staticClass: "vl-icon icon-left-arrow-d", on: { click: function($event) { return _vm.$emit("prev") } } }) ]), _vm._v(" "), _c( "div", { staticClass: "vl-date-picker--panel-header-content" }, [_vm._t("header")], 2 ), _vm._v(" "), _c("div", { staticClass: "vl-date-picker--panel-header-next" }, [ _c("span", { staticClass: "vl-icon icon-right-arrow-d", on: { click: function($event) { return _vm.$emit("next") } } }) ]) ]), _vm._v(" "), _c( "div", { staticClass: "vl-date-picker--panel-body", on: { click: function($event) { $event.stopPropagation() } } }, [ _c( "div", { staticClass: "vl-date-picker--table", on: { wheel: _vm.onWheel } }, [ _c( "div", { staticClass: "vl-date-picker--table-header" }, [_vm._t("title")], 2 ), _vm._v(" "), _c( "div", { staticClass: "vl-date-picker--table-body" }, _vm._l(_vm.view, function(row, rowIndex) { return _c( "div", { key: rowIndex, staticClass: "vl-date-picker--table-row", class: _vm.getRowClass(row, rowIndex), attrs: { title: _vm.getRowTip(row) }, on: { click: function($event) { return _vm.onRowClick(row, rowIndex) } } }, _vm._l(row, function(cell, cellIndex) { return _c( "div", { key: cellIndex, staticClass: "vl-date-picker--table-cell", class: { "vl-date-picker--panel-value-highlight": cell.highlight }, attrs: { title: _vm.getCellTitle(cell) }, on: { click: function($event) { return _vm.onCellClick(cell) } } }, [ _c("span", { staticClass: "vl-date-picker--panel-value", class: _vm.getCellClass(cell), domProps: { innerHTML: _vm._s(_vm.renderCell(cell)) } }) ] ) }), 0 ) }), 0 ) ] ), _vm._v(" "), _vm._t("append") ], 2 ) ] ) } var BasePanelvue_type_template_id_030994bd_staticRenderFns = [] BasePanelvue_type_template_id_030994bd_render._withStripped = true // CONCATENATED MODULE: ./components/lib/date-picker/src/BasePanel.vue?vue&type=template&id=030994bd // CONCATENATED MODULE: ./node_modules/vue-loader/lib??vue-loader-options!./components/lib/date-picker/src/BasePanel.vue?vue&type=script&lang=js /* harmony default export */ var BasePanelvue_type_script_lang_js = ({ name: "BasePanel", inject: { picker: 'datePicker' }, props: { view: { type: Array, required: true }, extraClass: [String, Object, Array], rowClassHandler: Function }, methods: { getCellClass(cell) { return { 'vl-date-picker--panel-value-active': cell.active, 'vl-date-picker--panel-value-current': cell.current, 'vl-date-picker--panel-value-overflow': cell.overflow, 'vl-date-picker--panel-value-disabled': cell.disabled } }, onRowClick(row, index) { if (!row.every(cell => !cell.disabled)) { return } this.$emit('pick-row', { row, index }) }, onCellClick(cell) { if (cell.disabled) { return } this.$emit('pick-cell', cell) }, onWheel(e) { if (!this.picker.mousewheel) { return } e.preventDefault() e.stopPropagation() const deltaY = e.deltaY if (deltaY < 0) { // 向上 this.$emit('prev', { wheel: true }) } else if (deltaY > 0) { // 向下 this.$emit('next', { wheel: true }) } }, getRowClass(row, index) { if (!this.rowClassHandler) { return '' } return this.rowClassHandler({ row, index }) }, getRowTip(row) { return row[0].rowTip || '' }, getCellTitle(cell) { let title = cell.tip const lunar = cell.lunar if (this.picker.showFestival && lunar.solarFestival) { title += ' ' + lunar.solarFestival } if (!this.picker.showLunar) { return title } let lunarTitle switch (cell.type) { case 'year': lunarTitle = ` ${lunar.lunarYear}(${lunar.GanZhiYear})年` break case 'month': lunarTitle = ` ${lunar.lunarYear}(${lunar.GanZhiYear})年${lunar.lunarMonthName}` break case 'date': // 对日的提示信息进行换行 title += '\n' lunarTitle = `${lunar.lunarYear}(${lunar.GanZhiYear})年${lunar.lunarMonthName}${lunar.lunarDayName}` if (this.picker.showFestival && lunar.lunarFestival) { lunarTitle += ' ' + lunar.lunarFestival } break } if (lunarTitle) { title += '农历' + lunarTitle } return title }, renderCell(cell) { const lunar = cell.lunar let cls = 'vl-date-picker--panel-value--solar' if (this.picker.showFestival && cell.type === 'date') { // 是否存在公历节日 if (lunar.solarFestival) { cls += ' is-festival' } } const result = [ `<span class="${cls}">${cell.text}</span>` ] if (this.picker.showLunar) { let content let isFestival = false switch (cell.type) { case 'year': content = lunar.GanZhiYear break case 'month': content = lunar.lunarMonthName break case 'date': isFestival = this.picker.showFestival && !!lunar.lunarFestival if (isFestival) { content = lunar.lunarFestival } else { content = lunar.lunarDay === 1 ? lunar.lunarMonthName : lunar.lunarDayName } break } result.push(`<span class="vl-date-picker--panel-value--lunar${isFestival ? ' is-festival' : ''}">${content}</span>`) } if (this.picker.markFunction) { const markResult = this.picker.markFunction(cell) if (typeof markResult === 'string') { result.push(`<span class="vl-date-picker--panel-value--marker">${markResult}</span>`) } } return result.join('')