calendar.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  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 = 66);
  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. /***/ 13:
  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. /***/ 36:
  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. /***/ 66:
  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__(13);
  330. var button_default = /*#__PURE__*/__webpack_require__.n(button_);
  331. // EXTERNAL MODULE: external "element-ui/lib/button-group"
  332. var button_group_ = __webpack_require__(36);
  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. data: function data() {
  355. return {
  356. WEEK_DAYS: Object(date_util_["getI18nSettings"])().dayNames
  357. };
  358. },
  359. methods: {
  360. toNestedArr: function toNestedArr(days) {
  361. return Object(date_util_["range"])(days.length / 7).map(function (_, index) {
  362. var start = index * 7;
  363. return days.slice(start, start + 7);
  364. });
  365. },
  366. getFormateDate: function getFormateDate(day, type) {
  367. if (!day || ['prev', 'current', 'next'].indexOf(type) === -1) {
  368. throw new Error('invalid day or type');
  369. }
  370. var prefix = this.curMonthDatePrefix;
  371. if (type === 'prev') {
  372. prefix = this.prevMonthDatePrefix;
  373. } else if (type === 'next') {
  374. prefix = this.nextMonthDatePrefix;
  375. }
  376. day = ('00' + day).slice(-2);
  377. return prefix + '-' + day;
  378. },
  379. getCellClass: function getCellClass(_ref) {
  380. var text = _ref.text,
  381. type = _ref.type;
  382. var classes = [type];
  383. if (type === 'current') {
  384. var date = this.getFormateDate(text, type);
  385. if (date === this.selectedDay) {
  386. classes.push('is-selected');
  387. }
  388. if (date === this.formatedToday) {
  389. classes.push('is-today');
  390. }
  391. }
  392. return classes;
  393. },
  394. pickDay: function pickDay(_ref2) {
  395. var text = _ref2.text,
  396. type = _ref2.type;
  397. var date = this.getFormateDate(text, type);
  398. this.$emit('pick', date);
  399. },
  400. cellRenderProxy: function cellRenderProxy(_ref3) {
  401. var text = _ref3.text,
  402. type = _ref3.type;
  403. var h = this.$createElement;
  404. var render = this.elCalendar.$scopedSlots.dateCell;
  405. if (!render) return h('span', [text]);
  406. var day = this.getFormateDate(text, type);
  407. var date = new Date(day);
  408. var data = {
  409. isSelected: this.selectedDay === day,
  410. type: type + '-month',
  411. day: day
  412. };
  413. return render({ date: date, data: data });
  414. }
  415. },
  416. computed: {
  417. prevMonthDatePrefix: function prevMonthDatePrefix() {
  418. var temp = new Date(this.date.getTime());
  419. temp.setDate(0);
  420. return date_default.a.format(temp, 'yyyy-MM');
  421. },
  422. curMonthDatePrefix: function curMonthDatePrefix() {
  423. return date_default.a.format(this.date, 'yyyy-MM');
  424. },
  425. nextMonthDatePrefix: function nextMonthDatePrefix() {
  426. var temp = new Date(this.date.getFullYear(), this.date.getMonth() + 1, 1);
  427. return date_default.a.format(temp, 'yyyy-MM');
  428. },
  429. formatedToday: function formatedToday() {
  430. return this.elCalendar.formatedToday;
  431. },
  432. isInRange: function isInRange() {
  433. return this.range && this.range.length;
  434. },
  435. rows: function rows() {
  436. var days = [];
  437. // if range exists, should render days in range.
  438. if (this.isInRange) {
  439. var _range = this.range,
  440. start = _range[0],
  441. end = _range[1];
  442. var currentMonthRange = Object(date_util_["range"])(end.getDate() - start.getDate() + 1).map(function (_, index) {
  443. return {
  444. text: start.getDate() + index,
  445. type: 'current'
  446. };
  447. });
  448. var remaining = currentMonthRange.length % 7;
  449. remaining = remaining === 0 ? 0 : 7 - remaining;
  450. var nextMonthRange = Object(date_util_["range"])(remaining).map(function (_, index) {
  451. return {
  452. text: index + 1,
  453. type: 'next'
  454. };
  455. });
  456. days = currentMonthRange.concat(nextMonthRange);
  457. } else {
  458. var date = this.date;
  459. var firstDay = Object(date_util_["getFirstDayOfMonth"])(date);
  460. firstDay = firstDay === 0 ? 7 : firstDay;
  461. var firstDayOfWeek = typeof this.firstDayOfWeek === 'number' ? this.firstDayOfWeek : 1;
  462. var prevMonthDays = Object(date_util_["getPrevMonthLastDays"])(date, firstDay - firstDayOfWeek).map(function (day) {
  463. return {
  464. text: day,
  465. type: 'prev'
  466. };
  467. });
  468. var currentMonthDays = Object(date_util_["getMonthDays"])(date).map(function (day) {
  469. return {
  470. text: day,
  471. type: 'current'
  472. };
  473. });
  474. days = [].concat(prevMonthDays, currentMonthDays);
  475. var nextMonthDays = Object(date_util_["range"])(42 - days.length).map(function (_, index) {
  476. return {
  477. text: index + 1,
  478. type: 'next'
  479. };
  480. });
  481. days = days.concat(nextMonthDays);
  482. }
  483. return this.toNestedArr(days);
  484. },
  485. weekDays: function weekDays() {
  486. var start = this.firstDayOfWeek;
  487. var WEEK_DAYS = this.WEEK_DAYS;
  488. if (typeof start !== 'number' || start === 0) {
  489. return WEEK_DAYS.slice();
  490. } else {
  491. return WEEK_DAYS.slice(start).concat(WEEK_DAYS.slice(0, start));
  492. }
  493. }
  494. },
  495. render: function render() {
  496. var _this = this;
  497. var h = arguments[0];
  498. var thead = this.hideHeader ? null : h('thead', [this.weekDays.map(function (day) {
  499. return h(
  500. 'th',
  501. { key: day },
  502. [day]
  503. );
  504. })]);
  505. return h(
  506. 'table',
  507. {
  508. 'class': {
  509. 'el-calendar-table': true,
  510. 'is-range': this.isInRange
  511. },
  512. attrs: { cellspacing: '0',
  513. cellpadding: '0' }
  514. },
  515. [thead, h('tbody', [this.rows.map(function (row, index) {
  516. return h(
  517. 'tr',
  518. {
  519. 'class': {
  520. 'el-calendar-table__row': true,
  521. 'el-calendar-table__row--hide-border': index === 0 && _this.hideHeader
  522. },
  523. key: index },
  524. [row.map(function (cell, key) {
  525. return h(
  526. 'td',
  527. { key: key,
  528. 'class': _this.getCellClass(cell),
  529. on: {
  530. 'click': _this.pickDay.bind(_this, cell)
  531. }
  532. },
  533. [h(
  534. 'div',
  535. { 'class': 'el-calendar-day' },
  536. [_this.cellRenderProxy(cell)]
  537. )]
  538. );
  539. })]
  540. );
  541. })])]
  542. );
  543. }
  544. });
  545. // CONCATENATED MODULE: ./packages/calendar/src/date-table.vue?vue&type=script&lang=js&
  546. /* harmony default export */ var src_date_tablevue_type_script_lang_js_ = (date_tablevue_type_script_lang_js_);
  547. // EXTERNAL MODULE: ./node_modules/vue-loader/lib/runtime/componentNormalizer.js
  548. var componentNormalizer = __webpack_require__(0);
  549. // CONCATENATED MODULE: ./packages/calendar/src/date-table.vue
  550. var date_table_render, date_table_staticRenderFns
  551. /* normalize component */
  552. var component = Object(componentNormalizer["a" /* default */])(
  553. src_date_tablevue_type_script_lang_js_,
  554. date_table_render,
  555. date_table_staticRenderFns,
  556. false,
  557. null,
  558. null,
  559. null
  560. )
  561. /* hot reload */
  562. if (false) { var api; }
  563. component.options.__file = "packages/calendar/src/date-table.vue"
  564. /* harmony default export */ var date_table = (component.exports);
  565. // 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&
  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. //
  624. var validTypes = ['prev-month', 'today', 'next-month'];
  625. var weekDays = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
  626. var oneDay = 86400000;
  627. /* harmony default export */ var mainvue_type_script_lang_js_ = ({
  628. name: 'ElCalendar',
  629. mixins: [locale_default.a],
  630. components: {
  631. DateTable: date_table,
  632. ElButton: button_default.a,
  633. ElButtonGroup: button_group_default.a
  634. },
  635. props: {
  636. value: [Date, String, Number],
  637. range: {
  638. type: Array,
  639. validator: function validator(range) {
  640. if (Array.isArray(range)) {
  641. return range.length === 2 && range.every(function (item) {
  642. return typeof item === 'string' || typeof item === 'number' || item instanceof Date;
  643. });
  644. } else {
  645. return true;
  646. }
  647. }
  648. },
  649. firstDayOfWeek: {
  650. type: Number,
  651. default: 1
  652. }
  653. },
  654. provide: function provide() {
  655. return {
  656. elCalendar: this
  657. };
  658. },
  659. methods: {
  660. pickDay: function pickDay(day) {
  661. this.realSelectedDay = day;
  662. },
  663. selectDate: function selectDate(type) {
  664. if (validTypes.indexOf(type) === -1) {
  665. throw new Error('invalid type ' + type);
  666. }
  667. var day = '';
  668. if (type === 'prev-month') {
  669. day = this.prevMonthDatePrefix + '-01';
  670. } else if (type === 'next-month') {
  671. day = this.nextMonthDatePrefix + '-01';
  672. } else {
  673. day = this.formatedToday;
  674. }
  675. if (day === this.formatedDate) return;
  676. this.pickDay(day);
  677. },
  678. toDate: function toDate(val) {
  679. if (!val) {
  680. throw new Error('invalid val');
  681. }
  682. return val instanceof Date ? val : new Date(val);
  683. },
  684. rangeValidator: function rangeValidator(date, isStart) {
  685. var firstDayOfWeek = this.realFirstDayOfWeek;
  686. var expected = isStart ? firstDayOfWeek : firstDayOfWeek === 0 ? 6 : firstDayOfWeek - 1;
  687. var message = (isStart ? 'start' : 'end') + ' of range should be ' + weekDays[expected] + '.';
  688. if (date.getDay() !== expected) {
  689. console.warn('[ElementCalendar]', message, 'Invalid range will be ignored.');
  690. return false;
  691. }
  692. return true;
  693. }
  694. },
  695. computed: {
  696. prevMonthDatePrefix: function prevMonthDatePrefix() {
  697. var temp = new Date(this.date.getTime());
  698. temp.setDate(0);
  699. return date_default.a.format(temp, 'yyyy-MM');
  700. },
  701. curMonthDatePrefix: function curMonthDatePrefix() {
  702. return date_default.a.format(this.date, 'yyyy-MM');
  703. },
  704. nextMonthDatePrefix: function nextMonthDatePrefix() {
  705. var temp = new Date(this.date.getFullYear(), this.date.getMonth() + 1, 1);
  706. return date_default.a.format(temp, 'yyyy-MM');
  707. },
  708. formatedDate: function formatedDate() {
  709. return date_default.a.format(this.date, 'yyyy-MM-dd');
  710. },
  711. i18nDate: function i18nDate() {
  712. var year = this.date.getFullYear();
  713. var month = this.date.getMonth() + 1;
  714. return year + ' ' + this.t('el.datepicker.year') + ' ' + this.t('el.datepicker.month' + month);
  715. },
  716. formatedToday: function formatedToday() {
  717. return date_default.a.format(this.now, 'yyyy-MM-dd');
  718. },
  719. realSelectedDay: {
  720. get: function get() {
  721. if (!this.value) return this.selectedDay;
  722. return this.formatedDate;
  723. },
  724. set: function set(val) {
  725. this.selectedDay = val;
  726. var date = new Date(val);
  727. this.$emit('input', date);
  728. }
  729. },
  730. date: function date() {
  731. if (!this.value) {
  732. if (this.realSelectedDay) {
  733. var d = this.selectedDay.split('-');
  734. return new Date(d[0], d[1] - 1, d[2]);
  735. } else if (this.validatedRange.length) {
  736. return this.validatedRange[0][0];
  737. }
  738. return this.now;
  739. } else {
  740. return this.toDate(this.value);
  741. }
  742. },
  743. // if range is valid, we get a two-digit array
  744. validatedRange: function validatedRange() {
  745. var _this = this;
  746. var range = this.range;
  747. if (!range) return [];
  748. range = range.reduce(function (prev, val, index) {
  749. var date = _this.toDate(val);
  750. if (_this.rangeValidator(date, index === 0)) {
  751. prev = prev.concat(date);
  752. }
  753. return prev;
  754. }, []);
  755. if (range.length === 2) {
  756. var _range = range,
  757. start = _range[0],
  758. end = _range[1];
  759. if (start > end) {
  760. console.warn('[ElementCalendar]end time should be greater than start time');
  761. return [];
  762. }
  763. // start time and end time in one month
  764. if (Object(date_util_["validateRangeInOneMonth"])(start, end)) {
  765. return [[start, end]];
  766. }
  767. var data = [];
  768. var startDay = new Date(start.getFullYear(), start.getMonth() + 1, 1);
  769. var lastDay = this.toDate(startDay.getTime() - oneDay);
  770. if (!Object(date_util_["validateRangeInOneMonth"])(startDay, end)) {
  771. console.warn('[ElementCalendar]start time and end time interval must not exceed two months');
  772. return [];
  773. }
  774. // 第一个月的时间范围
  775. data.push([start, lastDay]);
  776. // 下一月的时间范围,需要计算一下该月的第一个周起始日
  777. var firstDayOfWeek = this.realFirstDayOfWeek;
  778. var nextMontFirstDay = startDay.getDay();
  779. var interval = 0;
  780. if (nextMontFirstDay !== firstDayOfWeek) {
  781. if (firstDayOfWeek === 0) {
  782. interval = 7 - nextMontFirstDay;
  783. } else {
  784. interval = firstDayOfWeek - nextMontFirstDay;
  785. interval = interval > 0 ? interval : 7 + interval;
  786. }
  787. }
  788. startDay = this.toDate(startDay.getTime() + interval * oneDay);
  789. if (startDay.getDate() < end.getDate()) {
  790. data.push([startDay, end]);
  791. }
  792. return data;
  793. }
  794. return [];
  795. },
  796. realFirstDayOfWeek: function realFirstDayOfWeek() {
  797. if (this.firstDayOfWeek < 1 || this.firstDayOfWeek > 6) {
  798. return 0;
  799. }
  800. return Math.floor(this.firstDayOfWeek);
  801. }
  802. },
  803. data: function data() {
  804. return {
  805. selectedDay: '',
  806. now: new Date()
  807. };
  808. }
  809. });
  810. // CONCATENATED MODULE: ./packages/calendar/src/main.vue?vue&type=script&lang=js&
  811. /* harmony default export */ var src_mainvue_type_script_lang_js_ = (mainvue_type_script_lang_js_);
  812. // CONCATENATED MODULE: ./packages/calendar/src/main.vue
  813. /* normalize component */
  814. var main_component = Object(componentNormalizer["a" /* default */])(
  815. src_mainvue_type_script_lang_js_,
  816. render,
  817. staticRenderFns,
  818. false,
  819. null,
  820. null,
  821. null
  822. )
  823. /* hot reload */
  824. if (false) { var main_api; }
  825. main_component.options.__file = "packages/calendar/src/main.vue"
  826. /* harmony default export */ var main = (main_component.exports);
  827. // CONCATENATED MODULE: ./packages/calendar/index.js
  828. /* istanbul ignore next */
  829. main.install = function (Vue) {
  830. Vue.component(main.name, main);
  831. };
  832. /* harmony default export */ var calendar = __webpack_exports__["default"] = (main);
  833. /***/ })
  834. /******/ });