imatrix-ui 0.2.6-up → 0.2.7-up

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 (206) hide show
  1. package/README.md +7 -7
  2. package/index.html +13 -13
  3. package/lib/super-ui.css +1 -1
  4. package/lib/super-ui.js +2724 -1932
  5. package/lib/super-ui.umd.cjs +24 -24
  6. package/package.json +1 -1
  7. package/packages/IntervalSelection/index.js +6 -6
  8. package/packages/IntervalSelection/src/quarterScope.vue +405 -405
  9. package/packages/IntervalSelection/src/sectionDate.vue +475 -475
  10. package/packages/breadcrumb/index.js +6 -6
  11. package/packages/breadcrumb/src/breadcrumb.vue +81 -81
  12. package/packages/department-tree/index.js +6 -6
  13. package/packages/department-tree/src/department-tree.vue +113 -113
  14. package/packages/department-tree-inline/index.js +6 -6
  15. package/packages/department-tree-inline/src/department-multi-tree-inline.vue +472 -472
  16. package/packages/department-tree-inline/src/department-single-tree-inline.vue +340 -340
  17. package/packages/department-tree-inline/src/department-tree-inline.vue +86 -86
  18. package/packages/department-tree-inline/src/department-tree-service.js +344 -344
  19. package/packages/department-tree-inline/src/search-result.vue +235 -235
  20. package/packages/department-user-tree/index.js +6 -6
  21. package/packages/department-user-tree/src/department-user-multiple-tree.vue +129 -129
  22. package/packages/department-user-tree/src/department-user-single-tree.vue +94 -94
  23. package/packages/department-user-tree/src/department-user-tree.vue +114 -114
  24. package/packages/department-user-tree-inline/index.js +9 -9
  25. package/packages/department-user-tree-inline/src/department-user-multiple-tree-inline.vue +731 -731
  26. package/packages/department-user-tree-inline/src/department-user-single-tree-inline.vue +334 -334
  27. package/packages/department-user-tree-inline/src/department-user-tree-inline.vue +87 -87
  28. package/packages/department-user-tree-inline/src/department-user-tree-multi-service.js +309 -309
  29. package/packages/department-user-tree-inline/src/department-user-tree-single-service.js +179 -179
  30. package/packages/department-user-tree-inline/src/search-result.vue +273 -273
  31. package/packages/directives/prevent-reclick.js +22 -22
  32. package/packages/dynamic-source-select/index.js +6 -6
  33. package/packages/dynamic-source-select/src/dynamic-source-select-service.js +106 -106
  34. package/packages/dynamic-source-select/src/dynamic-source-select.vue +675 -675
  35. package/packages/dynamic-source-select/src/events.js +78 -78
  36. package/packages/fs-preview/index.js +6 -6
  37. package/packages/fs-preview/src/fs-preview.vue +287 -287
  38. package/packages/fs-upload/index.js +6 -6
  39. package/packages/fs-upload/src/fs-upload-multi.vue +443 -443
  40. package/packages/fs-upload/src/fs-upload-single.vue +353 -353
  41. package/packages/fs-upload/src/fs-upload.vue +191 -191
  42. package/packages/fs-upload/src/see-big-picture.vue +67 -67
  43. package/packages/fs-upload-list/index.js +6 -6
  44. package/packages/fs-upload-list/src/fs-upload-list.vue +372 -372
  45. package/packages/hamburger/index.js +6 -6
  46. package/packages/hamburger/src/hamburger.vue +40 -40
  47. package/packages/index.js +123 -123
  48. package/packages/multipart-upload/index.js +6 -6
  49. package/packages/multipart-upload/src/index.vue +66 -66
  50. package/packages/multipart-upload/src/multipart-upload-form.vue +377 -377
  51. package/packages/multipart-upload/src/multipart-upload-list.vue +517 -517
  52. package/packages/organization-input/index.js +6 -6
  53. package/packages/organization-input/src/organization-input.vue +583 -583
  54. package/packages/plugins/export-data-new.js +623 -623
  55. package/packages/plugins/export-data.js +431 -431
  56. package/packages/plugins/index.js +15 -15
  57. package/packages/plugins/public-method.js +47 -47
  58. package/packages/remove-department/index.js +6 -6
  59. package/packages/remove-department/src/remove-department.vue +200 -200
  60. package/packages/remove-department/src/remove-dept-service.js +31 -31
  61. package/packages/remove-user/index.js +6 -6
  62. package/packages/remove-user/src/remove-user-service.js +31 -31
  63. package/packages/remove-user/src/remove-user.vue +226 -226
  64. package/packages/remove-workgroup/index.js +6 -6
  65. package/packages/remove-workgroup/src/remove-workgroup-service.js +31 -31
  66. package/packages/remove-workgroup/src/remove-workgroup.vue +183 -183
  67. package/packages/rich-editor/index.js +7 -7
  68. package/packages/rich-editor/index.vue +297 -297
  69. package/packages/rich-editor/langs/zh-Hans.js +438 -438
  70. package/packages/rich-editor/viewer.vue +105 -105
  71. package/packages/scan-code-input/index.js +6 -6
  72. package/packages/scan-code-input/src/events.js +34 -34
  73. package/packages/scan-code-input/src/scan-code-input-colse.vue +140 -140
  74. package/packages/scan-code-input/src/scan-code-input.vue +132 -132
  75. package/packages/secret-info/index.js +7 -7
  76. package/packages/secret-info/index.vue +100 -100
  77. package/packages/super-grid/index.js +7 -7
  78. package/packages/super-grid/src/apis.js +1092 -1092
  79. package/packages/super-grid/src/columns-config.vue +427 -427
  80. package/packages/super-grid/src/custom-formatter.js +394 -394
  81. package/packages/super-grid/src/eventBus.js +2 -2
  82. package/packages/super-grid/src/events.js +56 -56
  83. package/packages/super-grid/src/formValidatorUtil.js +300 -300
  84. package/packages/super-grid/src/formatter.js +196 -196
  85. package/packages/super-grid/src/group-column.vue +99 -99
  86. package/packages/super-grid/src/header-context-menu.vue +82 -82
  87. package/packages/super-grid/src/index-column.vue +69 -69
  88. package/packages/super-grid/src/public-methods.js +30 -30
  89. package/packages/super-grid/src/row-operation.vue +193 -193
  90. package/packages/super-grid/src/search-button.vue +74 -74
  91. package/packages/super-grid/src/search-condition-input.vue +73 -73
  92. package/packages/super-grid/src/search-condition-list.vue +68 -68
  93. package/packages/super-grid/src/search-form-advancedQuery.vue +819 -819
  94. package/packages/super-grid/src/search-form-dialog.vue +77 -77
  95. package/packages/super-grid/src/search-form-item.vue +495 -495
  96. package/packages/super-grid/src/search-form-number.vue +111 -111
  97. package/packages/super-grid/src/search-form-ordinarySearch.vue +239 -239
  98. package/packages/super-grid/src/search-form.vue +762 -762
  99. package/packages/super-grid/src/search-methods.js +592 -592
  100. package/packages/super-grid/src/selection-column.vue +46 -46
  101. package/packages/super-grid/src/store.js +3 -3
  102. package/packages/super-grid/src/super-grid-service.js +728 -728
  103. package/packages/super-grid/src/super-grid.vue +3011 -3011
  104. package/packages/super-grid/src/utils.js +880 -880
  105. package/packages/super-grid/src/view-image-dialog.vue +176 -176
  106. package/packages/super-nine-grid/index.js +7 -7
  107. package/packages/super-nine-grid/src/apis.js +108 -108
  108. package/packages/super-nine-grid/src/custom-formatter.js +73 -73
  109. package/packages/super-nine-grid/src/formatter.js +134 -134
  110. package/packages/super-nine-grid/src/search-form-number.vue +35 -35
  111. package/packages/super-nine-grid/src/search-form.vue +700 -700
  112. package/packages/super-nine-grid/src/search-methods.js +151 -151
  113. package/packages/super-nine-grid/src/store.js +3 -3
  114. package/packages/super-nine-grid/src/super-grid-service.js +107 -107
  115. package/packages/svg-icon/index.js +6 -6
  116. package/packages/svg-icon/src/svg-icon.vue +43 -43
  117. package/packages/utils/date-util.js +292 -292
  118. package/packages/utils/dom.js +227 -227
  119. package/packages/utils/gogocodeTransfer.js +59 -59
  120. package/packages/utils/memory-cache-utils.js +117 -117
  121. package/packages/utils/utils.js +180 -180
  122. package/packages/utils/value-set.js +97 -97
  123. package/packages/valid-code/index.js +7 -7
  124. package/packages/valid-code/src/valid-code.vue +104 -104
  125. package/packages/workflow-button/index.js +6 -6
  126. package/packages/workflow-button/src/workflow-button.vue +550 -550
  127. package/packages/workflow-history-list/index.js +6 -6
  128. package/packages/workflow-history-list/src/api.js +7 -7
  129. package/packages/workflow-history-list/src/workflow-history-list.vue +291 -291
  130. package/packages/workgroup-tree/index.js +6 -6
  131. package/packages/workgroup-tree/src/workgroup-tree.vue +86 -86
  132. package/packages/workgroup-tree-inline/index.js +6 -6
  133. package/packages/workgroup-tree-inline/src/search-result.vue +222 -222
  134. package/packages/workgroup-tree-inline/src/workgroup-tree-inline.vue +516 -516
  135. package/packages/workgroup-tree-inline/src/workgroup-tree-service.js +93 -93
  136. package/packages/workgroup-user-tree/index.js +6 -6
  137. package/packages/workgroup-user-tree/src/workgroup-user-tree.vue +103 -103
  138. package/packages/workgroup-user-tree-inline/index.js +9 -9
  139. package/packages/workgroup-user-tree-inline/src/search-result.vue +266 -266
  140. package/packages/workgroup-user-tree-inline/src/workgroup-tree-inline-service.js +239 -239
  141. package/packages/workgroup-user-tree-inline/src/workgroup-user-tree-inline.vue +657 -657
  142. package/packages/year-range-picker/index.js +6 -6
  143. package/packages/year-range-picker/src/year-range-picker.vue +53 -53
  144. package/src/api/sso-service.js +172 -172
  145. package/src/api/tab.js +36 -36
  146. package/src/api/user-service.js +11 -11
  147. package/src/directives/permission/index.js +13 -13
  148. package/src/directives/permission/permission.js +20 -20
  149. package/src/i18n/langs/cn.js +259 -259
  150. package/src/i18n/langs/en.js +269 -269
  151. package/src/index.js +93 -93
  152. package/src/plugins.js +18 -18
  153. package/src/router/index.js +8 -26
  154. package/src/store/getters.js +15 -15
  155. package/src/store/index.js +19 -19
  156. package/src/store/modules/app.js +54 -54
  157. package/src/store/modules/tab-content.js +36 -36
  158. package/src/store/modules/user.js +285 -285
  159. package/src/utils/auth.js +61 -61
  160. package/src/utils/calculator/calculator-factory-wf.js +558 -558
  161. package/src/utils/calculator/calculator-factory.js +145 -145
  162. package/src/utils/calculator/calculator-util.js +166 -166
  163. package/src/utils/eventBus.js +2 -2
  164. package/src/utils/iconUtils.js +28 -28
  165. package/src/utils/index.js +102 -102
  166. package/src/utils/jump-page-utils.js +824 -824
  167. package/src/utils/menu.js +19 -19
  168. package/src/utils/permission.js +31 -31
  169. package/src/utils/permissionAuth.js +96 -96
  170. package/src/utils/range-selector.js +188 -188
  171. package/src/utils/request.js +269 -269
  172. package/src/utils/restful-interface-utils.js +57 -57
  173. package/src/utils/util.js +703 -703
  174. package/src/utils/validate.js +34 -34
  175. package/src/utils/watermark.js +108 -108
  176. package/src/utils/workflow-util.js +93 -93
  177. package/src/views/404.vue +248 -248
  178. package/src/views/dsc-component/Sidebar/Item.vue +84 -84
  179. package/src/views/dsc-component/Sidebar/Link.vue +38 -38
  180. package/src/views/dsc-component/Sidebar/SidebarItem.vue +198 -198
  181. package/src/views/dsc-component/Sidebar/index.vue +229 -229
  182. package/src/views/dsc-component/tabs/tab-content.vue +203 -203
  183. package/src/views/error-page/401.vue +106 -106
  184. package/src/views/error-page/404.vue +248 -248
  185. package/src/views/layout/EmptyLayout.vue +3 -3
  186. package/src/views/layout/Layout.vue +81 -81
  187. package/src/views/layout/NewLayout.vue +18 -18
  188. package/src/views/layout/components/AppMain.vue +39 -39
  189. package/src/views/layout/components/Breadcrumb/index.vue +158 -158
  190. package/src/views/layout/components/Menubar/Item.vue +79 -79
  191. package/src/views/layout/components/Menubar/Link.vue +38 -38
  192. package/src/views/layout/components/Menubar/index.vue +210 -210
  193. package/src/views/layout/components/Sidebar/Item.vue +53 -53
  194. package/src/views/layout/components/Sidebar/Link.vue +38 -38
  195. package/src/views/layout/components/Sidebar/index.vue +141 -141
  196. package/src/views/layout/components/iframe-page.vue +38 -38
  197. package/src/views/layout/components/index.js +4 -4
  198. package/src/views/layout/components/tabs/tab-content.vue +207 -207
  199. package/src/views/layout/mixin/ResizeHandler.js +41 -41
  200. package/src/views/layout/tab-content-iframe-index.vue +38 -38
  201. package/src/views/layout/tab-content-index.vue +93 -93
  202. package/src/views/login/authredirect.vue +10 -10
  203. package/src/views/login/index.vue +296 -296
  204. package/src/views/login/update-password.vue +243 -243
  205. package/src/views/redirect/index.vue +14 -14
  206. package/src/views/wf-history/tache-subprocess-history.vue +45 -45
@@ -1,292 +1,292 @@
1
- import fecha from 'element-ui/src/utils/date';
2
- import { t } from 'element-ui/src/locale';
3
-
4
- const weeks = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
5
- const months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
6
-
7
- const newArray = function(start, end) {
8
- let result = [];
9
- for (let i = start; i <= end; i++) {
10
- result.push(i);
11
- }
12
- return result;
13
- };
14
-
15
- export const getI18nSettings = () => {
16
- return {
17
- dayNamesShort: weeks.map(week => t(`el.datepicker.weeks.${ week }`)),
18
- dayNames: weeks.map(week => t(`el.datepicker.weeks.${ week }`)),
19
- monthNamesShort: months.map(month => t(`el.datepicker.months.${ month }`)),
20
- monthNames: months.map((month, index) => t(`el.datepicker.month${ index + 1 }`)),
21
- amPm: ['am', 'pm']
22
- };
23
- };
24
-
25
- export const toDate = function(date) {
26
- return isDate(date) ? new Date(date) : null;
27
- };
28
-
29
- export const isDate = function(date) {
30
- if (date === null || date === undefined) return false;
31
- if (isNaN(new Date(date).getTime())) return false;
32
- if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
33
- return true;
34
- };
35
-
36
- export const isDateObject = function(val) {
37
- return val instanceof Date;
38
- };
39
-
40
- export const formatDate = function(date, format) {
41
- date = toDate(date);
42
- if (!date) return '';
43
- return fecha.format(date, format || 'yyyy-MM-dd', getI18nSettings());
44
- };
45
-
46
- export const parseDate = function(string, format) {
47
- return fecha.parse(string, format || 'yyyy-MM-dd', getI18nSettings());
48
- };
49
-
50
- export const getDayCountOfMonth = function(year, month) {
51
- if (month === 3 || month === 5 || month === 8 || month === 10) {
52
- return 30;
53
- }
54
-
55
- if (month === 1) {
56
- if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
57
- return 29;
58
- } else {
59
- return 28;
60
- }
61
- }
62
-
63
- return 31;
64
- };
65
-
66
- export const getDayCountOfYear = function(year) {
67
- const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
68
- return isLeapYear ? 366 : 365;
69
- };
70
-
71
- export const getFirstDayOfMonth = function(date) {
72
- const temp = new Date(date.getTime());
73
- temp.setDate(1);
74
- return temp.getDay();
75
- };
76
-
77
- // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
78
- // {prev, next} Date should work for Daylight Saving Time
79
- // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
80
- export const prevDate = function(date, amount = 1) {
81
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
82
- };
83
-
84
- export const nextDate = function(date, amount = 1) {
85
- return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
86
- };
87
-
88
- export const getStartDateOfMonth = function(year, month) {
89
- const result = new Date(year, month, 1);
90
- const day = result.getDay();
91
-
92
- if (day === 0) {
93
- return prevDate(result, 7);
94
- } else {
95
- return prevDate(result, day);
96
- }
97
- };
98
-
99
- export const getWeekNumber = function(src) {
100
- if (!isDate(src)) return null;
101
- const date = new Date(src.getTime());
102
- date.setHours(0, 0, 0, 0);
103
- // Thursday in current week decides the year.
104
- date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
105
- // January 4 is always in week 1.
106
- const week1 = new Date(date.getFullYear(), 0, 4);
107
- // Adjust to Thursday in week 1 and count number of weeks from date to week 1.
108
- // Rounding should be fine for Daylight Saving Time. Its shift should never be more than 12 hours.
109
- return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
110
- };
111
-
112
- export const getRangeHours = function(ranges) {
113
- const hours = [];
114
- let disabledHours = [];
115
-
116
- (ranges || []).forEach(range => {
117
- const value = range.map(date => date.getHours());
118
-
119
- disabledHours = disabledHours.concat(newArray(value[0], value[1]));
120
- });
121
-
122
- if (disabledHours.length) {
123
- for (let i = 0; i < 24; i++) {
124
- hours[i] = disabledHours.indexOf(i) === -1;
125
- }
126
- } else {
127
- for (let i = 0; i < 24; i++) {
128
- hours[i] = false;
129
- }
130
- }
131
-
132
- return hours;
133
- };
134
-
135
- export const getPrevMonthLastDays = (date, amount) => {
136
- if (amount <= 0) return [];
137
- const temp = new Date(date.getTime());
138
- temp.setDate(0);
139
- const lastDay = temp.getDate();
140
- return range(amount).map((_, index) => lastDay - (amount - index - 1));
141
- };
142
-
143
- export const getMonthDays = (date) => {
144
- const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
145
- const days = temp.getDate();
146
- return range(days).map((_, index) => index + 1);
147
- };
148
-
149
- function setRangeData(arr, start, end, value) {
150
- for (let i = start; i < end; i++) {
151
- arr[i] = value;
152
- }
153
- }
154
-
155
- export const getRangeMinutes = function(ranges, hour) {
156
- const minutes = new Array(60);
157
-
158
- if (ranges.length > 0) {
159
- ranges.forEach(range => {
160
- const start = range[0];
161
- const end = range[1];
162
- const startHour = start.getHours();
163
- const startMinute = start.getMinutes();
164
- const endHour = end.getHours();
165
- const endMinute = end.getMinutes();
166
- if (startHour === hour && endHour !== hour) {
167
- setRangeData(minutes, startMinute, 60, true);
168
- } else if (startHour === hour && endHour === hour) {
169
- setRangeData(minutes, startMinute, endMinute + 1, true);
170
- } else if (startHour !== hour && endHour === hour) {
171
- setRangeData(minutes, 0, endMinute + 1, true);
172
- } else if (startHour < hour && endHour > hour) {
173
- setRangeData(minutes, 0, 60, true);
174
- }
175
- });
176
- } else {
177
- setRangeData(minutes, 0, 60, true);
178
- }
179
- return minutes;
180
- };
181
-
182
- export const range = function(n) {
183
- // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
184
- return Array.apply(null, {length: n}).map((_, n) => n);
185
- };
186
-
187
- export const modifyDate = function(date, y, m, d) {
188
- return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
189
- };
190
-
191
- export const modifyTime = function(date, h, m, s) {
192
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
193
- };
194
-
195
- export const modifyWithTimeString = (date, time) => {
196
- if (date == null || !time) {
197
- return date;
198
- }
199
- time = parseDate(time, 'HH:mm:ss');
200
- return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
201
- };
202
-
203
- export const clearTime = function(date) {
204
- return new Date(date.getFullYear(), date.getMonth(), date.getDate());
205
- };
206
-
207
- export const clearMilliseconds = function(date) {
208
- return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
209
- };
210
-
211
- export const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
212
- // TODO: refactory a more elegant solution
213
- if (ranges.length === 0) return date;
214
- const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
215
- const ndate = normalizeDate(date);
216
- const nranges = ranges.map(range => range.map(normalizeDate));
217
- if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
218
-
219
- let minDate = nranges[0][0];
220
- let maxDate = nranges[0][0];
221
-
222
- nranges.forEach(nrange => {
223
- minDate = new Date(Math.min(nrange[0], minDate));
224
- maxDate = new Date(Math.max(nrange[1], minDate));
225
- });
226
-
227
- const ret = ndate < minDate ? minDate : maxDate;
228
- // preserve Year/Month/Date
229
- return modifyDate(
230
- ret,
231
- date.getFullYear(),
232
- date.getMonth(),
233
- date.getDate()
234
- );
235
- };
236
-
237
- export const timeWithinRange = function(date, selectableRange, format) {
238
- const limitedDate = limitTimeRange(date, selectableRange, format);
239
- return limitedDate.getTime() === date.getTime();
240
- };
241
-
242
- export const changeYearMonthAndClampDate = function(date, year, month) {
243
- // clamp date to the number of days in `year`, `month`
244
- // eg: (2010-1-31, 2010, 2) => 2010-2-28
245
- const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
246
- return modifyDate(date, year, month, monthDate);
247
- };
248
-
249
- export const prevMonth = function(date) {
250
- const year = date.getFullYear();
251
- const month = date.getMonth();
252
- return month === 0
253
- ? changeYearMonthAndClampDate(date, year - 1, 11)
254
- : changeYearMonthAndClampDate(date, year, month - 1);
255
- };
256
-
257
- export const nextMonth = function(date) {
258
- const year = date.getFullYear();
259
- const month = date.getMonth();
260
- return month === 11
261
- ? changeYearMonthAndClampDate(date, year + 1, 0)
262
- : changeYearMonthAndClampDate(date, year, month + 1);
263
- };
264
-
265
- export const prevYear = function(date, amount = 1) {
266
- const year = date.getFullYear();
267
- const month = date.getMonth();
268
- return changeYearMonthAndClampDate(date, year - amount, month);
269
- };
270
-
271
- export const nextYear = function(date, amount = 1) {
272
- const year = date.getFullYear();
273
- const month = date.getMonth();
274
- return changeYearMonthAndClampDate(date, year + amount, month);
275
- };
276
-
277
- export const extractDateFormat = function(format) {
278
- return format
279
- .replace(/\W?m{1,2}|\W?ZZ/g, '')
280
- .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
281
- .trim();
282
- };
283
-
284
- export const extractTimeFormat = function(format) {
285
- return format
286
- .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
287
- .trim();
288
- };
289
-
290
- export const validateRangeInOneMonth = function(start, end) {
291
- return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
292
- };
1
+ import fecha from 'element-ui/src/utils/date';
2
+ import { t } from 'element-ui/src/locale';
3
+
4
+ const weeks = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
5
+ const months = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec'];
6
+
7
+ const newArray = function(start, end) {
8
+ let result = [];
9
+ for (let i = start; i <= end; i++) {
10
+ result.push(i);
11
+ }
12
+ return result;
13
+ };
14
+
15
+ export const getI18nSettings = () => {
16
+ return {
17
+ dayNamesShort: weeks.map(week => t(`el.datepicker.weeks.${ week }`)),
18
+ dayNames: weeks.map(week => t(`el.datepicker.weeks.${ week }`)),
19
+ monthNamesShort: months.map(month => t(`el.datepicker.months.${ month }`)),
20
+ monthNames: months.map((month, index) => t(`el.datepicker.month${ index + 1 }`)),
21
+ amPm: ['am', 'pm']
22
+ };
23
+ };
24
+
25
+ export const toDate = function(date) {
26
+ return isDate(date) ? new Date(date) : null;
27
+ };
28
+
29
+ export const isDate = function(date) {
30
+ if (date === null || date === undefined) return false;
31
+ if (isNaN(new Date(date).getTime())) return false;
32
+ if (Array.isArray(date)) return false; // deal with `new Date([ new Date() ]) -> new Date()`
33
+ return true;
34
+ };
35
+
36
+ export const isDateObject = function(val) {
37
+ return val instanceof Date;
38
+ };
39
+
40
+ export const formatDate = function(date, format) {
41
+ date = toDate(date);
42
+ if (!date) return '';
43
+ return fecha.format(date, format || 'yyyy-MM-dd', getI18nSettings());
44
+ };
45
+
46
+ export const parseDate = function(string, format) {
47
+ return fecha.parse(string, format || 'yyyy-MM-dd', getI18nSettings());
48
+ };
49
+
50
+ export const getDayCountOfMonth = function(year, month) {
51
+ if (month === 3 || month === 5 || month === 8 || month === 10) {
52
+ return 30;
53
+ }
54
+
55
+ if (month === 1) {
56
+ if (year % 4 === 0 && year % 100 !== 0 || year % 400 === 0) {
57
+ return 29;
58
+ } else {
59
+ return 28;
60
+ }
61
+ }
62
+
63
+ return 31;
64
+ };
65
+
66
+ export const getDayCountOfYear = function(year) {
67
+ const isLeapYear = year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
68
+ return isLeapYear ? 366 : 365;
69
+ };
70
+
71
+ export const getFirstDayOfMonth = function(date) {
72
+ const temp = new Date(date.getTime());
73
+ temp.setDate(1);
74
+ return temp.getDay();
75
+ };
76
+
77
+ // see: https://stackoverflow.com/questions/3674539/incrementing-a-date-in-javascript
78
+ // {prev, next} Date should work for Daylight Saving Time
79
+ // Adding 24 * 60 * 60 * 1000 does not work in the above scenario
80
+ export const prevDate = function(date, amount = 1) {
81
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() - amount);
82
+ };
83
+
84
+ export const nextDate = function(date, amount = 1) {
85
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate() + amount);
86
+ };
87
+
88
+ export const getStartDateOfMonth = function(year, month) {
89
+ const result = new Date(year, month, 1);
90
+ const day = result.getDay();
91
+
92
+ if (day === 0) {
93
+ return prevDate(result, 7);
94
+ } else {
95
+ return prevDate(result, day);
96
+ }
97
+ };
98
+
99
+ export const getWeekNumber = function(src) {
100
+ if (!isDate(src)) return null;
101
+ const date = new Date(src.getTime());
102
+ date.setHours(0, 0, 0, 0);
103
+ // Thursday in current week decides the year.
104
+ date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);
105
+ // January 4 is always in week 1.
106
+ const week1 = new Date(date.getFullYear(), 0, 4);
107
+ // Adjust to Thursday in week 1 and count number of weeks from date to week 1.
108
+ // Rounding should be fine for Daylight Saving Time. Its shift should never be more than 12 hours.
109
+ return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000 - 3 + (week1.getDay() + 6) % 7) / 7);
110
+ };
111
+
112
+ export const getRangeHours = function(ranges) {
113
+ const hours = [];
114
+ let disabledHours = [];
115
+
116
+ (ranges || []).forEach(range => {
117
+ const value = range.map(date => date.getHours());
118
+
119
+ disabledHours = disabledHours.concat(newArray(value[0], value[1]));
120
+ });
121
+
122
+ if (disabledHours.length) {
123
+ for (let i = 0; i < 24; i++) {
124
+ hours[i] = disabledHours.indexOf(i) === -1;
125
+ }
126
+ } else {
127
+ for (let i = 0; i < 24; i++) {
128
+ hours[i] = false;
129
+ }
130
+ }
131
+
132
+ return hours;
133
+ };
134
+
135
+ export const getPrevMonthLastDays = (date, amount) => {
136
+ if (amount <= 0) return [];
137
+ const temp = new Date(date.getTime());
138
+ temp.setDate(0);
139
+ const lastDay = temp.getDate();
140
+ return range(amount).map((_, index) => lastDay - (amount - index - 1));
141
+ };
142
+
143
+ export const getMonthDays = (date) => {
144
+ const temp = new Date(date.getFullYear(), date.getMonth() + 1, 0);
145
+ const days = temp.getDate();
146
+ return range(days).map((_, index) => index + 1);
147
+ };
148
+
149
+ function setRangeData(arr, start, end, value) {
150
+ for (let i = start; i < end; i++) {
151
+ arr[i] = value;
152
+ }
153
+ }
154
+
155
+ export const getRangeMinutes = function(ranges, hour) {
156
+ const minutes = new Array(60);
157
+
158
+ if (ranges.length > 0) {
159
+ ranges.forEach(range => {
160
+ const start = range[0];
161
+ const end = range[1];
162
+ const startHour = start.getHours();
163
+ const startMinute = start.getMinutes();
164
+ const endHour = end.getHours();
165
+ const endMinute = end.getMinutes();
166
+ if (startHour === hour && endHour !== hour) {
167
+ setRangeData(minutes, startMinute, 60, true);
168
+ } else if (startHour === hour && endHour === hour) {
169
+ setRangeData(minutes, startMinute, endMinute + 1, true);
170
+ } else if (startHour !== hour && endHour === hour) {
171
+ setRangeData(minutes, 0, endMinute + 1, true);
172
+ } else if (startHour < hour && endHour > hour) {
173
+ setRangeData(minutes, 0, 60, true);
174
+ }
175
+ });
176
+ } else {
177
+ setRangeData(minutes, 0, 60, true);
178
+ }
179
+ return minutes;
180
+ };
181
+
182
+ export const range = function(n) {
183
+ // see https://stackoverflow.com/questions/3746725/create-a-javascript-array-containing-1-n
184
+ return Array.apply(null, {length: n}).map((_, n) => n);
185
+ };
186
+
187
+ export const modifyDate = function(date, y, m, d) {
188
+ return new Date(y, m, d, date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds());
189
+ };
190
+
191
+ export const modifyTime = function(date, h, m, s) {
192
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), h, m, s, date.getMilliseconds());
193
+ };
194
+
195
+ export const modifyWithTimeString = (date, time) => {
196
+ if (date == null || !time) {
197
+ return date;
198
+ }
199
+ time = parseDate(time, 'HH:mm:ss');
200
+ return modifyTime(date, time.getHours(), time.getMinutes(), time.getSeconds());
201
+ };
202
+
203
+ export const clearTime = function(date) {
204
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate());
205
+ };
206
+
207
+ export const clearMilliseconds = function(date) {
208
+ return new Date(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), 0);
209
+ };
210
+
211
+ export const limitTimeRange = function(date, ranges, format = 'HH:mm:ss') {
212
+ // TODO: refactory a more elegant solution
213
+ if (ranges.length === 0) return date;
214
+ const normalizeDate = date => fecha.parse(fecha.format(date, format), format);
215
+ const ndate = normalizeDate(date);
216
+ const nranges = ranges.map(range => range.map(normalizeDate));
217
+ if (nranges.some(nrange => ndate >= nrange[0] && ndate <= nrange[1])) return date;
218
+
219
+ let minDate = nranges[0][0];
220
+ let maxDate = nranges[0][0];
221
+
222
+ nranges.forEach(nrange => {
223
+ minDate = new Date(Math.min(nrange[0], minDate));
224
+ maxDate = new Date(Math.max(nrange[1], minDate));
225
+ });
226
+
227
+ const ret = ndate < minDate ? minDate : maxDate;
228
+ // preserve Year/Month/Date
229
+ return modifyDate(
230
+ ret,
231
+ date.getFullYear(),
232
+ date.getMonth(),
233
+ date.getDate()
234
+ );
235
+ };
236
+
237
+ export const timeWithinRange = function(date, selectableRange, format) {
238
+ const limitedDate = limitTimeRange(date, selectableRange, format);
239
+ return limitedDate.getTime() === date.getTime();
240
+ };
241
+
242
+ export const changeYearMonthAndClampDate = function(date, year, month) {
243
+ // clamp date to the number of days in `year`, `month`
244
+ // eg: (2010-1-31, 2010, 2) => 2010-2-28
245
+ const monthDate = Math.min(date.getDate(), getDayCountOfMonth(year, month));
246
+ return modifyDate(date, year, month, monthDate);
247
+ };
248
+
249
+ export const prevMonth = function(date) {
250
+ const year = date.getFullYear();
251
+ const month = date.getMonth();
252
+ return month === 0
253
+ ? changeYearMonthAndClampDate(date, year - 1, 11)
254
+ : changeYearMonthAndClampDate(date, year, month - 1);
255
+ };
256
+
257
+ export const nextMonth = function(date) {
258
+ const year = date.getFullYear();
259
+ const month = date.getMonth();
260
+ return month === 11
261
+ ? changeYearMonthAndClampDate(date, year + 1, 0)
262
+ : changeYearMonthAndClampDate(date, year, month + 1);
263
+ };
264
+
265
+ export const prevYear = function(date, amount = 1) {
266
+ const year = date.getFullYear();
267
+ const month = date.getMonth();
268
+ return changeYearMonthAndClampDate(date, year - amount, month);
269
+ };
270
+
271
+ export const nextYear = function(date, amount = 1) {
272
+ const year = date.getFullYear();
273
+ const month = date.getMonth();
274
+ return changeYearMonthAndClampDate(date, year + amount, month);
275
+ };
276
+
277
+ export const extractDateFormat = function(format) {
278
+ return format
279
+ .replace(/\W?m{1,2}|\W?ZZ/g, '')
280
+ .replace(/\W?h{1,2}|\W?s{1,3}|\W?a/gi, '')
281
+ .trim();
282
+ };
283
+
284
+ export const extractTimeFormat = function(format) {
285
+ return format
286
+ .replace(/\W?D{1,2}|\W?Do|\W?d{1,4}|\W?M{1,4}|\W?y{2,4}/g, '')
287
+ .trim();
288
+ };
289
+
290
+ export const validateRangeInOneMonth = function(start, end) {
291
+ return (start.getMonth() === end.getMonth()) && (start.getFullYear() === end.getFullYear());
292
+ };