eoss 0.1.0-alpha.39 → 0.1.0-alpha.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/lib/0.js +1 -1
  2. package/lib/1.js +1 -1
  3. package/lib/10.js +1 -1
  4. package/lib/11.js +1 -1
  5. package/lib/12.js +1 -1
  6. package/lib/13.js +1 -1
  7. package/lib/14.js +1 -1
  8. package/lib/15.js +1 -1
  9. package/lib/16.js +1 -1
  10. package/lib/17.js +1 -1
  11. package/lib/18.js +1 -1
  12. package/lib/19.js +1 -1
  13. package/lib/20.js +1 -1
  14. package/lib/21.js +1 -1
  15. package/lib/22.js +1 -1
  16. package/lib/23.js +1 -1
  17. package/lib/24.js +1 -1
  18. package/lib/25.js +1 -1
  19. package/lib/26.js +1 -1
  20. package/lib/27.js +1 -1
  21. package/lib/28.js +1 -1
  22. package/lib/29.js +1 -1
  23. package/lib/3.js +1 -1
  24. package/lib/30.js +1 -1
  25. package/lib/31.js +1 -1
  26. package/lib/32.js +1 -1
  27. package/lib/33.js +1 -1
  28. package/lib/34.js +1 -1
  29. package/lib/35.js +1 -1
  30. package/lib/36.js +1 -1
  31. package/lib/37.js +1 -1
  32. package/lib/38.js +1 -1
  33. package/lib/39.js +1 -1
  34. package/lib/4.js +1 -1
  35. package/lib/40.js +1 -1
  36. package/lib/41.js +1 -1
  37. package/lib/42.js +1 -1
  38. package/lib/43.js +1 -1
  39. package/lib/44.js +1 -1
  40. package/lib/45.js +1 -1
  41. package/lib/46.js +1 -1
  42. package/lib/47.js +1 -1
  43. package/lib/48.js +1 -1
  44. package/lib/49.js +1 -1
  45. package/lib/5.js +1 -1
  46. package/lib/50.js +1 -1
  47. package/lib/51.js +1 -1
  48. package/lib/52.js +1 -1
  49. package/lib/53.js +1 -1
  50. package/lib/54.js +1 -1
  51. package/lib/55.js +1 -1
  52. package/lib/56.js +1 -1
  53. package/lib/57.js +1 -1
  54. package/lib/58.js +1 -1
  55. package/lib/59.js +1 -1
  56. package/lib/6.js +1 -1
  57. package/lib/60.js +1 -1
  58. package/lib/61.js +1 -1
  59. package/lib/62.js +1 -1
  60. package/lib/63.js +1 -1
  61. package/lib/64.js +1 -1
  62. package/lib/65.js +1 -1
  63. package/lib/66.js +1 -1
  64. package/lib/67.js +1 -1
  65. package/lib/68.js +1 -1
  66. package/lib/69.js +1 -1
  67. package/lib/7.js +1 -1
  68. package/lib/70.js +1 -1
  69. package/lib/71.js +1 -1
  70. package/lib/72.js +1 -1
  71. package/lib/73.js +1 -1
  72. package/lib/74.js +1 -1
  73. package/lib/75.js +1 -1
  74. package/lib/76.js +1 -1
  75. package/lib/77.js +1 -1
  76. package/lib/78.js +1 -1
  77. package/lib/79.js +1 -1
  78. package/lib/8.js +1 -1
  79. package/lib/80.js +1 -1
  80. package/lib/81.js +1 -1
  81. package/lib/9.js +1 -1
  82. package/lib/account-login.js +837 -862
  83. package/lib/alert.js +2 -2
  84. package/lib/aside.js +2 -2
  85. package/lib/audit-trajectory.js +4 -4
  86. package/lib/autocomplete.js +1813 -1988
  87. package/lib/avatar.js +2 -2
  88. package/lib/backtop.js +2 -2
  89. package/lib/badge.js +2 -2
  90. package/lib/breadcrumb-item.js +4 -4
  91. package/lib/breadcrumb.js +4 -4
  92. package/lib/button-group.js +4 -4
  93. package/lib/button.js +2 -2
  94. package/lib/ca-login.js +837 -862
  95. package/lib/calendar.js +839 -864
  96. package/lib/card.js +2 -2
  97. package/lib/carousel-item.js +846 -871
  98. package/lib/carousel.js +839 -864
  99. package/lib/cascader-panel.js +852 -877
  100. package/lib/cascader.js +2048 -2223
  101. package/lib/checkbox-button.js +4 -4
  102. package/lib/checkbox-group.js +859 -884
  103. package/lib/checkbox.js +4 -4
  104. package/lib/col.js +2 -2
  105. package/lib/collapse-item.js +1040 -1065
  106. package/lib/collapse.js +1040 -1065
  107. package/lib/color-picker.js +972 -1122
  108. package/lib/container.js +2 -2
  109. package/lib/cron.js +12 -12
  110. package/lib/data-table.js +843 -868
  111. package/lib/date-picker.js +10520 -10695
  112. package/lib/descriptions-item.js +4 -4
  113. package/lib/descriptions.js +4 -4
  114. package/lib/dialog.js +837 -862
  115. package/lib/divider.js +2 -2
  116. package/lib/drawer.js +2 -2
  117. package/lib/dropdown-item.js +4 -4
  118. package/lib/dropdown-menu.js +974 -1124
  119. package/lib/dropdown.js +841 -866
  120. package/lib/email-login.js +837 -862
  121. package/lib/empty.js +2 -2
  122. package/lib/eoss.common.js +4023 -2668
  123. package/lib/flip.js +2 -2
  124. package/lib/flow-group.js +853 -878
  125. package/lib/flow.js +868 -893
  126. package/lib/flows.js +854 -879
  127. package/lib/footer.js +2 -2
  128. package/lib/form-item.js +860 -885
  129. package/lib/form.js +933 -950
  130. package/lib/guide.js +2 -2
  131. package/lib/header.js +2 -2
  132. package/lib/icon.js +837 -862
  133. package/lib/icons.js +2 -2
  134. package/lib/image-viewer.js +837 -862
  135. package/lib/image.js +4 -4
  136. package/lib/index.js +1 -1
  137. package/lib/infinite-scroll.js +2 -2
  138. package/lib/input-number.js +6 -6
  139. package/lib/input.js +839 -864
  140. package/lib/link.js +2 -2
  141. package/lib/loading.js +2 -2
  142. package/lib/login.js +867 -891
  143. package/lib/lowcode-view.js +1843 -1185
  144. package/lib/lowcode.js +3050 -1569
  145. package/lib/main.js +970 -988
  146. package/lib/marquee.js +837 -862
  147. package/lib/menu-item-group.js +15 -15
  148. package/lib/menu-item.js +6 -6
  149. package/lib/menu.js +2227 -2368
  150. package/lib/message-box.js +843 -868
  151. package/lib/message.js +839 -864
  152. package/lib/notification.js +861 -886
  153. package/lib/option-group.js +4 -4
  154. package/lib/option.js +839 -864
  155. package/lib/page-header.js +2 -2
  156. package/lib/pagination.js +839 -864
  157. package/lib/phone-login.js +847 -866
  158. package/lib/popconfirm.js +4 -4
  159. package/lib/popover.js +1831 -2006
  160. package/lib/process-config.js +839 -864
  161. package/lib/process-module.js +846 -871
  162. package/lib/process-rule.js +905 -930
  163. package/lib/progress.js +2 -2
  164. package/lib/qr-code.js +4 -4
  165. package/lib/qrcode-login.js +839 -864
  166. package/lib/radio-button.js +4 -4
  167. package/lib/radio-group.js +850 -875
  168. package/lib/radio.js +4 -4
  169. package/lib/rate.js +837 -862
  170. package/lib/retrial-auth.js +837 -862
  171. package/lib/row.js +2 -2
  172. package/lib/scrollbar.js +839 -864
  173. package/lib/select.js +2139 -2314
  174. package/lib/selector-panel.js +940 -965
  175. package/lib/selector.js +852 -877
  176. package/lib/slider.js +4 -4
  177. package/lib/step.js +32 -32
  178. package/lib/steps.js +874 -899
  179. package/lib/submenu.js +1269 -1385
  180. package/lib/switch.js +839 -864
  181. package/lib/tab-pane.js +4 -4
  182. package/lib/table-column.js +840 -865
  183. package/lib/table.js +1825 -2000
  184. package/lib/tabs.js +846 -871
  185. package/lib/tag.js +2 -2
  186. package/lib/theme-chalk/fonts/iconfont.ttf +0 -0
  187. package/lib/theme-chalk/fonts/iconfont.woff +0 -0
  188. package/lib/theme-chalk/index.css +1 -1
  189. package/lib/theme-chalk/lowcode.css +1 -1
  190. package/lib/time-picker.js +6471 -6646
  191. package/lib/time-select.js +5039 -5214
  192. package/lib/timeline-item.js +2 -2
  193. package/lib/timeline.js +2 -2
  194. package/lib/tips.js +837 -862
  195. package/lib/toolbar.js +4 -4
  196. package/lib/tooltip.js +1813 -1988
  197. package/lib/transfer.js +837 -862
  198. package/lib/tree-group.js +853 -878
  199. package/lib/tree.js +1026 -1051
  200. package/lib/update-history.js +4 -4
  201. package/lib/upload.js +859 -884
  202. package/lib/wujie.js +841 -866
  203. package/package.json +1 -1
  204. package/packages/flow-group/src/main.vue +2 -2
  205. package/packages/form/src/form-item-render.vue +1 -0
  206. package/packages/form/src/form-item.vue +12 -6
  207. package/packages/form/src/form.vue +5 -5
  208. package/packages/login/src/login.vue +1 -0
  209. package/packages/lowcode/src/attribute/function.vue +28 -9
  210. package/packages/lowcode/src/attribute/props.vue +202 -0
  211. package/packages/lowcode/src/attribute/styles.vue +79 -5
  212. package/packages/lowcode/src/attribute.vue +61 -4
  213. package/packages/lowcode/src/canvas.vue +159 -2
  214. package/packages/lowcode/src/form-render.vue +305 -0
  215. package/packages/lowcode/src/lowcode.vue +33 -13
  216. package/packages/lowcode/src/modules.vue +53 -37
  217. package/packages/lowcode/src/render.vue +80 -25
  218. package/packages/lowcode/src/util/components.js +100 -0
  219. package/packages/lowcode/src/util/props-util.js +67 -0
  220. package/packages/lowcode/src/util/source-generator.js +69 -9
  221. package/packages/lowcode/src/util/source-parser.js +64 -10
  222. package/packages/lowcode-view/src/render.vue +48 -18
  223. package/packages/main/src/components/userinfo.vue +0 -1
  224. package/packages/menu/src/menu-item-group.vue +1 -1
  225. package/packages/menu/src/mixins.js +8 -4
  226. package/packages/menu/src/submenu.vue +35 -5
  227. package/packages/phone-login/src/phone-login.vue +5 -2
  228. package/packages/theme-chalk/dist/fonts/iconfont.ttf +0 -0
  229. package/packages/theme-chalk/dist/fonts/iconfont.woff +0 -0
  230. package/packages/theme-chalk/src/fonts/iconfont.ttf +0 -0
  231. package/packages/theme-chalk/src/fonts/iconfont.woff +0 -0
  232. package/packages/theme-chalk/src/lowcode.scss +21 -2
  233. package/src/index.js +336 -336
@@ -82,7 +82,7 @@ module.exports =
82
82
  /******/
83
83
  /******/
84
84
  /******/ // Load entry module and return exports
85
- /******/ return __webpack_require__(__webpack_require__.s = 195);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 202);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -4696,7 +4696,73 @@ module.exports = require("lodash/cloneDeep");
4696
4696
 
4697
4697
  /***/ }),
4698
4698
 
4699
- /***/ 195:
4699
+ /***/ 2:
4700
+ /***/ (function(module, exports) {
4701
+
4702
+ module.exports = require("vue");
4703
+
4704
+ /***/ }),
4705
+
4706
+ /***/ 20:
4707
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
4708
+
4709
+ "use strict";
4710
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return doEncrypt; });
4711
+ /* unused harmony export doDecrypt */
4712
+ /* harmony import */ var _storage__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
4713
+ var sm2 = __webpack_require__(42).sm2;
4714
+
4715
+
4716
+ /**
4717
+ * doEncrypt
4718
+ * @desc:sm2加密
4719
+ * @author huangbo
4720
+ * @date 2022年5月7日
4721
+ * @param {string} [data] - 被加密的字符串
4722
+ * @param {string} [key] - 公钥
4723
+ **/
4724
+ var doEncrypt = function doEncrypt(_ref) {
4725
+ var data = _ref.data,
4726
+ key = _ref.key,
4727
+ mode = _ref.mode;
4728
+
4729
+ if (!key) {
4730
+ key = Object(_storage__WEBPACK_IMPORTED_MODULE_0__[/* getStorage */ "a"])('secretKey');
4731
+ }
4732
+ if (!mode) {
4733
+ mode = 1;
4734
+ }
4735
+ if (!new RegExp('^04').test(key)) {
4736
+ key = '04' + key;
4737
+ }
4738
+ var result = sm2.doEncrypt(data, key, mode);
4739
+ return result;
4740
+ };
4741
+
4742
+ /**
4743
+ * doDecrypt
4744
+ * @desc:sm2解密
4745
+ * @author huangbo
4746
+ * @date 2022年5月7日
4747
+ * @param {string} [data] - 被解密的加密字符串
4748
+ * @param {string} [key] - 私钥
4749
+ **/
4750
+ var doDecrypt = function doDecrypt(_ref2) {
4751
+ var data = _ref2.data,
4752
+ key = _ref2.key,
4753
+ mode = _ref2.mode;
4754
+
4755
+ var cipherMode = mode ? mode : 1;
4756
+ if (new RegExp('^04').test(key)) {
4757
+ key = key.slice(2);
4758
+ }
4759
+ var result = sm2.doDecrypt(data, key, cipherMode);
4760
+ return result;
4761
+ };
4762
+
4763
+ /***/ }),
4764
+
4765
+ /***/ 202:
4700
4766
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
4701
4767
 
4702
4768
  "use strict";
@@ -5578,7 +5644,7 @@ companyReportDetailvue_type_template_id_0f5af266_render._withStripped = true
5578
5644
  // CONCATENATED MODULE: ./packages/process-rule/src/companyReportDetail.vue?vue&type=template&id=0f5af266&
5579
5645
 
5580
5646
  // EXTERNAL MODULE: external "eoss/lib/data-table"
5581
- var data_table_ = __webpack_require__(47);
5647
+ var data_table_ = __webpack_require__(48);
5582
5648
  var data_table_default = /*#__PURE__*/__webpack_require__.n(data_table_);
5583
5649
 
5584
5650
  // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/process-rule/src/companyReportDetail.vue?vue&type=script&lang=js&
@@ -6451,72 +6517,6 @@ main.install = function (Vue) {
6451
6517
 
6452
6518
  /***/ }),
6453
6519
 
6454
- /***/ 2:
6455
- /***/ (function(module, exports) {
6456
-
6457
- module.exports = require("vue");
6458
-
6459
- /***/ }),
6460
-
6461
- /***/ 20:
6462
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
6463
-
6464
- "use strict";
6465
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return doEncrypt; });
6466
- /* unused harmony export doDecrypt */
6467
- /* harmony import */ var _storage__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
6468
- var sm2 = __webpack_require__(42).sm2;
6469
-
6470
-
6471
- /**
6472
- * doEncrypt
6473
- * @desc:sm2加密
6474
- * @author huangbo
6475
- * @date 2022年5月7日
6476
- * @param {string} [data] - 被加密的字符串
6477
- * @param {string} [key] - 公钥
6478
- **/
6479
- var doEncrypt = function doEncrypt(_ref) {
6480
- var data = _ref.data,
6481
- key = _ref.key,
6482
- mode = _ref.mode;
6483
-
6484
- if (!key) {
6485
- key = Object(_storage__WEBPACK_IMPORTED_MODULE_0__[/* getStorage */ "a"])('secretKey');
6486
- }
6487
- if (!mode) {
6488
- mode = 1;
6489
- }
6490
- if (!new RegExp('^04').test(key)) {
6491
- key = '04' + key;
6492
- }
6493
- var result = sm2.doEncrypt(data, key, mode);
6494
- return result;
6495
- };
6496
-
6497
- /**
6498
- * doDecrypt
6499
- * @desc:sm2解密
6500
- * @author huangbo
6501
- * @date 2022年5月7日
6502
- * @param {string} [data] - 被解密的加密字符串
6503
- * @param {string} [key] - 私钥
6504
- **/
6505
- var doDecrypt = function doDecrypt(_ref2) {
6506
- var data = _ref2.data,
6507
- key = _ref2.key,
6508
- mode = _ref2.mode;
6509
-
6510
- var cipherMode = mode ? mode : 1;
6511
- if (new RegExp('^04').test(key)) {
6512
- key = key.slice(2);
6513
- }
6514
- var result = sm2.doDecrypt(data, key, cipherMode);
6515
- return result;
6516
- };
6517
-
6518
- /***/ }),
6519
-
6520
6520
  /***/ 21:
6521
6521
  /***/ (function(module, exports) {
6522
6522
 
@@ -6745,7 +6745,7 @@ module.exports = require("sm-crypto");
6745
6745
 
6746
6746
  /***/ }),
6747
6747
 
6748
- /***/ 47:
6748
+ /***/ 48:
6749
6749
  /***/ (function(module, exports) {
6750
6750
 
6751
6751
  module.exports = require("eoss/lib/data-table");
@@ -7375,759 +7375,736 @@ var changeInTime = '/baseIssueRules/changeInTime';
7375
7375
  /* unused harmony export getSecond */
7376
7376
  /* unused harmony export getWeekday */
7377
7377
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
7378
- /* Modified from https://github.com/taylorhakes/fecha
7379
- *
7380
- * The MIT License (MIT)
7381
- *
7382
- * Copyright (c) 2015 Taylor Hakes
7383
- *
7384
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7385
- * of this software and associated documentation files (the "Software"), to deal
7386
- * in the Software without restriction, including without limitation the rights
7387
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7388
- * copies of the Software, and to permit persons to whom the Software is
7389
- * furnished to do so, subject to the following conditions:
7390
- *
7391
- * The above copyright notice and this permission notice shall be included in all
7392
- * copies or substantial portions of the Software.
7393
- *
7394
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
7395
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7396
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
7397
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
7398
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
7399
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
7400
- * SOFTWARE.
7401
- */
7402
-
7403
- /*eslint-disable*/
7404
- // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
7405
-
7406
-
7378
+
7379
+
7407
7380
  /**
7408
7381
  * Parse or format dates
7409
7382
  * @class fecha
7410
- */
7411
- const fecha = {};
7412
- const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
7413
- const twoDigits = '\\d\\d?';
7414
- const threeDigits = '\\d{3}';
7415
- const fourDigits = '\\d{4}';
7416
- const word = '[^\\s]+';
7417
- const literal = /\[([^]*?)\]/gm;
7418
- const noop = function () {};
7419
-
7420
- function regexEscape(str) {
7421
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
7422
- }
7423
-
7424
- function shorten(arr, sLen) {
7425
- const newArr = [];
7426
- for (let i = 0, len = arr.length; i < len; i++) {
7427
- newArr.push(arr[i].substr(0, sLen));
7428
- }
7429
- return newArr;
7430
- }
7431
-
7432
- function monthUpdate() {
7433
- return function (d, v) {
7434
- const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
7435
- if (~index) {
7436
- d.month = index;
7437
- }
7438
- };
7439
- }
7440
-
7441
- function pad(val, len) {
7442
- val = String(val);
7443
- len = len || 2;
7444
- while (val.length < len) {
7445
- val = '0' + val;
7446
- }
7447
- return val;
7448
- }
7449
-
7450
- // 直接使用中文日期名称常量
7451
- const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
7452
- const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
7453
- const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
7454
- const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
7455
- const amPm = ['上午', '下午'];
7456
- const DoFn = function DoFn(D) {
7457
- return D + '日';
7458
- };
7459
-
7460
- const formatFlags = {
7461
- D: function(dateObj) {
7462
- return dateObj.getDay();
7463
- },
7464
- DD: function(dateObj) {
7465
- return pad(dateObj.getDay());
7466
- },
7467
- Do: function(dateObj) {
7468
- return DoFn(dateObj.getDate());
7469
- },
7470
- d: function(dateObj) {
7471
- return dateObj.getDate();
7472
- },
7473
- dd: function(dateObj) {
7474
- return pad(dateObj.getDate());
7475
- },
7476
- ddd: function(dateObj) {
7477
- return dayNamesShort[dateObj.getDay()];
7478
- },
7479
- dddd: function(dateObj) {
7480
- return dayNames[dateObj.getDay()];
7481
- },
7482
- M: function(dateObj) {
7483
- return dateObj.getMonth() + 1;
7484
- },
7485
- MM: function(dateObj) {
7486
- return pad(dateObj.getMonth() + 1);
7487
- },
7488
- MMM: function(dateObj) {
7489
- return monthNamesShort[dateObj.getMonth()];
7490
- },
7491
- MMMM: function(dateObj) {
7492
- return monthNames[dateObj.getMonth()];
7493
- },
7494
- yy: function(dateObj) {
7495
- return pad(String(dateObj.getFullYear()), 4).substr(2);
7496
- },
7497
- yyyy: function(dateObj) {
7498
- return pad(dateObj.getFullYear(), 4);
7499
- },
7500
- h: function(dateObj) {
7501
- return dateObj.getHours() % 12 || 12;
7502
- },
7503
- hh: function(dateObj) {
7504
- return pad(dateObj.getHours() % 12 || 12);
7505
- },
7506
- H: function(dateObj) {
7507
- return dateObj.getHours();
7508
- },
7509
- HH: function(dateObj) {
7510
- return pad(dateObj.getHours());
7511
- },
7512
- m: function(dateObj) {
7513
- return dateObj.getMinutes();
7514
- },
7515
- mm: function(dateObj) {
7516
- return pad(dateObj.getMinutes());
7517
- },
7518
- s: function(dateObj) {
7519
- return dateObj.getSeconds();
7520
- },
7521
- ss: function(dateObj) {
7522
- return pad(dateObj.getSeconds());
7523
- },
7524
- S: function(dateObj) {
7525
- return Math.round(dateObj.getMilliseconds() / 100);
7526
- },
7527
- SS: function(dateObj) {
7528
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
7529
- },
7530
- SSS: function(dateObj) {
7531
- return pad(dateObj.getMilliseconds(), 3);
7532
- },
7533
- a: function(dateObj) {
7534
- return dateObj.getHours() < 12 ? '上午' : '下午';
7535
- },
7536
- A: function(dateObj) {
7537
- return dateObj.getHours() < 12 ? '上午' : '下午';
7538
- },
7539
- ZZ: function(dateObj) {
7540
- const o = dateObj.getTimezoneOffset();
7541
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
7542
- }
7543
- };
7544
-
7545
- const parseFlags = {
7546
- d: [twoDigits, function (d, v) {
7547
- d.day = v;
7548
- }],
7549
- Do: [twoDigits + word, function (d, v) {
7550
- d.day = parseInt(v, 10);
7551
- }],
7552
- M: [twoDigits, function (d, v) {
7553
- d.month = v - 1;
7554
- }],
7555
- yy: [twoDigits, function (d, v) {
7556
- const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
7557
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
7558
- }],
7559
- h: [twoDigits, function (d, v) {
7560
- d.hour = v;
7561
- }],
7562
- m: [twoDigits, function (d, v) {
7563
- d.minute = v;
7564
- }],
7565
- s: [twoDigits, function (d, v) {
7566
- d.second = v;
7567
- }],
7568
- yyyy: [fourDigits, function (d, v) {
7569
- d.year = v;
7570
- }],
7571
- S: ['\\d', function (d, v) {
7572
- d.millisecond = v * 100;
7573
- }],
7574
- SS: ['\\d{2}', function (d, v) {
7575
- d.millisecond = v * 10;
7576
- }],
7577
- SSS: [threeDigits, function (d, v) {
7578
- d.millisecond = v;
7579
- }],
7580
- D: [twoDigits, noop],
7581
- ddd: [word, noop],
7582
- MMM: [word, monthUpdate('monthNamesShort')],
7583
- MMMM: [word, monthUpdate('monthNames')],
7584
- a: [word, function (d, v) {
7585
- const val = v.toLowerCase();
7586
- if (val === '上午') {
7587
- d.isPm = false;
7588
- } else if (val === '下午') {
7589
- d.isPm = true;
7590
- }
7591
- }],
7592
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
7593
- let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
7594
-
7595
- if (parts) {
7596
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
7597
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
7598
- }
7599
- }]
7600
- };
7601
- parseFlags.dd = parseFlags.d;
7602
- parseFlags.dddd = parseFlags.ddd;
7603
- parseFlags.DD = parseFlags.D;
7604
- parseFlags.mm = parseFlags.m;
7605
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
7606
- parseFlags.MM = parseFlags.M;
7607
- parseFlags.ss = parseFlags.s;
7608
- parseFlags.A = parseFlags.a;
7609
-
7610
-
7611
- // Some common format strings
7612
- fecha.masks = {
7613
- default: 'ddd MMM dd yyyy HH:mm:ss',
7614
- shortDate: 'M/D/yy',
7615
- mediumDate: 'MMM d, yyyy',
7616
- longDate: 'MMMM d, yyyy',
7617
- fullDate: 'dddd, MMMM d, yyyy',
7618
- shortTime: 'HH:mm',
7619
- mediumTime: 'HH:mm:ss',
7620
- longTime: 'HH:mm:ss.SSS'
7621
- };
7622
-
7383
+ */
7384
+ var fecha = {};
7385
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
7386
+ var twoDigits = '\\d\\d?';
7387
+ var threeDigits = '\\d{3}';
7388
+ var fourDigits = '\\d{4}';
7389
+ var word = '[^\\s]+';
7390
+ var literal = /\[([^]*?)\]/gm;
7391
+ var noop = function noop() {};
7392
+
7393
+ function regexEscape(str) {
7394
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
7395
+ }
7396
+
7397
+ function shorten(arr, sLen) {
7398
+ var newArr = [];
7399
+ for (var i = 0, len = arr.length; i < len; i++) {
7400
+ newArr.push(arr[i].substr(0, sLen));
7401
+ }
7402
+ return newArr;
7403
+ }
7404
+
7405
+ function monthUpdate() {
7406
+ return function (d, v) {
7407
+ var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
7408
+ if (~index) {
7409
+ d.month = index;
7410
+ }
7411
+ };
7412
+ }
7413
+
7414
+ function pad(val, len) {
7415
+ val = String(val);
7416
+ len = len || 2;
7417
+ while (val.length < len) {
7418
+ val = '0' + val;
7419
+ }
7420
+ return val;
7421
+ }
7422
+
7423
+ // 直接使用中文日期名称常量
7424
+ var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
7425
+ var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
7426
+ var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
7427
+ var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
7428
+ var amPm = ['上午', '下午'];
7429
+ var DoFn = function DoFn(D) {
7430
+ return D + '日';
7431
+ };
7432
+
7433
+ var formatFlags = {
7434
+ D: function D(dateObj) {
7435
+ return dateObj.getDay();
7436
+ },
7437
+ DD: function DD(dateObj) {
7438
+ return pad(dateObj.getDay());
7439
+ },
7440
+ Do: function Do(dateObj) {
7441
+ return DoFn(dateObj.getDate());
7442
+ },
7443
+ d: function d(dateObj) {
7444
+ return dateObj.getDate();
7445
+ },
7446
+ dd: function dd(dateObj) {
7447
+ return pad(dateObj.getDate());
7448
+ },
7449
+ ddd: function ddd(dateObj) {
7450
+ return dayNamesShort[dateObj.getDay()];
7451
+ },
7452
+ dddd: function dddd(dateObj) {
7453
+ return dayNames[dateObj.getDay()];
7454
+ },
7455
+ M: function M(dateObj) {
7456
+ return dateObj.getMonth() + 1;
7457
+ },
7458
+ MM: function MM(dateObj) {
7459
+ return pad(dateObj.getMonth() + 1);
7460
+ },
7461
+ MMM: function MMM(dateObj) {
7462
+ return monthNamesShort[dateObj.getMonth()];
7463
+ },
7464
+ MMMM: function MMMM(dateObj) {
7465
+ return monthNames[dateObj.getMonth()];
7466
+ },
7467
+ yy: function yy(dateObj) {
7468
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
7469
+ },
7470
+ yyyy: function yyyy(dateObj) {
7471
+ return pad(dateObj.getFullYear(), 4);
7472
+ },
7473
+ h: function h(dateObj) {
7474
+ return dateObj.getHours() % 12 || 12;
7475
+ },
7476
+ hh: function hh(dateObj) {
7477
+ return pad(dateObj.getHours() % 12 || 12);
7478
+ },
7479
+ H: function H(dateObj) {
7480
+ return dateObj.getHours();
7481
+ },
7482
+ HH: function HH(dateObj) {
7483
+ return pad(dateObj.getHours());
7484
+ },
7485
+ m: function m(dateObj) {
7486
+ return dateObj.getMinutes();
7487
+ },
7488
+ mm: function mm(dateObj) {
7489
+ return pad(dateObj.getMinutes());
7490
+ },
7491
+ s: function s(dateObj) {
7492
+ return dateObj.getSeconds();
7493
+ },
7494
+ ss: function ss(dateObj) {
7495
+ return pad(dateObj.getSeconds());
7496
+ },
7497
+ S: function S(dateObj) {
7498
+ return Math.round(dateObj.getMilliseconds() / 100);
7499
+ },
7500
+ SS: function SS(dateObj) {
7501
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
7502
+ },
7503
+ SSS: function SSS(dateObj) {
7504
+ return pad(dateObj.getMilliseconds(), 3);
7505
+ },
7506
+ a: function a(dateObj) {
7507
+ return dateObj.getHours() < 12 ? '上午' : '下午';
7508
+ },
7509
+ A: function A(dateObj) {
7510
+ return dateObj.getHours() < 12 ? '上午' : '下午';
7511
+ },
7512
+ ZZ: function ZZ(dateObj) {
7513
+ var o = dateObj.getTimezoneOffset();
7514
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
7515
+ }
7516
+ };
7517
+
7518
+ var parseFlags = {
7519
+ d: [twoDigits, function (d, v) {
7520
+ d.day = v;
7521
+ }],
7522
+ Do: [twoDigits + word, function (d, v) {
7523
+ d.day = parseInt(v, 10);
7524
+ }],
7525
+ M: [twoDigits, function (d, v) {
7526
+ d.month = v - 1;
7527
+ }],
7528
+ yy: [twoDigits, function (d, v) {
7529
+ var da = new Date(),
7530
+ cent = +('' + da.getFullYear()).substr(0, 2);
7531
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
7532
+ }],
7533
+ h: [twoDigits, function (d, v) {
7534
+ d.hour = v;
7535
+ }],
7536
+ m: [twoDigits, function (d, v) {
7537
+ d.minute = v;
7538
+ }],
7539
+ s: [twoDigits, function (d, v) {
7540
+ d.second = v;
7541
+ }],
7542
+ yyyy: [fourDigits, function (d, v) {
7543
+ d.year = v;
7544
+ }],
7545
+ S: ['\\d', function (d, v) {
7546
+ d.millisecond = v * 100;
7547
+ }],
7548
+ SS: ['\\d{2}', function (d, v) {
7549
+ d.millisecond = v * 10;
7550
+ }],
7551
+ SSS: [threeDigits, function (d, v) {
7552
+ d.millisecond = v;
7553
+ }],
7554
+ D: [twoDigits, noop],
7555
+ ddd: [word, noop],
7556
+ MMM: [word, monthUpdate('monthNamesShort')],
7557
+ MMMM: [word, monthUpdate('monthNames')],
7558
+ a: [word, function (d, v) {
7559
+ var val = v.toLowerCase();
7560
+ if (val === '上午') {
7561
+ d.isPm = false;
7562
+ } else if (val === '下午') {
7563
+ d.isPm = true;
7564
+ }
7565
+ }],
7566
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
7567
+ var parts = (v + '').match(/([+-]|\d\d)/gi),
7568
+ minutes = void 0;
7569
+
7570
+ if (parts) {
7571
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
7572
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
7573
+ }
7574
+ }]
7575
+ };
7576
+ parseFlags.dd = parseFlags.d;
7577
+ parseFlags.dddd = parseFlags.ddd;
7578
+ parseFlags.DD = parseFlags.D;
7579
+ parseFlags.mm = parseFlags.m;
7580
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
7581
+ parseFlags.MM = parseFlags.M;
7582
+ parseFlags.ss = parseFlags.s;
7583
+ parseFlags.A = parseFlags.a;
7584
+
7585
+ // Some common format strings
7586
+ fecha.masks = {
7587
+ default: 'ddd MMM dd yyyy HH:mm:ss',
7588
+ shortDate: 'M/D/yy',
7589
+ mediumDate: 'MMM d, yyyy',
7590
+ longDate: 'MMMM d, yyyy',
7591
+ fullDate: 'dddd, MMMM d, yyyy',
7592
+ shortTime: 'HH:mm',
7593
+ mediumTime: 'HH:mm:ss',
7594
+ longTime: 'HH:mm:ss.SSS'
7595
+ };
7596
+
7623
7597
  /***
7624
7598
  * Format a date
7625
7599
  * @method format
7626
7600
  * @param {Date|number} dateObj
7627
7601
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
7628
- */
7629
- fecha.format = function (dateObj, mask) {
7630
- if (typeof dateObj === 'number') {
7631
- dateObj = new Date(dateObj);
7632
- }
7633
-
7634
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
7635
- throw new Error('Invalid Date in fecha.format');
7636
- }
7637
-
7638
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
7639
-
7640
- const literals = [];
7641
-
7642
- // Make literals inactive by replacing them with ??
7643
- mask = mask.replace(literal, function($0, $1) {
7644
- literals.push($1);
7645
- return '@@@';
7646
- });
7647
- // Apply formatting rules
7648
- mask = mask.replace(token, function ($0) {
7649
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
7650
- });
7651
- // Inline literal values back into the formatted value
7652
- return mask.replace(/@@@/g, function() {
7653
- return literals.shift();
7654
- });
7655
- };
7656
-
7602
+ */
7603
+ fecha.format = function (dateObj, mask) {
7604
+ if (typeof dateObj === 'number') {
7605
+ dateObj = new Date(dateObj);
7606
+ }
7607
+
7608
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
7609
+ throw new Error('Invalid Date in fecha.format');
7610
+ }
7611
+
7612
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
7613
+
7614
+ var literals = [];
7615
+
7616
+ // Make literals inactive by replacing them with ??
7617
+ mask = mask.replace(literal, function ($0, $1) {
7618
+ literals.push($1);
7619
+ return '@@@';
7620
+ });
7621
+ // Apply formatting rules
7622
+ mask = mask.replace(token, function ($0) {
7623
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
7624
+ });
7625
+ // Inline literal values back into the formatted value
7626
+ return mask.replace(/@@@/g, function () {
7627
+ return literals.shift();
7628
+ });
7629
+ };
7630
+
7657
7631
  /**
7658
7632
  * Parse a date string into an object, changes - into /
7659
7633
  * @method parse
7660
7634
  * @param {string} dateStr Date string
7661
7635
  * @param {string} format Date parse format
7662
7636
  * @returns {Date|boolean}
7663
- */
7664
- fecha.parse = function (dateStr, format) {
7665
- if (typeof format !== 'string') {
7666
- throw new Error('Invalid format in fecha.parse');
7667
- }
7668
-
7669
- format = fecha.masks[format] || format;
7670
-
7671
- // Avoid regular expression denial of service, fail early for really long strings
7672
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
7673
- if (dateStr.length > 1000) {
7674
- return null;
7675
- }
7676
-
7677
- const dateInfo = {};
7678
- const parseInfo = [];
7679
- const literals = [];
7680
- format = format.replace(literal, function($0, $1) {
7681
- literals.push($1);
7682
- return '@@@';
7683
- });
7684
- let newFormat = regexEscape(format).replace(token, function ($0) {
7685
- if (parseFlags[$0]) {
7686
- const info = parseFlags[$0];
7687
- parseInfo.push(info[1]);
7688
- return '(' + info[0] + ')';
7689
- }
7690
-
7691
- return $0;
7692
- });
7693
- newFormat = newFormat.replace(/@@@/g, function() {
7694
- return literals.shift();
7695
- });
7696
- const matches = dateStr.match(new RegExp(newFormat, 'i'));
7697
- if (!matches) {
7698
- return null;
7699
- }
7700
-
7701
- for (let i = 1; i < matches.length; i++) {
7702
- parseInfo[i - 1](dateInfo, matches[i]);
7703
- }
7704
-
7705
- const today = new Date();
7706
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
7707
- dateInfo.hour = +dateInfo.hour + 12;
7708
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
7709
- dateInfo.hour = 0;
7710
- }
7711
-
7712
- let date;
7713
- if (dateInfo.timezoneOffset != null) {
7714
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
7715
- date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
7716
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
7717
- } else {
7718
- date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
7719
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
7720
- }
7721
- return date;
7722
- };
7723
-
7724
- // 导出fecha对象
7725
-
7726
-
7727
- // 以下是从date-util.js合并的函数
7728
- const newArray = function(start, end) {
7729
- let result = [];
7730
- for (let i = start; i <= end; i++) {
7731
- result.push(i);
7732
- }
7733
- return result;
7734
- };
7735
-
7736
- const getSettings = () => {
7737
- return {
7738
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
7739
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
7740
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
7741
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
7742
- amPm: ['上午', '下午']
7743
- };
7744
- };
7745
-
7746
- const toDate = function(date) {
7747
- return isDate(date) ? new Date(date) : null;
7748
- };
7749
-
7750
- const isDate = function(date) {
7751
- if (date === null || date === undefined) return false;
7752
- if (isNaN(new Date(date).getTime())) return false;
7753
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
7754
- return true;
7755
- };
7756
-
7757
- const isDateObject = function(val) {
7758
- return val instanceof Date;
7759
- };
7760
-
7761
- const formatDate = function (date, format = 'yyyy-MM-dd') {
7762
- // 处理多种输入类型
7763
- if (!date) return '';
7764
-
7765
- // 如果是时间戳,转成日期对象
7766
- if (typeof date === 'number') {
7767
- date = new Date(date);
7768
- }
7769
- // 如果是字符串,转成日期对象
7770
- if (typeof date === 'string') {
7771
- date = new Date(date);
7772
- }
7773
-
7774
- // 调用toDate进一步验证和转换
7775
- date = toDate(date);
7776
- if (!date) return '';
7777
-
7778
- // 兼容大写和小写的格式标记
7779
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
7780
- const lowercaseFormat = format
7781
- .replace(/YYYY/g, 'yyyy')
7782
- .replace(/D/g, 'd')
7783
-
7784
- // 使用fecha库进行格式化,支持中文配置
7785
- const str = fecha.format(date, lowercaseFormat, getSettings());
7786
- return str;
7787
- };
7788
-
7789
- const parseDate = function(string, format) {
7790
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
7791
- };
7792
-
7793
- const getDayCountOfMonth = function(year, month) {
7794
- if (month === 3 || month === 5 || month === 8 || month === 10) {
7795
- return 30;
7796
- }
7797
-
7798
- if (month === 1) {
7799
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
7800
- return 29;
7801
- } else {
7802
- return 28;
7803
- }
7804
- }
7805
-
7806
- return 31;
7807
- };
7808
-
7809
- const getDayCountOfYear = function(year) {
7810
- const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
7811
- return isLeapYear ? 366 : 365;
7812
- };
7813
-
7814
- const getFirstDayOfMonth = function(date) {
7815
- const temp = new Date(date.getTime());
7816
- temp.setDate(1);
7817
- return temp.getDay();
7818
- };
7819
-
7820
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
7821
- // {prev, next} Date should work for Daylight Saving Time
7822
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
7823
- const prevDate = function(date, amount = 1) {
7824
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
7825
- };
7826
-
7827
- const nextDate = function(date, amount = 1) {
7828
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
7829
- };
7830
-
7831
- const getStartDateOfMonth = function(year, month) {
7832
- const result = new Date(year, month, 1);
7833
- const day = result.getDay();
7834
-
7835
- if (day === 0) {
7836
- return prevDate(result, 7);
7837
- } else {
7838
- return prevDate(result, day);
7839
- }
7840
- };
7841
-
7842
- const getWeekNumber = function(date) {
7843
- // 支持多种输入类型
7844
- if (!date||!isDate(date)) {
7845
- date = new Date();
7846
- }
7847
- if (typeof date === 'string') {
7848
- date = new Date(date);
7849
- }
7850
-
7851
- // 验证日期有效性
7852
- if (!isDate(date)) return null;
7853
-
7854
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
7855
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
7856
- // 将星期日的星期数设为7
7857
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
7858
- // 获取当年的第一天
7859
- const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
7860
- // 计算到最近的星期四的完整周数
7861
- const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
7862
- // 返回周数
7863
- return weekNo;
7864
- };
7865
-
7866
- const getRangeHours = function(ranges) {
7867
- const hours = [];
7868
- let disabledHours = [];
7869
-
7870
- (ranges || []).forEach(range => {
7871
- const value = range.map(date => date.getHours());
7872
-
7873
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
7874
- });
7875
-
7876
- if (disabledHours.length) {
7877
- for (let i = 0; i < 24; i++) {
7878
- hours[i] = disabledHours.indexOf(i) === -1;
7879
- }
7880
- } else {
7881
- for (let i = 0; i < 24; i++) {
7882
- hours[i] = false;
7883
- }
7884
- }
7885
-
7886
- return hours;
7887
- };
7888
-
7889
- const getPrevMonthLastDays = (date, amount) => {
7890
- if (amount <= 0) return [];
7891
- const temp = new Date(date.getTime());
7892
- temp.setDate(0);
7893
- const lastDay = temp.getDate();
7894
- return range(amount).map((_, index) => lastDay - (amount - index - 1));
7895
- };
7896
-
7897
- const getMonthDays = (date) => {
7898
- const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
7899
- const days = temp.getDate();
7900
- return range(days).map((_, index) => index + 1);
7901
- };
7902
-
7903
- function setRangeData(arr, start, end, value) {
7904
- for (let i = start; i < end; i++) {
7905
- arr[i] = value;
7906
- }
7907
- }
7908
-
7909
- const getRangeMinutes = function(ranges, hour) {
7910
- const minutes = new Array(60);
7911
-
7912
- if (ranges.length > 0) {
7913
- ranges.forEach(range => {
7914
- const start = range[0];
7915
- const end = range[1];
7916
- const startHour = start.getHours();
7917
- const startMinute = start.getMinutes();
7918
- const endHour = end.getHours();
7919
- const endMinute = end.getMinutes();
7920
- if (startHour === hour && endHour !== hour) {
7921
- setRangeData(minutes, startMinute, 60, true);
7922
- } else if (startHour === hour && endHour === hour) {
7923
- setRangeData(minutes, startMinute, endMinute + 1, true);
7924
- } else if (startHour !== hour && endHour === hour) {
7925
- setRangeData(minutes, 0, endMinute + 1, true);
7926
- } else if (startHour < hour && endHour > hour) {
7927
- setRangeData(minutes, 0, 60, true);
7928
- }
7929
- });
7930
- } else {
7931
- setRangeData(minutes, 0, 60, true);
7932
- }
7933
- return minutes;
7934
- };
7935
-
7936
- const range = function(n) {
7937
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
7938
- return Array.apply(null, {length: n}).map((_, n) => n);
7939
- };
7940
-
7941
- const modifyDate = function(date, y, m, d) {
7942
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
7943
- };
7944
-
7945
- const modifyTime = function(date, h, m, s) {
7946
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
7947
- };
7948
-
7949
- const modifyWithTimeString = (date, time) => {
7950
- if (date == null || !time) {
7951
- return date;
7952
- }
7953
- time = parseDate(time, 'HH:mm:ss');
7954
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
7955
- };
7956
-
7957
- const clearTime = function(date) {
7958
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
7959
- };
7960
-
7961
- const clearMilliseconds = function(date) {
7962
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
7963
- };
7964
-
7965
- const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
7966
- // TODO: refactory a more elegant solution
7967
- if (ranges.length === 0) return date;
7968
- const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
7969
- const ndate = normalizeDate(date);
7970
- const nranges = ranges.map(range => range.map(normalizeDate));
7971
- if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
7972
-
7973
- let minDate = nranges[0][0];
7974
- let maxDate = nranges[0][0];
7975
-
7976
- nranges.forEach(nrange => {
7977
- minDate = new Date(Math.min(nrange[0], minDate));
7978
- maxDate = new Date(Math.max(nrange[1], minDate));
7979
- });
7980
-
7981
- const ret = ndate < minDate ? minDate : maxDate;
7982
- // preserve Year/Month/Date
7983
- return modifyDate(
7984
- ret,
7985
- date.getFullYear(),
7986
- date.getMonth(),
7987
- date.getDate()
7988
- );
7989
- };
7990
-
7991
- const timeWithinRange = function(date, selectableRange, format) {
7992
- const limitedDate = limitTimeRange(date, selectableRange, format);
7993
- return limitedDate.getTime() === date.getTime();
7994
- };
7995
-
7996
- const changeYearMonthAndClampDate = function(date, year, month) {
7997
- // clamp date to the number of days in `year`, `month`
7998
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
7999
- const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
8000
- return modifyDate(date, year, month, monthDate);
8001
- };
8002
-
8003
- const prevMonth = function(date) {
8004
- const year = date.getFullYear();
8005
- const month = date.getMonth();
8006
- return month === 0
8007
- ? changeYearMonthAndClampDate(date, year - 1, 11)
8008
- : changeYearMonthAndClampDate(date, year, month - 1);
8009
- };
8010
-
8011
- const nextMonth = function(date) {
8012
- const year = date.getFullYear();
8013
- const month = date.getMonth();
8014
- return month === 11
8015
- ? changeYearMonthAndClampDate(date, year + 1, 0)
8016
- : changeYearMonthAndClampDate(date, year, month + 1);
8017
- };
8018
-
8019
- const prevYear = function(date, amount = 1) {
8020
- const year = date.getFullYear();
8021
- const month = date.getMonth();
8022
- return changeYearMonthAndClampDate(date, year - amount, month);
8023
- };
8024
-
8025
- const nextYear = function(date, amount = 1) {
8026
- const year = date.getFullYear();
8027
- const month = date.getMonth();
8028
- return changeYearMonthAndClampDate(date, year + amount, month);
8029
- };
8030
-
8031
- const extractDateFormat = function(format) {
8032
- return format
8033
- .replace(/\W?m{1,2}|\W?ZZ/g, '')
8034
- .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
8035
- .trim();
8036
- };
8037
-
8038
- const extractTimeFormat = function(format) {
8039
- return format
8040
- .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
8041
- .trim();
8042
- };
8043
-
8044
- const validateRangeInOneMonth = function(start, end) {
8045
- return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
8046
- };
8047
-
7637
+ */
7638
+ fecha.parse = function (dateStr, format) {
7639
+ if (typeof format !== 'string') {
7640
+ throw new Error('Invalid format in fecha.parse');
7641
+ }
7642
+
7643
+ format = fecha.masks[format] || format;
7644
+
7645
+ // Avoid regular expression denial of service, fail early for really long strings
7646
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
7647
+ if (dateStr.length > 1000) {
7648
+ return null;
7649
+ }
7650
+
7651
+ var dateInfo = {};
7652
+ var parseInfo = [];
7653
+ var literals = [];
7654
+ format = format.replace(literal, function ($0, $1) {
7655
+ literals.push($1);
7656
+ return '@@@';
7657
+ });
7658
+ var newFormat = regexEscape(format).replace(token, function ($0) {
7659
+ if (parseFlags[$0]) {
7660
+ var info = parseFlags[$0];
7661
+ parseInfo.push(info[1]);
7662
+ return '(' + info[0] + ')';
7663
+ }
7664
+
7665
+ return $0;
7666
+ });
7667
+ newFormat = newFormat.replace(/@@@/g, function () {
7668
+ return literals.shift();
7669
+ });
7670
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
7671
+ if (!matches) {
7672
+ return null;
7673
+ }
7674
+
7675
+ for (var i = 1; i < matches.length; i++) {
7676
+ parseInfo[i - 1](dateInfo, matches[i]);
7677
+ }
7678
+
7679
+ var today = new Date();
7680
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
7681
+ dateInfo.hour = +dateInfo.hour + 12;
7682
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
7683
+ dateInfo.hour = 0;
7684
+ }
7685
+
7686
+ var date = void 0;
7687
+ if (dateInfo.timezoneOffset != null) {
7688
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
7689
+ 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));
7690
+ } else {
7691
+ 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);
7692
+ }
7693
+ return date;
7694
+ };
7695
+
7696
+ // 导出fecha对象
7697
+
7698
+
7699
+ // 以下是从date-util.js合并的函数
7700
+ var newArray = function newArray(start, end) {
7701
+ var result = [];
7702
+ for (var i = start; i <= end; i++) {
7703
+ result.push(i);
7704
+ }
7705
+ return result;
7706
+ };
7707
+
7708
+ var getSettings = function getSettings() {
7709
+ return {
7710
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
7711
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
7712
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
7713
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
7714
+ amPm: ['上午', '下午']
7715
+ };
7716
+ };
7717
+
7718
+ var toDate = function toDate(date) {
7719
+ return isDate(date) ? new Date(date) : null;
7720
+ };
7721
+
7722
+ var isDate = function isDate(date) {
7723
+ if (date === null || date === undefined) return false;
7724
+ if (isNaN(new Date(date).getTime())) return false;
7725
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
7726
+ return true;
7727
+ };
7728
+
7729
+ var isDateObject = function isDateObject(val) {
7730
+ return val instanceof Date;
7731
+ };
7732
+
7733
+ var formatDate = function formatDate(date) {
7734
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
7735
+
7736
+ // 处理多种输入类型
7737
+ if (!date) return '';
7738
+
7739
+ // 如果是时间戳,转成日期对象
7740
+ if (typeof date === 'number') {
7741
+ date = new Date(date);
7742
+ }
7743
+ // 如果是字符串,转成日期对象
7744
+ if (typeof date === 'string') {
7745
+ date = new Date(date);
7746
+ }
7747
+
7748
+ // 调用toDate进一步验证和转换
7749
+ date = toDate(date);
7750
+ if (!date) return '';
7751
+
7752
+ // 兼容大写和小写的格式标记
7753
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
7754
+ var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
7755
+
7756
+ // 使用fecha库进行格式化,支持中文配置
7757
+ var str = fecha.format(date, lowercaseFormat, getSettings());
7758
+ return str;
7759
+ };
7760
+
7761
+ var parseDate = function parseDate(string, format) {
7762
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
7763
+ };
7764
+
7765
+ var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
7766
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
7767
+ return 30;
7768
+ }
7769
+
7770
+ if (month === 1) {
7771
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
7772
+ return 29;
7773
+ } else {
7774
+ return 28;
7775
+ }
7776
+ }
7777
+
7778
+ return 31;
7779
+ };
7780
+
7781
+ var getDayCountOfYear = function getDayCountOfYear(year) {
7782
+ var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
7783
+ return isLeapYear ? 366 : 365;
7784
+ };
7785
+
7786
+ var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
7787
+ var temp = new Date(date.getTime());
7788
+ temp.setDate(1);
7789
+ return temp.getDay();
7790
+ };
7791
+
7792
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
7793
+ // {prev, next} Date should work for Daylight Saving Time
7794
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
7795
+ var prevDate = function prevDate(date) {
7796
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
7797
+
7798
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
7799
+ };
7800
+
7801
+ var nextDate = function nextDate(date) {
7802
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
7803
+
7804
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
7805
+ };
7806
+
7807
+ var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
7808
+ var result = new Date(year, month, 1);
7809
+ var day = result.getDay();
7810
+
7811
+ if (day === 0) {
7812
+ return prevDate(result, 7);
7813
+ } else {
7814
+ return prevDate(result, day);
7815
+ }
7816
+ };
7817
+
7818
+ var getWeekNumber = function getWeekNumber(date) {
7819
+ // 支持多种输入类型
7820
+ if (!date || !isDate(date)) {
7821
+ date = new Date();
7822
+ }
7823
+ if (typeof date === 'string') {
7824
+ date = new Date(date);
7825
+ }
7826
+
7827
+ // 验证日期有效性
7828
+ if (!isDate(date)) return null;
7829
+
7830
+ var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
7831
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
7832
+ // 将星期日的星期数设为7
7833
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
7834
+ // 获取当年的第一天
7835
+ var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
7836
+ // 计算到最近的星期四的完整周数
7837
+ var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
7838
+ // 返回周数
7839
+ return weekNo;
7840
+ };
7841
+
7842
+ var getRangeHours = function getRangeHours(ranges) {
7843
+ var hours = [];
7844
+ var disabledHours = [];
7845
+
7846
+ (ranges || []).forEach(function (range) {
7847
+ var value = range.map(function (date) {
7848
+ return date.getHours();
7849
+ });
7850
+
7851
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
7852
+ });
7853
+
7854
+ if (disabledHours.length) {
7855
+ for (var i = 0; i < 24; i++) {
7856
+ hours[i] = disabledHours.indexOf(i) === -1;
7857
+ }
7858
+ } else {
7859
+ for (var _i = 0; _i < 24; _i++) {
7860
+ hours[_i] = false;
7861
+ }
7862
+ }
7863
+
7864
+ return hours;
7865
+ };
7866
+
7867
+ var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
7868
+ if (amount <= 0) return [];
7869
+ var temp = new Date(date.getTime());
7870
+ temp.setDate(0);
7871
+ var lastDay = temp.getDate();
7872
+ return range(amount).map(function (_, index) {
7873
+ return lastDay - (amount - index - 1);
7874
+ });
7875
+ };
7876
+
7877
+ var getMonthDays = function getMonthDays(date) {
7878
+ var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
7879
+ var days = temp.getDate();
7880
+ return range(days).map(function (_, index) {
7881
+ return index + 1;
7882
+ });
7883
+ };
7884
+
7885
+ function setRangeData(arr, start, end, value) {
7886
+ for (var i = start; i < end; i++) {
7887
+ arr[i] = value;
7888
+ }
7889
+ }
7890
+
7891
+ var getRangeMinutes = function getRangeMinutes(ranges, hour) {
7892
+ var minutes = new Array(60);
7893
+
7894
+ if (ranges.length > 0) {
7895
+ ranges.forEach(function (range) {
7896
+ var start = range[0];
7897
+ var end = range[1];
7898
+ var startHour = start.getHours();
7899
+ var startMinute = start.getMinutes();
7900
+ var endHour = end.getHours();
7901
+ var endMinute = end.getMinutes();
7902
+ if (startHour === hour && endHour !== hour) {
7903
+ setRangeData(minutes, startMinute, 60, true);
7904
+ } else if (startHour === hour && endHour === hour) {
7905
+ setRangeData(minutes, startMinute, endMinute + 1, true);
7906
+ } else if (startHour !== hour && endHour === hour) {
7907
+ setRangeData(minutes, 0, endMinute + 1, true);
7908
+ } else if (startHour < hour && endHour > hour) {
7909
+ setRangeData(minutes, 0, 60, true);
7910
+ }
7911
+ });
7912
+ } else {
7913
+ setRangeData(minutes, 0, 60, true);
7914
+ }
7915
+ return minutes;
7916
+ };
7917
+
7918
+ var range = function range(n) {
7919
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
7920
+ return Array.apply(null, { length: n }).map(function (_, n) {
7921
+ return n;
7922
+ });
7923
+ };
7924
+
7925
+ var modifyDate = function modifyDate(date, y, m, d) {
7926
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
7927
+ };
7928
+
7929
+ var modifyTime = function modifyTime(date, h, m, s) {
7930
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
7931
+ };
7932
+
7933
+ var modifyWithTimeString = function modifyWithTimeString(date, time) {
7934
+ if (date == null || !time) {
7935
+ return date;
7936
+ }
7937
+ time = parseDate(time, 'HH:mm:ss');
7938
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
7939
+ };
7940
+
7941
+ var clearTime = function clearTime(date) {
7942
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
7943
+ };
7944
+
7945
+ var clearMilliseconds = function clearMilliseconds(date) {
7946
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
7947
+ };
7948
+
7949
+ var limitTimeRange = function limitTimeRange(date, ranges) {
7950
+ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
7951
+
7952
+ // TODO: refactory a more elegant solution
7953
+ if (ranges.length === 0) return date;
7954
+ var normalizeDate = function normalizeDate(date) {
7955
+ return fecha.parse(fecha.format(date, format), format);
7956
+ };
7957
+ var ndate = normalizeDate(date);
7958
+ var nranges = ranges.map(function (range) {
7959
+ return range.map(normalizeDate);
7960
+ });
7961
+ if (nranges.some(function (nrange) {
7962
+ return ndate >= nrange[0] && ndate <= nrange[1];
7963
+ })) return date;
7964
+
7965
+ var minDate = nranges[0][0];
7966
+ var maxDate = nranges[0][0];
7967
+
7968
+ nranges.forEach(function (nrange) {
7969
+ minDate = new Date(Math.min(nrange[0], minDate));
7970
+ maxDate = new Date(Math.max(nrange[1], minDate));
7971
+ });
7972
+
7973
+ var ret = ndate < minDate ? minDate : maxDate;
7974
+ // preserve Year/Month/Date
7975
+ return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
7976
+ };
7977
+
7978
+ var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
7979
+ var limitedDate = limitTimeRange(date, selectableRange, format);
7980
+ return limitedDate.getTime() === date.getTime();
7981
+ };
7982
+
7983
+ var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
7984
+ // clamp date to the number of days in `year`, `month`
7985
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
7986
+ var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
7987
+ return modifyDate(date, year, month, monthDate);
7988
+ };
7989
+
7990
+ var prevMonth = function prevMonth(date) {
7991
+ var year = date.getFullYear();
7992
+ var month = date.getMonth();
7993
+ return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
7994
+ };
7995
+
7996
+ var nextMonth = function nextMonth(date) {
7997
+ var year = date.getFullYear();
7998
+ var month = date.getMonth();
7999
+ return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
8000
+ };
8001
+
8002
+ var prevYear = function prevYear(date) {
8003
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
8004
+
8005
+ var year = date.getFullYear();
8006
+ var month = date.getMonth();
8007
+ return changeYearMonthAndClampDate(date, year - amount, month);
8008
+ };
8009
+
8010
+ var nextYear = function nextYear(date) {
8011
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
8012
+
8013
+ var year = date.getFullYear();
8014
+ var month = date.getMonth();
8015
+ return changeYearMonthAndClampDate(date, year + amount, month);
8016
+ };
8017
+
8018
+ var extractDateFormat = function extractDateFormat(format) {
8019
+ return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
8020
+ };
8021
+
8022
+ var extractTimeFormat = function extractTimeFormat(format) {
8023
+ return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
8024
+ };
8025
+
8026
+ var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
8027
+ return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
8028
+ };
8029
+
8048
8030
  /**
8049
8031
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
8050
8032
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
8051
8033
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
8052
8034
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
8053
8035
  * @returns {number} 工作日数量
8054
- */
8055
- const calculateNetworkDays = function (start_date, end_date, holidays = []) {
8056
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
8057
- throw new Error(
8058
- "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
8059
- );
8060
- }
8061
-
8062
- const startDateObj = new Date(start_date);
8063
- const endDateObj = new Date(end_date);
8064
-
8065
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
8066
- throw new Error(
8067
- "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
8068
- );
8069
- }
8070
-
8071
- if (startDateObj > endDateObj) {
8072
- throw new Error('Start date should be earlier than or equal to end date.');
8073
- }
8074
-
8075
- let workdays = 0;
8076
-
8077
- // Iterate through each day in the date range
8078
- for (
8079
- let currentDate = new Date(startDateObj);
8080
- currentDate <= endDateObj;
8081
- currentDate.setDate(currentDate.getDate() + 1)
8082
- ) {
8083
- // Check if the current day is a weekend (Saturday or Sunday)
8084
- const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
8085
-
8086
- // Check if the current day is a holiday
8087
- const isHoliday = holidays.some((holiday) => {
8088
- const holidayDate = new Date(holiday);
8089
- return currentDate.toDateString() === holidayDate.toDateString();
8090
- });
8091
-
8092
- // If it's a workday (not a weekend or holiday), increment the workdays count
8093
- if (!isWeekend && !isHoliday) {
8094
- workdays++;
8095
- }
8096
- }
8097
-
8098
- return workdays;
8099
- };
8100
-
8036
+ */
8037
+ var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
8038
+ var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
8039
+
8040
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
8041
+ throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
8042
+ }
8043
+
8044
+ var startDateObj = new Date(start_date);
8045
+ var endDateObj = new Date(end_date);
8046
+
8047
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
8048
+ throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
8049
+ }
8050
+
8051
+ if (startDateObj > endDateObj) {
8052
+ throw new Error('Start date should be earlier than or equal to end date.');
8053
+ }
8054
+
8055
+ var workdays = 0;
8056
+
8057
+ // Iterate through each day in the date range
8058
+
8059
+ var _loop = function _loop(currentDate) {
8060
+ // Check if the current day is a weekend (Saturday or Sunday)
8061
+ var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
8062
+
8063
+ // Check if the current day is a holiday
8064
+ var isHoliday = holidays.some(function (holiday) {
8065
+ var holidayDate = new Date(holiday);
8066
+ return currentDate.toDateString() === holidayDate.toDateString();
8067
+ });
8068
+
8069
+ // If it's a workday (not a weekend or holiday), increment the workdays count
8070
+ if (!isWeekend && !isHoliday) {
8071
+ workdays++;
8072
+ }
8073
+ };
8074
+
8075
+ for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
8076
+ _loop(currentDate);
8077
+ }
8078
+
8079
+ return workdays;
8080
+ };
8081
+
8101
8082
  /**
8102
8083
  * 日期加减天数
8103
8084
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
8104
8085
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
8105
8086
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
8106
- */
8107
- const dateAddDays = function (start_date, days) {
8108
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
8109
- throw new Error(
8110
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
8111
- );
8112
- }
8113
-
8114
- const startDateObj = new Date(start_date);
8115
- if (isNaN(startDateObj.getTime())) {
8116
- throw new Error(
8117
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
8118
- );
8119
- }
8120
-
8121
- const resultDateObj = new Date(startDateObj);
8122
- resultDateObj.setDate(resultDateObj.getDate() + days);
8123
-
8124
- const resultYear = resultDateObj.getFullYear();
8125
- const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
8126
- const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
8127
-
8128
- return `${resultYear}-${resultMonth}-${resultDay}`;
8129
- };
8130
-
8087
+ */
8088
+ var dateAddDays = function dateAddDays(start_date, days) {
8089
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
8090
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days.");
8091
+ }
8092
+
8093
+ var startDateObj = new Date(start_date);
8094
+ if (isNaN(startDateObj.getTime())) {
8095
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
8096
+ }
8097
+
8098
+ var resultDateObj = new Date(startDateObj);
8099
+ resultDateObj.setDate(resultDateObj.getDate() + days);
8100
+
8101
+ var resultYear = resultDateObj.getFullYear();
8102
+ var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
8103
+ var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
8104
+
8105
+ return resultYear + '-' + resultMonth + '-' + resultDay;
8106
+ };
8107
+
8131
8108
  /**
8132
8109
  * 计算两个日期之间的差值
8133
8110
  * @date 2023年12月14日
@@ -8135,182 +8112,180 @@ const dateAddDays = function (start_date, days) {
8135
8112
  * @param {String} end_date - 结束日期字符串
8136
8113
  * @param {String} unit - 单位:year/month/day
8137
8114
  * @returns {Number} 差值
8138
- */
8139
- const dateDiff = function (start_date, end_date, unit = 'day') {
8140
- // Assuming date strings are in "YYYY-MM-DD" format
8141
- var startDate = new Date(start_date);
8142
- var endDate = new Date(end_date);
8143
-
8144
- // If the date is invalid, return 0
8145
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
8146
- return 0;
8147
- }
8148
-
8149
- if (unit === 'year') {
8150
- return endDate.getFullYear() - startDate.getFullYear();
8151
- } else if (unit === 'month') {
8152
- return (
8153
- (endDate.getFullYear() - startDate.getFullYear()) * 12 +
8154
- (endDate.getMonth() - startDate.getMonth())
8155
- );
8156
- } else {
8157
- // Default to day
8158
- var timeDifference = endDate - startDate;
8159
- // Calculate days (86400000 milliseconds per day)
8160
- return Math.floor(timeDifference / 86400000);
8161
- }
8162
- };
8163
-
8115
+ */
8116
+ var dateDiff = function dateDiff(start_date, end_date) {
8117
+ var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
8118
+
8119
+ // Assuming date strings are in "YYYY-MM-DD" format
8120
+ var startDate = new Date(start_date);
8121
+ var endDate = new Date(end_date);
8122
+
8123
+ // If the date is invalid, return 0
8124
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
8125
+ return 0;
8126
+ }
8127
+
8128
+ if (unit === 'year') {
8129
+ return endDate.getFullYear() - startDate.getFullYear();
8130
+ } else if (unit === 'month') {
8131
+ return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
8132
+ } else {
8133
+ // Default to day
8134
+ var timeDifference = endDate - startDate;
8135
+ // Calculate days (86400000 milliseconds per day)
8136
+ return Math.floor(timeDifference / 86400000);
8137
+ }
8138
+ };
8139
+
8164
8140
  /**
8165
8141
  * 获取月份中的日期
8166
8142
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
8167
8143
  * @returns {number} 月份中的日期(1-31)
8168
- */
8169
- const dayOfMonth = function (date) {
8170
- if (typeof date !== 'string') {
8171
- throw new Error(
8172
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
8173
- );
8174
- }
8175
-
8176
- const dateObj = new Date(date);
8177
- if (isNaN(dateObj.getTime())) {
8178
- throw new Error(
8179
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
8180
- );
8181
- }
8182
-
8183
- return dateObj.getDate();
8184
- };
8185
-
8144
+ */
8145
+ var dayOfMonth = function dayOfMonth(date) {
8146
+ if (typeof date !== 'string') {
8147
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
8148
+ }
8149
+
8150
+ var dateObj = new Date(date);
8151
+ if (isNaN(dateObj.getTime())) {
8152
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
8153
+ }
8154
+
8155
+ return dateObj.getDate();
8156
+ };
8157
+
8186
8158
  /**
8187
8159
  * 获取当前日期
8188
8160
  * @date 2022年5月7日
8189
8161
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
8190
8162
  * @returns {string} 当前日期的格式化字符串
8191
- */
8192
- const getCurrentDate = function (format = 'YYYY-MM-DD') {
8193
- return formatDate(new Date(), format);
8194
- };
8195
-
8163
+ */
8164
+ var getCurrentDate = function getCurrentDate() {
8165
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
8166
+
8167
+ return formatDate(new Date(), format);
8168
+ };
8169
+
8196
8170
  /**
8197
8171
  * 获取当前日期时间
8198
8172
  * @date 2022年5月7日
8199
8173
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
8200
8174
  * @returns {string} 当前日期时间的格式化字符串
8201
- */
8202
- const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
8203
- return formatDate(new Date(), format);
8204
- };
8205
-
8175
+ */
8176
+ var getCurrentDateTime = function getCurrentDateTime() {
8177
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
8178
+
8179
+ return formatDate(new Date(), format);
8180
+ };
8181
+
8206
8182
  /**
8207
8183
  * 获取小时
8208
8184
  * @date 2022年5月7日
8209
8185
  * @param {Date|string} [date] - 日期对象或日期字符串
8210
8186
  * @returns {number} 小时数(0-23)
8211
- */
8212
- const getHour = function (date) {
8213
- if (!date) {
8214
- return new Date().getHours();
8215
- }
8216
- if (typeof date === 'string') {
8217
- date = new Date(date);
8218
- }
8219
- return date.getHours();
8220
- };
8221
-
8187
+ */
8188
+ var getHour = function getHour(date) {
8189
+ if (!date) {
8190
+ return new Date().getHours();
8191
+ }
8192
+ if (typeof date === 'string') {
8193
+ date = new Date(date);
8194
+ }
8195
+ return date.getHours();
8196
+ };
8197
+
8222
8198
  /**
8223
8199
  * 获取分钟
8224
8200
  * @date 2022年5月7日
8225
8201
  * @param {Date|string} [date] - 日期对象或日期字符串
8226
8202
  * @returns {number} 分钟数(0-59)
8227
- */
8228
- const getMinute = function (date) {
8229
- if (!date) {
8230
- return new Date().getMinutes();
8231
- }
8232
- if (typeof date === 'string') {
8233
- date = new Date(date);
8234
- }
8235
- return date.getMinutes();
8236
- };
8237
-
8203
+ */
8204
+ var getMinute = function getMinute(date) {
8205
+ if (!date) {
8206
+ return new Date().getMinutes();
8207
+ }
8208
+ if (typeof date === 'string') {
8209
+ date = new Date(date);
8210
+ }
8211
+ return date.getMinutes();
8212
+ };
8213
+
8238
8214
  /**
8239
8215
  * 获取月份
8240
8216
  * @date 2022年5月7日
8241
8217
  * @param {Date|string} [date] - 日期对象或日期字符串
8242
8218
  * @returns {number} 月份数(1-12)
8243
- */
8244
- const getMonth = function (date) {
8245
- if (!date) {
8246
- return new Date().getMonth() + 1;
8247
- }
8248
- if (typeof date === 'string') {
8249
- date = new Date(date);
8250
- }
8251
- return date.getMonth() + 1;
8252
- };
8253
-
8219
+ */
8220
+ var getMonth = function getMonth(date) {
8221
+ if (!date) {
8222
+ return new Date().getMonth() + 1;
8223
+ }
8224
+ if (typeof date === 'string') {
8225
+ date = new Date(date);
8226
+ }
8227
+ return date.getMonth() + 1;
8228
+ };
8229
+
8254
8230
  /**
8255
8231
  * 获取秒
8256
8232
  * @date 2022年5月7日
8257
8233
  * @param {Date|string} [date] - 日期对象或日期字符串
8258
8234
  * @returns {number} 秒数(0-59)
8259
- */
8260
- const getSecond = function (date) {
8261
- if (!date) {
8262
- return new Date().getSeconds();
8263
- }
8264
- if (typeof date === 'string') {
8265
- date = new Date(date);
8266
- }
8267
- return date.getSeconds();
8268
- };
8269
-
8235
+ */
8236
+ var getSecond = function getSecond(date) {
8237
+ if (!date) {
8238
+ return new Date().getSeconds();
8239
+ }
8240
+ if (typeof date === 'string') {
8241
+ date = new Date(date);
8242
+ }
8243
+ return date.getSeconds();
8244
+ };
8245
+
8270
8246
  /**
8271
8247
  * 获取星期几
8272
8248
  * @date 2022年5月7日
8273
8249
  * @param {Date|string} [date] - 日期对象或日期字符串
8274
8250
  * @returns {number} 星期几(0-6,0表示星期日)
8275
- */
8276
- const getWeekday = function (date) {
8277
- if (!date) {
8278
- return new Date().getDay();
8279
- }
8280
- if (typeof date === 'string') {
8281
- date = new Date(date);
8282
- }
8283
- return date.getDay();
8284
- };
8285
-
8286
-
8251
+ */
8252
+ var getWeekday = function getWeekday(date) {
8253
+ if (!date) {
8254
+ return new Date().getDay();
8255
+ }
8256
+ if (typeof date === 'string') {
8257
+ date = new Date(date);
8258
+ }
8259
+ return date.getDay();
8260
+ };
8261
+
8287
8262
  /**
8288
8263
  * @desc 获取上午/下午/晚上
8289
8264
  * @author huangbo
8290
8265
  * @date 2022年5月7日
8291
8266
  * @param {String} [time] - 时间
8292
- **/
8293
- const timeCycle = function (time) {
8294
- let hour = 0;
8295
- if (!time) {
8296
- hour = new Date().getHours();
8297
- } else if (typeof time === 'string') {
8298
- // 从时间字符串中提取小时
8299
- const match = time.match(/^(\d{1,2})/);
8300
- if (match) {
8301
- hour = parseInt(match[1], 10);
8302
- }
8303
- } else if (typeof time === 'number') {
8304
- hour = time;
8305
- }
8306
- // 判断时间段
8307
- if (hour >= 5 && hour < 12) {
8308
- return '上午';
8309
- } else if (hour >= 12 && hour < 18) {
8310
- return '下午';
8311
- } else {
8312
- return '晚上';
8313
- }
8267
+ **/
8268
+ var timeCycle = function timeCycle(time) {
8269
+ var hour = 0;
8270
+ if (!time) {
8271
+ hour = new Date().getHours();
8272
+ } else if (typeof time === 'string') {
8273
+ // 从时间字符串中提取小时
8274
+ var match = time.match(/^(\d{1,2})/);
8275
+ if (match) {
8276
+ hour = parseInt(match[1], 10);
8277
+ }
8278
+ } else if (typeof time === 'number') {
8279
+ hour = time;
8280
+ }
8281
+ // 判断时间段
8282
+ if (hour >= 5 && hour < 12) {
8283
+ return '上午';
8284
+ } else if (hour >= 12 && hour < 18) {
8285
+ return '下午';
8286
+ } else {
8287
+ return '晚上';
8288
+ }
8314
8289
  };
8315
8290
 
8316
8291
  /***/ }),