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
package/lib/flow-group.js CHANGED
@@ -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 = 240);
85
+ /******/ return __webpack_require__(__webpack_require__.s = 247);
86
86
  /******/ })
87
87
  /************************************************************************/
88
88
  /******/ ({
@@ -3486,14 +3486,14 @@ var getRgb = function getRgb($color) {
3486
3486
 
3487
3487
  /***/ }),
3488
3488
 
3489
- /***/ 135:
3489
+ /***/ 139:
3490
3490
  /***/ (function(module, exports) {
3491
3491
 
3492
3492
  module.exports = require("eoss/lib/flow");
3493
3493
 
3494
3494
  /***/ }),
3495
3495
 
3496
- /***/ 136:
3496
+ /***/ 140:
3497
3497
  /***/ (function(module, exports) {
3498
3498
 
3499
3499
  module.exports = require("eoss/lib/tree-group");
@@ -3535,14 +3535,14 @@ module.exports = require("vue");
3535
3535
 
3536
3536
  /***/ }),
3537
3537
 
3538
- /***/ 240:
3538
+ /***/ 247:
3539
3539
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
3540
3540
 
3541
3541
  "use strict";
3542
3542
  // ESM COMPAT FLAG
3543
3543
  __webpack_require__.r(__webpack_exports__);
3544
3544
 
3545
- // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/flow-group/src/main.vue?vue&type=template&id=0b62d00c&
3545
+ // CONCATENATED MODULE: ./node_modules/vue-loader/lib/loaders/templateLoader.js??vue-loader-options!./node_modules/vue-loader/lib??vue-loader-options!./packages/flow-group/src/main.vue?vue&type=template&id=07e61e00&
3546
3546
  var render = function () {
3547
3547
  var _vm = this
3548
3548
  var _h = _vm.$createElement
@@ -4009,7 +4009,7 @@ var render = function () {
4009
4009
  _vm.showMsg,
4010
4010
  full: "",
4011
4011
  autoId: true,
4012
- "show-button": false,
4012
+ "show-default-buttons": false,
4013
4013
  closeDialog: false,
4014
4014
  display:
4015
4015
  _vm.activeName ===
@@ -4471,7 +4471,7 @@ var render = function () {
4471
4471
  ref: "esFlowForm",
4472
4472
  refInFor: true,
4473
4473
  attrs: {
4474
- "show-button": false,
4474
+ "show-default-buttons": false,
4475
4475
  showMsg:
4476
4476
  _vm.showMsg,
4477
4477
  full: "",
@@ -4859,13 +4859,13 @@ var staticRenderFns = []
4859
4859
  render._withStripped = true
4860
4860
 
4861
4861
 
4862
- // CONCATENATED MODULE: ./packages/flow-group/src/main.vue?vue&type=template&id=0b62d00c&
4862
+ // CONCATENATED MODULE: ./packages/flow-group/src/main.vue?vue&type=template&id=07e61e00&
4863
4863
 
4864
4864
  // EXTERNAL MODULE: ./src/utils/util.js
4865
4865
  var util = __webpack_require__(1);
4866
4866
 
4867
4867
  // EXTERNAL MODULE: external "eoss/lib/data-table"
4868
- var data_table_ = __webpack_require__(47);
4868
+ var data_table_ = __webpack_require__(48);
4869
4869
  var data_table_default = /*#__PURE__*/__webpack_require__.n(data_table_);
4870
4870
 
4871
4871
  // EXTERNAL MODULE: external "eoss/lib/dialog"
@@ -4873,7 +4873,7 @@ var dialog_ = __webpack_require__(37);
4873
4873
  var dialog_default = /*#__PURE__*/__webpack_require__.n(dialog_);
4874
4874
 
4875
4875
  // EXTERNAL MODULE: external "eoss/lib/flow"
4876
- var flow_ = __webpack_require__(135);
4876
+ var flow_ = __webpack_require__(139);
4877
4877
  var flow_default = /*#__PURE__*/__webpack_require__.n(flow_);
4878
4878
 
4879
4879
  // EXTERNAL MODULE: external "eoss/lib/form"
@@ -4881,19 +4881,19 @@ var form_ = __webpack_require__(25);
4881
4881
  var form_default = /*#__PURE__*/__webpack_require__.n(form_);
4882
4882
 
4883
4883
  // EXTERNAL MODULE: external "eoss/lib/tab-pane"
4884
- var tab_pane_ = __webpack_require__(59);
4884
+ var tab_pane_ = __webpack_require__(60);
4885
4885
  var tab_pane_default = /*#__PURE__*/__webpack_require__.n(tab_pane_);
4886
4886
 
4887
4887
  // EXTERNAL MODULE: external "eoss/lib/tabs"
4888
- var tabs_ = __webpack_require__(55);
4888
+ var tabs_ = __webpack_require__(57);
4889
4889
  var tabs_default = /*#__PURE__*/__webpack_require__.n(tabs_);
4890
4890
 
4891
4891
  // EXTERNAL MODULE: external "eoss/lib/tree-group"
4892
- var tree_group_ = __webpack_require__(136);
4892
+ var tree_group_ = __webpack_require__(140);
4893
4893
  var tree_group_default = /*#__PURE__*/__webpack_require__.n(tree_group_);
4894
4894
 
4895
4895
  // EXTERNAL MODULE: external "eoss/lib/upload"
4896
- var upload_ = __webpack_require__(49);
4896
+ var upload_ = __webpack_require__(50);
4897
4897
  var upload_default = /*#__PURE__*/__webpack_require__.n(upload_);
4898
4898
 
4899
4899
  // CONCATENATED MODULE: ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib??vue-loader-options!./packages/flow-group/src/main.vue?vue&type=script&lang=js&
@@ -5873,28 +5873,28 @@ function normalizeComponent(
5873
5873
 
5874
5874
  /***/ }),
5875
5875
 
5876
- /***/ 47:
5876
+ /***/ 48:
5877
5877
  /***/ (function(module, exports) {
5878
5878
 
5879
5879
  module.exports = require("eoss/lib/data-table");
5880
5880
 
5881
5881
  /***/ }),
5882
5882
 
5883
- /***/ 49:
5883
+ /***/ 50:
5884
5884
  /***/ (function(module, exports) {
5885
5885
 
5886
5886
  module.exports = require("eoss/lib/upload");
5887
5887
 
5888
5888
  /***/ }),
5889
5889
 
5890
- /***/ 55:
5890
+ /***/ 57:
5891
5891
  /***/ (function(module, exports) {
5892
5892
 
5893
5893
  module.exports = require("eoss/lib/tabs");
5894
5894
 
5895
5895
  /***/ }),
5896
5896
 
5897
- /***/ 59:
5897
+ /***/ 60:
5898
5898
  /***/ (function(module, exports) {
5899
5899
 
5900
5900
  module.exports = require("eoss/lib/tab-pane");
@@ -5951,759 +5951,736 @@ module.exports = require("eoss/lib/tab-pane");
5951
5951
  /* unused harmony export getSecond */
5952
5952
  /* unused harmony export getWeekday */
5953
5953
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "F", function() { return timeCycle; });
5954
- /* Modified from https://github.com/taylorhakes/fecha
5955
- *
5956
- * The MIT License (MIT)
5957
- *
5958
- * Copyright (c) 2015 Taylor Hakes
5959
- *
5960
- * Permission is hereby granted, free of charge, to any person obtaining a copy
5961
- * of this software and associated documentation files (the "Software"), to deal
5962
- * in the Software without restriction, including without limitation the rights
5963
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
5964
- * copies of the Software, and to permit persons to whom the Software is
5965
- * furnished to do so, subject to the following conditions:
5966
- *
5967
- * The above copyright notice and this permission notice shall be included in all
5968
- * copies or substantial portions of the Software.
5969
- *
5970
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
5971
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
5972
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
5973
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
5974
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
5975
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
5976
- * SOFTWARE.
5977
- */
5978
-
5979
- /*eslint-disable*/
5980
- // 把 YYYY-MM-DD 改成了 yyyy-MM-dd
5981
-
5982
-
5954
+
5955
+
5983
5956
  /**
5984
5957
  * Parse or format dates
5985
5958
  * @class fecha
5986
- */
5987
- const fecha = {};
5988
- const token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
5989
- const twoDigits = '\\d\\d?';
5990
- const threeDigits = '\\d{3}';
5991
- const fourDigits = '\\d{4}';
5992
- const word = '[^\\s]+';
5993
- const literal = /\[([^]*?)\]/gm;
5994
- const noop = function () {};
5995
-
5996
- function regexEscape(str) {
5997
- return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5998
- }
5999
-
6000
- function shorten(arr, sLen) {
6001
- const newArr = [];
6002
- for (let i = 0, len = arr.length; i < len; i++) {
6003
- newArr.push(arr[i].substr(0, sLen));
6004
- }
6005
- return newArr;
6006
- }
6007
-
6008
- function monthUpdate() {
6009
- return function (d, v) {
6010
- const index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
6011
- if (~index) {
6012
- d.month = index;
6013
- }
6014
- };
6015
- }
6016
-
6017
- function pad(val, len) {
6018
- val = String(val);
6019
- len = len || 2;
6020
- while (val.length < len) {
6021
- val = '0' + val;
6022
- }
6023
- return val;
6024
- }
6025
-
6026
- // 直接使用中文日期名称常量
6027
- const dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
6028
- const monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
6029
- const monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
6030
- const dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
6031
- const amPm = ['上午', '下午'];
6032
- const DoFn = function DoFn(D) {
6033
- return D + '日';
6034
- };
6035
-
6036
- const formatFlags = {
6037
- D: function(dateObj) {
6038
- return dateObj.getDay();
6039
- },
6040
- DD: function(dateObj) {
6041
- return pad(dateObj.getDay());
6042
- },
6043
- Do: function(dateObj) {
6044
- return DoFn(dateObj.getDate());
6045
- },
6046
- d: function(dateObj) {
6047
- return dateObj.getDate();
6048
- },
6049
- dd: function(dateObj) {
6050
- return pad(dateObj.getDate());
6051
- },
6052
- ddd: function(dateObj) {
6053
- return dayNamesShort[dateObj.getDay()];
6054
- },
6055
- dddd: function(dateObj) {
6056
- return dayNames[dateObj.getDay()];
6057
- },
6058
- M: function(dateObj) {
6059
- return dateObj.getMonth() + 1;
6060
- },
6061
- MM: function(dateObj) {
6062
- return pad(dateObj.getMonth() + 1);
6063
- },
6064
- MMM: function(dateObj) {
6065
- return monthNamesShort[dateObj.getMonth()];
6066
- },
6067
- MMMM: function(dateObj) {
6068
- return monthNames[dateObj.getMonth()];
6069
- },
6070
- yy: function(dateObj) {
6071
- return pad(String(dateObj.getFullYear()), 4).substr(2);
6072
- },
6073
- yyyy: function(dateObj) {
6074
- return pad(dateObj.getFullYear(), 4);
6075
- },
6076
- h: function(dateObj) {
6077
- return dateObj.getHours() % 12 || 12;
6078
- },
6079
- hh: function(dateObj) {
6080
- return pad(dateObj.getHours() % 12 || 12);
6081
- },
6082
- H: function(dateObj) {
6083
- return dateObj.getHours();
6084
- },
6085
- HH: function(dateObj) {
6086
- return pad(dateObj.getHours());
6087
- },
6088
- m: function(dateObj) {
6089
- return dateObj.getMinutes();
6090
- },
6091
- mm: function(dateObj) {
6092
- return pad(dateObj.getMinutes());
6093
- },
6094
- s: function(dateObj) {
6095
- return dateObj.getSeconds();
6096
- },
6097
- ss: function(dateObj) {
6098
- return pad(dateObj.getSeconds());
6099
- },
6100
- S: function(dateObj) {
6101
- return Math.round(dateObj.getMilliseconds() / 100);
6102
- },
6103
- SS: function(dateObj) {
6104
- return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
6105
- },
6106
- SSS: function(dateObj) {
6107
- return pad(dateObj.getMilliseconds(), 3);
6108
- },
6109
- a: function(dateObj) {
6110
- return dateObj.getHours() < 12 ? '上午' : '下午';
6111
- },
6112
- A: function(dateObj) {
6113
- return dateObj.getHours() < 12 ? '上午' : '下午';
6114
- },
6115
- ZZ: function(dateObj) {
6116
- const o = dateObj.getTimezoneOffset();
6117
- return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
6118
- }
6119
- };
6120
-
6121
- const parseFlags = {
6122
- d: [twoDigits, function (d, v) {
6123
- d.day = v;
6124
- }],
6125
- Do: [twoDigits + word, function (d, v) {
6126
- d.day = parseInt(v, 10);
6127
- }],
6128
- M: [twoDigits, function (d, v) {
6129
- d.month = v - 1;
6130
- }],
6131
- yy: [twoDigits, function (d, v) {
6132
- const da = new Date(), cent = +('' + da.getFullYear()).substr(0, 2);
6133
- d.year = '' + (v > 68 ? cent - 1 : cent) + v;
6134
- }],
6135
- h: [twoDigits, function (d, v) {
6136
- d.hour = v;
6137
- }],
6138
- m: [twoDigits, function (d, v) {
6139
- d.minute = v;
6140
- }],
6141
- s: [twoDigits, function (d, v) {
6142
- d.second = v;
6143
- }],
6144
- yyyy: [fourDigits, function (d, v) {
6145
- d.year = v;
6146
- }],
6147
- S: ['\\d', function (d, v) {
6148
- d.millisecond = v * 100;
6149
- }],
6150
- SS: ['\\d{2}', function (d, v) {
6151
- d.millisecond = v * 10;
6152
- }],
6153
- SSS: [threeDigits, function (d, v) {
6154
- d.millisecond = v;
6155
- }],
6156
- D: [twoDigits, noop],
6157
- ddd: [word, noop],
6158
- MMM: [word, monthUpdate('monthNamesShort')],
6159
- MMMM: [word, monthUpdate('monthNames')],
6160
- a: [word, function (d, v) {
6161
- const val = v.toLowerCase();
6162
- if (val === '上午') {
6163
- d.isPm = false;
6164
- } else if (val === '下午') {
6165
- d.isPm = true;
6166
- }
6167
- }],
6168
- ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
6169
- let parts = (v + '').match(/([+-]|\d\d)/gi), minutes;
6170
-
6171
- if (parts) {
6172
- minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
6173
- d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
6174
- }
6175
- }]
6176
- };
6177
- parseFlags.dd = parseFlags.d;
6178
- parseFlags.dddd = parseFlags.ddd;
6179
- parseFlags.DD = parseFlags.D;
6180
- parseFlags.mm = parseFlags.m;
6181
- parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
6182
- parseFlags.MM = parseFlags.M;
6183
- parseFlags.ss = parseFlags.s;
6184
- parseFlags.A = parseFlags.a;
6185
-
6186
-
6187
- // Some common format strings
6188
- fecha.masks = {
6189
- default: 'ddd MMM dd yyyy HH:mm:ss',
6190
- shortDate: 'M/D/yy',
6191
- mediumDate: 'MMM d, yyyy',
6192
- longDate: 'MMMM d, yyyy',
6193
- fullDate: 'dddd, MMMM d, yyyy',
6194
- shortTime: 'HH:mm',
6195
- mediumTime: 'HH:mm:ss',
6196
- longTime: 'HH:mm:ss.SSS'
6197
- };
6198
-
5959
+ */
5960
+ var fecha = {};
5961
+ var token = /d{1,4}|M{1,4}|yy(?:yy)?|S{1,3}|Do|ZZ|([HhMsDm])\1?|[aA]|"[^"]*"|'[^']*'/g;
5962
+ var twoDigits = '\\d\\d?';
5963
+ var threeDigits = '\\d{3}';
5964
+ var fourDigits = '\\d{4}';
5965
+ var word = '[^\\s]+';
5966
+ var literal = /\[([^]*?)\]/gm;
5967
+ var noop = function noop() {};
5968
+
5969
+ function regexEscape(str) {
5970
+ return str.replace(/[|\\{()[^$+*?.-]/g, '\\$&');
5971
+ }
5972
+
5973
+ function shorten(arr, sLen) {
5974
+ var newArr = [];
5975
+ for (var i = 0, len = arr.length; i < len; i++) {
5976
+ newArr.push(arr[i].substr(0, sLen));
5977
+ }
5978
+ return newArr;
5979
+ }
5980
+
5981
+ function monthUpdate() {
5982
+ return function (d, v) {
5983
+ var index = ['january', 'february', 'march', 'april', 'may', 'june', 'july', 'august', 'september', 'october', 'november', 'december'].indexOf(v.toLowerCase());
5984
+ if (~index) {
5985
+ d.month = index;
5986
+ }
5987
+ };
5988
+ }
5989
+
5990
+ function pad(val, len) {
5991
+ val = String(val);
5992
+ len = len || 2;
5993
+ while (val.length < len) {
5994
+ val = '0' + val;
5995
+ }
5996
+ return val;
5997
+ }
5998
+
5999
+ // 直接使用中文日期名称常量
6000
+ var dayNames = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
6001
+ var monthNames = ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'];
6002
+ var monthNamesShort = ['一', '二', '三', '四', '五', '六', '七', '八', '九', '十', '十一', '十二'];
6003
+ var dayNamesShort = ['日', '一', '二', '三', '四', '五', '六'];
6004
+ var amPm = ['上午', '下午'];
6005
+ var DoFn = function DoFn(D) {
6006
+ return D + '日';
6007
+ };
6008
+
6009
+ var formatFlags = {
6010
+ D: function D(dateObj) {
6011
+ return dateObj.getDay();
6012
+ },
6013
+ DD: function DD(dateObj) {
6014
+ return pad(dateObj.getDay());
6015
+ },
6016
+ Do: function Do(dateObj) {
6017
+ return DoFn(dateObj.getDate());
6018
+ },
6019
+ d: function d(dateObj) {
6020
+ return dateObj.getDate();
6021
+ },
6022
+ dd: function dd(dateObj) {
6023
+ return pad(dateObj.getDate());
6024
+ },
6025
+ ddd: function ddd(dateObj) {
6026
+ return dayNamesShort[dateObj.getDay()];
6027
+ },
6028
+ dddd: function dddd(dateObj) {
6029
+ return dayNames[dateObj.getDay()];
6030
+ },
6031
+ M: function M(dateObj) {
6032
+ return dateObj.getMonth() + 1;
6033
+ },
6034
+ MM: function MM(dateObj) {
6035
+ return pad(dateObj.getMonth() + 1);
6036
+ },
6037
+ MMM: function MMM(dateObj) {
6038
+ return monthNamesShort[dateObj.getMonth()];
6039
+ },
6040
+ MMMM: function MMMM(dateObj) {
6041
+ return monthNames[dateObj.getMonth()];
6042
+ },
6043
+ yy: function yy(dateObj) {
6044
+ return pad(String(dateObj.getFullYear()), 4).substr(2);
6045
+ },
6046
+ yyyy: function yyyy(dateObj) {
6047
+ return pad(dateObj.getFullYear(), 4);
6048
+ },
6049
+ h: function h(dateObj) {
6050
+ return dateObj.getHours() % 12 || 12;
6051
+ },
6052
+ hh: function hh(dateObj) {
6053
+ return pad(dateObj.getHours() % 12 || 12);
6054
+ },
6055
+ H: function H(dateObj) {
6056
+ return dateObj.getHours();
6057
+ },
6058
+ HH: function HH(dateObj) {
6059
+ return pad(dateObj.getHours());
6060
+ },
6061
+ m: function m(dateObj) {
6062
+ return dateObj.getMinutes();
6063
+ },
6064
+ mm: function mm(dateObj) {
6065
+ return pad(dateObj.getMinutes());
6066
+ },
6067
+ s: function s(dateObj) {
6068
+ return dateObj.getSeconds();
6069
+ },
6070
+ ss: function ss(dateObj) {
6071
+ return pad(dateObj.getSeconds());
6072
+ },
6073
+ S: function S(dateObj) {
6074
+ return Math.round(dateObj.getMilliseconds() / 100);
6075
+ },
6076
+ SS: function SS(dateObj) {
6077
+ return pad(Math.round(dateObj.getMilliseconds() / 10), 2);
6078
+ },
6079
+ SSS: function SSS(dateObj) {
6080
+ return pad(dateObj.getMilliseconds(), 3);
6081
+ },
6082
+ a: function a(dateObj) {
6083
+ return dateObj.getHours() < 12 ? '上午' : '下午';
6084
+ },
6085
+ A: function A(dateObj) {
6086
+ return dateObj.getHours() < 12 ? '上午' : '下午';
6087
+ },
6088
+ ZZ: function ZZ(dateObj) {
6089
+ var o = dateObj.getTimezoneOffset();
6090
+ return (o > 0 ? '-' : '+') + pad(Math.floor(Math.abs(o) / 60) * 100 + Math.abs(o) % 60, 4);
6091
+ }
6092
+ };
6093
+
6094
+ var parseFlags = {
6095
+ d: [twoDigits, function (d, v) {
6096
+ d.day = v;
6097
+ }],
6098
+ Do: [twoDigits + word, function (d, v) {
6099
+ d.day = parseInt(v, 10);
6100
+ }],
6101
+ M: [twoDigits, function (d, v) {
6102
+ d.month = v - 1;
6103
+ }],
6104
+ yy: [twoDigits, function (d, v) {
6105
+ var da = new Date(),
6106
+ cent = +('' + da.getFullYear()).substr(0, 2);
6107
+ d.year = '' + (v > 68 ? cent - 1 : cent) + v;
6108
+ }],
6109
+ h: [twoDigits, function (d, v) {
6110
+ d.hour = v;
6111
+ }],
6112
+ m: [twoDigits, function (d, v) {
6113
+ d.minute = v;
6114
+ }],
6115
+ s: [twoDigits, function (d, v) {
6116
+ d.second = v;
6117
+ }],
6118
+ yyyy: [fourDigits, function (d, v) {
6119
+ d.year = v;
6120
+ }],
6121
+ S: ['\\d', function (d, v) {
6122
+ d.millisecond = v * 100;
6123
+ }],
6124
+ SS: ['\\d{2}', function (d, v) {
6125
+ d.millisecond = v * 10;
6126
+ }],
6127
+ SSS: [threeDigits, function (d, v) {
6128
+ d.millisecond = v;
6129
+ }],
6130
+ D: [twoDigits, noop],
6131
+ ddd: [word, noop],
6132
+ MMM: [word, monthUpdate('monthNamesShort')],
6133
+ MMMM: [word, monthUpdate('monthNames')],
6134
+ a: [word, function (d, v) {
6135
+ var val = v.toLowerCase();
6136
+ if (val === '上午') {
6137
+ d.isPm = false;
6138
+ } else if (val === '下午') {
6139
+ d.isPm = true;
6140
+ }
6141
+ }],
6142
+ ZZ: ['[^\\s]*?[\\+\\-]\\d\\d:?\\d\\d|[^\\s]*?Z', function (d, v) {
6143
+ var parts = (v + '').match(/([+-]|\d\d)/gi),
6144
+ minutes = void 0;
6145
+
6146
+ if (parts) {
6147
+ minutes = +(parts[1] * 60) + parseInt(parts[2], 10);
6148
+ d.timezoneOffset = parts[0] === '+' ? minutes : -minutes;
6149
+ }
6150
+ }]
6151
+ };
6152
+ parseFlags.dd = parseFlags.d;
6153
+ parseFlags.dddd = parseFlags.ddd;
6154
+ parseFlags.DD = parseFlags.D;
6155
+ parseFlags.mm = parseFlags.m;
6156
+ parseFlags.hh = parseFlags.H = parseFlags.HH = parseFlags.h;
6157
+ parseFlags.MM = parseFlags.M;
6158
+ parseFlags.ss = parseFlags.s;
6159
+ parseFlags.A = parseFlags.a;
6160
+
6161
+ // Some common format strings
6162
+ fecha.masks = {
6163
+ default: 'ddd MMM dd yyyy HH:mm:ss',
6164
+ shortDate: 'M/D/yy',
6165
+ mediumDate: 'MMM d, yyyy',
6166
+ longDate: 'MMMM d, yyyy',
6167
+ fullDate: 'dddd, MMMM d, yyyy',
6168
+ shortTime: 'HH:mm',
6169
+ mediumTime: 'HH:mm:ss',
6170
+ longTime: 'HH:mm:ss.SSS'
6171
+ };
6172
+
6199
6173
  /***
6200
6174
  * Format a date
6201
6175
  * @method format
6202
6176
  * @param {Date|number} dateObj
6203
6177
  * @param {string} mask Format of the date, i.e. 'mm-dd-yy' or 'shortDate'
6204
- */
6205
- fecha.format = function (dateObj, mask) {
6206
- if (typeof dateObj === 'number') {
6207
- dateObj = new Date(dateObj);
6208
- }
6209
-
6210
- if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
6211
- throw new Error('Invalid Date in fecha.format');
6212
- }
6213
-
6214
- mask = fecha.masks[mask] || mask || fecha.masks['default'];
6215
-
6216
- const literals = [];
6217
-
6218
- // Make literals inactive by replacing them with ??
6219
- mask = mask.replace(literal, function($0, $1) {
6220
- literals.push($1);
6221
- return '@@@';
6222
- });
6223
- // Apply formatting rules
6224
- mask = mask.replace(token, function ($0) {
6225
- return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
6226
- });
6227
- // Inline literal values back into the formatted value
6228
- return mask.replace(/@@@/g, function() {
6229
- return literals.shift();
6230
- });
6231
- };
6232
-
6178
+ */
6179
+ fecha.format = function (dateObj, mask) {
6180
+ if (typeof dateObj === 'number') {
6181
+ dateObj = new Date(dateObj);
6182
+ }
6183
+
6184
+ if (Object.prototype.toString.call(dateObj) !== '[object Date]' || isNaN(dateObj.getTime())) {
6185
+ throw new Error('Invalid Date in fecha.format');
6186
+ }
6187
+
6188
+ mask = fecha.masks[mask] || mask || fecha.masks['default'];
6189
+
6190
+ var literals = [];
6191
+
6192
+ // Make literals inactive by replacing them with ??
6193
+ mask = mask.replace(literal, function ($0, $1) {
6194
+ literals.push($1);
6195
+ return '@@@';
6196
+ });
6197
+ // Apply formatting rules
6198
+ mask = mask.replace(token, function ($0) {
6199
+ return $0 in formatFlags ? formatFlags[$0](dateObj) : $0.slice(1, $0.length - 1);
6200
+ });
6201
+ // Inline literal values back into the formatted value
6202
+ return mask.replace(/@@@/g, function () {
6203
+ return literals.shift();
6204
+ });
6205
+ };
6206
+
6233
6207
  /**
6234
6208
  * Parse a date string into an object, changes - into /
6235
6209
  * @method parse
6236
6210
  * @param {string} dateStr Date string
6237
6211
  * @param {string} format Date parse format
6238
6212
  * @returns {Date|boolean}
6239
- */
6240
- fecha.parse = function (dateStr, format) {
6241
- if (typeof format !== 'string') {
6242
- throw new Error('Invalid format in fecha.parse');
6243
- }
6244
-
6245
- format = fecha.masks[format] || format;
6246
-
6247
- // Avoid regular expression denial of service, fail early for really long strings
6248
- // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
6249
- if (dateStr.length > 1000) {
6250
- return null;
6251
- }
6252
-
6253
- const dateInfo = {};
6254
- const parseInfo = [];
6255
- const literals = [];
6256
- format = format.replace(literal, function($0, $1) {
6257
- literals.push($1);
6258
- return '@@@';
6259
- });
6260
- let newFormat = regexEscape(format).replace(token, function ($0) {
6261
- if (parseFlags[$0]) {
6262
- const info = parseFlags[$0];
6263
- parseInfo.push(info[1]);
6264
- return '(' + info[0] + ')';
6265
- }
6266
-
6267
- return $0;
6268
- });
6269
- newFormat = newFormat.replace(/@@@/g, function() {
6270
- return literals.shift();
6271
- });
6272
- const matches = dateStr.match(new RegExp(newFormat, 'i'));
6273
- if (!matches) {
6274
- return null;
6275
- }
6276
-
6277
- for (let i = 1; i < matches.length; i++) {
6278
- parseInfo[i - 1](dateInfo, matches[i]);
6279
- }
6280
-
6281
- const today = new Date();
6282
- if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
6283
- dateInfo.hour = +dateInfo.hour + 12;
6284
- } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
6285
- dateInfo.hour = 0;
6286
- }
6287
-
6288
- let date;
6289
- if (dateInfo.timezoneOffset != null) {
6290
- dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
6291
- date = new Date(Date.UTC(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
6292
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0));
6293
- } else {
6294
- date = new Date(dateInfo.year || today.getFullYear(), dateInfo.month || 0, dateInfo.day || 1,
6295
- dateInfo.hour || 0, dateInfo.minute || 0, dateInfo.second || 0, dateInfo.millisecond || 0);
6296
- }
6297
- return date;
6298
- };
6299
-
6300
- // 导出fecha对象
6301
-
6302
-
6303
- // 以下是从date-util.js合并的函数
6304
- const newArray = function(start, end) {
6305
- let result = [];
6306
- for (let i = start; i <= end; i++) {
6307
- result.push(i);
6308
- }
6309
- return result;
6310
- };
6311
-
6312
- const getSettings = () => {
6313
- return {
6314
- dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
6315
- dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
6316
- monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
6317
- monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
6318
- amPm: ['上午', '下午']
6319
- };
6320
- };
6321
-
6322
- const toDate = function(date) {
6323
- return isDate(date) ? new Date(date) : null;
6324
- };
6325
-
6326
- const isDate = function(date) {
6327
- if (date === null || date === undefined) return false;
6328
- if (isNaN(new Date(date).getTime())) return false;
6329
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
6330
- return true;
6331
- };
6332
-
6333
- const isDateObject = function(val) {
6334
- return val instanceof Date;
6335
- };
6336
-
6337
- const formatDate = function (date, format = 'yyyy-MM-dd') {
6338
- // 处理多种输入类型
6339
- if (!date) return '';
6340
-
6341
- // 如果是时间戳,转成日期对象
6342
- if (typeof date === 'number') {
6343
- date = new Date(date);
6344
- }
6345
- // 如果是字符串,转成日期对象
6346
- if (typeof date === 'string') {
6347
- date = new Date(date);
6348
- }
6349
-
6350
- // 调用toDate进一步验证和转换
6351
- date = toDate(date);
6352
- if (!date) return '';
6353
-
6354
- // 兼容大写和小写的格式标记
6355
- // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
6356
- const lowercaseFormat = format
6357
- .replace(/YYYY/g, 'yyyy')
6358
- .replace(/D/g, 'd')
6359
-
6360
- // 使用fecha库进行格式化,支持中文配置
6361
- const str = fecha.format(date, lowercaseFormat, getSettings());
6362
- return str;
6363
- };
6364
-
6365
- const parseDate = function(string, format) {
6366
- return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
6367
- };
6368
-
6369
- const getDayCountOfMonth = function(year, month) {
6370
- if (month === 3 || month === 5 || month === 8 || month === 10) {
6371
- return 30;
6372
- }
6373
-
6374
- if (month === 1) {
6375
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
6376
- return 29;
6377
- } else {
6378
- return 28;
6379
- }
6380
- }
6381
-
6382
- return 31;
6383
- };
6384
-
6385
- const getDayCountOfYear = function(year) {
6386
- const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
6387
- return isLeapYear ? 366 : 365;
6388
- };
6389
-
6390
- const getFirstDayOfMonth = function(date) {
6391
- const temp = new Date(date.getTime());
6392
- temp.setDate(1);
6393
- return temp.getDay();
6394
- };
6395
-
6396
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
6397
- // {prev, next} Date should work for Daylight Saving Time
6398
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
6399
- const prevDate = function(date, amount = 1) {
6400
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
6401
- };
6402
-
6403
- const nextDate = function(date, amount = 1) {
6404
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
6405
- };
6406
-
6407
- const getStartDateOfMonth = function(year, month) {
6408
- const result = new Date(year, month, 1);
6409
- const day = result.getDay();
6410
-
6411
- if (day === 0) {
6412
- return prevDate(result, 7);
6413
- } else {
6414
- return prevDate(result, day);
6415
- }
6416
- };
6417
-
6418
- const getWeekNumber = function(date) {
6419
- // 支持多种输入类型
6420
- if (!date||!isDate(date)) {
6421
- date = new Date();
6422
- }
6423
- if (typeof date === 'string') {
6424
- date = new Date(date);
6425
- }
6426
-
6427
- // 验证日期有效性
6428
- if (!isDate(date)) return null;
6429
-
6430
- const d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
6431
- // 设置为最近的星期四:当前日期 + 4 - 当前星期数
6432
- // 将星期日的星期数设为7
6433
- d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
6434
- // 获取当年的第一天
6435
- const yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
6436
- // 计算到最近的星期四的完整周数
6437
- const weekNo = Math.ceil((((d - yearStart) / 86400000) + 1) / 7);
6438
- // 返回周数
6439
- return weekNo;
6440
- };
6441
-
6442
- const getRangeHours = function(ranges) {
6443
- const hours = [];
6444
- let disabledHours = [];
6445
-
6446
- (ranges || []).forEach(range => {
6447
- const value = range.map(date => date.getHours());
6448
-
6449
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
6450
- });
6451
-
6452
- if (disabledHours.length) {
6453
- for (let i = 0; i < 24; i++) {
6454
- hours[i] = disabledHours.indexOf(i) === -1;
6455
- }
6456
- } else {
6457
- for (let i = 0; i < 24; i++) {
6458
- hours[i] = false;
6459
- }
6460
- }
6461
-
6462
- return hours;
6463
- };
6464
-
6465
- const getPrevMonthLastDays = (date, amount) => {
6466
- if (amount <= 0) return [];
6467
- const temp = new Date(date.getTime());
6468
- temp.setDate(0);
6469
- const lastDay = temp.getDate();
6470
- return range(amount).map((_, index) => lastDay - (amount - index - 1));
6471
- };
6472
-
6473
- const getMonthDays = (date) => {
6474
- const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
6475
- const days = temp.getDate();
6476
- return range(days).map((_, index) => index + 1);
6477
- };
6478
-
6479
- function setRangeData(arr, start, end, value) {
6480
- for (let i = start; i < end; i++) {
6481
- arr[i] = value;
6482
- }
6483
- }
6484
-
6485
- const getRangeMinutes = function(ranges, hour) {
6486
- const minutes = new Array(60);
6487
-
6488
- if (ranges.length > 0) {
6489
- ranges.forEach(range => {
6490
- const start = range[0];
6491
- const end = range[1];
6492
- const startHour = start.getHours();
6493
- const startMinute = start.getMinutes();
6494
- const endHour = end.getHours();
6495
- const endMinute = end.getMinutes();
6496
- if (startHour === hour && endHour !== hour) {
6497
- setRangeData(minutes, startMinute, 60, true);
6498
- } else if (startHour === hour && endHour === hour) {
6499
- setRangeData(minutes, startMinute, endMinute + 1, true);
6500
- } else if (startHour !== hour && endHour === hour) {
6501
- setRangeData(minutes, 0, endMinute + 1, true);
6502
- } else if (startHour < hour && endHour > hour) {
6503
- setRangeData(minutes, 0, 60, true);
6504
- }
6505
- });
6506
- } else {
6507
- setRangeData(minutes, 0, 60, true);
6508
- }
6509
- return minutes;
6510
- };
6511
-
6512
- const range = function(n) {
6513
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
6514
- return Array.apply(null, {length: n}).map((_, n) => n);
6515
- };
6516
-
6517
- const modifyDate = function(date, y, m, d) {
6518
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
6519
- };
6520
-
6521
- const modifyTime = function(date, h, m, s) {
6522
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
6523
- };
6524
-
6525
- const modifyWithTimeString = (date, time) => {
6526
- if (date == null || !time) {
6527
- return date;
6528
- }
6529
- time = parseDate(time, 'HH:mm:ss');
6530
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
6531
- };
6532
-
6533
- const clearTime = function(date) {
6534
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
6535
- };
6536
-
6537
- const clearMilliseconds = function(date) {
6538
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
6539
- };
6540
-
6541
- const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
6542
- // TODO: refactory a more elegant solution
6543
- if (ranges.length === 0) return date;
6544
- const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
6545
- const ndate = normalizeDate(date);
6546
- const nranges = ranges.map(range => range.map(normalizeDate));
6547
- if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
6548
-
6549
- let minDate = nranges[0][0];
6550
- let maxDate = nranges[0][0];
6551
-
6552
- nranges.forEach(nrange => {
6553
- minDate = new Date(Math.min(nrange[0], minDate));
6554
- maxDate = new Date(Math.max(nrange[1], minDate));
6555
- });
6556
-
6557
- const ret = ndate < minDate ? minDate : maxDate;
6558
- // preserve Year/Month/Date
6559
- return modifyDate(
6560
- ret,
6561
- date.getFullYear(),
6562
- date.getMonth(),
6563
- date.getDate()
6564
- );
6565
- };
6566
-
6567
- const timeWithinRange = function(date, selectableRange, format) {
6568
- const limitedDate = limitTimeRange(date, selectableRange, format);
6569
- return limitedDate.getTime() === date.getTime();
6570
- };
6571
-
6572
- const changeYearMonthAndClampDate = function(date, year, month) {
6573
- // clamp date to the number of days in `year`, `month`
6574
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
6575
- const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
6576
- return modifyDate(date, year, month, monthDate);
6577
- };
6578
-
6579
- const prevMonth = function(date) {
6580
- const year = date.getFullYear();
6581
- const month = date.getMonth();
6582
- return month === 0
6583
- ? changeYearMonthAndClampDate(date, year - 1, 11)
6584
- : changeYearMonthAndClampDate(date, year, month - 1);
6585
- };
6586
-
6587
- const nextMonth = function(date) {
6588
- const year = date.getFullYear();
6589
- const month = date.getMonth();
6590
- return month === 11
6591
- ? changeYearMonthAndClampDate(date, year + 1, 0)
6592
- : changeYearMonthAndClampDate(date, year, month + 1);
6593
- };
6594
-
6595
- const prevYear = function(date, amount = 1) {
6596
- const year = date.getFullYear();
6597
- const month = date.getMonth();
6598
- return changeYearMonthAndClampDate(date, year - amount, month);
6599
- };
6600
-
6601
- const nextYear = function(date, amount = 1) {
6602
- const year = date.getFullYear();
6603
- const month = date.getMonth();
6604
- return changeYearMonthAndClampDate(date, year + amount, month);
6605
- };
6606
-
6607
- const extractDateFormat = function(format) {
6608
- return format
6609
- .replace(/\W?m{1,2}|\W?ZZ/g, '')
6610
- .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
6611
- .trim();
6612
- };
6613
-
6614
- const extractTimeFormat = function(format) {
6615
- return format
6616
- .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
6617
- .trim();
6618
- };
6619
-
6620
- const validateRangeInOneMonth = function(start, end) {
6621
- return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
6622
- };
6623
-
6213
+ */
6214
+ fecha.parse = function (dateStr, format) {
6215
+ if (typeof format !== 'string') {
6216
+ throw new Error('Invalid format in fecha.parse');
6217
+ }
6218
+
6219
+ format = fecha.masks[format] || format;
6220
+
6221
+ // Avoid regular expression denial of service, fail early for really long strings
6222
+ // https://www.owasp.org/index.php/Regular_expression_Denial_of_Service_-_ReDoS
6223
+ if (dateStr.length > 1000) {
6224
+ return null;
6225
+ }
6226
+
6227
+ var dateInfo = {};
6228
+ var parseInfo = [];
6229
+ var literals = [];
6230
+ format = format.replace(literal, function ($0, $1) {
6231
+ literals.push($1);
6232
+ return '@@@';
6233
+ });
6234
+ var newFormat = regexEscape(format).replace(token, function ($0) {
6235
+ if (parseFlags[$0]) {
6236
+ var info = parseFlags[$0];
6237
+ parseInfo.push(info[1]);
6238
+ return '(' + info[0] + ')';
6239
+ }
6240
+
6241
+ return $0;
6242
+ });
6243
+ newFormat = newFormat.replace(/@@@/g, function () {
6244
+ return literals.shift();
6245
+ });
6246
+ var matches = dateStr.match(new RegExp(newFormat, 'i'));
6247
+ if (!matches) {
6248
+ return null;
6249
+ }
6250
+
6251
+ for (var i = 1; i < matches.length; i++) {
6252
+ parseInfo[i - 1](dateInfo, matches[i]);
6253
+ }
6254
+
6255
+ var today = new Date();
6256
+ if (dateInfo.isPm === true && dateInfo.hour != null && +dateInfo.hour !== 12) {
6257
+ dateInfo.hour = +dateInfo.hour + 12;
6258
+ } else if (dateInfo.isPm === false && +dateInfo.hour === 12) {
6259
+ dateInfo.hour = 0;
6260
+ }
6261
+
6262
+ var date = void 0;
6263
+ if (dateInfo.timezoneOffset != null) {
6264
+ dateInfo.minute = +(dateInfo.minute || 0) - +dateInfo.timezoneOffset;
6265
+ 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));
6266
+ } else {
6267
+ 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);
6268
+ }
6269
+ return date;
6270
+ };
6271
+
6272
+ // 导出fecha对象
6273
+
6274
+
6275
+ // 以下是从date-util.js合并的函数
6276
+ var newArray = function newArray(start, end) {
6277
+ var result = [];
6278
+ for (var i = start; i <= end; i++) {
6279
+ result.push(i);
6280
+ }
6281
+ return result;
6282
+ };
6283
+
6284
+ var getSettings = function getSettings() {
6285
+ return {
6286
+ dayNamesShort: ['日', '一', '二', '三', '四', '五', '六'],
6287
+ dayNames: ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'],
6288
+ monthNamesShort: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
6289
+ monthNames: ['一月', '二月', '三月', '四月', '五月', '六月', '七月', '八月', '九月', '十月', '十一月', '十二月'],
6290
+ amPm: ['上午', '下午']
6291
+ };
6292
+ };
6293
+
6294
+ var toDate = function toDate(date) {
6295
+ return isDate(date) ? new Date(date) : null;
6296
+ };
6297
+
6298
+ var isDate = function isDate(date) {
6299
+ if (date === null || date === undefined) return false;
6300
+ if (isNaN(new Date(date).getTime())) return false;
6301
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
6302
+ return true;
6303
+ };
6304
+
6305
+ var isDateObject = function isDateObject(val) {
6306
+ return val instanceof Date;
6307
+ };
6308
+
6309
+ var formatDate = function formatDate(date) {
6310
+ var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'yyyy-MM-dd';
6311
+
6312
+ // 处理多种输入类型
6313
+ if (!date) return '';
6314
+
6315
+ // 如果是时间戳,转成日期对象
6316
+ if (typeof date === 'number') {
6317
+ date = new Date(date);
6318
+ }
6319
+ // 如果是字符串,转成日期对象
6320
+ if (typeof date === 'string') {
6321
+ date = new Date(date);
6322
+ }
6323
+
6324
+ // 调用toDate进一步验证和转换
6325
+ date = toDate(date);
6326
+ if (!date) return '';
6327
+
6328
+ // 兼容大写和小写的格式标记
6329
+ // 将大写的YYYY/MM/DD/HH/mm/ss转换为小写的yyyy/mm/dd/hh/mm/ss
6330
+ var lowercaseFormat = format.replace(/YYYY/g, 'yyyy').replace(/D/g, 'd');
6331
+
6332
+ // 使用fecha库进行格式化,支持中文配置
6333
+ var str = fecha.format(date, lowercaseFormat, getSettings());
6334
+ return str;
6335
+ };
6336
+
6337
+ var parseDate = function parseDate(string, format) {
6338
+ return fecha.parse(string, format || 'yyyy-MM-dd', getSettings());
6339
+ };
6340
+
6341
+ var getDayCountOfMonth = function getDayCountOfMonth(year, month) {
6342
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
6343
+ return 30;
6344
+ }
6345
+
6346
+ if (month === 1) {
6347
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
6348
+ return 29;
6349
+ } else {
6350
+ return 28;
6351
+ }
6352
+ }
6353
+
6354
+ return 31;
6355
+ };
6356
+
6357
+ var getDayCountOfYear = function getDayCountOfYear(year) {
6358
+ var isLeapYear = year % 400 === 0 || year % 100 !== 0 && year % 4 === 0;
6359
+ return isLeapYear ? 366 : 365;
6360
+ };
6361
+
6362
+ var getFirstDayOfMonth = function getFirstDayOfMonth(date) {
6363
+ var temp = new Date(date.getTime());
6364
+ temp.setDate(1);
6365
+ return temp.getDay();
6366
+ };
6367
+
6368
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
6369
+ // {prev, next} Date should work for Daylight Saving Time
6370
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
6371
+ var prevDate = function prevDate(date) {
6372
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6373
+
6374
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
6375
+ };
6376
+
6377
+ var nextDate = function nextDate(date) {
6378
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6379
+
6380
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
6381
+ };
6382
+
6383
+ var getStartDateOfMonth = function getStartDateOfMonth(year, month) {
6384
+ var result = new Date(year, month, 1);
6385
+ var day = result.getDay();
6386
+
6387
+ if (day === 0) {
6388
+ return prevDate(result, 7);
6389
+ } else {
6390
+ return prevDate(result, day);
6391
+ }
6392
+ };
6393
+
6394
+ var getWeekNumber = function getWeekNumber(date) {
6395
+ // 支持多种输入类型
6396
+ if (!date || !isDate(date)) {
6397
+ date = new Date();
6398
+ }
6399
+ if (typeof date === 'string') {
6400
+ date = new Date(date);
6401
+ }
6402
+
6403
+ // 验证日期有效性
6404
+ if (!isDate(date)) return null;
6405
+
6406
+ var d = new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate()));
6407
+ // 设置为最近的星期四:当前日期 + 4 - 当前星期数
6408
+ // 将星期日的星期数设为7
6409
+ d.setUTCDate(d.getUTCDate() + 4 - (d.getUTCDay() || 7));
6410
+ // 获取当年的第一天
6411
+ var yearStart = new Date(Date.UTC(d.getUTCFullYear(), 0, 1));
6412
+ // 计算到最近的星期四的完整周数
6413
+ var weekNo = Math.ceil(((d - yearStart) / 86400000 + 1) / 7);
6414
+ // 返回周数
6415
+ return weekNo;
6416
+ };
6417
+
6418
+ var getRangeHours = function getRangeHours(ranges) {
6419
+ var hours = [];
6420
+ var disabledHours = [];
6421
+
6422
+ (ranges || []).forEach(function (range) {
6423
+ var value = range.map(function (date) {
6424
+ return date.getHours();
6425
+ });
6426
+
6427
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
6428
+ });
6429
+
6430
+ if (disabledHours.length) {
6431
+ for (var i = 0; i < 24; i++) {
6432
+ hours[i] = disabledHours.indexOf(i) === -1;
6433
+ }
6434
+ } else {
6435
+ for (var _i = 0; _i < 24; _i++) {
6436
+ hours[_i] = false;
6437
+ }
6438
+ }
6439
+
6440
+ return hours;
6441
+ };
6442
+
6443
+ var getPrevMonthLastDays = function getPrevMonthLastDays(date, amount) {
6444
+ if (amount <= 0) return [];
6445
+ var temp = new Date(date.getTime());
6446
+ temp.setDate(0);
6447
+ var lastDay = temp.getDate();
6448
+ return range(amount).map(function (_, index) {
6449
+ return lastDay - (amount - index - 1);
6450
+ });
6451
+ };
6452
+
6453
+ var getMonthDays = function getMonthDays(date) {
6454
+ var temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
6455
+ var days = temp.getDate();
6456
+ return range(days).map(function (_, index) {
6457
+ return index + 1;
6458
+ });
6459
+ };
6460
+
6461
+ function setRangeData(arr, start, end, value) {
6462
+ for (var i = start; i < end; i++) {
6463
+ arr[i] = value;
6464
+ }
6465
+ }
6466
+
6467
+ var getRangeMinutes = function getRangeMinutes(ranges, hour) {
6468
+ var minutes = new Array(60);
6469
+
6470
+ if (ranges.length > 0) {
6471
+ ranges.forEach(function (range) {
6472
+ var start = range[0];
6473
+ var end = range[1];
6474
+ var startHour = start.getHours();
6475
+ var startMinute = start.getMinutes();
6476
+ var endHour = end.getHours();
6477
+ var endMinute = end.getMinutes();
6478
+ if (startHour === hour && endHour !== hour) {
6479
+ setRangeData(minutes, startMinute, 60, true);
6480
+ } else if (startHour === hour && endHour === hour) {
6481
+ setRangeData(minutes, startMinute, endMinute + 1, true);
6482
+ } else if (startHour !== hour && endHour === hour) {
6483
+ setRangeData(minutes, 0, endMinute + 1, true);
6484
+ } else if (startHour < hour && endHour > hour) {
6485
+ setRangeData(minutes, 0, 60, true);
6486
+ }
6487
+ });
6488
+ } else {
6489
+ setRangeData(minutes, 0, 60, true);
6490
+ }
6491
+ return minutes;
6492
+ };
6493
+
6494
+ var range = function range(n) {
6495
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
6496
+ return Array.apply(null, { length: n }).map(function (_, n) {
6497
+ return n;
6498
+ });
6499
+ };
6500
+
6501
+ var modifyDate = function modifyDate(date, y, m, d) {
6502
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
6503
+ };
6504
+
6505
+ var modifyTime = function modifyTime(date, h, m, s) {
6506
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
6507
+ };
6508
+
6509
+ var modifyWithTimeString = function modifyWithTimeString(date, time) {
6510
+ if (date == null || !time) {
6511
+ return date;
6512
+ }
6513
+ time = parseDate(time, 'HH:mm:ss');
6514
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
6515
+ };
6516
+
6517
+ var clearTime = function clearTime(date) {
6518
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
6519
+ };
6520
+
6521
+ var clearMilliseconds = function clearMilliseconds(date) {
6522
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
6523
+ };
6524
+
6525
+ var limitTimeRange = function limitTimeRange(date, ranges) {
6526
+ var format = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'HH:mm:ss';
6527
+
6528
+ // TODO: refactory a more elegant solution
6529
+ if (ranges.length === 0) return date;
6530
+ var normalizeDate = function normalizeDate(date) {
6531
+ return fecha.parse(fecha.format(date, format), format);
6532
+ };
6533
+ var ndate = normalizeDate(date);
6534
+ var nranges = ranges.map(function (range) {
6535
+ return range.map(normalizeDate);
6536
+ });
6537
+ if (nranges.some(function (nrange) {
6538
+ return ndate >= nrange[0] && ndate <= nrange[1];
6539
+ })) return date;
6540
+
6541
+ var minDate = nranges[0][0];
6542
+ var maxDate = nranges[0][0];
6543
+
6544
+ nranges.forEach(function (nrange) {
6545
+ minDate = new Date(Math.min(nrange[0], minDate));
6546
+ maxDate = new Date(Math.max(nrange[1], minDate));
6547
+ });
6548
+
6549
+ var ret = ndate < minDate ? minDate : maxDate;
6550
+ // preserve Year/Month/Date
6551
+ return modifyDate(ret, date.getFullYear(), date.getMonth(), date.getDate());
6552
+ };
6553
+
6554
+ var timeWithinRange = function timeWithinRange(date, selectableRange, format) {
6555
+ var limitedDate = limitTimeRange(date, selectableRange, format);
6556
+ return limitedDate.getTime() === date.getTime();
6557
+ };
6558
+
6559
+ var changeYearMonthAndClampDate = function changeYearMonthAndClampDate(date, year, month) {
6560
+ // clamp date to the number of days in `year`, `month`
6561
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
6562
+ var monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
6563
+ return modifyDate(date, year, month, monthDate);
6564
+ };
6565
+
6566
+ var prevMonth = function prevMonth(date) {
6567
+ var year = date.getFullYear();
6568
+ var month = date.getMonth();
6569
+ return month === 0 ? changeYearMonthAndClampDate(date, year - 1, 11) : changeYearMonthAndClampDate(date, year, month - 1);
6570
+ };
6571
+
6572
+ var nextMonth = function nextMonth(date) {
6573
+ var year = date.getFullYear();
6574
+ var month = date.getMonth();
6575
+ return month === 11 ? changeYearMonthAndClampDate(date, year + 1, 0) : changeYearMonthAndClampDate(date, year, month + 1);
6576
+ };
6577
+
6578
+ var prevYear = function prevYear(date) {
6579
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6580
+
6581
+ var year = date.getFullYear();
6582
+ var month = date.getMonth();
6583
+ return changeYearMonthAndClampDate(date, year - amount, month);
6584
+ };
6585
+
6586
+ var nextYear = function nextYear(date) {
6587
+ var amount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
6588
+
6589
+ var year = date.getFullYear();
6590
+ var month = date.getMonth();
6591
+ return changeYearMonthAndClampDate(date, year + amount, month);
6592
+ };
6593
+
6594
+ var extractDateFormat = function extractDateFormat(format) {
6595
+ return format.replace(/\W?m{1,2}|\W?ZZ/g, '').replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '').trim();
6596
+ };
6597
+
6598
+ var extractTimeFormat = function extractTimeFormat(format) {
6599
+ return format.replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '').trim();
6600
+ };
6601
+
6602
+ var validateRangeInOneMonth = function validateRangeInOneMonth(start, end) {
6603
+ return start.getMonth() === end.getMonth() && start.getFullYear() === end.getFullYear();
6604
+ };
6605
+
6624
6606
  /**
6625
6607
  * 计算两个日期之间的工作日数量(不包括周末和节假日)
6626
6608
  * @param {string} start_date - 开始日期字符串,格式为 "YYYY-MM-DD"
6627
6609
  * @param {string} end_date - 结束日期字符串,格式为 "YYYY-MM-DD"
6628
6610
  * @param {Array<string>} holidays - 假期日期字符串数组,格式为 "YYYY-MM-DD"
6629
6611
  * @returns {number} 工作日数量
6630
- */
6631
- const calculateNetworkDays = function (start_date, end_date, holidays = []) {
6632
- if (typeof start_date !== 'string' || typeof end_date !== 'string') {
6633
- throw new Error(
6634
- "Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'."
6635
- );
6636
- }
6637
-
6638
- const startDateObj = new Date(start_date);
6639
- const endDateObj = new Date(end_date);
6640
-
6641
- if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
6642
- throw new Error(
6643
- "Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'."
6644
- );
6645
- }
6646
-
6647
- if (startDateObj > endDateObj) {
6648
- throw new Error('Start date should be earlier than or equal to end date.');
6649
- }
6650
-
6651
- let workdays = 0;
6652
-
6653
- // Iterate through each day in the date range
6654
- for (
6655
- let currentDate = new Date(startDateObj);
6656
- currentDate <= endDateObj;
6657
- currentDate.setDate(currentDate.getDate() + 1)
6658
- ) {
6659
- // Check if the current day is a weekend (Saturday or Sunday)
6660
- const isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
6661
-
6662
- // Check if the current day is a holiday
6663
- const isHoliday = holidays.some((holiday) => {
6664
- const holidayDate = new Date(holiday);
6665
- return currentDate.toDateString() === holidayDate.toDateString();
6666
- });
6667
-
6668
- // If it's a workday (not a weekend or holiday), increment the workdays count
6669
- if (!isWeekend && !isHoliday) {
6670
- workdays++;
6671
- }
6672
- }
6673
-
6674
- return workdays;
6675
- };
6676
-
6612
+ */
6613
+ var calculateNetworkDays = function calculateNetworkDays(start_date, end_date) {
6614
+ var holidays = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
6615
+
6616
+ if (typeof start_date !== 'string' || typeof end_date !== 'string') {
6617
+ throw new Error("Invalid input. Please provide valid date strings in the format 'YYYY-MM-DD'.");
6618
+ }
6619
+
6620
+ var startDateObj = new Date(start_date);
6621
+ var endDateObj = new Date(end_date);
6622
+
6623
+ if (isNaN(startDateObj.getTime()) || isNaN(endDateObj.getTime())) {
6624
+ throw new Error("Invalid date format. Please provide valid date strings in the format 'YYYY-MM-DD'.");
6625
+ }
6626
+
6627
+ if (startDateObj > endDateObj) {
6628
+ throw new Error('Start date should be earlier than or equal to end date.');
6629
+ }
6630
+
6631
+ var workdays = 0;
6632
+
6633
+ // Iterate through each day in the date range
6634
+
6635
+ var _loop = function _loop(currentDate) {
6636
+ // Check if the current day is a weekend (Saturday or Sunday)
6637
+ var isWeekend = currentDate.getDay() === 0 || currentDate.getDay() === 6;
6638
+
6639
+ // Check if the current day is a holiday
6640
+ var isHoliday = holidays.some(function (holiday) {
6641
+ var holidayDate = new Date(holiday);
6642
+ return currentDate.toDateString() === holidayDate.toDateString();
6643
+ });
6644
+
6645
+ // If it's a workday (not a weekend or holiday), increment the workdays count
6646
+ if (!isWeekend && !isHoliday) {
6647
+ workdays++;
6648
+ }
6649
+ };
6650
+
6651
+ for (var currentDate = new Date(startDateObj); currentDate <= endDateObj; currentDate.setDate(currentDate.getDate() + 1)) {
6652
+ _loop(currentDate);
6653
+ }
6654
+
6655
+ return workdays;
6656
+ };
6657
+
6677
6658
  /**
6678
6659
  * 日期加减天数
6679
6660
  * @param {string} start_date - 起始日期字符串,格式为 "YYYY-MM-DD"
6680
6661
  * @param {number} days - 要加上或减去的天数,正数表示加,负数表示减
6681
6662
  * @returns {string} 结果日期,格式为 "YYYY-MM-DD"
6682
- */
6683
- const dateAddDays = function (start_date, days) {
6684
- if (typeof start_date !== 'string' || !Number.isInteger(days)) {
6685
- throw new Error(
6686
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD' and a valid integer for the number of days."
6687
- );
6688
- }
6689
-
6690
- const startDateObj = new Date(start_date);
6691
- if (isNaN(startDateObj.getTime())) {
6692
- throw new Error(
6693
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
6694
- );
6695
- }
6696
-
6697
- const resultDateObj = new Date(startDateObj);
6698
- resultDateObj.setDate(resultDateObj.getDate() + days);
6699
-
6700
- const resultYear = resultDateObj.getFullYear();
6701
- const resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
6702
- const resultDay = String(resultDateObj.getDate()).padStart(2, '0');
6703
-
6704
- return `${resultYear}-${resultMonth}-${resultDay}`;
6705
- };
6706
-
6663
+ */
6664
+ var dateAddDays = function dateAddDays(start_date, days) {
6665
+ if (typeof start_date !== 'string' || !Number.isInteger(days)) {
6666
+ 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.");
6667
+ }
6668
+
6669
+ var startDateObj = new Date(start_date);
6670
+ if (isNaN(startDateObj.getTime())) {
6671
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6672
+ }
6673
+
6674
+ var resultDateObj = new Date(startDateObj);
6675
+ resultDateObj.setDate(resultDateObj.getDate() + days);
6676
+
6677
+ var resultYear = resultDateObj.getFullYear();
6678
+ var resultMonth = String(resultDateObj.getMonth() + 1).padStart(2, '0');
6679
+ var resultDay = String(resultDateObj.getDate()).padStart(2, '0');
6680
+
6681
+ return resultYear + '-' + resultMonth + '-' + resultDay;
6682
+ };
6683
+
6707
6684
  /**
6708
6685
  * 计算两个日期之间的差值
6709
6686
  * @date 2023年12月14日
@@ -6711,182 +6688,180 @@ const dateAddDays = function (start_date, days) {
6711
6688
  * @param {String} end_date - 结束日期字符串
6712
6689
  * @param {String} unit - 单位:year/month/day
6713
6690
  * @returns {Number} 差值
6714
- */
6715
- const dateDiff = function (start_date, end_date, unit = 'day') {
6716
- // Assuming date strings are in "YYYY-MM-DD" format
6717
- var startDate = new Date(start_date);
6718
- var endDate = new Date(end_date);
6719
-
6720
- // If the date is invalid, return 0
6721
- if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
6722
- return 0;
6723
- }
6724
-
6725
- if (unit === 'year') {
6726
- return endDate.getFullYear() - startDate.getFullYear();
6727
- } else if (unit === 'month') {
6728
- return (
6729
- (endDate.getFullYear() - startDate.getFullYear()) * 12 +
6730
- (endDate.getMonth() - startDate.getMonth())
6731
- );
6732
- } else {
6733
- // Default to day
6734
- var timeDifference = endDate - startDate;
6735
- // Calculate days (86400000 milliseconds per day)
6736
- return Math.floor(timeDifference / 86400000);
6737
- }
6738
- };
6739
-
6691
+ */
6692
+ var dateDiff = function dateDiff(start_date, end_date) {
6693
+ var unit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 'day';
6694
+
6695
+ // Assuming date strings are in "YYYY-MM-DD" format
6696
+ var startDate = new Date(start_date);
6697
+ var endDate = new Date(end_date);
6698
+
6699
+ // If the date is invalid, return 0
6700
+ if (isNaN(startDate.getTime()) || isNaN(endDate.getTime())) {
6701
+ return 0;
6702
+ }
6703
+
6704
+ if (unit === 'year') {
6705
+ return endDate.getFullYear() - startDate.getFullYear();
6706
+ } else if (unit === 'month') {
6707
+ return (endDate.getFullYear() - startDate.getFullYear()) * 12 + (endDate.getMonth() - startDate.getMonth());
6708
+ } else {
6709
+ // Default to day
6710
+ var timeDifference = endDate - startDate;
6711
+ // Calculate days (86400000 milliseconds per day)
6712
+ return Math.floor(timeDifference / 86400000);
6713
+ }
6714
+ };
6715
+
6740
6716
  /**
6741
6717
  * 获取月份中的日期
6742
6718
  * @param {string} date - 日期字符串,格式为 "YYYY-MM-DD"
6743
6719
  * @returns {number} 月份中的日期(1-31)
6744
- */
6745
- const dayOfMonth = function (date) {
6746
- if (typeof date !== 'string') {
6747
- throw new Error(
6748
- "Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'."
6749
- );
6750
- }
6751
-
6752
- const dateObj = new Date(date);
6753
- if (isNaN(dateObj.getTime())) {
6754
- throw new Error(
6755
- "Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'."
6756
- );
6757
- }
6758
-
6759
- return dateObj.getDate();
6760
- };
6761
-
6720
+ */
6721
+ var dayOfMonth = function dayOfMonth(date) {
6722
+ if (typeof date !== 'string') {
6723
+ throw new Error("Invalid input. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6724
+ }
6725
+
6726
+ var dateObj = new Date(date);
6727
+ if (isNaN(dateObj.getTime())) {
6728
+ throw new Error("Invalid date format. Please provide a valid date string in the format 'YYYY-MM-DD'.");
6729
+ }
6730
+
6731
+ return dateObj.getDate();
6732
+ };
6733
+
6762
6734
  /**
6763
6735
  * 获取当前日期
6764
6736
  * @date 2022年5月7日
6765
6737
  * @param {string} format - 日期格式,默认为'YYYY-MM-DD'
6766
6738
  * @returns {string} 当前日期的格式化字符串
6767
- */
6768
- const getCurrentDate = function (format = 'YYYY-MM-DD') {
6769
- return formatDate(new Date(), format);
6770
- };
6771
-
6739
+ */
6740
+ var getCurrentDate = function getCurrentDate() {
6741
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD';
6742
+
6743
+ return formatDate(new Date(), format);
6744
+ };
6745
+
6772
6746
  /**
6773
6747
  * 获取当前日期时间
6774
6748
  * @date 2022年5月7日
6775
6749
  * @param {string} format - 日期时间格式,默认为'YYYY-MM-DD HH:mm:ss'
6776
6750
  * @returns {string} 当前日期时间的格式化字符串
6777
- */
6778
- const getCurrentDateTime = function (format = 'YYYY-MM-DD HH:mm:ss') {
6779
- return formatDate(new Date(), format);
6780
- };
6781
-
6751
+ */
6752
+ var getCurrentDateTime = function getCurrentDateTime() {
6753
+ var format = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'YYYY-MM-DD HH:mm:ss';
6754
+
6755
+ return formatDate(new Date(), format);
6756
+ };
6757
+
6782
6758
  /**
6783
6759
  * 获取小时
6784
6760
  * @date 2022年5月7日
6785
6761
  * @param {Date|string} [date] - 日期对象或日期字符串
6786
6762
  * @returns {number} 小时数(0-23)
6787
- */
6788
- const getHour = function (date) {
6789
- if (!date) {
6790
- return new Date().getHours();
6791
- }
6792
- if (typeof date === 'string') {
6793
- date = new Date(date);
6794
- }
6795
- return date.getHours();
6796
- };
6797
-
6763
+ */
6764
+ var getHour = function getHour(date) {
6765
+ if (!date) {
6766
+ return new Date().getHours();
6767
+ }
6768
+ if (typeof date === 'string') {
6769
+ date = new Date(date);
6770
+ }
6771
+ return date.getHours();
6772
+ };
6773
+
6798
6774
  /**
6799
6775
  * 获取分钟
6800
6776
  * @date 2022年5月7日
6801
6777
  * @param {Date|string} [date] - 日期对象或日期字符串
6802
6778
  * @returns {number} 分钟数(0-59)
6803
- */
6804
- const getMinute = function (date) {
6805
- if (!date) {
6806
- return new Date().getMinutes();
6807
- }
6808
- if (typeof date === 'string') {
6809
- date = new Date(date);
6810
- }
6811
- return date.getMinutes();
6812
- };
6813
-
6779
+ */
6780
+ var getMinute = function getMinute(date) {
6781
+ if (!date) {
6782
+ return new Date().getMinutes();
6783
+ }
6784
+ if (typeof date === 'string') {
6785
+ date = new Date(date);
6786
+ }
6787
+ return date.getMinutes();
6788
+ };
6789
+
6814
6790
  /**
6815
6791
  * 获取月份
6816
6792
  * @date 2022年5月7日
6817
6793
  * @param {Date|string} [date] - 日期对象或日期字符串
6818
6794
  * @returns {number} 月份数(1-12)
6819
- */
6820
- const getMonth = function (date) {
6821
- if (!date) {
6822
- return new Date().getMonth() + 1;
6823
- }
6824
- if (typeof date === 'string') {
6825
- date = new Date(date);
6826
- }
6827
- return date.getMonth() + 1;
6828
- };
6829
-
6795
+ */
6796
+ var getMonth = function getMonth(date) {
6797
+ if (!date) {
6798
+ return new Date().getMonth() + 1;
6799
+ }
6800
+ if (typeof date === 'string') {
6801
+ date = new Date(date);
6802
+ }
6803
+ return date.getMonth() + 1;
6804
+ };
6805
+
6830
6806
  /**
6831
6807
  * 获取秒
6832
6808
  * @date 2022年5月7日
6833
6809
  * @param {Date|string} [date] - 日期对象或日期字符串
6834
6810
  * @returns {number} 秒数(0-59)
6835
- */
6836
- const getSecond = function (date) {
6837
- if (!date) {
6838
- return new Date().getSeconds();
6839
- }
6840
- if (typeof date === 'string') {
6841
- date = new Date(date);
6842
- }
6843
- return date.getSeconds();
6844
- };
6845
-
6811
+ */
6812
+ var getSecond = function getSecond(date) {
6813
+ if (!date) {
6814
+ return new Date().getSeconds();
6815
+ }
6816
+ if (typeof date === 'string') {
6817
+ date = new Date(date);
6818
+ }
6819
+ return date.getSeconds();
6820
+ };
6821
+
6846
6822
  /**
6847
6823
  * 获取星期几
6848
6824
  * @date 2022年5月7日
6849
6825
  * @param {Date|string} [date] - 日期对象或日期字符串
6850
6826
  * @returns {number} 星期几(0-6,0表示星期日)
6851
- */
6852
- const getWeekday = function (date) {
6853
- if (!date) {
6854
- return new Date().getDay();
6855
- }
6856
- if (typeof date === 'string') {
6857
- date = new Date(date);
6858
- }
6859
- return date.getDay();
6860
- };
6861
-
6862
-
6827
+ */
6828
+ var getWeekday = function getWeekday(date) {
6829
+ if (!date) {
6830
+ return new Date().getDay();
6831
+ }
6832
+ if (typeof date === 'string') {
6833
+ date = new Date(date);
6834
+ }
6835
+ return date.getDay();
6836
+ };
6837
+
6863
6838
  /**
6864
6839
  * @desc 获取上午/下午/晚上
6865
6840
  * @author huangbo
6866
6841
  * @date 2022年5月7日
6867
6842
  * @param {String} [time] - 时间
6868
- **/
6869
- const timeCycle = function (time) {
6870
- let hour = 0;
6871
- if (!time) {
6872
- hour = new Date().getHours();
6873
- } else if (typeof time === 'string') {
6874
- // 从时间字符串中提取小时
6875
- const match = time.match(/^(\d{1,2})/);
6876
- if (match) {
6877
- hour = parseInt(match[1], 10);
6878
- }
6879
- } else if (typeof time === 'number') {
6880
- hour = time;
6881
- }
6882
- // 判断时间段
6883
- if (hour >= 5 && hour < 12) {
6884
- return '上午';
6885
- } else if (hour >= 12 && hour < 18) {
6886
- return '下午';
6887
- } else {
6888
- return '晚上';
6889
- }
6843
+ **/
6844
+ var timeCycle = function timeCycle(time) {
6845
+ var hour = 0;
6846
+ if (!time) {
6847
+ hour = new Date().getHours();
6848
+ } else if (typeof time === 'string') {
6849
+ // 从时间字符串中提取小时
6850
+ var match = time.match(/^(\d{1,2})/);
6851
+ if (match) {
6852
+ hour = parseInt(match[1], 10);
6853
+ }
6854
+ } else if (typeof time === 'number') {
6855
+ hour = time;
6856
+ }
6857
+ // 判断时间段
6858
+ if (hour >= 5 && hour < 12) {
6859
+ return '上午';
6860
+ } else if (hour >= 12 && hour < 18) {
6861
+ return '下午';
6862
+ } else {
6863
+ return '晚上';
6864
+ }
6890
6865
  };
6891
6866
 
6892
6867
  /***/ }),