calendar.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/
  6. /******/ // The require function
  7. /******/ function __webpack_require__(moduleId) {
  8. /******/
  9. /******/ // Check if module is in cache
  10. /******/ if(installedModules[moduleId]) {
  11. /******/ return installedModules[moduleId].exports;
  12. /******/ }
  13. /******/ // Create a new module (and put it into the cache)
  14. /******/ var module = installedModules[moduleId] = {
  15. /******/ i: moduleId,
  16. /******/ l: false,
  17. /******/ exports: {}
  18. /******/ };
  19. /******/
  20. /******/ // Execute the module function
  21. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  22. /******/
  23. /******/ // Flag the module as loaded
  24. /******/ module.l = true;
  25. /******/
  26. /******/ // Return the exports of the module
  27. /******/ return module.exports;
  28. /******/ }
  29. /******/
  30. /******/
  31. /******/ // expose the modules object (__webpack_modules__)
  32. /******/ __webpack_require__.m = modules;
  33. /******/
  34. /******/ // expose the module cache
  35. /******/ __webpack_require__.c = installedModules;
  36. /******/
  37. /******/ // define getter function for harmony exports
  38. /******/ __webpack_require__.d = function(exports, name, getter) {
  39. /******/ if(!__webpack_require__.o(exports, name)) {
  40. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  41. /******/ }
  42. /******/ };
  43. /******/
  44. /******/ // define __esModule on exports
  45. /******/ __webpack_require__.r = function(exports) {
  46. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  47. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  48. /******/ }
  49. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  50. /******/ };
  51. /******/
  52. /******/ // create a fake namespace object
  53. /******/ // mode & 1: value is a module id, require it
  54. /******/ // mode & 2: merge all properties of value into the ns
  55. /******/ // mode & 4: return value when already ns object
  56. /******/ // mode & 8|1: behave like require
  57. /******/ __webpack_require__.t = function(value, mode) {
  58. /******/ if(mode & 1) value = __webpack_require__(value);
  59. /******/ if(mode & 8) return value;
  60. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  61. /******/ var ns = Object.create(null);
  62. /******/ __webpack_require__.r(ns);
  63. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  64. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  65. /******/ return ns;
  66. /******/ };
  67. /******/
  68. /******/ // getDefaultExport function for compatibility with non-harmony modules
  69. /******/ __webpack_require__.n = function(module) {
  70. /******/ var getter = module && module.__esModule ?
  71. /******/ function getDefault() { return module['default']; } :
  72. /******/ function getModuleExports() { return module; };
  73. /******/ __webpack_require__.d(getter, 'a', getter);
  74. /******/ return getter;
  75. /******/ };
  76. /******/
  77. /******/ // Object.prototype.hasOwnProperty.call
  78. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  79. /******/
  80. /******/ // __webpack_public_path__
  81. /******/ __webpack_require__.p = "/dist/";
  82. /******/
  83. /******/
  84. /******/ // Load entry module and return exports
  85. /******/ return __webpack_require__(__webpack_require__.s = 70);
  86. /******/ })
  87. /************************************************************************/
  88. /******/ ({
  89. /***/ 0:
  90. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  91. "use strict";
  92. /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return normalizeComponent; });
  93. /* globals __VUE_SSR_CONTEXT__ */
  94. // IMPORTANT: Do NOT use ES2015 features in this file (except for modules).
  95. // This module is a runtime utility for cleaner component module output and will
  96. // be included in the final webpack user bundle.
  97. function normalizeComponent (
  98. scriptExports,
  99. render,
  100. staticRenderFns,
  101. functionalTemplate,
  102. injectStyles,
  103. scopeId,
  104. moduleIdentifier, /* server only */
  105. shadowMode /* vue-cli only */
  106. ) {
  107. // Vue.extend constructor export interop
  108. var options = typeof scriptExports === 'function'
  109. ? scriptExports.options
  110. : scriptExports
  111. // render functions
  112. if (render) {
  113. options.render = render
  114. options.staticRenderFns = staticRenderFns
  115. options._compiled = true
  116. }
  117. // functional template
  118. if (functionalTemplate) {
  119. options.functional = true
  120. }
  121. // scopedId
  122. if (scopeId) {
  123. options._scopeId = 'data-v-' + scopeId
  124. }
  125. var hook
  126. if (moduleIdentifier) { // server build
  127. hook = function (context) {
  128. // 2.3 injection
  129. context =
  130. context || // cached call
  131. (this.$vnode && this.$vnode.ssrContext) || // stateful
  132. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  133. // 2.2 with runInNewContext: true
  134. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  135. context = __VUE_SSR_CONTEXT__
  136. }
  137. // inject component styles
  138. if (injectStyles) {
  139. injectStyles.call(this, context)
  140. }
  141. // register component module identifier for async chunk inferrence
  142. if (context && context._registeredComponents) {
  143. context._registeredComponents.add(moduleIdentifier)
  144. }
  145. }
  146. // used by ssr in case component is cached and beforeCreate
  147. // never gets called
  148. options._ssrRegister = hook
  149. } else if (injectStyles) {
  150. hook = shadowMode
  151. ? function () { injectStyles.call(this, this.$root.$options.shadowRoot) }
  152. : injectStyles
  153. }
  154. if (hook) {
  155. if (options.functional) {
  156. // for template-only hot-reload because in that case the render fn doesn't
  157. // go through the normalizer
  158. options._injectStyles = hook
  159. // register for functioal component in vue file
  160. var originalRender = options.render
  161. options.render = function renderWithStyleInjection (h, context) {
  162. hook.call(context)
  163. return originalRender(h, context)
  164. }
  165. } else {
  166. // inject component registration as beforeCreate hook
  167. var existing = options.beforeCreate
  168. options.beforeCreate = existing
  169. ? [].concat(existing, hook)
  170. : [hook]
  171. }
  172. }
  173. return {
  174. exports: scriptExports,
  175. options: options
  176. }
  177. }
  178. /***/ }),
  179. /***/ 1:
  180. /***/ (function(module, exports) {
  181. module.exports = require("element-ui/lib/utils/date-util");
  182. /***/ }),
  183. /***/ 14:
  184. /***/ (function(module, exports) {
  185. module.exports = require("element-ui/lib/button");
  186. /***/ }),
  187. /***/ 24:
  188. /***/ (function(module, exports) {
  189. module.exports = require("element-ui/lib/utils/date");
  190. /***/ }),
  191. /***/ 35:
  192. /***/ (function(module, exports) {
  193. module.exports = require("element-ui/lib/button-group");
  194. /***/ }),
  195. /***/ 6:
  196. /***/ (function(module, exports) {
  197. module.exports = require("element-ui/lib/mixins/locale");
  198. /***/ }),
  199. /***/ 70:
  200. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  201. "use strict";
  202. __webpack_require__.r(__webpack_exports__);
  203. // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/calendar/src/main.vue?vue&type=template&id=6d9756be&
  204. var render = function() {
  205. var _vm = this
  206. var _h = _vm.$createElement
  207. var _c = _vm._self._c || _h
  208. return _c("div", { staticClass: "el-calendar" }, [
  209. _c("div", { staticClass: "el-calendar__header" }, [
  210. _c("div", { staticClass: "el-calendar__title" }, [
  211. _vm._v("\n " + _vm._s(_vm.i18nDate) + "\n ")
  212. ]),
  213. _vm.validatedRange.length === 0
  214. ? _c(
  215. "div",
  216. { staticClass: "el-calendar__button-group" },
  217. [
  218. _c(
  219. "el-button-group",
  220. [
  221. _c(
  222. "el-button",
  223. {
  224. attrs: { type: "plain", size: "mini" },
  225. on: {
  226. click: function($event) {
  227. _vm.selectDate("prev-month")
  228. }
  229. }
  230. },
  231. [
  232. _vm._v(
  233. "\n " +
  234. _vm._s(_vm.t("el.datepicker.prevMonth")) +
  235. "\n "
  236. )
  237. ]
  238. ),
  239. _c(
  240. "el-button",
  241. {
  242. attrs: { type: "plain", size: "mini" },
  243. on: {
  244. click: function($event) {
  245. _vm.selectDate("today")
  246. }
  247. }
  248. },
  249. [
  250. _vm._v(
  251. "\n " +
  252. _vm._s(_vm.t("el.datepicker.today")) +
  253. "\n "
  254. )
  255. ]
  256. ),
  257. _c(
  258. "el-button",
  259. {
  260. attrs: { type: "plain", size: "mini" },
  261. on: {
  262. click: function($event) {
  263. _vm.selectDate("next-month")
  264. }
  265. }
  266. },
  267. [
  268. _vm._v(
  269. "\n " +
  270. _vm._s(_vm.t("el.datepicker.nextMonth")) +
  271. "\n "
  272. )
  273. ]
  274. )
  275. ],
  276. 1
  277. )
  278. ],
  279. 1
  280. )
  281. : _vm._e()
  282. ]),
  283. _vm.validatedRange.length === 0
  284. ? _c(
  285. "div",
  286. { key: "no-range", staticClass: "el-calendar__body" },
  287. [
  288. _c("date-table", {
  289. attrs: {
  290. date: _vm.date,
  291. "selected-day": _vm.realSelectedDay,
  292. "first-day-of-week": _vm.realFirstDayOfWeek
  293. },
  294. on: { pick: _vm.pickDay }
  295. })
  296. ],
  297. 1
  298. )
  299. : _c(
  300. "div",
  301. { key: "has-range", staticClass: "el-calendar__body" },
  302. _vm._l(_vm.validatedRange, function(range, index) {
  303. return _c("date-table", {
  304. key: index,
  305. attrs: {
  306. date: range[0],
  307. "selected-day": _vm.realSelectedDay,
  308. range: range,
  309. "hide-header": index !== 0,
  310. "first-day-of-week": _vm.realFirstDayOfWeek
  311. },
  312. on: { pick: _vm.pickDay }
  313. })
  314. }),
  315. 1
  316. )
  317. ])
  318. }
  319. var staticRenderFns = []
  320. render._withStripped = true
  321. // CONCATENATED MODULE: ./packages/calendar/src/main.vue?vue&type=template&id=6d9756be&
  322. // EXTERNAL MODULE: external "element-ui/lib/mixins/locale"
  323. var locale_ = __webpack_require__(6);
  324. var locale_default = /*#__PURE__*/__webpack_require__.n(locale_);
  325. // EXTERNAL MODULE: external "element-ui/lib/utils/date"
  326. var date_ = __webpack_require__(24);
  327. var date_default = /*#__PURE__*/__webpack_require__.n(date_);
  328. // EXTERNAL MODULE: external "element-ui/lib/button"
  329. var button_ = __webpack_require__(14);
  330. var button_default = /*#__PURE__*/__webpack_require__.n(button_);
  331. // EXTERNAL MODULE: external "element-ui/lib/button-group"
  332. var button_group_ = __webpack_require__(35);
  333. var button_group_default = /*#__PURE__*/__webpack_require__.n(button_group_);
  334. // EXTERNAL MODULE: external "element-ui/lib/utils/date-util"
  335. var date_util_ = __webpack_require__(1);
  336. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/calendar/src/date-table.vue?vue&type=script&lang=js&
  337. /* harmony default export */ var date_tablevue_type_script_lang_js_ = ({
  338. props: {
  339. selectedDay: String, // formated date yyyy-MM-dd
  340. range: {
  341. type: Array,
  342. validator: function validator(val) {
  343. if (!(val && val.length)) return true;
  344. var start = val[0],
  345. end = val[1];
  346. return Object(date_util_["validateRangeInOneMonth"])(start, end);
  347. }
  348. },
  349. date: Date,
  350. hideHeader: Boolean,
  351. firstDayOfWeek: Number
  352. },
  353. inject: ['elCalendar'],
  354. methods: {
  355. toNestedArr: function toNestedArr(days) {
  356. return Object(date_util_["range"])(days.length / 7).map(function (_, index) {
  357. var start = index * 7;
  358. return days.slice(start, start + 7);
  359. });
  360. },
  361. getFormateDate: function getFormateDate(day, type) {
  362. if (!day || ['prev', 'current', 'next'].indexOf(type) === -1) {
  363. throw new Error('invalid day or type');
  364. }
  365. var prefix = this.curMonthDatePrefix;
  366. if (type === 'prev') {
  367. prefix = this.prevMonthDatePrefix;
  368. } else if (type === 'next') {
  369. prefix = this.nextMonthDatePrefix;
  370. }
  371. day = ('00' + day).slice(-2);
  372. return prefix + '-' + day;
  373. },
  374. getCellClass: function getCellClass(_ref) {
  375. var text = _ref.text,
  376. type = _ref.type;
  377. var classes = [type];
  378. if (type === 'current') {
  379. var date = this.getFormateDate(text, type);
  380. if (date === this.selectedDay) {
  381. classes.push('is-selected');
  382. }
  383. if (date === this.formatedToday) {
  384. classes.push('is-today');
  385. }
  386. }
  387. return classes;
  388. },
  389. pickDay: function pickDay(_ref2) {
  390. var text = _ref2.text,
  391. type = _ref2.type;
  392. var date = this.getFormateDate(text, type);
  393. this.$emit('pick', date);
  394. },
  395. cellRenderProxy: function cellRenderProxy(_ref3) {
  396. var text = _ref3.text,
  397. type = _ref3.type;
  398. var h = this.$createElement;
  399. var render = this.elCalendar.$scopedSlots.dateCell;
  400. if (!render) return h('span', [text]);
  401. var day = this.getFormateDate(text, type);
  402. var date = new Date(day);
  403. var data = {
  404. isSelected: this.selectedDay === day,
  405. type: type + '-month',
  406. day: day
  407. };
  408. return render({ date: date, data: data });
  409. }
  410. },
  411. computed: {
  412. WEEK_DAYS: function WEEK_DAYS() {
  413. return Object(date_util_["getI18nSettings"])().dayNames;
  414. },
  415. prevMonthDatePrefix: function prevMonthDatePrefix() {
  416. var temp = new Date(this.date.getTime());
  417. temp.setDate(0);
  418. return date_default.a.format(temp, 'yyyy-MM');
  419. },
  420. curMonthDatePrefix: function curMonthDatePrefix() {
  421. return date_default.a.format(this.date, 'yyyy-MM');
  422. },
  423. nextMonthDatePrefix: function nextMonthDatePrefix() {
  424. var temp = new Date(this.date.getFullYear(), this.date.getMonth() + 1, 1);
  425. return date_default.a.format(temp, 'yyyy-MM');
  426. },
  427. formatedToday: function formatedToday() {
  428. return this.elCalendar.formatedToday;
  429. },
  430. isInRange: function isInRange() {
  431. return this.range && this.range.length;
  432. },
  433. rows: function rows() {
  434. var days = [];
  435. // if range exists, should render days in range.
  436. if (this.isInRange) {
  437. var _range = this.range,
  438. start = _range[0],
  439. end = _range[1];
  440. var currentMonthRange = Object(date_util_["range"])(end.getDate() - start.getDate() + 1).map(function (_, index) {
  441. return {
  442. text: start.getDate() + index,
  443. type: 'current'
  444. };
  445. });
  446. var remaining = currentMonthRange.length % 7;
  447. remaining = remaining === 0 ? 0 : 7 - remaining;
  448. var nextMonthRange = Object(date_util_["range"])(remaining).map(function (_, index) {
  449. return {
  450. text: index + 1,
  451. type: 'next'
  452. };
  453. });
  454. days = currentMonthRange.concat(nextMonthRange);
  455. } else {
  456. var date = this.date;
  457. var firstDay = Object(date_util_["getFirstDayOfMonth"])(date);
  458. firstDay = firstDay === 0 ? 7 : firstDay;
  459. var firstDayOfWeek = typeof this.firstDayOfWeek === 'number' ? this.firstDayOfWeek : 1;
  460. var offset = (7 + firstDay - firstDayOfWeek) % 7;
  461. var prevMonthDays = Object(date_util_["getPrevMonthLastDays"])(date, offset).map(function (day) {
  462. return {
  463. text: day,
  464. type: 'prev'
  465. };
  466. });
  467. var currentMonthDays = Object(date_util_["getMonthDays"])(date).map(function (day) {
  468. return {
  469. text: day,
  470. type: 'current'
  471. };
  472. });
  473. days = [].concat(prevMonthDays, currentMonthDays);
  474. var nextMonthDays = Object(date_util_["range"])(42 - days.length).map(function (_, index) {
  475. return {
  476. text: index + 1,
  477. type: 'next'
  478. };
  479. });
  480. days = days.concat(nextMonthDays);
  481. }
  482. return this.toNestedArr(days);
  483. },
  484. weekDays: function weekDays() {
  485. var start = this.firstDayOfWeek;
  486. var WEEK_DAYS = this.WEEK_DAYS;
  487. if (typeof start !== 'number' || start === 0) {
  488. return WEEK_DAYS.slice();
  489. } else {
  490. return WEEK_DAYS.slice(start).concat(WEEK_DAYS.slice(0, start));
  491. }
  492. }
  493. },
  494. render: function render() {
  495. var _this = this;
  496. var h = arguments[0];
  497. var thead = this.hideHeader ? null : h('thead', [this.weekDays.map(function (day) {
  498. return h(
  499. 'th',
  500. { key: day },
  501. [day]
  502. );
  503. })]);
  504. return h(
  505. 'table',
  506. {
  507. 'class': {
  508. 'el-calendar-table': true,
  509. 'is-range': this.isInRange
  510. },
  511. attrs: { cellspacing: '0',
  512. cellpadding: '0' }
  513. },
  514. [thead, h('tbody', [this.rows.map(function (row, index) {
  515. return h(
  516. 'tr',
  517. {
  518. 'class': {
  519. 'el-calendar-table__row': true,
  520. 'el-calendar-table__row--hide-border': index === 0 && _this.hideHeader
  521. },
  522. key: index },
  523. [row.map(function (cell, key) {
  524. return h(
  525. 'td',
  526. { key: key,
  527. 'class': _this.getCellClass(cell),
  528. on: {
  529. 'click': _this.pickDay.bind(_this, cell)
  530. }
  531. },
  532. [h(
  533. 'div',
  534. { 'class': 'el-calendar-day' },
  535. [_this.cellRenderProxy(cell)]
  536. )]
  537. );
  538. })]
  539. );
  540. })])]
  541. );
  542. }
  543. });
  544. // CONCATENATED MODULE: ./packages/calendar/src/date-table.vue?vue&type=script&lang=js&
  545. /* harmony default export */ var src_date_tablevue_type_script_lang_js_ = (date_tablevue_type_script_lang_js_);
  546. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  547. var componentNormalizer = __webpack_require__(0);
  548. // CONCATENATED MODULE: ./packages/calendar/src/date-table.vue
  549. var date_table_render, date_table_staticRenderFns
  550. /* normalize component */
  551. var component = Object(componentNormalizer["a" /* default */])(
  552. src_date_tablevue_type_script_lang_js_,
  553. date_table_render,
  554. date_table_staticRenderFns,
  555. false,
  556. null,
  557. null,
  558. null
  559. )
  560. /* hot reload */
  561. if (false) { var api; }
  562. component.options.__file = "packages/calendar/src/date-table.vue"
  563. /* harmony default export */ var date_table = (component.exports);
  564. // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/calendar/src/main.vue?vue&type=script&lang=js&
  565. //
  566. //
  567. //
  568. //
  569. //
  570. //
  571. //
  572. //
  573. //
  574. //
  575. //
  576. //
  577. //
  578. //
  579. //
  580. //
  581. //
  582. //
  583. //
  584. //
  585. //
  586. //
  587. //
  588. //
  589. //
  590. //
  591. //
  592. //
  593. //
  594. //
  595. //
  596. //
  597. //
  598. //
  599. //
  600. //
  601. //
  602. //
  603. //
  604. //
  605. //
  606. //
  607. //
  608. //
  609. //
  610. //
  611. //
  612. //
  613. //
  614. //
  615. //
  616. //
  617. //
  618. //
  619. //
  620. //
  621. //
  622. //
  623. var validTypes = ['prev-month', 'today', 'next-month'];
  624. var weekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  625. var oneDay = 86400000;
  626. /* harmony default export */ var mainvue_type_script_lang_js_ = ({
  627. name: 'ElCalendar',
  628. mixins: [locale_default.a],
  629. components: {
  630. DateTable: date_table,
  631. ElButton: button_default.a,
  632. ElButtonGroup: button_group_default.a
  633. },
  634. props: {
  635. value: [Date, String, Number],
  636. range: {
  637. type: Array,
  638. validator: function validator(range) {
  639. if (Array.isArray(range)) {
  640. return range.length === 2 && range.every(function (item) {
  641. return typeof item === 'string' || typeof item === 'number' || item instanceof Date;
  642. });
  643. } else {
  644. return true;
  645. }
  646. }
  647. },
  648. firstDayOfWeek: {
  649. type: Number,
  650. default: 1
  651. }
  652. },
  653. provide: function provide() {
  654. return {
  655. elCalendar: this
  656. };
  657. },
  658. methods: {
  659. pickDay: function pickDay(day) {
  660. this.realSelectedDay = day;
  661. },
  662. selectDate: function selectDate(type) {
  663. if (validTypes.indexOf(type) === -1) {
  664. throw new Error('invalid type ' + type);
  665. }
  666. var day = '';
  667. if (type === 'prev-month') {
  668. day = this.prevMonthDatePrefix + '-01';
  669. } else if (type === 'next-month') {
  670. day = this.nextMonthDatePrefix + '-01';
  671. } else {
  672. day = this.formatedToday;
  673. }
  674. if (day === this.formatedDate) return;
  675. this.pickDay(day);
  676. },
  677. toDate: function toDate(val) {
  678. if (!val) {
  679. throw new Error('invalid val');
  680. }
  681. return val instanceof Date ? val : new Date(val);
  682. },
  683. rangeValidator: function rangeValidator(date, isStart) {
  684. var firstDayOfWeek = this.realFirstDayOfWeek;
  685. var expected = isStart ? firstDayOfWeek : firstDayOfWeek === 0 ? 6 : firstDayOfWeek - 1;
  686. var message = (isStart ? 'start' : 'end') + ' of range should be ' + weekDays[expected] + '.';
  687. if (date.getDay() !== expected) {
  688. console.warn('[ElementCalendar]', message, 'Invalid range will be ignored.');
  689. return false;
  690. }
  691. return true;
  692. }
  693. },
  694. computed: {
  695. prevMonthDatePrefix: function prevMonthDatePrefix() {
  696. var temp = new Date(this.date.getTime());
  697. temp.setDate(0);
  698. return date_default.a.format(temp, 'yyyy-MM');
  699. },
  700. curMonthDatePrefix: function curMonthDatePrefix() {
  701. return date_default.a.format(this.date, 'yyyy-MM');
  702. },
  703. nextMonthDatePrefix: function nextMonthDatePrefix() {
  704. var temp = new Date(this.date.getFullYear(), this.date.getMonth() + 1, 1);
  705. return date_default.a.format(temp, 'yyyy-MM');
  706. },
  707. formatedDate: function formatedDate() {
  708. return date_default.a.format(this.date, 'yyyy-MM-dd');
  709. },
  710. i18nDate: function i18nDate() {
  711. var year = this.date.getFullYear();
  712. var month = this.date.getMonth() + 1;
  713. return year + ' ' + this.t('el.datepicker.year') + ' ' + this.t('el.datepicker.month' + month);
  714. },
  715. formatedToday: function formatedToday() {
  716. return date_default.a.format(this.now, 'yyyy-MM-dd');
  717. },
  718. realSelectedDay: {
  719. get: function get() {
  720. if (!this.value) return this.selectedDay;
  721. return this.formatedDate;
  722. },
  723. set: function set(val) {
  724. this.selectedDay = val;
  725. var date = new Date(val);
  726. this.$emit('input', date);
  727. }
  728. },
  729. date: function date() {
  730. if (!this.value) {
  731. if (this.realSelectedDay) {
  732. var d = this.selectedDay.split('-');
  733. return new Date(d[0], d[1] - 1, d[2]);
  734. } else if (this.validatedRange.length) {
  735. return this.validatedRange[0][0];
  736. }
  737. return this.now;
  738. } else {
  739. return this.toDate(this.value);
  740. }
  741. },
  742. // if range is valid, we get a two-digit array
  743. validatedRange: function validatedRange() {
  744. var _this = this;
  745. var range = this.range;
  746. if (!range) return [];
  747. range = range.reduce(function (prev, val, index) {
  748. var date = _this.toDate(val);
  749. if (_this.rangeValidator(date, index === 0)) {
  750. prev = prev.concat(date);
  751. }
  752. return prev;
  753. }, []);
  754. if (range.length === 2) {
  755. var _range = range,
  756. start = _range[0],
  757. end = _range[1];
  758. if (start > end) {
  759. console.warn('[ElementCalendar]end time should be greater than start time');
  760. return [];
  761. }
  762. // start time and end time in one month
  763. if (Object(date_util_["validateRangeInOneMonth"])(start, end)) {
  764. return [[start, end]];
  765. }
  766. var data = [];
  767. var startDay = new Date(start.getFullYear(), start.getMonth() + 1, 1);
  768. var lastDay = this.toDate(startDay.getTime() - oneDay);
  769. if (!Object(date_util_["validateRangeInOneMonth"])(startDay, end)) {
  770. console.warn('[ElementCalendar]start time and end time interval must not exceed two months');
  771. return [];
  772. }
  773. // 第一个月的时间范围
  774. data.push([start, lastDay]);
  775. // 下一月的时间范围,需要计算一下该月的第一个周起始日
  776. var firstDayOfWeek = this.realFirstDayOfWeek;
  777. var nextMontFirstDay = startDay.getDay();
  778. var interval = 0;
  779. if (nextMontFirstDay !== firstDayOfWeek) {
  780. if (firstDayOfWeek === 0) {
  781. interval = 7 - nextMontFirstDay;
  782. } else {
  783. interval = firstDayOfWeek - nextMontFirstDay;
  784. interval = interval > 0 ? interval : 7 + interval;
  785. }
  786. }
  787. startDay = this.toDate(startDay.getTime() + interval * oneDay);
  788. if (startDay.getDate() < end.getDate()) {
  789. data.push([startDay, end]);
  790. }
  791. return data;
  792. }
  793. return [];
  794. },
  795. realFirstDayOfWeek: function realFirstDayOfWeek() {
  796. if (this.firstDayOfWeek < 1 || this.firstDayOfWeek > 6) {
  797. return 0;
  798. }
  799. return Math.floor(this.firstDayOfWeek);
  800. }
  801. },
  802. data: function data() {
  803. return {
  804. selectedDay: '',
  805. now: new Date()
  806. };
  807. }
  808. });
  809. // CONCATENATED MODULE: ./packages/calendar/src/main.vue?vue&type=script&lang=js&
  810. /* harmony default export */ var src_mainvue_type_script_lang_js_ = (mainvue_type_script_lang_js_);
  811. // CONCATENATED MODULE: ./packages/calendar/src/main.vue
  812. /* normalize component */
  813. var main_component = Object(componentNormalizer["a" /* default */])(
  814. src_mainvue_type_script_lang_js_,
  815. render,
  816. staticRenderFns,
  817. false,
  818. null,
  819. null,
  820. null
  821. )
  822. /* hot reload */
  823. if (false) { var main_api; }
  824. main_component.options.__file = "packages/calendar/src/main.vue"
  825. /* harmony default export */ var main = (main_component.exports);
  826. // CONCATENATED MODULE: ./packages/calendar/index.js
  827. /* istanbul ignore next */
  828. main.install = function (Vue) {
  829. Vue.component(main.name, main);
  830. };
  831. /* harmony default export */ var calendar = __webpack_exports__["default"] = (main);
  832. /***/ })
  833. /******/ });