index.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. module.exports =
  2. /******/ (function(modules) { // webpackBootstrap
  3. /******/ // The module cache
  4. /******/ var installedModules = {};
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/ // Check if module is in cache
  8. /******/ if(installedModules[moduleId])
  9. /******/ return installedModules[moduleId].exports;
  10. /******/ // Create a new module (and put it into the cache)
  11. /******/ var module = installedModules[moduleId] = {
  12. /******/ i: moduleId,
  13. /******/ l: false,
  14. /******/ exports: {}
  15. /******/ };
  16. /******/ // Execute the module function
  17. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  18. /******/ // Flag the module as loaded
  19. /******/ module.l = true;
  20. /******/ // Return the exports of the module
  21. /******/ return module.exports;
  22. /******/ }
  23. /******/ // expose the modules object (__webpack_modules__)
  24. /******/ __webpack_require__.m = modules;
  25. /******/ // expose the module cache
  26. /******/ __webpack_require__.c = installedModules;
  27. /******/ // identity function for calling harmony imports with the correct context
  28. /******/ __webpack_require__.i = function(value) { return value; };
  29. /******/ // define getter function for harmony exports
  30. /******/ __webpack_require__.d = function(exports, name, getter) {
  31. /******/ if(!__webpack_require__.o(exports, name)) {
  32. /******/ Object.defineProperty(exports, name, {
  33. /******/ configurable: false,
  34. /******/ enumerable: true,
  35. /******/ get: getter
  36. /******/ });
  37. /******/ }
  38. /******/ };
  39. /******/ // getDefaultExport function for compatibility with non-harmony modules
  40. /******/ __webpack_require__.n = function(module) {
  41. /******/ var getter = module && module.__esModule ?
  42. /******/ function getDefault() { return module['default']; } :
  43. /******/ function getModuleExports() { return module; };
  44. /******/ __webpack_require__.d(getter, 'a', getter);
  45. /******/ return getter;
  46. /******/ };
  47. /******/ // Object.prototype.hasOwnProperty.call
  48. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  49. /******/ // __webpack_public_path__
  50. /******/ __webpack_require__.p = "";
  51. /******/ // Load entry module and return exports
  52. /******/ return __webpack_require__(__webpack_require__.s = 215);
  53. /******/ })
  54. /************************************************************************/
  55. /******/ ({
  56. /***/ 0:
  57. /***/ function(module, exports) {
  58. /* globals __VUE_SSR_CONTEXT__ */
  59. // this module is a runtime utility for cleaner component module output and will
  60. // be included in the final webpack user bundle
  61. module.exports = function normalizeComponent (
  62. rawScriptExports,
  63. compiledTemplate,
  64. injectStyles,
  65. scopeId,
  66. moduleIdentifier /* server only */
  67. ) {
  68. var esModule
  69. var scriptExports = rawScriptExports = rawScriptExports || {}
  70. // ES6 modules interop
  71. var type = typeof rawScriptExports.default
  72. if (type === 'object' || type === 'function') {
  73. esModule = rawScriptExports
  74. scriptExports = rawScriptExports.default
  75. }
  76. // Vue.extend constructor export interop
  77. var options = typeof scriptExports === 'function'
  78. ? scriptExports.options
  79. : scriptExports
  80. // render functions
  81. if (compiledTemplate) {
  82. options.render = compiledTemplate.render
  83. options.staticRenderFns = compiledTemplate.staticRenderFns
  84. }
  85. // scopedId
  86. if (scopeId) {
  87. options._scopeId = scopeId
  88. }
  89. var hook
  90. if (moduleIdentifier) { // server build
  91. hook = function (context) {
  92. // 2.3 injection
  93. context =
  94. context || // cached call
  95. (this.$vnode && this.$vnode.ssrContext) || // stateful
  96. (this.parent && this.parent.$vnode && this.parent.$vnode.ssrContext) // functional
  97. // 2.2 with runInNewContext: true
  98. if (!context && typeof __VUE_SSR_CONTEXT__ !== 'undefined') {
  99. context = __VUE_SSR_CONTEXT__
  100. }
  101. // inject component styles
  102. if (injectStyles) {
  103. injectStyles.call(this, context)
  104. }
  105. // register component module identifier for async chunk inferrence
  106. if (context && context._registeredComponents) {
  107. context._registeredComponents.add(moduleIdentifier)
  108. }
  109. }
  110. // used by ssr in case component is cached and beforeCreate
  111. // never gets called
  112. options._ssrRegister = hook
  113. } else if (injectStyles) {
  114. hook = injectStyles
  115. }
  116. if (hook) {
  117. var functional = options.functional
  118. var existing = functional
  119. ? options.render
  120. : options.beforeCreate
  121. if (!functional) {
  122. // inject component registration as beforeCreate hook
  123. options.beforeCreate = existing
  124. ? [].concat(existing, hook)
  125. : [hook]
  126. } else {
  127. // register for functioal component in vue file
  128. options.render = function renderWithStyleInjection (h, context) {
  129. hook.call(context)
  130. return existing(h, context)
  131. }
  132. }
  133. }
  134. return {
  135. esModule: esModule,
  136. exports: scriptExports,
  137. options: options
  138. }
  139. }
  140. /***/ },
  141. /***/ 112:
  142. /***/ function(module, exports) {
  143. // removed by extract-text-webpack-plugin
  144. /***/ },
  145. /***/ 136:
  146. /***/ function(module, exports, __webpack_require__) {
  147. function injectStyle (ssrContext) {
  148. __webpack_require__(112)
  149. }
  150. var Component = __webpack_require__(0)(
  151. /* script */
  152. __webpack_require__(58),
  153. /* template */
  154. __webpack_require__(182),
  155. /* styles */
  156. injectStyle,
  157. /* scopeId */
  158. null,
  159. /* moduleIdentifier (server only) */
  160. null
  161. )
  162. module.exports = Component.exports
  163. /***/ },
  164. /***/ 182:
  165. /***/ function(module, exports) {
  166. module.exports={render:function (){var _vm=this;var _h=_vm.$createElement;var _c=_vm._self._c||_h;
  167. return _c('mt-popup', {
  168. staticClass: "mint-datetime",
  169. attrs: {
  170. "closeOnClickModal": _vm.closeOnClickModal,
  171. "position": "bottom"
  172. },
  173. model: {
  174. value: (_vm.visible),
  175. callback: function($$v) {
  176. _vm.visible = $$v
  177. },
  178. expression: "visible"
  179. }
  180. }, [_c('mt-picker', {
  181. ref: "picker",
  182. staticClass: "mint-datetime-picker",
  183. attrs: {
  184. "slots": _vm.dateSlots,
  185. "visible-item-count": _vm.visibleItemCount,
  186. "show-toolbar": ""
  187. },
  188. on: {
  189. "change": _vm.onChange
  190. }
  191. }, [_c('span', {
  192. staticClass: "mint-datetime-action mint-datetime-cancel",
  193. on: {
  194. "click": function($event) {
  195. _vm.visible = false;
  196. _vm.$emit('cancel')
  197. }
  198. }
  199. }, [_vm._v(_vm._s(_vm.cancelText))]), _vm._v(" "), _c('span', {
  200. staticClass: "mint-datetime-action mint-datetime-confirm",
  201. on: {
  202. "click": _vm.confirm
  203. }
  204. }, [_vm._v(_vm._s(_vm.confirmText))])])], 1)
  205. },staticRenderFns: []}
  206. /***/ },
  207. /***/ 201:
  208. /***/ function(module, exports) {
  209. module.exports = require("mint-ui/lib/picker");
  210. /***/ },
  211. /***/ 202:
  212. /***/ function(module, exports) {
  213. module.exports = require("mint-ui/lib/picker/style.css");
  214. /***/ },
  215. /***/ 203:
  216. /***/ function(module, exports) {
  217. module.exports = require("mint-ui/lib/popup");
  218. /***/ },
  219. /***/ 204:
  220. /***/ function(module, exports) {
  221. module.exports = require("mint-ui/lib/popup/style.css");
  222. /***/ },
  223. /***/ 215:
  224. /***/ function(module, exports, __webpack_require__) {
  225. module.exports = __webpack_require__(24);
  226. /***/ },
  227. /***/ 24:
  228. /***/ function(module, exports, __webpack_require__) {
  229. "use strict";
  230. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__src_datetime_picker_vue__ = __webpack_require__(136);
  231. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0__src_datetime_picker_vue___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0__src_datetime_picker_vue__);
  232. Object.defineProperty(exports, "__esModule", { value: true });
  233. /* harmony reexport (default from non-hamory) */ __webpack_require__.d(exports, "default", function() { return __WEBPACK_IMPORTED_MODULE_0__src_datetime_picker_vue___default.a; });
  234. /***/ },
  235. /***/ 58:
  236. /***/ function(module, exports, __webpack_require__) {
  237. "use strict";
  238. Object.defineProperty(exports, "__esModule", { value: true });
  239. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_mint_ui_packages_picker_index_js__ = __webpack_require__(201);
  240. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_mint_ui_packages_picker_index_js___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_mint_ui_packages_picker_index_js__);
  241. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_mint_ui_packages_popup_index_js__ = __webpack_require__(203);
  242. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_1_mint_ui_packages_popup_index_js___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_1_mint_ui_packages_popup_index_js__);
  243. //
  244. //
  245. //
  246. //
  247. //
  248. //
  249. //
  250. //
  251. //
  252. //
  253. //
  254. //
  255. //
  256. //
  257. //
  258. //
  259. //
  260. //
  261. //
  262. //
  263. //
  264. //
  265. //
  266. //
  267. //
  268. //
  269. //
  270. //
  271. //
  272. //
  273. //
  274. //
  275. //
  276. //
  277. //
  278. //
  279. //
  280. //
  281. //
  282. //
  283. //
  284. //
  285. //
  286. //
  287. //
  288. //
  289. //
  290. //
  291. //
  292. //
  293. if (true) {
  294. __webpack_require__(202);
  295. __webpack_require__(204);
  296. }
  297. var FORMAT_MAP = {
  298. Y: 'year',
  299. M: 'month',
  300. D: 'date',
  301. H: 'hour',
  302. m: 'minute'
  303. };
  304. /* harmony default export */ exports["default"] = {
  305. name: 'mt-datetime-picker',
  306. props: {
  307. cancelText: {
  308. type: String,
  309. default: '取消'
  310. },
  311. confirmText: {
  312. type: String,
  313. default: '确定'
  314. },
  315. type: {
  316. type: String,
  317. default: 'datetime'
  318. },
  319. startDate: {
  320. type: Date,
  321. default: function default$1() {
  322. return new Date(new Date().getFullYear() - 10, 0, 1);
  323. }
  324. },
  325. endDate: {
  326. type: Date,
  327. default: function default$2() {
  328. return new Date(new Date().getFullYear() + 10, 11, 31);
  329. }
  330. },
  331. startHour: {
  332. type: Number,
  333. default: 0
  334. },
  335. endHour: {
  336. type: Number,
  337. default: 23
  338. },
  339. yearFormat: {
  340. type: String,
  341. default: '{value}'
  342. },
  343. monthFormat: {
  344. type: String,
  345. default: '{value}'
  346. },
  347. dateFormat: {
  348. type: String,
  349. default: '{value}'
  350. },
  351. hourFormat: {
  352. type: String,
  353. default: '{value}'
  354. },
  355. minuteFormat: {
  356. type: String,
  357. default: '{value}'
  358. },
  359. visibleItemCount: {
  360. type: Number,
  361. default: 7
  362. },
  363. closeOnClickModal: {
  364. type: Boolean,
  365. default: true
  366. },
  367. value: null
  368. },
  369. data: function data() {
  370. return {
  371. visible: false,
  372. startYear: null,
  373. endYear: null,
  374. startMonth: 1,
  375. endMonth: 12,
  376. startDay: 1,
  377. endDay: 31,
  378. currentValue: null,
  379. selfTriggered: false,
  380. dateSlots: [],
  381. shortMonthDates: [],
  382. longMonthDates: [],
  383. febDates: [],
  384. leapFebDates: []
  385. };
  386. },
  387. components: {
  388. 'mt-picker': __WEBPACK_IMPORTED_MODULE_0_mint_ui_packages_picker_index_js___default.a,
  389. 'mt-popup': __WEBPACK_IMPORTED_MODULE_1_mint_ui_packages_popup_index_js___default.a
  390. },
  391. methods: {
  392. open: function open() {
  393. this.visible = true;
  394. },
  395. close: function close() {
  396. this.visible = false;
  397. },
  398. isLeapYear: function isLeapYear(year) {
  399. return (year % 400 === 0) || (year % 100 !== 0 && year % 4 === 0);
  400. },
  401. isShortMonth: function isShortMonth(month) {
  402. return [4, 6, 9, 11].indexOf(month) > -1;
  403. },
  404. getMonthEndDay: function getMonthEndDay(year, month) {
  405. if (this.isShortMonth(month)) {
  406. return 30;
  407. } else if (month === 2) {
  408. return this.isLeapYear(year) ? 29 : 28;
  409. } else {
  410. return 31;
  411. }
  412. },
  413. getTrueValue: function getTrueValue(formattedValue) {
  414. if (!formattedValue) return;
  415. while (isNaN(parseInt(formattedValue, 10))) {
  416. formattedValue = formattedValue.slice(1);
  417. }
  418. return parseInt(formattedValue, 10);
  419. },
  420. getValue: function getValue(values) {
  421. var this$1 = this;
  422. var value;
  423. if (this.type === 'time') {
  424. value = values.map(function (value) { return ('0' + this$1.getTrueValue(value)).slice(-2); }).join(':');
  425. } else {
  426. var year = this.getTrueValue(values[0]);
  427. var month = this.getTrueValue(values[1]);
  428. var date = this.getTrueValue(values[2]);
  429. var maxDate = this.getMonthEndDay(year, month);
  430. if (date > maxDate) {
  431. this.selfTriggered = true;
  432. date = 1;
  433. }
  434. var hour = this.typeStr.indexOf('H') > -1 ? this.getTrueValue(values[this.typeStr.indexOf('H')]) : 0;
  435. var minute = this.typeStr.indexOf('m') > -1 ? this.getTrueValue(values[this.typeStr.indexOf('m')]) : 0;
  436. value = new Date(year, month - 1, date, hour, minute);
  437. }
  438. return value;
  439. },
  440. onChange: function onChange(picker) {
  441. var values = picker.$children.filter(function (child) { return child.currentValue !== undefined; }).map(function (child) { return child.currentValue; });
  442. if (this.selfTriggered) {
  443. this.selfTriggered = false;
  444. return;
  445. }
  446. if (values.length !== 0) {
  447. this.currentValue = this.getValue(values);
  448. this.handleValueChange();
  449. }
  450. },
  451. fillValues: function fillValues(type, start, end) {
  452. var this$1 = this;
  453. var values = [];
  454. for (var i = start; i <= end; i++) {
  455. if (i < 10) {
  456. values.push(this$1[((FORMAT_MAP[type]) + "Format")].replace('{value}', ('0' + i).slice(-2)));
  457. } else {
  458. values.push(this$1[((FORMAT_MAP[type]) + "Format")].replace('{value}', i));
  459. }
  460. }
  461. return values;
  462. },
  463. pushSlots: function pushSlots(slots, type, start, end) {
  464. slots.push({
  465. flex: 1,
  466. values: this.fillValues(type, start, end)
  467. });
  468. },
  469. generateSlots: function generateSlots() {
  470. var this$1 = this;
  471. var dateSlots = [];
  472. var INTERVAL_MAP = {
  473. Y: this.rims.year,
  474. M: this.rims.month,
  475. D: this.rims.date,
  476. H: this.rims.hour,
  477. m: this.rims.min
  478. };
  479. var typesArr = this.typeStr.split('');
  480. typesArr.forEach(function (type) {
  481. if (INTERVAL_MAP[type]) {
  482. this$1.pushSlots.apply(null, [dateSlots, type].concat(INTERVAL_MAP[type]));
  483. }
  484. });
  485. if (this.typeStr === 'Hm') {
  486. dateSlots.splice(1, 0, {
  487. divider: true,
  488. content: ':'
  489. });
  490. }
  491. this.dateSlots = dateSlots;
  492. this.handleExceededValue();
  493. },
  494. handleExceededValue: function handleExceededValue() {
  495. var this$1 = this;
  496. var values = [];
  497. if (this.type === 'time') {
  498. var currentValue = this.currentValue.split(':');
  499. values = [
  500. this.hourFormat.replace('{value}', currentValue[0]),
  501. this.minuteFormat.replace('{value}', currentValue[1])
  502. ];
  503. } else {
  504. values = [
  505. this.yearFormat.replace('{value}', this.getYear(this.currentValue)),
  506. this.monthFormat.replace('{value}', ('0' + this.getMonth(this.currentValue)).slice(-2)),
  507. this.dateFormat.replace('{value}', ('0' + this.getDate(this.currentValue)).slice(-2))
  508. ];
  509. if (this.type === 'datetime') {
  510. values.push(
  511. this.hourFormat.replace('{value}', ('0' + this.getHour(this.currentValue)).slice(-2)),
  512. this.minuteFormat.replace('{value}', ('0' + this.getMinute(this.currentValue)).slice(-2))
  513. );
  514. }
  515. }
  516. this.dateSlots.filter(function (child) { return child.values !== undefined; })
  517. .map(function (slot) { return slot.values; }).forEach(function (slotValues, index) {
  518. if (slotValues.indexOf(values[index]) === -1) {
  519. values[index] = slotValues[0];
  520. }
  521. });
  522. this.$nextTick(function () {
  523. this$1.setSlotsByValues(values);
  524. });
  525. },
  526. setSlotsByValues: function setSlotsByValues(values) {
  527. var setSlotValue = this.$refs.picker.setSlotValue;
  528. if (this.type === 'time') {
  529. setSlotValue(0, values[0]);
  530. setSlotValue(1, values[1]);
  531. }
  532. if (this.type !== 'time') {
  533. setSlotValue(0, values[0]);
  534. setSlotValue(1, values[1]);
  535. setSlotValue(2, values[2]);
  536. if (this.type === 'datetime') {
  537. setSlotValue(3, values[3]);
  538. setSlotValue(4, values[4]);
  539. }
  540. }
  541. [].forEach.call(this.$refs.picker.$children, function (child) { return child.doOnValueChange(); });
  542. },
  543. rimDetect: function rimDetect(result, rim) {
  544. var position = rim === 'start' ? 0 : 1;
  545. var rimDate = rim === 'start' ? this.startDate : this.endDate;
  546. if (this.getYear(this.currentValue) === rimDate.getFullYear()) {
  547. result.month[position] = rimDate.getMonth() + 1;
  548. if (this.getMonth(this.currentValue) === rimDate.getMonth() + 1) {
  549. result.date[position] = rimDate.getDate();
  550. if (this.getDate(this.currentValue) === rimDate.getDate()) {
  551. result.hour[position] = rimDate.getHours();
  552. if (this.getHour(this.currentValue) === rimDate.getHours()) {
  553. result.min[position] = rimDate.getMinutes();
  554. }
  555. }
  556. }
  557. }
  558. },
  559. isDateString: function isDateString(str) {
  560. return /\d{4}(\-|\/|.)\d{1,2}\1\d{1,2}/.test(str);
  561. },
  562. getYear: function getYear(value) {
  563. return this.isDateString(value) ? value.split(' ')[0].split(/-|\/|\./)[0] : value.getFullYear();
  564. },
  565. getMonth: function getMonth(value) {
  566. return this.isDateString(value) ? value.split(' ')[0].split(/-|\/|\./)[1] : value.getMonth() + 1;
  567. },
  568. getDate: function getDate(value) {
  569. return this.isDateString(value) ? value.split(' ')[0].split(/-|\/|\./)[2] : value.getDate();
  570. },
  571. getHour: function getHour(value) {
  572. if (this.isDateString(value)) {
  573. var str = value.split(' ')[1] || '00:00:00';
  574. return str.split(':')[0];
  575. }
  576. return value.getHours();
  577. },
  578. getMinute: function getMinute(value) {
  579. if (this.isDateString(value)) {
  580. var str = value.split(' ')[1] || '00:00:00';
  581. return str.split(':')[1];
  582. }
  583. return value.getMinutes();
  584. },
  585. confirm: function confirm() {
  586. this.visible = false;
  587. this.$emit('confirm', this.currentValue);
  588. },
  589. handleValueChange: function handleValueChange() {
  590. this.$emit('input', this.currentValue);
  591. }
  592. },
  593. computed: {
  594. rims: function rims() {
  595. if (!this.currentValue) return { year: [], month: [], date: [], hour: [], min: [] };
  596. var result;
  597. if (this.type === 'time') {
  598. result = {
  599. hour: [this.startHour, this.endHour],
  600. min: [0, 59]
  601. };
  602. return result;
  603. }
  604. result = {
  605. year: [this.startDate.getFullYear(), this.endDate.getFullYear()],
  606. month: [1, 12],
  607. date: [1, this.getMonthEndDay(this.getYear(this.currentValue), this.getMonth(this.currentValue))],
  608. hour: [0, 23],
  609. min: [0, 59]
  610. };
  611. this.rimDetect(result, 'start');
  612. this.rimDetect(result, 'end');
  613. return result;
  614. },
  615. typeStr: function typeStr() {
  616. if (this.type === 'time') {
  617. return 'Hm';
  618. } else if (this.type === 'date') {
  619. return 'YMD';
  620. } else {
  621. return 'YMDHm';
  622. }
  623. }
  624. },
  625. watch: {
  626. value: function value(val) {
  627. this.currentValue = val;
  628. },
  629. rims: function rims$1() {
  630. this.generateSlots();
  631. },
  632. visible: function visible(val) {
  633. this.$emit('visible-change', val);
  634. }
  635. },
  636. mounted: function mounted() {
  637. this.currentValue = this.value;
  638. if (!this.value) {
  639. if (this.type.indexOf('date') > -1) {
  640. this.currentValue = this.startDate;
  641. } else {
  642. this.currentValue = (('0' + this.startHour).slice(-2)) + ":00";
  643. }
  644. }
  645. this.generateSlots();
  646. }
  647. };
  648. /***/ }
  649. /******/ });