iov-design 2.15.59 → 2.15.61

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 (250) hide show
  1. package/README.md +148 -148
  2. package/lib/alert.js +24 -105
  3. package/lib/aside.js +24 -34
  4. package/lib/autocomplete.js +36 -240
  5. package/lib/avatar.js +21 -20
  6. package/lib/backtop.js +27 -52
  7. package/lib/badge.js +30 -58
  8. package/lib/breadcrumb-item.js +24 -53
  9. package/lib/breadcrumb.js +24 -37
  10. package/lib/button-group.js +24 -29
  11. package/lib/button.js +38 -60
  12. package/lib/calendar.js +29 -146
  13. package/lib/card.js +24 -51
  14. package/lib/carousel-item.js +30 -68
  15. package/lib/carousel.js +27 -159
  16. package/lib/cascader-panel.js +41 -64
  17. package/lib/cascader.js +37 -470
  18. package/lib/checkbox-button.js +28 -164
  19. package/lib/checkbox-group.js +24 -37
  20. package/lib/checkbox.js +35 -189
  21. package/lib/col.js +1 -0
  22. package/lib/collapse-item.js +27 -125
  23. package/lib/collapse.js +24 -37
  24. package/lib/color-picker.js +104 -424
  25. package/lib/container.js +24 -34
  26. package/lib/date-picker.js +126 -1981
  27. package/lib/descriptions-item.js +1 -0
  28. package/lib/descriptions.js +1 -0
  29. package/lib/dialog.js +24 -137
  30. package/lib/divider.js +29 -64
  31. package/lib/drawer.js +24 -139
  32. package/lib/dropdown-item.js +27 -45
  33. package/lib/dropdown-menu.js +24 -51
  34. package/lib/dropdown.js +21 -20
  35. package/lib/empty.js +24 -61
  36. package/lib/footer.js +24 -34
  37. package/lib/form-item.js +42 -128
  38. package/lib/form.js +27 -40
  39. package/lib/header.js +24 -34
  40. package/lib/icon.js +24 -29
  41. package/lib/image.js +36 -220
  42. package/lib/index.js +1 -1
  43. package/lib/infinite-scroll.js +1 -0
  44. package/lib/input-number.js +30 -163
  45. package/lib/input.js +42 -274
  46. package/lib/iov-design.common.js +1638 -11132
  47. package/lib/link.js +33 -55
  48. package/lib/loading.js +24 -77
  49. package/lib/locale/format.js +10 -10
  50. package/lib/main.js +24 -29
  51. package/lib/menu-item-group.js +24 -40
  52. package/lib/menu-item.js +27 -83
  53. package/lib/menu.js +21 -20
  54. package/lib/message-box.js +24 -321
  55. package/lib/message.js +30 -82
  56. package/lib/mixins/migrating.js +20 -20
  57. package/lib/notification.js +24 -109
  58. package/lib/option-group.js +24 -50
  59. package/lib/option.js +27 -76
  60. package/lib/page-header.js +24 -56
  61. package/lib/pagination.js +24 -97
  62. package/lib/popconfirm.js +24 -97
  63. package/lib/popover.js +24 -89
  64. package/lib/progress.js +30 -133
  65. package/lib/radio-button.js +29 -111
  66. package/lib/radio-group.js +24 -39
  67. package/lib/radio.js +36 -152
  68. package/lib/rate.js +24 -94
  69. package/lib/result.js +72 -187
  70. package/lib/row.js +1 -0
  71. package/lib/scrollbar.js +1 -0
  72. package/lib/select.js +48 -637
  73. package/lib/skeleton-item.js +36 -68
  74. package/lib/skeleton.js +28 -70
  75. package/lib/slider.js +36 -267
  76. package/lib/spinner.js +24 -51
  77. package/lib/statistic.js +24 -76
  78. package/lib/step.js +29 -118
  79. package/lib/steps.js +27 -40
  80. package/lib/submenu.js +21 -20
  81. package/lib/switch.js +24 -130
  82. package/lib/tab-pane.js +24 -52
  83. package/lib/table-column.js +1 -0
  84. package/lib/table.js +93 -633
  85. package/lib/tabs.js +34 -49
  86. package/lib/tag.js +22 -21
  87. package/lib/theme-chalk/base.css +1 -1
  88. package/lib/theme-chalk/button.css +1 -1
  89. package/lib/theme-chalk/calendar.css +1 -1
  90. package/lib/theme-chalk/cascader-panel.css +1 -1
  91. package/lib/theme-chalk/cascader.css +1 -1
  92. package/lib/theme-chalk/dropdown.css +1 -1
  93. package/lib/theme-chalk/index.css +1 -1
  94. package/lib/theme-chalk/iovfont.css +1 -1
  95. package/lib/theme-chalk/link.css +1 -1
  96. package/lib/theme-chalk/message-box.css +1 -1
  97. package/lib/theme-chalk/pagination.css +1 -1
  98. package/lib/theme-chalk/radio.css +1 -1
  99. package/lib/theme-chalk/select.css +1 -1
  100. package/lib/theme-chalk/table-column.css +1 -1
  101. package/lib/theme-chalk/table.css +1 -1
  102. package/lib/theme-chalk/tabs.css +1 -1
  103. package/lib/theme-chalk/tag.css +1 -1
  104. package/lib/theme-chalk/transfer.css +1 -1
  105. package/lib/time-picker.js +58 -820
  106. package/lib/time-select.js +42 -303
  107. package/lib/timeline-item.js +29 -75
  108. package/lib/timeline.js +21 -20
  109. package/lib/tooltip.js +1 -0
  110. package/lib/transfer.js +36 -299
  111. package/lib/tree.js +54 -243
  112. package/lib/upload.js +86 -654
  113. package/lib/utils/clickoutside.js +7 -7
  114. package/lib/utils/vue-popper.js +7 -7
  115. package/package.json +154 -154
  116. package/packages/autocomplete/src/autocomplete-suggestions.vue +76 -76
  117. package/packages/autocomplete/src/autocomplete.vue +285 -285
  118. package/packages/button/src/button.vue +90 -90
  119. package/packages/calendar/src/date-table.vue +200 -200
  120. package/packages/calendar/src/main.vue +280 -280
  121. package/packages/carousel/src/item.vue +138 -138
  122. package/packages/carousel/src/main.vue +315 -315
  123. package/packages/cascader/src/cascader.vue +776 -776
  124. package/packages/cascader-panel/src/cascader-menu.vue +138 -138
  125. package/packages/cascader-panel/src/cascader-node.vue +246 -246
  126. package/packages/cascader-panel/src/cascader-panel.vue +391 -391
  127. package/packages/cascader-panel/src/node.js +166 -166
  128. package/packages/cascader-panel/src/store.js +58 -58
  129. package/packages/checkbox/src/checkbox-button.vue +199 -199
  130. package/packages/checkbox/src/checkbox-group.vue +49 -49
  131. package/packages/checkbox/src/checkbox.vue +225 -225
  132. package/packages/collapse/src/collapse-item.vue +114 -114
  133. package/packages/color-picker/src/components/picker-dropdown.vue +121 -121
  134. package/packages/color-picker/src/main.vue +188 -188
  135. package/packages/date-picker/src/basic/date-table.vue +441 -441
  136. package/packages/date-picker/src/basic/month-table.vue +269 -269
  137. package/packages/date-picker/src/basic/time-spinner.vue +304 -304
  138. package/packages/date-picker/src/basic/year-table.vue +111 -111
  139. package/packages/date-picker/src/panel/date-range.vue +680 -680
  140. package/packages/date-picker/src/panel/date.vue +609 -609
  141. package/packages/date-picker/src/panel/month-range.vue +289 -289
  142. package/packages/date-picker/src/panel/time-range.vue +248 -248
  143. package/packages/date-picker/src/panel/time-select.vue +178 -178
  144. package/packages/date-picker/src/panel/time.vue +186 -186
  145. package/packages/date-picker/src/picker.vue +967 -967
  146. package/packages/descriptions/src/index.js +180 -180
  147. package/packages/dialog/src/component.vue +262 -262
  148. package/packages/drawer/src/main.vue +205 -205
  149. package/packages/dropdown/src/dropdown-item.vue +37 -37
  150. package/packages/dropdown/src/dropdown-menu.vue +63 -63
  151. package/packages/dropdown/src/dropdown.vue +293 -293
  152. package/packages/empty/src/index.vue +70 -70
  153. package/packages/form/src/form-item.vue +324 -324
  154. package/packages/form/src/form.vue +182 -182
  155. package/packages/image/src/image-viewer.vue +330 -330
  156. package/packages/image/src/main.vue +249 -249
  157. package/packages/infinite-scroll/src/main.js +150 -150
  158. package/packages/input/src/input.vue +477 -477
  159. package/packages/input-number/src/input-number.vue +283 -283
  160. package/packages/link/src/main.vue +2 -0
  161. package/packages/loading/src/directive.js +133 -133
  162. package/packages/loading/src/index.js +106 -106
  163. package/packages/menu/src/menu-item.vue +112 -112
  164. package/packages/menu/src/menu.vue +325 -325
  165. package/packages/menu/src/submenu.vue +349 -349
  166. package/packages/message/src/main.js +91 -91
  167. package/packages/message-box/src/main.js +216 -216
  168. package/packages/message-box/src/main.vue +333 -333
  169. package/packages/notification/src/main.js +94 -94
  170. package/packages/page-header/src/main.vue +30 -30
  171. package/packages/pagination/src/pagination.js +390 -390
  172. package/packages/popconfirm/src/main.vue +104 -104
  173. package/packages/popover/src/main.vue +239 -239
  174. package/packages/radio/src/radio-button.vue +115 -115
  175. package/packages/radio/src/radio-group.vue +115 -115
  176. package/packages/radio/src/radio.vue +148 -148
  177. package/packages/rate/src/main.vue +348 -348
  178. package/packages/scrollbar/src/bar.js +92 -92
  179. package/packages/scrollbar/src/main.js +130 -130
  180. package/packages/select/src/option-group.vue +60 -60
  181. package/packages/select/src/option.vue +171 -171
  182. package/packages/select/src/select-dropdown.vue +74 -74
  183. package/packages/select/src/select.vue +979 -979
  184. package/packages/slider/src/button.vue +238 -238
  185. package/packages/slider/src/main.vue +427 -427
  186. package/packages/statistic/src/main.vue +204 -204
  187. package/packages/steps/src/steps.vue +68 -68
  188. package/packages/switch/src/component.vue +182 -182
  189. package/packages/table/src/config.js +153 -153
  190. package/packages/table/src/filter-panel.vue +194 -194
  191. package/packages/table/src/store/current.js +76 -76
  192. package/packages/table/src/store/helper.js +41 -41
  193. package/packages/table/src/store/index.js +147 -147
  194. package/packages/table/src/store/watcher.js +502 -502
  195. package/packages/table/src/table-body.js +469 -469
  196. package/packages/table/src/table-column.js +328 -328
  197. package/packages/table/src/table-header.js +571 -571
  198. package/packages/table/src/table-layout.js +249 -249
  199. package/packages/table/src/table-row.js +101 -101
  200. package/packages/table/src/table.vue +740 -740
  201. package/packages/table/src/util.js +273 -273
  202. package/packages/tabs/src/tab-bar.vue +57 -57
  203. package/packages/tabs/src/tab-nav.vue +294 -294
  204. package/packages/tabs/src/tabs.vue +201 -201
  205. package/packages/tag/src/tag.vue +1 -1
  206. package/packages/theme-chalk/src/button.scss +416 -416
  207. package/packages/theme-chalk/src/cascader.scss +252 -252
  208. package/packages/theme-chalk/src/checkbox.scss +419 -419
  209. package/packages/theme-chalk/src/common/var.scss +795 -816
  210. package/packages/theme-chalk/src/form.scss +201 -201
  211. package/packages/theme-chalk/src/input.scss +591 -591
  212. package/packages/theme-chalk/src/iovfont.scss +803 -784
  213. package/packages/theme-chalk/src/link.scss +36 -19
  214. package/packages/theme-chalk/src/message-box.scss +207 -207
  215. package/packages/theme-chalk/src/mixins/_button.scss +136 -136
  216. package/packages/theme-chalk/src/mixins/mixins.scss +190 -190
  217. package/packages/theme-chalk/src/radio-button.scss +115 -115
  218. package/packages/theme-chalk/src/radio.scss +1 -0
  219. package/packages/theme-chalk/src/select.scss +270 -270
  220. package/packages/theme-chalk/src/table.scss +1 -2
  221. package/packages/theme-chalk/src/tabs.scss +755 -750
  222. package/packages/theme-chalk/src/tag.scss +4 -4
  223. package/packages/theme-chalk/src/upload.scss +568 -568
  224. package/packages/tooltip/src/main.js +242 -242
  225. package/packages/transfer/src/main.vue +231 -231
  226. package/packages/transfer/src/transfer-panel.vue +251 -251
  227. package/packages/tree/src/model/node.js +484 -484
  228. package/packages/tree/src/tree-node.vue +279 -279
  229. package/packages/tree/src/tree.vue +496 -496
  230. package/packages/upload/src/index.vue +420 -420
  231. package/packages/upload/src/upload-file.vue +98 -98
  232. package/packages/upload/src/upload-list.vue +115 -115
  233. package/packages/upload/src/upload-picture.vue +98 -98
  234. package/packages/upload/src/upload.vue +231 -231
  235. package/packages/upload/src/utils.js +31 -31
  236. package/src/directives/repeat-click.js +26 -26
  237. package/src/index.js +259 -259
  238. package/src/locale/format.js +46 -46
  239. package/src/locale/index.js +48 -48
  240. package/src/locale/lang/lo-LA.js +126 -126
  241. package/src/mixins/locale.js +9 -9
  242. package/src/mixins/migrating.js +54 -54
  243. package/src/transitions/collapse-transition.js +77 -77
  244. package/src/utils/clickoutside.js +76 -76
  245. package/src/utils/date-util.js +282 -282
  246. package/src/utils/popup/index.js +218 -218
  247. package/src/utils/popup/popup-manager.js +194 -194
  248. package/src/utils/util.js +245 -245
  249. package/src/utils/vdom.js +5 -5
  250. package/src/utils/vue-popper.js +198 -198
@@ -1,441 +1,441 @@
1
- <template>
2
- <table
3
- cellspacing="0"
4
- cellpadding="0"
5
- class="el-date-table"
6
- @click="handleClick"
7
- @mousemove="handleMouseMove"
8
- :class="{ 'is-week-mode': selectionMode === 'week' }">
9
- <tbody>
10
- <tr>
11
- <th v-if="showWeekNumber">{{ t('el.datepicker.week') }}</th>
12
- <th v-for="(week, key) in WEEKS" :key="key">{{ t('el.datepicker.weeks.' + week) }}</th>
13
- </tr>
14
- <tr
15
- class="el-date-table__row"
16
- v-for="(row, key) in rows"
17
- :class="{ current: isWeekActive(row[1]) }"
18
- :key="key">
19
- <td
20
- v-for="(cell, key) in row"
21
- :class="getCellClasses(cell)"
22
- :key="key">
23
- <div>
24
- <span>
25
- {{ cell.text }}
26
- </span>
27
- </div>
28
- </td>
29
- </tr>
30
- </tbody>
31
- </table>
32
- </template>
33
-
34
- <script>
35
- import { getFirstDayOfMonth, getDayCountOfMonth, getWeekNumber, getStartDateOfMonth, prevDate, nextDate, isDate, clearTime as _clearTime} from 'iov-design/src/utils/date-util';
36
- import Locale from 'iov-design/src/mixins/locale';
37
- import { arrayFindIndex, arrayFind, coerceTruthyValueToArray } from 'iov-design/src/utils/util';
38
-
39
- const WEEKS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
40
- const getDateTimestamp = function(time) {
41
- if (typeof time === 'number' || typeof time === 'string') {
42
- return _clearTime(new Date(time)).getTime();
43
- } else if (time instanceof Date) {
44
- return _clearTime(time).getTime();
45
- } else {
46
- return NaN;
47
- }
48
- };
49
-
50
- // remove the first element that satisfies `pred` from arr
51
- // return a new array if modification occurs
52
- // return the original array otherwise
53
- const removeFromArray = function(arr, pred) {
54
- const idx = typeof pred === 'function' ? arrayFindIndex(arr, pred) : arr.indexOf(pred);
55
- return idx >= 0 ? [...arr.slice(0, idx), ...arr.slice(idx + 1)] : arr;
56
- };
57
-
58
- export default {
59
- mixins: [Locale],
60
-
61
- props: {
62
- firstDayOfWeek: {
63
- default: 7,
64
- type: Number,
65
- validator: val => val >= 1 && val <= 7
66
- },
67
-
68
- value: {},
69
-
70
- defaultValue: {
71
- validator(val) {
72
- // either: null, valid Date object, Array of valid Date objects
73
- return val === null || isDate(val) || (Array.isArray(val) && val.every(isDate));
74
- }
75
- },
76
-
77
- date: {},
78
-
79
- selectionMode: {
80
- default: 'day'
81
- },
82
-
83
- showWeekNumber: {
84
- type: Boolean,
85
- default: false
86
- },
87
-
88
- disabledDate: {},
89
-
90
- cellClassName: {},
91
-
92
- minDate: {},
93
-
94
- maxDate: {},
95
-
96
- rangeState: {
97
- default() {
98
- return {
99
- endDate: null,
100
- selecting: false
101
- };
102
- }
103
- }
104
- },
105
-
106
- computed: {
107
- offsetDay() {
108
- const week = this.firstDayOfWeek;
109
- // 周日为界限,左右偏移的天数,3217654 例如周一就是 -1,目的是调整前两行日期的位置
110
- return week > 3 ? 7 - week : -week;
111
- },
112
-
113
- WEEKS() {
114
- const week = this.firstDayOfWeek;
115
- return WEEKS.concat(WEEKS).slice(week, week + 7);
116
- },
117
-
118
- year() {
119
- return this.date.getFullYear();
120
- },
121
-
122
- month() {
123
- return this.date.getMonth();
124
- },
125
-
126
- startDate() {
127
- return getStartDateOfMonth(this.year, this.month);
128
- },
129
-
130
- rows() {
131
- // TODO: refactory rows / getCellClasses
132
- const date = new Date(this.year, this.month, 1);
133
- let day = getFirstDayOfMonth(date); // day of first day
134
- const dateCountOfMonth = getDayCountOfMonth(date.getFullYear(), date.getMonth());
135
- const dateCountOfLastMonth = getDayCountOfMonth(date.getFullYear(), (date.getMonth() === 0 ? 11 : date.getMonth() - 1));
136
-
137
- day = (day === 0 ? 7 : day);
138
-
139
- const offset = this.offsetDay;
140
- const rows = this.tableRows;
141
- let count = 1;
142
-
143
- const startDate = this.startDate;
144
- const disabledDate = this.disabledDate;
145
- const cellClassName = this.cellClassName;
146
- const selectedDate = this.selectionMode === 'dates' ? coerceTruthyValueToArray(this.value) : [];
147
- const now = getDateTimestamp(new Date());
148
-
149
- for (let i = 0; i < 6; i++) {
150
- const row = rows[i];
151
-
152
- if (this.showWeekNumber) {
153
- if (!row[0]) {
154
- row[0] = { type: 'week', text: getWeekNumber(nextDate(startDate, i * 7 + 1)) };
155
- }
156
- }
157
-
158
- for (let j = 0; j < 7; j++) {
159
- let cell = row[this.showWeekNumber ? j + 1 : j];
160
- if (!cell) {
161
- cell = { row: i, column: j, type: 'normal', inRange: false, start: false, end: false };
162
- }
163
-
164
- cell.type = 'normal';
165
-
166
- const index = i * 7 + j;
167
- const time = nextDate(startDate, index - offset).getTime();
168
- cell.inRange = time >= getDateTimestamp(this.minDate) && time <= getDateTimestamp(this.maxDate);
169
- cell.start = this.minDate && time === getDateTimestamp(this.minDate);
170
- cell.end = this.maxDate && time === getDateTimestamp(this.maxDate);
171
- const isToday = time === now;
172
-
173
- if (isToday) {
174
- cell.type = 'today';
175
- }
176
-
177
- if (i >= 0 && i <= 1) {
178
- const numberOfDaysFromPreviousMonth = day + offset < 0 ? 7 + day + offset : day + offset;
179
-
180
- if (j + i * 7 >= numberOfDaysFromPreviousMonth) {
181
- cell.text = count++;
182
- } else {
183
- cell.text = dateCountOfLastMonth - (numberOfDaysFromPreviousMonth - j % 7) + 1 + i * 7;
184
- cell.type = 'prev-month';
185
- }
186
- } else {
187
- if (count <= dateCountOfMonth) {
188
- cell.text = count++;
189
- } else {
190
- cell.text = count++ - dateCountOfMonth;
191
- cell.type = 'next-month';
192
- }
193
- }
194
-
195
- let cellDate = new Date(time);
196
- cell.disabled = typeof disabledDate === 'function' && disabledDate(cellDate);
197
- cell.selected = arrayFind(selectedDate, date => date.getTime() === cellDate.getTime());
198
- cell.customClass = typeof cellClassName === 'function' && cellClassName(cellDate);
199
- this.$set(row, this.showWeekNumber ? j + 1 : j, cell);
200
- }
201
-
202
- if (this.selectionMode === 'week') {
203
- const start = this.showWeekNumber ? 1 : 0;
204
- const end = this.showWeekNumber ? 7 : 6;
205
- const isWeekActive = this.isWeekActive(row[start + 1]);
206
-
207
- row[start].inRange = isWeekActive;
208
- row[start].start = isWeekActive;
209
- row[end].inRange = isWeekActive;
210
- row[end].end = isWeekActive;
211
- }
212
- }
213
-
214
- return rows;
215
- }
216
- },
217
-
218
- watch: {
219
- 'rangeState.endDate'(newVal) {
220
- this.markRange(this.minDate, newVal);
221
- },
222
-
223
- minDate(newVal, oldVal) {
224
- if (getDateTimestamp(newVal) !== getDateTimestamp(oldVal)) {
225
- this.markRange(this.minDate, this.maxDate);
226
- }
227
- },
228
-
229
- maxDate(newVal, oldVal) {
230
- if (getDateTimestamp(newVal) !== getDateTimestamp(oldVal)) {
231
- this.markRange(this.minDate, this.maxDate);
232
- }
233
- }
234
- },
235
-
236
- data() {
237
- return {
238
- tableRows: [ [], [], [], [], [], [] ],
239
- lastRow: null,
240
- lastColumn: null
241
- };
242
- },
243
-
244
- methods: {
245
- cellMatchesDate(cell, date) {
246
- const value = new Date(date);
247
- return this.year === value.getFullYear() &&
248
- this.month === value.getMonth() &&
249
- Number(cell.text) === value.getDate();
250
- },
251
-
252
- getCellClasses(cell) {
253
- const selectionMode = this.selectionMode;
254
- const defaultValue = this.defaultValue ? Array.isArray(this.defaultValue) ? this.defaultValue : [this.defaultValue] : [];
255
-
256
- let classes = [];
257
- if ((cell.type === 'normal' || cell.type === 'today') && !cell.disabled) {
258
- classes.push('available');
259
- if (cell.type === 'today') {
260
- classes.push('today');
261
- }
262
- } else {
263
- classes.push(cell.type);
264
- }
265
-
266
- if (cell.type === 'normal' && defaultValue.some(date => this.cellMatchesDate(cell, date))) {
267
- classes.push('default');
268
- }
269
-
270
- if (selectionMode === 'day' && (cell.type === 'normal' || cell.type === 'today') && this.cellMatchesDate(cell, this.value)) {
271
- classes.push('current');
272
- }
273
-
274
- if (cell.inRange && ((cell.type === 'normal' || cell.type === 'today') || this.selectionMode === 'week')) {
275
- classes.push('in-range');
276
-
277
- if (cell.start) {
278
- classes.push('start-date');
279
- }
280
-
281
- if (cell.end) {
282
- classes.push('end-date');
283
- }
284
- }
285
-
286
- if (cell.disabled) {
287
- classes.push('disabled');
288
- }
289
-
290
- if (cell.selected) {
291
- classes.push('selected');
292
- }
293
-
294
- if (cell.customClass) {
295
- classes.push(cell.customClass);
296
- }
297
-
298
- return classes.join(' ');
299
- },
300
-
301
- getDateOfCell(row, column) {
302
- const offsetFromStart = row * 7 + (column - (this.showWeekNumber ? 1 : 0)) - this.offsetDay;
303
- return nextDate(this.startDate, offsetFromStart);
304
- },
305
-
306
- isWeekActive(cell) {
307
- if (this.selectionMode !== 'week') return false;
308
- const newDate = new Date(this.year, this.month, 1);
309
- const year = newDate.getFullYear();
310
- const month = newDate.getMonth();
311
-
312
- if (cell.type === 'prev-month') {
313
- newDate.setMonth(month === 0 ? 11 : month - 1);
314
- newDate.setFullYear(month === 0 ? year - 1 : year);
315
- }
316
-
317
- if (cell.type === 'next-month') {
318
- newDate.setMonth(month === 11 ? 0 : month + 1);
319
- newDate.setFullYear(month === 11 ? year + 1 : year);
320
- }
321
-
322
- newDate.setDate(parseInt(cell.text, 10));
323
-
324
- if (isDate(this.value)) {
325
- const dayOffset = (this.value.getDay() - this.firstDayOfWeek + 7) % 7 - 1;
326
- const weekDate = prevDate(this.value, dayOffset);
327
- return weekDate.getTime() === newDate.getTime();
328
- }
329
- return false;
330
- },
331
-
332
- markRange(minDate, maxDate) {
333
- minDate = getDateTimestamp(minDate);
334
- maxDate = getDateTimestamp(maxDate) || minDate;
335
- [minDate, maxDate] = [Math.min(minDate, maxDate), Math.max(minDate, maxDate)];
336
-
337
- const startDate = this.startDate;
338
- const rows = this.rows;
339
- for (let i = 0, k = rows.length; i < k; i++) {
340
- const row = rows[i];
341
- for (let j = 0, l = row.length; j < l; j++) {
342
- if (this.showWeekNumber && j === 0) continue;
343
-
344
- const cell = row[j];
345
- const index = i * 7 + j + (this.showWeekNumber ? -1 : 0);
346
- const time = nextDate(startDate, index - this.offsetDay).getTime();
347
-
348
- cell.inRange = minDate && time >= minDate && time <= maxDate;
349
- cell.start = minDate && time === minDate;
350
- cell.end = maxDate && time === maxDate;
351
- }
352
- }
353
- },
354
-
355
- handleMouseMove(event) {
356
- if (!this.rangeState.selecting) return;
357
-
358
- let target = event.target;
359
- if (target.tagName === 'SPAN') {
360
- target = target.parentNode.parentNode;
361
- }
362
- if (target.tagName === 'DIV') {
363
- target = target.parentNode;
364
- }
365
- if (target.tagName !== 'TD') return;
366
-
367
- const row = target.parentNode.rowIndex - 1;
368
- const column = target.cellIndex;
369
-
370
- // can not select disabled date
371
- if (this.rows[row][column].disabled) return;
372
-
373
- // only update rangeState when mouse moves to a new cell
374
- // this avoids frequent Date object creation and improves performance
375
- if (row !== this.lastRow || column !== this.lastColumn) {
376
- this.lastRow = row;
377
- this.lastColumn = column;
378
- this.$emit('changerange', {
379
- minDate: this.minDate,
380
- maxDate: this.maxDate,
381
- rangeState: {
382
- selecting: true,
383
- endDate: this.getDateOfCell(row, column)
384
- }
385
- });
386
- }
387
- },
388
-
389
- handleClick(event) {
390
- let target = event.target;
391
- if (target.tagName === 'SPAN') {
392
- target = target.parentNode.parentNode;
393
- }
394
- if (target.tagName === 'DIV') {
395
- target = target.parentNode;
396
- }
397
-
398
- if (target.tagName !== 'TD') return;
399
-
400
- const row = target.parentNode.rowIndex - 1;
401
- const column = this.selectionMode === 'week' ? 1 : target.cellIndex;
402
- const cell = this.rows[row][column];
403
-
404
- if (cell.disabled || cell.type === 'week') return;
405
-
406
- const newDate = this.getDateOfCell(row, column);
407
-
408
- if (this.selectionMode === 'range') {
409
- if (!this.rangeState.selecting) {
410
- this.$emit('pick', {minDate: newDate, maxDate: null});
411
- this.rangeState.selecting = true;
412
- } else {
413
- if (newDate >= this.minDate) {
414
- this.$emit('pick', {minDate: this.minDate, maxDate: newDate});
415
- } else {
416
- this.$emit('pick', {minDate: newDate, maxDate: this.minDate});
417
- }
418
- this.rangeState.selecting = false;
419
- }
420
- } else if (this.selectionMode === 'day') {
421
- this.$emit('pick', newDate);
422
- } else if (this.selectionMode === 'week') {
423
- const weekNumber = getWeekNumber(newDate);
424
- const value = newDate.getFullYear() + 'w' + weekNumber;
425
- this.$emit('pick', {
426
- year: newDate.getFullYear(),
427
- week: weekNumber,
428
- value: value,
429
- date: newDate
430
- });
431
- } else if (this.selectionMode === 'dates') {
432
- const value = this.value || [];
433
- const newValue = cell.selected
434
- ? removeFromArray(value, date => date.getTime() === newDate.getTime())
435
- : [...value, newDate];
436
- this.$emit('pick', newValue);
437
- }
438
- }
439
- }
440
- };
441
- </script>
1
+ <template>
2
+ <table
3
+ cellspacing="0"
4
+ cellpadding="0"
5
+ class="el-date-table"
6
+ @click="handleClick"
7
+ @mousemove="handleMouseMove"
8
+ :class="{ 'is-week-mode': selectionMode === 'week' }">
9
+ <tbody>
10
+ <tr>
11
+ <th v-if="showWeekNumber">{{ t('el.datepicker.week') }}</th>
12
+ <th v-for="(week, key) in WEEKS" :key="key">{{ t('el.datepicker.weeks.' + week) }}</th>
13
+ </tr>
14
+ <tr
15
+ class="el-date-table__row"
16
+ v-for="(row, key) in rows"
17
+ :class="{ current: isWeekActive(row[1]) }"
18
+ :key="key">
19
+ <td
20
+ v-for="(cell, key) in row"
21
+ :class="getCellClasses(cell)"
22
+ :key="key">
23
+ <div>
24
+ <span>
25
+ {{ cell.text }}
26
+ </span>
27
+ </div>
28
+ </td>
29
+ </tr>
30
+ </tbody>
31
+ </table>
32
+ </template>
33
+
34
+ <script>
35
+ import { getFirstDayOfMonth, getDayCountOfMonth, getWeekNumber, getStartDateOfMonth, prevDate, nextDate, isDate, clearTime as _clearTime} from 'iov-design/src/utils/date-util';
36
+ import Locale from 'iov-design/src/mixins/locale';
37
+ import { arrayFindIndex, arrayFind, coerceTruthyValueToArray } from 'iov-design/src/utils/util';
38
+
39
+ const WEEKS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
40
+ const getDateTimestamp = function(time) {
41
+ if (typeof time === 'number' || typeof time === 'string') {
42
+ return _clearTime(new Date(time)).getTime();
43
+ } else if (time instanceof Date) {
44
+ return _clearTime(time).getTime();
45
+ } else {
46
+ return NaN;
47
+ }
48
+ };
49
+
50
+ // remove the first element that satisfies `pred` from arr
51
+ // return a new array if modification occurs
52
+ // return the original array otherwise
53
+ const removeFromArray = function(arr, pred) {
54
+ const idx = typeof pred === 'function' ? arrayFindIndex(arr, pred) : arr.indexOf(pred);
55
+ return idx >= 0 ? [...arr.slice(0, idx), ...arr.slice(idx + 1)] : arr;
56
+ };
57
+
58
+ export default {
59
+ mixins: [Locale],
60
+
61
+ props: {
62
+ firstDayOfWeek: {
63
+ default: 7,
64
+ type: Number,
65
+ validator: val => val >= 1 && val <= 7
66
+ },
67
+
68
+ value: {},
69
+
70
+ defaultValue: {
71
+ validator(val) {
72
+ // either: null, valid Date object, Array of valid Date objects
73
+ return val === null || isDate(val) || (Array.isArray(val) && val.every(isDate));
74
+ }
75
+ },
76
+
77
+ date: {},
78
+
79
+ selectionMode: {
80
+ default: 'day'
81
+ },
82
+
83
+ showWeekNumber: {
84
+ type: Boolean,
85
+ default: false
86
+ },
87
+
88
+ disabledDate: {},
89
+
90
+ cellClassName: {},
91
+
92
+ minDate: {},
93
+
94
+ maxDate: {},
95
+
96
+ rangeState: {
97
+ default() {
98
+ return {
99
+ endDate: null,
100
+ selecting: false
101
+ };
102
+ }
103
+ }
104
+ },
105
+
106
+ computed: {
107
+ offsetDay() {
108
+ const week = this.firstDayOfWeek;
109
+ // 周日为界限,左右偏移的天数,3217654 例如周一就是 -1,目的是调整前两行日期的位置
110
+ return week > 3 ? 7 - week : -week;
111
+ },
112
+
113
+ WEEKS() {
114
+ const week = this.firstDayOfWeek;
115
+ return WEEKS.concat(WEEKS).slice(week, week + 7);
116
+ },
117
+
118
+ year() {
119
+ return this.date.getFullYear();
120
+ },
121
+
122
+ month() {
123
+ return this.date.getMonth();
124
+ },
125
+
126
+ startDate() {
127
+ return getStartDateOfMonth(this.year, this.month);
128
+ },
129
+
130
+ rows() {
131
+ // TODO: refactory rows / getCellClasses
132
+ const date = new Date(this.year, this.month, 1);
133
+ let day = getFirstDayOfMonth(date); // day of first day
134
+ const dateCountOfMonth = getDayCountOfMonth(date.getFullYear(), date.getMonth());
135
+ const dateCountOfLastMonth = getDayCountOfMonth(date.getFullYear(), (date.getMonth() === 0 ? 11 : date.getMonth() - 1));
136
+
137
+ day = (day === 0 ? 7 : day);
138
+
139
+ const offset = this.offsetDay;
140
+ const rows = this.tableRows;
141
+ let count = 1;
142
+
143
+ const startDate = this.startDate;
144
+ const disabledDate = this.disabledDate;
145
+ const cellClassName = this.cellClassName;
146
+ const selectedDate = this.selectionMode === 'dates' ? coerceTruthyValueToArray(this.value) : [];
147
+ const now = getDateTimestamp(new Date());
148
+
149
+ for (let i = 0; i < 6; i++) {
150
+ const row = rows[i];
151
+
152
+ if (this.showWeekNumber) {
153
+ if (!row[0]) {
154
+ row[0] = { type: 'week', text: getWeekNumber(nextDate(startDate, i * 7 + 1)) };
155
+ }
156
+ }
157
+
158
+ for (let j = 0; j < 7; j++) {
159
+ let cell = row[this.showWeekNumber ? j + 1 : j];
160
+ if (!cell) {
161
+ cell = { row: i, column: j, type: 'normal', inRange: false, start: false, end: false };
162
+ }
163
+
164
+ cell.type = 'normal';
165
+
166
+ const index = i * 7 + j;
167
+ const time = nextDate(startDate, index - offset).getTime();
168
+ cell.inRange = time >= getDateTimestamp(this.minDate) && time <= getDateTimestamp(this.maxDate);
169
+ cell.start = this.minDate && time === getDateTimestamp(this.minDate);
170
+ cell.end = this.maxDate && time === getDateTimestamp(this.maxDate);
171
+ const isToday = time === now;
172
+
173
+ if (isToday) {
174
+ cell.type = 'today';
175
+ }
176
+
177
+ if (i >= 0 && i <= 1) {
178
+ const numberOfDaysFromPreviousMonth = day + offset < 0 ? 7 + day + offset : day + offset;
179
+
180
+ if (j + i * 7 >= numberOfDaysFromPreviousMonth) {
181
+ cell.text = count++;
182
+ } else {
183
+ cell.text = dateCountOfLastMonth - (numberOfDaysFromPreviousMonth - j % 7) + 1 + i * 7;
184
+ cell.type = 'prev-month';
185
+ }
186
+ } else {
187
+ if (count <= dateCountOfMonth) {
188
+ cell.text = count++;
189
+ } else {
190
+ cell.text = count++ - dateCountOfMonth;
191
+ cell.type = 'next-month';
192
+ }
193
+ }
194
+
195
+ let cellDate = new Date(time);
196
+ cell.disabled = typeof disabledDate === 'function' && disabledDate(cellDate);
197
+ cell.selected = arrayFind(selectedDate, date => date.getTime() === cellDate.getTime());
198
+ cell.customClass = typeof cellClassName === 'function' && cellClassName(cellDate);
199
+ this.$set(row, this.showWeekNumber ? j + 1 : j, cell);
200
+ }
201
+
202
+ if (this.selectionMode === 'week') {
203
+ const start = this.showWeekNumber ? 1 : 0;
204
+ const end = this.showWeekNumber ? 7 : 6;
205
+ const isWeekActive = this.isWeekActive(row[start + 1]);
206
+
207
+ row[start].inRange = isWeekActive;
208
+ row[start].start = isWeekActive;
209
+ row[end].inRange = isWeekActive;
210
+ row[end].end = isWeekActive;
211
+ }
212
+ }
213
+
214
+ return rows;
215
+ }
216
+ },
217
+
218
+ watch: {
219
+ 'rangeState.endDate'(newVal) {
220
+ this.markRange(this.minDate, newVal);
221
+ },
222
+
223
+ minDate(newVal, oldVal) {
224
+ if (getDateTimestamp(newVal) !== getDateTimestamp(oldVal)) {
225
+ this.markRange(this.minDate, this.maxDate);
226
+ }
227
+ },
228
+
229
+ maxDate(newVal, oldVal) {
230
+ if (getDateTimestamp(newVal) !== getDateTimestamp(oldVal)) {
231
+ this.markRange(this.minDate, this.maxDate);
232
+ }
233
+ }
234
+ },
235
+
236
+ data() {
237
+ return {
238
+ tableRows: [ [], [], [], [], [], [] ],
239
+ lastRow: null,
240
+ lastColumn: null
241
+ };
242
+ },
243
+
244
+ methods: {
245
+ cellMatchesDate(cell, date) {
246
+ const value = new Date(date);
247
+ return this.year === value.getFullYear() &&
248
+ this.month === value.getMonth() &&
249
+ Number(cell.text) === value.getDate();
250
+ },
251
+
252
+ getCellClasses(cell) {
253
+ const selectionMode = this.selectionMode;
254
+ const defaultValue = this.defaultValue ? Array.isArray(this.defaultValue) ? this.defaultValue : [this.defaultValue] : [];
255
+
256
+ let classes = [];
257
+ if ((cell.type === 'normal' || cell.type === 'today') && !cell.disabled) {
258
+ classes.push('available');
259
+ if (cell.type === 'today') {
260
+ classes.push('today');
261
+ }
262
+ } else {
263
+ classes.push(cell.type);
264
+ }
265
+
266
+ if (cell.type === 'normal' && defaultValue.some(date => this.cellMatchesDate(cell, date))) {
267
+ classes.push('default');
268
+ }
269
+
270
+ if (selectionMode === 'day' && (cell.type === 'normal' || cell.type === 'today') && this.cellMatchesDate(cell, this.value)) {
271
+ classes.push('current');
272
+ }
273
+
274
+ if (cell.inRange && ((cell.type === 'normal' || cell.type === 'today') || this.selectionMode === 'week')) {
275
+ classes.push('in-range');
276
+
277
+ if (cell.start) {
278
+ classes.push('start-date');
279
+ }
280
+
281
+ if (cell.end) {
282
+ classes.push('end-date');
283
+ }
284
+ }
285
+
286
+ if (cell.disabled) {
287
+ classes.push('disabled');
288
+ }
289
+
290
+ if (cell.selected) {
291
+ classes.push('selected');
292
+ }
293
+
294
+ if (cell.customClass) {
295
+ classes.push(cell.customClass);
296
+ }
297
+
298
+ return classes.join(' ');
299
+ },
300
+
301
+ getDateOfCell(row, column) {
302
+ const offsetFromStart = row * 7 + (column - (this.showWeekNumber ? 1 : 0)) - this.offsetDay;
303
+ return nextDate(this.startDate, offsetFromStart);
304
+ },
305
+
306
+ isWeekActive(cell) {
307
+ if (this.selectionMode !== 'week') return false;
308
+ const newDate = new Date(this.year, this.month, 1);
309
+ const year = newDate.getFullYear();
310
+ const month = newDate.getMonth();
311
+
312
+ if (cell.type === 'prev-month') {
313
+ newDate.setMonth(month === 0 ? 11 : month - 1);
314
+ newDate.setFullYear(month === 0 ? year - 1 : year);
315
+ }
316
+
317
+ if (cell.type === 'next-month') {
318
+ newDate.setMonth(month === 11 ? 0 : month + 1);
319
+ newDate.setFullYear(month === 11 ? year + 1 : year);
320
+ }
321
+
322
+ newDate.setDate(parseInt(cell.text, 10));
323
+
324
+ if (isDate(this.value)) {
325
+ const dayOffset = (this.value.getDay() - this.firstDayOfWeek + 7) % 7 - 1;
326
+ const weekDate = prevDate(this.value, dayOffset);
327
+ return weekDate.getTime() === newDate.getTime();
328
+ }
329
+ return false;
330
+ },
331
+
332
+ markRange(minDate, maxDate) {
333
+ minDate = getDateTimestamp(minDate);
334
+ maxDate = getDateTimestamp(maxDate) || minDate;
335
+ [minDate, maxDate] = [Math.min(minDate, maxDate), Math.max(minDate, maxDate)];
336
+
337
+ const startDate = this.startDate;
338
+ const rows = this.rows;
339
+ for (let i = 0, k = rows.length; i < k; i++) {
340
+ const row = rows[i];
341
+ for (let j = 0, l = row.length; j < l; j++) {
342
+ if (this.showWeekNumber && j === 0) continue;
343
+
344
+ const cell = row[j];
345
+ const index = i * 7 + j + (this.showWeekNumber ? -1 : 0);
346
+ const time = nextDate(startDate, index - this.offsetDay).getTime();
347
+
348
+ cell.inRange = minDate && time >= minDate && time <= maxDate;
349
+ cell.start = minDate && time === minDate;
350
+ cell.end = maxDate && time === maxDate;
351
+ }
352
+ }
353
+ },
354
+
355
+ handleMouseMove(event) {
356
+ if (!this.rangeState.selecting) return;
357
+
358
+ let target = event.target;
359
+ if (target.tagName === 'SPAN') {
360
+ target = target.parentNode.parentNode;
361
+ }
362
+ if (target.tagName === 'DIV') {
363
+ target = target.parentNode;
364
+ }
365
+ if (target.tagName !== 'TD') return;
366
+
367
+ const row = target.parentNode.rowIndex - 1;
368
+ const column = target.cellIndex;
369
+
370
+ // can not select disabled date
371
+ if (this.rows[row][column].disabled) return;
372
+
373
+ // only update rangeState when mouse moves to a new cell
374
+ // this avoids frequent Date object creation and improves performance
375
+ if (row !== this.lastRow || column !== this.lastColumn) {
376
+ this.lastRow = row;
377
+ this.lastColumn = column;
378
+ this.$emit('changerange', {
379
+ minDate: this.minDate,
380
+ maxDate: this.maxDate,
381
+ rangeState: {
382
+ selecting: true,
383
+ endDate: this.getDateOfCell(row, column)
384
+ }
385
+ });
386
+ }
387
+ },
388
+
389
+ handleClick(event) {
390
+ let target = event.target;
391
+ if (target.tagName === 'SPAN') {
392
+ target = target.parentNode.parentNode;
393
+ }
394
+ if (target.tagName === 'DIV') {
395
+ target = target.parentNode;
396
+ }
397
+
398
+ if (target.tagName !== 'TD') return;
399
+
400
+ const row = target.parentNode.rowIndex - 1;
401
+ const column = this.selectionMode === 'week' ? 1 : target.cellIndex;
402
+ const cell = this.rows[row][column];
403
+
404
+ if (cell.disabled || cell.type === 'week') return;
405
+
406
+ const newDate = this.getDateOfCell(row, column);
407
+
408
+ if (this.selectionMode === 'range') {
409
+ if (!this.rangeState.selecting) {
410
+ this.$emit('pick', {minDate: newDate, maxDate: null});
411
+ this.rangeState.selecting = true;
412
+ } else {
413
+ if (newDate >= this.minDate) {
414
+ this.$emit('pick', {minDate: this.minDate, maxDate: newDate});
415
+ } else {
416
+ this.$emit('pick', {minDate: newDate, maxDate: this.minDate});
417
+ }
418
+ this.rangeState.selecting = false;
419
+ }
420
+ } else if (this.selectionMode === 'day') {
421
+ this.$emit('pick', newDate);
422
+ } else if (this.selectionMode === 'week') {
423
+ const weekNumber = getWeekNumber(newDate);
424
+ const value = newDate.getFullYear() + 'w' + weekNumber;
425
+ this.$emit('pick', {
426
+ year: newDate.getFullYear(),
427
+ week: weekNumber,
428
+ value: value,
429
+ date: newDate
430
+ });
431
+ } else if (this.selectionMode === 'dates') {
432
+ const value = this.value || [];
433
+ const newValue = cell.selected
434
+ ? removeFromArray(value, date => date.getTime() === newDate.getTime())
435
+ : [...value, newDate];
436
+ this.$emit('pick', newValue);
437
+ }
438
+ }
439
+ }
440
+ };
441
+ </script>