iov-design 2.15.60 → 2.15.62

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 (242) 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 +1635 -11132
  47. package/lib/link.js +31 -56
  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 +21 -20
  87. package/lib/theme-chalk/autocomplete.css +1 -1
  88. package/lib/theme-chalk/base.css +1 -1
  89. package/lib/theme-chalk/cascader.css +1 -1
  90. package/lib/theme-chalk/date-picker.css +1 -1
  91. package/lib/theme-chalk/index.css +1 -1
  92. package/lib/theme-chalk/input-number.css +1 -1
  93. package/lib/theme-chalk/input.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/select.css +1 -1
  99. package/lib/theme-chalk/slider.css +1 -1
  100. package/lib/theme-chalk/time-picker.css +1 -1
  101. package/lib/theme-chalk/transfer.css +1 -1
  102. package/lib/time-picker.js +58 -820
  103. package/lib/time-select.js +42 -303
  104. package/lib/timeline-item.js +29 -75
  105. package/lib/timeline.js +21 -20
  106. package/lib/tooltip.js +1 -0
  107. package/lib/transfer.js +36 -299
  108. package/lib/tree.js +54 -243
  109. package/lib/upload.js +86 -654
  110. package/lib/utils/clickoutside.js +7 -7
  111. package/lib/utils/vue-popper.js +7 -7
  112. package/package.json +154 -154
  113. package/packages/autocomplete/src/autocomplete-suggestions.vue +76 -76
  114. package/packages/autocomplete/src/autocomplete.vue +285 -285
  115. package/packages/button/src/button.vue +90 -90
  116. package/packages/calendar/src/date-table.vue +200 -200
  117. package/packages/calendar/src/main.vue +280 -280
  118. package/packages/carousel/src/item.vue +138 -138
  119. package/packages/carousel/src/main.vue +315 -315
  120. package/packages/cascader/src/cascader.vue +776 -776
  121. package/packages/cascader-panel/src/cascader-menu.vue +138 -138
  122. package/packages/cascader-panel/src/cascader-node.vue +246 -246
  123. package/packages/cascader-panel/src/cascader-panel.vue +391 -391
  124. package/packages/cascader-panel/src/node.js +166 -166
  125. package/packages/cascader-panel/src/store.js +58 -58
  126. package/packages/checkbox/src/checkbox-button.vue +199 -199
  127. package/packages/checkbox/src/checkbox-group.vue +49 -49
  128. package/packages/checkbox/src/checkbox.vue +225 -225
  129. package/packages/collapse/src/collapse-item.vue +114 -114
  130. package/packages/color-picker/src/components/picker-dropdown.vue +121 -121
  131. package/packages/color-picker/src/main.vue +188 -188
  132. package/packages/date-picker/src/basic/date-table.vue +441 -441
  133. package/packages/date-picker/src/basic/month-table.vue +269 -269
  134. package/packages/date-picker/src/basic/time-spinner.vue +304 -304
  135. package/packages/date-picker/src/basic/year-table.vue +111 -111
  136. package/packages/date-picker/src/panel/date-range.vue +680 -680
  137. package/packages/date-picker/src/panel/date.vue +609 -609
  138. package/packages/date-picker/src/panel/month-range.vue +289 -289
  139. package/packages/date-picker/src/panel/time-range.vue +248 -248
  140. package/packages/date-picker/src/panel/time-select.vue +178 -178
  141. package/packages/date-picker/src/panel/time.vue +186 -186
  142. package/packages/date-picker/src/picker.vue +967 -967
  143. package/packages/descriptions/src/index.js +180 -180
  144. package/packages/dialog/src/component.vue +262 -262
  145. package/packages/drawer/src/main.vue +205 -205
  146. package/packages/dropdown/src/dropdown-item.vue +37 -37
  147. package/packages/dropdown/src/dropdown-menu.vue +63 -63
  148. package/packages/dropdown/src/dropdown.vue +293 -293
  149. package/packages/empty/src/index.vue +70 -70
  150. package/packages/form/src/form-item.vue +324 -324
  151. package/packages/form/src/form.vue +182 -182
  152. package/packages/image/src/image-viewer.vue +330 -330
  153. package/packages/image/src/main.vue +249 -249
  154. package/packages/infinite-scroll/src/main.js +150 -150
  155. package/packages/input/src/input.vue +477 -477
  156. package/packages/input-number/src/input-number.vue +283 -283
  157. package/packages/loading/src/directive.js +133 -133
  158. package/packages/loading/src/index.js +106 -106
  159. package/packages/menu/src/menu-item.vue +112 -112
  160. package/packages/menu/src/menu.vue +325 -325
  161. package/packages/menu/src/submenu.vue +349 -349
  162. package/packages/message/src/main.js +91 -91
  163. package/packages/message-box/src/main.js +216 -216
  164. package/packages/message-box/src/main.vue +333 -333
  165. package/packages/notification/src/main.js +94 -94
  166. package/packages/page-header/src/main.vue +30 -30
  167. package/packages/pagination/src/pagination.js +390 -390
  168. package/packages/popconfirm/src/main.vue +104 -104
  169. package/packages/popover/src/main.vue +239 -239
  170. package/packages/radio/src/radio-button.vue +115 -115
  171. package/packages/radio/src/radio-group.vue +115 -115
  172. package/packages/radio/src/radio.vue +148 -148
  173. package/packages/rate/src/main.vue +348 -348
  174. package/packages/scrollbar/src/bar.js +92 -92
  175. package/packages/scrollbar/src/main.js +130 -130
  176. package/packages/select/src/option-group.vue +60 -60
  177. package/packages/select/src/option.vue +171 -171
  178. package/packages/select/src/select-dropdown.vue +74 -74
  179. package/packages/select/src/select.vue +979 -979
  180. package/packages/slider/src/button.vue +238 -238
  181. package/packages/slider/src/main.vue +427 -427
  182. package/packages/statistic/src/main.vue +204 -204
  183. package/packages/steps/src/steps.vue +68 -68
  184. package/packages/switch/src/component.vue +182 -182
  185. package/packages/table/src/config.js +153 -153
  186. package/packages/table/src/filter-panel.vue +194 -194
  187. package/packages/table/src/store/current.js +76 -76
  188. package/packages/table/src/store/helper.js +41 -41
  189. package/packages/table/src/store/index.js +147 -147
  190. package/packages/table/src/store/watcher.js +502 -502
  191. package/packages/table/src/table-body.js +469 -469
  192. package/packages/table/src/table-column.js +328 -328
  193. package/packages/table/src/table-header.js +571 -571
  194. package/packages/table/src/table-layout.js +249 -249
  195. package/packages/table/src/table-row.js +101 -101
  196. package/packages/table/src/table.vue +740 -740
  197. package/packages/table/src/util.js +273 -273
  198. package/packages/tabs/src/tab-bar.vue +57 -57
  199. package/packages/tabs/src/tab-nav.vue +294 -294
  200. package/packages/tabs/src/tabs.vue +201 -201
  201. package/packages/theme-chalk/src/button.scss +416 -416
  202. package/packages/theme-chalk/src/cascader.scss +252 -252
  203. package/packages/theme-chalk/src/checkbox.scss +419 -419
  204. package/packages/theme-chalk/src/common/var.scss +795 -795
  205. package/packages/theme-chalk/src/form.scss +201 -201
  206. package/packages/theme-chalk/src/input.scss +591 -591
  207. package/packages/theme-chalk/src/iovfont.scss +818 -803
  208. package/packages/theme-chalk/src/link.scss +8 -8
  209. package/packages/theme-chalk/src/message-box.scss +207 -207
  210. package/packages/theme-chalk/src/mixins/_button.scss +136 -136
  211. package/packages/theme-chalk/src/mixins/mixins.scss +190 -190
  212. package/packages/theme-chalk/src/radio-button.scss +115 -115
  213. package/packages/theme-chalk/src/select.scss +270 -270
  214. package/packages/theme-chalk/src/tabs.scss +755 -755
  215. package/packages/theme-chalk/src/upload.scss +568 -568
  216. package/packages/tooltip/src/main.js +242 -242
  217. package/packages/transfer/src/main.vue +231 -231
  218. package/packages/transfer/src/transfer-panel.vue +251 -251
  219. package/packages/tree/src/model/node.js +484 -484
  220. package/packages/tree/src/tree-node.vue +279 -279
  221. package/packages/tree/src/tree.vue +496 -496
  222. package/packages/upload/src/index.vue +420 -420
  223. package/packages/upload/src/upload-file.vue +98 -98
  224. package/packages/upload/src/upload-list.vue +115 -115
  225. package/packages/upload/src/upload-picture.vue +98 -98
  226. package/packages/upload/src/upload.vue +231 -231
  227. package/packages/upload/src/utils.js +31 -31
  228. package/src/directives/repeat-click.js +26 -26
  229. package/src/index.js +259 -259
  230. package/src/locale/format.js +46 -46
  231. package/src/locale/index.js +48 -48
  232. package/src/locale/lang/lo-LA.js +126 -126
  233. package/src/mixins/locale.js +9 -9
  234. package/src/mixins/migrating.js +54 -54
  235. package/src/transitions/collapse-transition.js +77 -77
  236. package/src/utils/clickoutside.js +76 -76
  237. package/src/utils/date-util.js +282 -282
  238. package/src/utils/popup/index.js +218 -218
  239. package/src/utils/popup/popup-manager.js +194 -194
  240. package/src/utils/util.js +245 -245
  241. package/src/utils/vdom.js +5 -5
  242. package/src/utils/vue-popper.js +198 -198
@@ -1,967 +1,967 @@
1
- <template>
2
- <el-input
3
- class="el-date-editor"
4
- :class="'el-date-editor--' + type"
5
- :readonly="!editable || readonly || type === 'dates' || type === 'week' || type === 'years' || type === 'months'"
6
- :disabled="pickerDisabled"
7
- :size="pickerSize"
8
- :name="name"
9
- v-bind="firstInputId"
10
- v-if="!ranged"
11
- v-clickoutside="handleClose"
12
- :placeholder="placeholder"
13
- @focus="handleFocus"
14
- @keydown.native="handleKeydown"
15
- :value="displayValue"
16
- @input="value => userInput = value"
17
- @change="handleChange"
18
- @mouseenter.native="handleMouseEnter"
19
- @mouseleave.native="showClose = false"
20
- :validateEvent="false"
21
- ref="reference">
22
- <template slot="prefixLabel">
23
- <slot name="prefixLabel"></slot>
24
- </template>
25
- <i v-if="!showClose" slot="prefix"
26
- class="el-input__icon"
27
- :class="triggerClass"
28
- @click="handleFocus">
29
- </i>
30
- <i slot="suffix"
31
- class="el-input__icon"
32
- @click="handleClickIcon"
33
- :class="[showClose ? '' + clearIcon + ' el-input__clear' : '']"
34
- v-if="haveTrigger">
35
- </i>
36
- </el-input>
37
- <div
38
- class="el-date-editor el-range-editor el-input__inner"
39
- :class="[
40
- 'el-date-editor--' + type,
41
- pickerSize ? `el-range-editor--${ pickerSize }` : '',
42
- pickerDisabled ? 'is-disabled' : '',
43
- pickerVisible ? 'is-active' : ''
44
- ]"
45
- @click="handleRangeClick"
46
- @mouseenter="handleMouseEnter"
47
- @mouseleave="showClose = false"
48
- @keydown="handleKeydown"
49
- ref="reference"
50
- v-clickoutside="handleClose"
51
- v-else>
52
- <div class="el-input-group__prefix-label" v-if="$slots.prefixLabel">
53
- <slot name="prefixLabel"></slot>
54
- </div>
55
- <input
56
- autocomplete="off"
57
- :placeholder="startPlaceholder"
58
- :value="displayValue && displayValue[0]"
59
- :disabled="pickerDisabled"
60
- v-bind="firstInputId"
61
- :readonly="!editable || readonly"
62
- :name="name && name[0]"
63
- @input="handleStartInput"
64
- @change="handleStartChange"
65
- @focus="handleFocus"
66
- class="el-range-input">
67
- <span v-if="$slots['range-separator']" class="el-range-separator">
68
- <slot name="range-separator"></slot>
69
- </span>
70
- <span v-else-if="rangeSeparator" class="el-range-separator">
71
- {{ rangeSeparator }}
72
- </span>
73
- <span v-else class="el-range-separator">
74
- <i class="iov-icon-arrow-half-right"></i>
75
- </span>
76
- <input
77
- autocomplete="off"
78
- :placeholder="endPlaceholder"
79
- :value="displayValue && displayValue[1]"
80
- :disabled="pickerDisabled"
81
- v-bind="secondInputId"
82
- :readonly="!editable || readonly"
83
- :name="name && name[1]"
84
- @input="handleEndInput"
85
- @change="handleEndChange"
86
- @focus="handleFocus"
87
- class="el-range-input">
88
- <i
89
- @click="handleClickIcon"
90
- :class="[showClose ? '' + clearIcon + ' el-input__clear' : '']"
91
- class="el-input__icon el-range__close-icon">
92
- </i>
93
- <i v-if="!showClose" :class="['el-input__icon', 'el-range__icon', triggerClass]"></i>
94
- </div>
95
- </template>
96
-
97
- <script>
98
- import Vue from 'vue';
99
- import Clickoutside from 'iov-design/src/utils/clickoutside';
100
- import { formatDate, parseDate, isDateObject, getWeekNumber } from 'iov-design/src/utils/date-util';
101
- import Popper from 'iov-design/src/utils/vue-popper';
102
- import Emitter from 'iov-design/src/mixins/emitter';
103
- import ElInput from 'iov-design/packages/input';
104
- import merge from 'iov-design/src/utils/merge';
105
-
106
- const NewPopper = {
107
- props: {
108
- appendToBody: Popper.props.appendToBody,
109
- offset: Popper.props.offset,
110
- boundariesPadding: Popper.props.boundariesPadding,
111
- arrowOffset: Popper.props.arrowOffset,
112
- transformOrigin: Popper.props.transformOrigin
113
- },
114
- methods: Popper.methods,
115
- data() {
116
- return merge({ visibleArrow: true }, Popper.data);
117
- },
118
- beforeDestroy: Popper.beforeDestroy
119
- };
120
-
121
- const DEFAULT_FORMATS = {
122
- date: 'yyyy-MM-dd',
123
- month: 'yyyy-MM',
124
- months: 'yyyy-MM',
125
- datetime: 'yyyy-MM-dd HH:mm:ss',
126
- time: 'HH:mm:ss',
127
- week: 'yyyywWW',
128
- timerange: 'HH:mm:ss',
129
- daterange: 'yyyy-MM-dd',
130
- monthrange: 'yyyy-MM',
131
- datetimerange: 'yyyy-MM-dd HH:mm:ss',
132
- year: 'yyyy',
133
- years: 'yyyy'
134
- };
135
- const HAVE_TRIGGER_TYPES = [
136
- 'date',
137
- 'datetime',
138
- 'time',
139
- 'time-select',
140
- 'week',
141
- 'month',
142
- 'year',
143
- 'daterange',
144
- 'monthrange',
145
- 'timerange',
146
- 'datetimerange',
147
- 'dates',
148
- 'months',
149
- 'years'
150
- ];
151
- const DATE_FORMATTER = function(value, format) {
152
- if (format === 'timestamp') return value.getTime();
153
- return formatDate(value, format);
154
- };
155
- const DATE_PARSER = function(text, format) {
156
- if (format === 'timestamp') return new Date(Number(text));
157
- return parseDate(text, format);
158
- };
159
- const RANGE_FORMATTER = function(value, format) {
160
- if (Array.isArray(value) && value.length === 2) {
161
- const start = value[0];
162
- const end = value[1];
163
-
164
- if (start && end) {
165
- return [DATE_FORMATTER(start, format), DATE_FORMATTER(end, format)];
166
- }
167
- }
168
- return '';
169
- };
170
- const RANGE_PARSER = function(array, format, separator) {
171
- if (!Array.isArray(array)) {
172
- array = array.split(separator);
173
- }
174
- if (array.length === 2) {
175
- const range1 = array[0];
176
- const range2 = array[1];
177
-
178
- return [DATE_PARSER(range1, format), DATE_PARSER(range2, format)];
179
- }
180
- return [];
181
- };
182
- const TYPE_VALUE_RESOLVER_MAP = {
183
- default: {
184
- formatter(value) {
185
- if (!value) return '';
186
- return '' + value;
187
- },
188
- parser(text) {
189
- if (text === undefined || text === '') return null;
190
- return text;
191
- }
192
- },
193
- week: {
194
- formatter(value, format) {
195
- let week = getWeekNumber(value);
196
- let month = value.getMonth();
197
- const trueDate = new Date(value);
198
- if (week === 1 && month === 11) {
199
- trueDate.setHours(0, 0, 0, 0);
200
- trueDate.setDate(trueDate.getDate() + 3 - (trueDate.getDay() + 6) % 7);
201
- }
202
- let date = formatDate(trueDate, format);
203
-
204
- date = /WW/.test(date)
205
- ? date.replace(/WW/, week < 10 ? '0' + week : week)
206
- : date.replace(/W/, week);
207
- return date;
208
- },
209
- parser(text, format) {
210
- // parse as if a normal date
211
- return TYPE_VALUE_RESOLVER_MAP.date.parser(text, format);
212
- }
213
- },
214
- date: {
215
- formatter: DATE_FORMATTER,
216
- parser: DATE_PARSER
217
- },
218
- datetime: {
219
- formatter: DATE_FORMATTER,
220
- parser: DATE_PARSER
221
- },
222
- daterange: {
223
- formatter: RANGE_FORMATTER,
224
- parser: RANGE_PARSER
225
- },
226
- monthrange: {
227
- formatter: RANGE_FORMATTER,
228
- parser: RANGE_PARSER
229
- },
230
- datetimerange: {
231
- formatter: RANGE_FORMATTER,
232
- parser: RANGE_PARSER
233
- },
234
- timerange: {
235
- formatter: RANGE_FORMATTER,
236
- parser: RANGE_PARSER
237
- },
238
- time: {
239
- formatter: DATE_FORMATTER,
240
- parser: DATE_PARSER
241
- },
242
- month: {
243
- formatter: DATE_FORMATTER,
244
- parser: DATE_PARSER
245
- },
246
- year: {
247
- formatter: DATE_FORMATTER,
248
- parser: DATE_PARSER
249
- },
250
- number: {
251
- formatter(value) {
252
- if (!value) return '';
253
- return '' + value;
254
- },
255
- parser(text) {
256
- let result = Number(text);
257
-
258
- if (!isNaN(text)) {
259
- return result;
260
- } else {
261
- return null;
262
- }
263
- }
264
- },
265
- dates: {
266
- formatter(value, format) {
267
- return value.map(date => DATE_FORMATTER(date, format));
268
- },
269
- parser(value, format) {
270
- return (typeof value === 'string' ? value.split(', ') : value)
271
- .map(date => date instanceof Date ? date : DATE_PARSER(date, format));
272
- }
273
- },
274
- months: {
275
- formatter(value, format) {
276
- return value.map(date => DATE_FORMATTER(date, format));
277
- },
278
- parser(value, format) {
279
- return (typeof value === 'string' ? value.split(', ') : value)
280
- .map(date => date instanceof Date ? date : DATE_PARSER(date, format));
281
- }
282
- },
283
- years: {
284
- formatter(value, format) {
285
- return value.map(date => DATE_FORMATTER(date, format));
286
- },
287
- parser(value, format) {
288
- return (typeof value === 'string' ? value.split(', ') : value)
289
- .map(date => date instanceof Date ? date : DATE_PARSER(date, format));
290
- }
291
- }
292
- };
293
- const PLACEMENT_MAP = {
294
- left: 'bottom-start',
295
- center: 'bottom',
296
- right: 'bottom-end'
297
- };
298
-
299
- const parseAsFormatAndType = (value, customFormat, type, rangeSeparator = '-') => {
300
- if (!value) return null;
301
- const parser = (
302
- TYPE_VALUE_RESOLVER_MAP[type] ||
303
- TYPE_VALUE_RESOLVER_MAP['default']
304
- ).parser;
305
- const format = customFormat || DEFAULT_FORMATS[type];
306
- return parser(value, format, rangeSeparator);
307
- };
308
-
309
- const formatAsFormatAndType = (value, customFormat, type) => {
310
- if (!value) return null;
311
- const formatter = (
312
- TYPE_VALUE_RESOLVER_MAP[type] ||
313
- TYPE_VALUE_RESOLVER_MAP['default']
314
- ).formatter;
315
- const format = customFormat || DEFAULT_FORMATS[type];
316
- return formatter(value, format);
317
- };
318
-
319
- /*
320
- * Considers:
321
- * 1. Date object
322
- * 2. date string
323
- * 3. array of 1 or 2
324
- */
325
- const valueEquals = function(a, b) {
326
- // considers Date object and string
327
- const dateEquals = function(a, b) {
328
- const aIsDate = a instanceof Date;
329
- const bIsDate = b instanceof Date;
330
- if (aIsDate && bIsDate) {
331
- return a.getTime() === b.getTime();
332
- }
333
- if (!aIsDate && !bIsDate) {
334
- return a === b;
335
- }
336
- return false;
337
- };
338
-
339
- const aIsArray = a instanceof Array;
340
- const bIsArray = b instanceof Array;
341
- if (aIsArray && bIsArray) {
342
- if (a.length !== b.length) {
343
- return false;
344
- }
345
- return a.every((item, index) => dateEquals(item, b[index]));
346
- }
347
- if (!aIsArray && !bIsArray) {
348
- return dateEquals(a, b);
349
- }
350
- return false;
351
- };
352
-
353
- const isString = function(val) {
354
- return typeof val === 'string' || val instanceof String;
355
- };
356
-
357
- const validator = function(val) {
358
- // either: String, Array of String, null / undefined
359
- return (
360
- val === null ||
361
- val === undefined ||
362
- isString(val) ||
363
- (Array.isArray(val) && val.length === 2 && val.every(isString))
364
- );
365
- };
366
-
367
- export default {
368
- mixins: [Emitter, NewPopper],
369
-
370
- inject: {
371
- elForm: {
372
- default: ''
373
- },
374
- elFormItem: {
375
- default: ''
376
- }
377
- },
378
-
379
- props: {
380
- size: String,
381
- format: String,
382
- valueFormat: String,
383
- readonly: Boolean,
384
- placeholder: String,
385
- startPlaceholder: String,
386
- endPlaceholder: String,
387
- prefixIcon: String,
388
- clearIcon: {
389
- type: String,
390
- default: 'iov-icon-close-mini'
391
- },
392
- name: {
393
- default: '',
394
- validator
395
- },
396
- disabled: Boolean,
397
- clearable: {
398
- type: Boolean,
399
- default: true
400
- },
401
- id: {
402
- default: '',
403
- validator
404
- },
405
- popperClass: String,
406
- editable: {
407
- type: Boolean,
408
- default: true
409
- },
410
- align: {
411
- type: String,
412
- default: 'left'
413
- },
414
- value: {},
415
- defaultValue: {},
416
- defaultTime: {},
417
- rangeSeparator: {
418
- default: ''
419
- },
420
- pickerOptions: {},
421
- unlinkPanels: Boolean,
422
- validateEvent: {
423
- type: Boolean,
424
- default: true
425
- }
426
- },
427
-
428
- components: { ElInput },
429
-
430
- directives: { Clickoutside },
431
-
432
- data() {
433
- return {
434
- pickerVisible: false,
435
- showClose: false,
436
- userInput: null,
437
- valueOnOpen: null, // value when picker opens, used to determine whether to emit change
438
- unwatchPickerOptions: null
439
- };
440
- },
441
-
442
- watch: {
443
- pickerVisible(val) {
444
- if (this.readonly || this.pickerDisabled) return;
445
- if (val) {
446
- this.showPicker();
447
- this.valueOnOpen = Array.isArray(this.value) ? [...this.value] : this.value;
448
- } else {
449
- this.hidePicker();
450
- this.emitChange(this.value);
451
- this.userInput = null;
452
- if (this.validateEvent) {
453
- this.dispatch('ElFormItem', 'el.form.blur');
454
- }
455
- this.$emit('blur', this);
456
- this.blur();
457
- }
458
- },
459
- parsedValue: {
460
- immediate: true,
461
- handler(val) {
462
- if (this.picker) {
463
- this.picker.value = val;
464
- }
465
- }
466
- },
467
- defaultValue(val) {
468
- // NOTE: should eventually move to jsx style picker + panel ?
469
- if (this.picker) {
470
- this.picker.defaultValue = val;
471
- }
472
- },
473
- value(val, oldVal) {
474
- if (!valueEquals(val, oldVal) && !this.pickerVisible && this.validateEvent) {
475
- this.dispatch('ElFormItem', 'el.form.change', val);
476
- }
477
- }
478
- },
479
-
480
- computed: {
481
- ranged() {
482
- return this.type.indexOf('range') > -1;
483
- },
484
-
485
- reference() {
486
- const reference = this.$refs.reference;
487
- return reference.$el || reference;
488
- },
489
-
490
- refInput() {
491
- if (this.reference) {
492
- return [].slice.call(this.reference.querySelectorAll('input'));
493
- }
494
- return [];
495
- },
496
-
497
- valueIsEmpty() {
498
- const val = this.value;
499
- if (Array.isArray(val)) {
500
- for (let i = 0, len = val.length; i < len; i++) {
501
- if (val[i]) {
502
- return false;
503
- }
504
- }
505
- } else {
506
- if (val) {
507
- return false;
508
- }
509
- }
510
- return true;
511
- },
512
-
513
- triggerClass() {
514
- return this.prefixIcon || (this.type.indexOf('time') !== -1 ? 'iov-icon-time' : 'iov-icon-date');
515
- },
516
-
517
- selectionMode() {
518
- if (this.type === 'week') {
519
- return 'week';
520
- } else if (this.type === 'month') {
521
- return 'month';
522
- } else if (this.type === 'year') {
523
- return 'year';
524
- } else if (this.type === 'dates') {
525
- return 'dates';
526
- } else if (this.type === 'months') {
527
- return 'months';
528
- } else if (this.type === 'years') {
529
- return 'years';
530
- }
531
-
532
- return 'day';
533
- },
534
-
535
- haveTrigger() {
536
- if (typeof this.showTrigger !== 'undefined') {
537
- return this.showTrigger;
538
- }
539
- return HAVE_TRIGGER_TYPES.indexOf(this.type) !== -1;
540
- },
541
-
542
- displayValue() {
543
- const formattedValue = formatAsFormatAndType(this.parsedValue, this.format, this.type, this.rangeSeparator);
544
- if (Array.isArray(this.userInput)) {
545
- return [
546
- this.userInput[0] || (formattedValue && formattedValue[0]) || '',
547
- this.userInput[1] || (formattedValue && formattedValue[1]) || ''
548
- ];
549
- } else if (this.userInput !== null) {
550
- return this.userInput;
551
- } else if (formattedValue) {
552
- return (this.type === 'dates' || this.type === 'years' || this.type === 'months')
553
- ? formattedValue.join(', ')
554
- : formattedValue;
555
- } else {
556
- return '';
557
- }
558
- },
559
-
560
- parsedValue() {
561
- if (!this.value) return this.value; // component value is not set
562
- if (this.type === 'time-select') return this.value; // time-select does not require parsing, this might change in next major version
563
-
564
- const valueIsDateObject = isDateObject(this.value) || (Array.isArray(this.value) && this.value.every(isDateObject));
565
- if (valueIsDateObject) {
566
- return this.value;
567
- }
568
-
569
- if (this.valueFormat) {
570
- return parseAsFormatAndType(this.value, this.valueFormat, this.type, this.rangeSeparator) || this.value;
571
- }
572
-
573
- // NOTE: deal with common but incorrect usage, should remove in next major version
574
- // user might provide string / timestamp without value-format, coerce them into date (or array of date)
575
- return Array.isArray(this.value) ? this.value.map(val => new Date(val)) : new Date(this.value);
576
- },
577
-
578
- _elFormItemSize() {
579
- return (this.elFormItem || {}).elFormItemSize;
580
- },
581
-
582
- pickerSize() {
583
- return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size;
584
- },
585
-
586
- pickerDisabled() {
587
- return this.disabled || (this.elForm || {}).disabled;
588
- },
589
-
590
- firstInputId() {
591
- const obj = {};
592
- let id;
593
- if (this.ranged) {
594
- id = this.id && this.id[0];
595
- } else {
596
- id = this.id;
597
- }
598
- if (id) obj.id = id;
599
- return obj;
600
- },
601
-
602
- secondInputId() {
603
- const obj = {};
604
- let id;
605
- if (this.ranged) {
606
- id = this.id && this.id[1];
607
- }
608
- if (id) obj.id = id;
609
- return obj;
610
- }
611
- },
612
-
613
- created() {
614
- // vue-popper
615
- this.popperOptions = {
616
- boundariesPadding: 0,
617
- gpuAcceleration: false
618
- };
619
- this.placement = PLACEMENT_MAP[this.align] || PLACEMENT_MAP.left;
620
-
621
- this.$on('fieldReset', this.handleFieldReset);
622
- },
623
-
624
- methods: {
625
- focus() {
626
- if (!this.ranged) {
627
- this.$refs.reference.focus();
628
- } else {
629
- this.handleFocus();
630
- }
631
- },
632
-
633
- blur() {
634
- this.refInput.forEach(input => input.blur());
635
- },
636
-
637
- // {parse, formatTo} Value deals maps component value with internal Date
638
- parseValue(value) {
639
- const isParsed = isDateObject(value) || (Array.isArray(value) && value.every(isDateObject));
640
- if (this.valueFormat && !isParsed) {
641
- return parseAsFormatAndType(value, this.valueFormat, this.type, this.rangeSeparator) || value;
642
- } else {
643
- return value;
644
- }
645
- },
646
-
647
- formatToValue(date) {
648
- const isFormattable = isDateObject(date) || (Array.isArray(date) && date.every(isDateObject));
649
- if (this.valueFormat && isFormattable) {
650
- return formatAsFormatAndType(date, this.valueFormat, this.type, this.rangeSeparator);
651
- } else {
652
- return date;
653
- }
654
- },
655
-
656
- // {parse, formatTo} String deals with user input
657
- parseString(value) {
658
- const type = Array.isArray(value) ? this.type : this.type.replace('range', '');
659
- return parseAsFormatAndType(value, this.format, type);
660
- },
661
-
662
- formatToString(value) {
663
- const type = Array.isArray(value) ? this.type : this.type.replace('range', '');
664
- return formatAsFormatAndType(value, this.format, type);
665
- },
666
-
667
- handleMouseEnter() {
668
- if (this.readonly || this.pickerDisabled) return;
669
- if (!this.valueIsEmpty && this.clearable) {
670
- this.showClose = true;
671
- }
672
- },
673
-
674
- handleChange() {
675
- if (this.userInput) {
676
- const value = this.parseString(this.displayValue);
677
- if (value) {
678
- this.picker.value = value;
679
- if (this.isValidValue(value)) {
680
- this.emitInput(value);
681
- this.userInput = null;
682
- }
683
- }
684
- }
685
- if (this.userInput === '') {
686
- this.emitInput(null);
687
- this.emitChange(null);
688
- this.userInput = null;
689
- }
690
- },
691
-
692
- handleStartInput(event) {
693
- if (this.userInput) {
694
- this.userInput = [event.target.value, this.userInput[1]];
695
- } else {
696
- this.userInput = [event.target.value, null];
697
- }
698
- },
699
-
700
- handleEndInput(event) {
701
- if (this.userInput) {
702
- this.userInput = [this.userInput[0], event.target.value];
703
- } else {
704
- this.userInput = [null, event.target.value];
705
- }
706
- },
707
-
708
- handleStartChange(event) {
709
- const value = this.parseString(this.userInput && this.userInput[0]);
710
- if (value) {
711
- this.userInput = [this.formatToString(value), this.displayValue[1]];
712
- const newValue = [value, this.picker.value && this.picker.value[1]];
713
- this.picker.value = newValue;
714
- if (this.isValidValue(newValue)) {
715
- this.emitInput(newValue);
716
- this.userInput = null;
717
- }
718
- }
719
- },
720
-
721
- handleEndChange(event) {
722
- const value = this.parseString(this.userInput && this.userInput[1]);
723
- if (value) {
724
- this.userInput = [this.displayValue[0], this.formatToString(value)];
725
- const newValue = [this.picker.value && this.picker.value[0], value];
726
- this.picker.value = newValue;
727
- if (this.isValidValue(newValue)) {
728
- this.emitInput(newValue);
729
- this.userInput = null;
730
- }
731
- }
732
- },
733
-
734
- handleClickIcon(event) {
735
- if (this.readonly || this.pickerDisabled) return;
736
- if (this.showClose) {
737
- this.valueOnOpen = this.value;
738
- event.stopPropagation();
739
- this.emitInput(null);
740
- this.emitChange(null);
741
- this.showClose = false;
742
- if (this.picker && typeof this.picker.handleClear === 'function') {
743
- this.picker.handleClear();
744
- }
745
- } else {
746
- this.pickerVisible = !this.pickerVisible;
747
- }
748
- },
749
-
750
- handleClose() {
751
- if (!this.pickerVisible) return;
752
- this.pickerVisible = false;
753
-
754
- if (this.type === 'dates' || this.type === 'years' || this.type === 'months') {
755
- // restore to former value
756
- const oldValue = parseAsFormatAndType(this.valueOnOpen, this.valueFormat, this.type, this.rangeSeparator) || this.valueOnOpen;
757
- this.emitInput(oldValue);
758
- }
759
- },
760
-
761
- handleFieldReset(initialValue) {
762
- this.userInput = initialValue === '' ? null : initialValue;
763
- },
764
-
765
- handleFocus() {
766
- const type = this.type;
767
-
768
- if (HAVE_TRIGGER_TYPES.indexOf(type) !== -1 && !this.pickerVisible) {
769
- this.pickerVisible = true;
770
- }
771
- this.$emit('focus', this);
772
- },
773
-
774
- handleKeydown(event) {
775
- const keyCode = event.keyCode;
776
-
777
- // ESC
778
- if (keyCode === 27) {
779
- this.pickerVisible = false;
780
- event.stopPropagation();
781
- return;
782
- }
783
-
784
- // Tab
785
- if (keyCode === 9) {
786
- if (!this.ranged) {
787
- this.handleChange();
788
- this.pickerVisible = this.picker.visible = false;
789
- this.blur();
790
- event.stopPropagation();
791
- } else {
792
- // user may change focus between two input
793
- setTimeout(() => {
794
- if (this.refInput.indexOf(document.activeElement) === -1) {
795
- this.pickerVisible = false;
796
- this.blur();
797
- event.stopPropagation();
798
- }
799
- }, 0);
800
- }
801
- return;
802
- }
803
-
804
- // Enter
805
- if (keyCode === 13) {
806
- if (this.userInput === '' || this.isValidValue(this.parseString(this.displayValue))) {
807
- this.handleChange();
808
- this.pickerVisible = this.picker.visible = false;
809
- this.blur();
810
- }
811
- event.stopPropagation();
812
- return;
813
- }
814
-
815
- // if user is typing, do not let picker handle key input
816
- if (this.userInput) {
817
- event.stopPropagation();
818
- return;
819
- }
820
-
821
- // delegate other keys to panel
822
- if (this.picker && this.picker.handleKeydown) {
823
- this.picker.handleKeydown(event);
824
- }
825
- },
826
-
827
- handleRangeClick() {
828
- const type = this.type;
829
-
830
- if (HAVE_TRIGGER_TYPES.indexOf(type) !== -1 && !this.pickerVisible) {
831
- this.pickerVisible = true;
832
- }
833
- this.$emit('focus', this);
834
- },
835
-
836
- hidePicker() {
837
- if (this.picker) {
838
- this.picker.resetView && this.picker.resetView();
839
- this.pickerVisible = this.picker.visible = false;
840
- this.destroyPopper();
841
- }
842
- },
843
-
844
- showPicker() {
845
- if (this.$isServer) return;
846
- if (!this.picker) {
847
- this.mountPicker();
848
- }
849
- this.pickerVisible = this.picker.visible = true;
850
-
851
- this.updatePopper();
852
-
853
- this.picker.value = this.parsedValue;
854
- this.picker.resetView && this.picker.resetView();
855
-
856
- this.$nextTick(() => {
857
- this.picker.adjustSpinners && this.picker.adjustSpinners();
858
- });
859
- },
860
-
861
- mountPicker() {
862
- this.picker = new Vue(this.panel).$mount();
863
- this.picker.defaultValue = this.defaultValue;
864
- this.picker.defaultTime = this.defaultTime;
865
- this.picker.popperClass = this.popperClass;
866
- this.popperElm = this.picker.$el;
867
- this.picker.width = this.reference.getBoundingClientRect().width;
868
- this.picker.showTime = this.type === 'datetime' || this.type === 'datetimerange';
869
- this.picker.selectionMode = this.selectionMode;
870
- this.picker.unlinkPanels = this.unlinkPanels;
871
- this.picker.arrowControl = this.arrowControl || this.timeArrowControl || false;
872
- this.$watch('format', (format) => {
873
- this.picker.format = format;
874
- });
875
-
876
- const updateOptions = () => {
877
- const options = this.pickerOptions;
878
-
879
- if (options && options.selectableRange) {
880
- let ranges = options.selectableRange;
881
- const parser = TYPE_VALUE_RESOLVER_MAP.datetimerange.parser;
882
- const format = DEFAULT_FORMATS.timerange;
883
-
884
- ranges = Array.isArray(ranges) ? ranges : [ranges];
885
- this.picker.selectableRange = ranges.map(range => parser(range, format, this.rangeSeparator));
886
- }
887
-
888
- for (const option in options) {
889
- if (options.hasOwnProperty(option) &&
890
- // 忽略 time-picker 的该配置项
891
- option !== 'selectableRange') {
892
- this.picker[option] = options[option];
893
- }
894
- }
895
-
896
- // main format must prevail over undocumented pickerOptions.format
897
- if (this.format) {
898
- this.picker.format = this.format;
899
- }
900
- };
901
- updateOptions();
902
- this.unwatchPickerOptions = this.$watch('pickerOptions', () => updateOptions(), { deep: true });
903
- this.$el.appendChild(this.picker.$el);
904
- this.picker.resetView && this.picker.resetView();
905
-
906
- this.picker.$on('dodestroy', this.doDestroy);
907
- this.picker.$on('pick', (date = '', visible = false) => {
908
- this.userInput = null;
909
- this.pickerVisible = this.picker.visible = visible;
910
- this.emitInput(date);
911
- this.picker.resetView && this.picker.resetView();
912
- });
913
-
914
- this.picker.$on('select-range', (start, end, pos) => {
915
- if (this.refInput.length === 0) return;
916
- if (!pos || pos === 'min') {
917
- this.refInput[0].setSelectionRange(start, end);
918
- this.refInput[0].focus();
919
- } else if (pos === 'max') {
920
- this.refInput[1].setSelectionRange(start, end);
921
- this.refInput[1].focus();
922
- }
923
- });
924
- },
925
-
926
- unmountPicker() {
927
- if (this.picker) {
928
- this.picker.$destroy();
929
- this.picker.$off();
930
- if (typeof this.unwatchPickerOptions === 'function') {
931
- this.unwatchPickerOptions();
932
- }
933
- this.picker.$el.parentNode.removeChild(this.picker.$el);
934
- }
935
- },
936
-
937
- emitChange(val) {
938
- // determine user real change only
939
- if (!valueEquals(val, this.valueOnOpen)) {
940
- this.$emit('change', val);
941
- this.valueOnOpen = val;
942
- if (this.validateEvent) {
943
- this.dispatch('ElFormItem', 'el.form.change', val);
944
- }
945
- }
946
- },
947
-
948
- emitInput(val) {
949
- const formatted = this.formatToValue(val);
950
- if (!valueEquals(this.value, formatted)) {
951
- this.$emit('input', formatted);
952
- }
953
- },
954
-
955
- isValidValue(value) {
956
- if (!this.picker) {
957
- this.mountPicker();
958
- }
959
- if (this.picker.isValidValue) {
960
- return value && this.picker.isValidValue(value);
961
- } else {
962
- return true;
963
- }
964
- }
965
- }
966
- };
967
- </script>
1
+ <template>
2
+ <el-input
3
+ class="el-date-editor"
4
+ :class="'el-date-editor--' + type"
5
+ :readonly="!editable || readonly || type === 'dates' || type === 'week' || type === 'years' || type === 'months'"
6
+ :disabled="pickerDisabled"
7
+ :size="pickerSize"
8
+ :name="name"
9
+ v-bind="firstInputId"
10
+ v-if="!ranged"
11
+ v-clickoutside="handleClose"
12
+ :placeholder="placeholder"
13
+ @focus="handleFocus"
14
+ @keydown.native="handleKeydown"
15
+ :value="displayValue"
16
+ @input="value => userInput = value"
17
+ @change="handleChange"
18
+ @mouseenter.native="handleMouseEnter"
19
+ @mouseleave.native="showClose = false"
20
+ :validateEvent="false"
21
+ ref="reference">
22
+ <template slot="prefixLabel">
23
+ <slot name="prefixLabel"></slot>
24
+ </template>
25
+ <i v-if="!showClose" slot="prefix"
26
+ class="el-input__icon"
27
+ :class="triggerClass"
28
+ @click="handleFocus">
29
+ </i>
30
+ <i slot="suffix"
31
+ class="el-input__icon"
32
+ @click="handleClickIcon"
33
+ :class="[showClose ? '' + clearIcon + ' el-input__clear' : '']"
34
+ v-if="haveTrigger">
35
+ </i>
36
+ </el-input>
37
+ <div
38
+ class="el-date-editor el-range-editor el-input__inner"
39
+ :class="[
40
+ 'el-date-editor--' + type,
41
+ pickerSize ? `el-range-editor--${ pickerSize }` : '',
42
+ pickerDisabled ? 'is-disabled' : '',
43
+ pickerVisible ? 'is-active' : ''
44
+ ]"
45
+ @click="handleRangeClick"
46
+ @mouseenter="handleMouseEnter"
47
+ @mouseleave="showClose = false"
48
+ @keydown="handleKeydown"
49
+ ref="reference"
50
+ v-clickoutside="handleClose"
51
+ v-else>
52
+ <div class="el-input-group__prefix-label" v-if="$slots.prefixLabel">
53
+ <slot name="prefixLabel"></slot>
54
+ </div>
55
+ <input
56
+ autocomplete="off"
57
+ :placeholder="startPlaceholder"
58
+ :value="displayValue && displayValue[0]"
59
+ :disabled="pickerDisabled"
60
+ v-bind="firstInputId"
61
+ :readonly="!editable || readonly"
62
+ :name="name && name[0]"
63
+ @input="handleStartInput"
64
+ @change="handleStartChange"
65
+ @focus="handleFocus"
66
+ class="el-range-input">
67
+ <span v-if="$slots['range-separator']" class="el-range-separator">
68
+ <slot name="range-separator"></slot>
69
+ </span>
70
+ <span v-else-if="rangeSeparator" class="el-range-separator">
71
+ {{ rangeSeparator }}
72
+ </span>
73
+ <span v-else class="el-range-separator">
74
+ <i class="iov-icon-arrow-half-right"></i>
75
+ </span>
76
+ <input
77
+ autocomplete="off"
78
+ :placeholder="endPlaceholder"
79
+ :value="displayValue && displayValue[1]"
80
+ :disabled="pickerDisabled"
81
+ v-bind="secondInputId"
82
+ :readonly="!editable || readonly"
83
+ :name="name && name[1]"
84
+ @input="handleEndInput"
85
+ @change="handleEndChange"
86
+ @focus="handleFocus"
87
+ class="el-range-input">
88
+ <i
89
+ @click="handleClickIcon"
90
+ :class="[showClose ? '' + clearIcon + ' el-input__clear' : '']"
91
+ class="el-input__icon el-range__close-icon">
92
+ </i>
93
+ <i v-if="!showClose" :class="['el-input__icon', 'el-range__icon', triggerClass]"></i>
94
+ </div>
95
+ </template>
96
+
97
+ <script>
98
+ import Vue from 'vue';
99
+ import Clickoutside from 'iov-design/src/utils/clickoutside';
100
+ import { formatDate, parseDate, isDateObject, getWeekNumber } from 'iov-design/src/utils/date-util';
101
+ import Popper from 'iov-design/src/utils/vue-popper';
102
+ import Emitter from 'iov-design/src/mixins/emitter';
103
+ import ElInput from 'iov-design/packages/input';
104
+ import merge from 'iov-design/src/utils/merge';
105
+
106
+ const NewPopper = {
107
+ props: {
108
+ appendToBody: Popper.props.appendToBody,
109
+ offset: Popper.props.offset,
110
+ boundariesPadding: Popper.props.boundariesPadding,
111
+ arrowOffset: Popper.props.arrowOffset,
112
+ transformOrigin: Popper.props.transformOrigin
113
+ },
114
+ methods: Popper.methods,
115
+ data() {
116
+ return merge({ visibleArrow: true }, Popper.data);
117
+ },
118
+ beforeDestroy: Popper.beforeDestroy
119
+ };
120
+
121
+ const DEFAULT_FORMATS = {
122
+ date: 'yyyy-MM-dd',
123
+ month: 'yyyy-MM',
124
+ months: 'yyyy-MM',
125
+ datetime: 'yyyy-MM-dd HH:mm:ss',
126
+ time: 'HH:mm:ss',
127
+ week: 'yyyywWW',
128
+ timerange: 'HH:mm:ss',
129
+ daterange: 'yyyy-MM-dd',
130
+ monthrange: 'yyyy-MM',
131
+ datetimerange: 'yyyy-MM-dd HH:mm:ss',
132
+ year: 'yyyy',
133
+ years: 'yyyy'
134
+ };
135
+ const HAVE_TRIGGER_TYPES = [
136
+ 'date',
137
+ 'datetime',
138
+ 'time',
139
+ 'time-select',
140
+ 'week',
141
+ 'month',
142
+ 'year',
143
+ 'daterange',
144
+ 'monthrange',
145
+ 'timerange',
146
+ 'datetimerange',
147
+ 'dates',
148
+ 'months',
149
+ 'years'
150
+ ];
151
+ const DATE_FORMATTER = function(value, format) {
152
+ if (format === 'timestamp') return value.getTime();
153
+ return formatDate(value, format);
154
+ };
155
+ const DATE_PARSER = function(text, format) {
156
+ if (format === 'timestamp') return new Date(Number(text));
157
+ return parseDate(text, format);
158
+ };
159
+ const RANGE_FORMATTER = function(value, format) {
160
+ if (Array.isArray(value) && value.length === 2) {
161
+ const start = value[0];
162
+ const end = value[1];
163
+
164
+ if (start && end) {
165
+ return [DATE_FORMATTER(start, format), DATE_FORMATTER(end, format)];
166
+ }
167
+ }
168
+ return '';
169
+ };
170
+ const RANGE_PARSER = function(array, format, separator) {
171
+ if (!Array.isArray(array)) {
172
+ array = array.split(separator);
173
+ }
174
+ if (array.length === 2) {
175
+ const range1 = array[0];
176
+ const range2 = array[1];
177
+
178
+ return [DATE_PARSER(range1, format), DATE_PARSER(range2, format)];
179
+ }
180
+ return [];
181
+ };
182
+ const TYPE_VALUE_RESOLVER_MAP = {
183
+ default: {
184
+ formatter(value) {
185
+ if (!value) return '';
186
+ return '' + value;
187
+ },
188
+ parser(text) {
189
+ if (text === undefined || text === '') return null;
190
+ return text;
191
+ }
192
+ },
193
+ week: {
194
+ formatter(value, format) {
195
+ let week = getWeekNumber(value);
196
+ let month = value.getMonth();
197
+ const trueDate = new Date(value);
198
+ if (week === 1 && month === 11) {
199
+ trueDate.setHours(0, 0, 0, 0);
200
+ trueDate.setDate(trueDate.getDate() + 3 - (trueDate.getDay() + 6) % 7);
201
+ }
202
+ let date = formatDate(trueDate, format);
203
+
204
+ date = /WW/.test(date)
205
+ ? date.replace(/WW/, week < 10 ? '0' + week : week)
206
+ : date.replace(/W/, week);
207
+ return date;
208
+ },
209
+ parser(text, format) {
210
+ // parse as if a normal date
211
+ return TYPE_VALUE_RESOLVER_MAP.date.parser(text, format);
212
+ }
213
+ },
214
+ date: {
215
+ formatter: DATE_FORMATTER,
216
+ parser: DATE_PARSER
217
+ },
218
+ datetime: {
219
+ formatter: DATE_FORMATTER,
220
+ parser: DATE_PARSER
221
+ },
222
+ daterange: {
223
+ formatter: RANGE_FORMATTER,
224
+ parser: RANGE_PARSER
225
+ },
226
+ monthrange: {
227
+ formatter: RANGE_FORMATTER,
228
+ parser: RANGE_PARSER
229
+ },
230
+ datetimerange: {
231
+ formatter: RANGE_FORMATTER,
232
+ parser: RANGE_PARSER
233
+ },
234
+ timerange: {
235
+ formatter: RANGE_FORMATTER,
236
+ parser: RANGE_PARSER
237
+ },
238
+ time: {
239
+ formatter: DATE_FORMATTER,
240
+ parser: DATE_PARSER
241
+ },
242
+ month: {
243
+ formatter: DATE_FORMATTER,
244
+ parser: DATE_PARSER
245
+ },
246
+ year: {
247
+ formatter: DATE_FORMATTER,
248
+ parser: DATE_PARSER
249
+ },
250
+ number: {
251
+ formatter(value) {
252
+ if (!value) return '';
253
+ return '' + value;
254
+ },
255
+ parser(text) {
256
+ let result = Number(text);
257
+
258
+ if (!isNaN(text)) {
259
+ return result;
260
+ } else {
261
+ return null;
262
+ }
263
+ }
264
+ },
265
+ dates: {
266
+ formatter(value, format) {
267
+ return value.map(date => DATE_FORMATTER(date, format));
268
+ },
269
+ parser(value, format) {
270
+ return (typeof value === 'string' ? value.split(', ') : value)
271
+ .map(date => date instanceof Date ? date : DATE_PARSER(date, format));
272
+ }
273
+ },
274
+ months: {
275
+ formatter(value, format) {
276
+ return value.map(date => DATE_FORMATTER(date, format));
277
+ },
278
+ parser(value, format) {
279
+ return (typeof value === 'string' ? value.split(', ') : value)
280
+ .map(date => date instanceof Date ? date : DATE_PARSER(date, format));
281
+ }
282
+ },
283
+ years: {
284
+ formatter(value, format) {
285
+ return value.map(date => DATE_FORMATTER(date, format));
286
+ },
287
+ parser(value, format) {
288
+ return (typeof value === 'string' ? value.split(', ') : value)
289
+ .map(date => date instanceof Date ? date : DATE_PARSER(date, format));
290
+ }
291
+ }
292
+ };
293
+ const PLACEMENT_MAP = {
294
+ left: 'bottom-start',
295
+ center: 'bottom',
296
+ right: 'bottom-end'
297
+ };
298
+
299
+ const parseAsFormatAndType = (value, customFormat, type, rangeSeparator = '-') => {
300
+ if (!value) return null;
301
+ const parser = (
302
+ TYPE_VALUE_RESOLVER_MAP[type] ||
303
+ TYPE_VALUE_RESOLVER_MAP['default']
304
+ ).parser;
305
+ const format = customFormat || DEFAULT_FORMATS[type];
306
+ return parser(value, format, rangeSeparator);
307
+ };
308
+
309
+ const formatAsFormatAndType = (value, customFormat, type) => {
310
+ if (!value) return null;
311
+ const formatter = (
312
+ TYPE_VALUE_RESOLVER_MAP[type] ||
313
+ TYPE_VALUE_RESOLVER_MAP['default']
314
+ ).formatter;
315
+ const format = customFormat || DEFAULT_FORMATS[type];
316
+ return formatter(value, format);
317
+ };
318
+
319
+ /*
320
+ * Considers:
321
+ * 1. Date object
322
+ * 2. date string
323
+ * 3. array of 1 or 2
324
+ */
325
+ const valueEquals = function(a, b) {
326
+ // considers Date object and string
327
+ const dateEquals = function(a, b) {
328
+ const aIsDate = a instanceof Date;
329
+ const bIsDate = b instanceof Date;
330
+ if (aIsDate && bIsDate) {
331
+ return a.getTime() === b.getTime();
332
+ }
333
+ if (!aIsDate && !bIsDate) {
334
+ return a === b;
335
+ }
336
+ return false;
337
+ };
338
+
339
+ const aIsArray = a instanceof Array;
340
+ const bIsArray = b instanceof Array;
341
+ if (aIsArray && bIsArray) {
342
+ if (a.length !== b.length) {
343
+ return false;
344
+ }
345
+ return a.every((item, index) => dateEquals(item, b[index]));
346
+ }
347
+ if (!aIsArray && !bIsArray) {
348
+ return dateEquals(a, b);
349
+ }
350
+ return false;
351
+ };
352
+
353
+ const isString = function(val) {
354
+ return typeof val === 'string' || val instanceof String;
355
+ };
356
+
357
+ const validator = function(val) {
358
+ // either: String, Array of String, null / undefined
359
+ return (
360
+ val === null ||
361
+ val === undefined ||
362
+ isString(val) ||
363
+ (Array.isArray(val) && val.length === 2 && val.every(isString))
364
+ );
365
+ };
366
+
367
+ export default {
368
+ mixins: [Emitter, NewPopper],
369
+
370
+ inject: {
371
+ elForm: {
372
+ default: ''
373
+ },
374
+ elFormItem: {
375
+ default: ''
376
+ }
377
+ },
378
+
379
+ props: {
380
+ size: String,
381
+ format: String,
382
+ valueFormat: String,
383
+ readonly: Boolean,
384
+ placeholder: String,
385
+ startPlaceholder: String,
386
+ endPlaceholder: String,
387
+ prefixIcon: String,
388
+ clearIcon: {
389
+ type: String,
390
+ default: 'iov-icon-close-mini'
391
+ },
392
+ name: {
393
+ default: '',
394
+ validator
395
+ },
396
+ disabled: Boolean,
397
+ clearable: {
398
+ type: Boolean,
399
+ default: true
400
+ },
401
+ id: {
402
+ default: '',
403
+ validator
404
+ },
405
+ popperClass: String,
406
+ editable: {
407
+ type: Boolean,
408
+ default: true
409
+ },
410
+ align: {
411
+ type: String,
412
+ default: 'left'
413
+ },
414
+ value: {},
415
+ defaultValue: {},
416
+ defaultTime: {},
417
+ rangeSeparator: {
418
+ default: ''
419
+ },
420
+ pickerOptions: {},
421
+ unlinkPanels: Boolean,
422
+ validateEvent: {
423
+ type: Boolean,
424
+ default: true
425
+ }
426
+ },
427
+
428
+ components: { ElInput },
429
+
430
+ directives: { Clickoutside },
431
+
432
+ data() {
433
+ return {
434
+ pickerVisible: false,
435
+ showClose: false,
436
+ userInput: null,
437
+ valueOnOpen: null, // value when picker opens, used to determine whether to emit change
438
+ unwatchPickerOptions: null
439
+ };
440
+ },
441
+
442
+ watch: {
443
+ pickerVisible(val) {
444
+ if (this.readonly || this.pickerDisabled) return;
445
+ if (val) {
446
+ this.showPicker();
447
+ this.valueOnOpen = Array.isArray(this.value) ? [...this.value] : this.value;
448
+ } else {
449
+ this.hidePicker();
450
+ this.emitChange(this.value);
451
+ this.userInput = null;
452
+ if (this.validateEvent) {
453
+ this.dispatch('ElFormItem', 'el.form.blur');
454
+ }
455
+ this.$emit('blur', this);
456
+ this.blur();
457
+ }
458
+ },
459
+ parsedValue: {
460
+ immediate: true,
461
+ handler(val) {
462
+ if (this.picker) {
463
+ this.picker.value = val;
464
+ }
465
+ }
466
+ },
467
+ defaultValue(val) {
468
+ // NOTE: should eventually move to jsx style picker + panel ?
469
+ if (this.picker) {
470
+ this.picker.defaultValue = val;
471
+ }
472
+ },
473
+ value(val, oldVal) {
474
+ if (!valueEquals(val, oldVal) && !this.pickerVisible && this.validateEvent) {
475
+ this.dispatch('ElFormItem', 'el.form.change', val);
476
+ }
477
+ }
478
+ },
479
+
480
+ computed: {
481
+ ranged() {
482
+ return this.type.indexOf('range') > -1;
483
+ },
484
+
485
+ reference() {
486
+ const reference = this.$refs.reference;
487
+ return reference.$el || reference;
488
+ },
489
+
490
+ refInput() {
491
+ if (this.reference) {
492
+ return [].slice.call(this.reference.querySelectorAll('input'));
493
+ }
494
+ return [];
495
+ },
496
+
497
+ valueIsEmpty() {
498
+ const val = this.value;
499
+ if (Array.isArray(val)) {
500
+ for (let i = 0, len = val.length; i < len; i++) {
501
+ if (val[i]) {
502
+ return false;
503
+ }
504
+ }
505
+ } else {
506
+ if (val) {
507
+ return false;
508
+ }
509
+ }
510
+ return true;
511
+ },
512
+
513
+ triggerClass() {
514
+ return this.prefixIcon || (this.type.indexOf('time') !== -1 ? 'iov-icon-time' : 'iov-icon-date');
515
+ },
516
+
517
+ selectionMode() {
518
+ if (this.type === 'week') {
519
+ return 'week';
520
+ } else if (this.type === 'month') {
521
+ return 'month';
522
+ } else if (this.type === 'year') {
523
+ return 'year';
524
+ } else if (this.type === 'dates') {
525
+ return 'dates';
526
+ } else if (this.type === 'months') {
527
+ return 'months';
528
+ } else if (this.type === 'years') {
529
+ return 'years';
530
+ }
531
+
532
+ return 'day';
533
+ },
534
+
535
+ haveTrigger() {
536
+ if (typeof this.showTrigger !== 'undefined') {
537
+ return this.showTrigger;
538
+ }
539
+ return HAVE_TRIGGER_TYPES.indexOf(this.type) !== -1;
540
+ },
541
+
542
+ displayValue() {
543
+ const formattedValue = formatAsFormatAndType(this.parsedValue, this.format, this.type, this.rangeSeparator);
544
+ if (Array.isArray(this.userInput)) {
545
+ return [
546
+ this.userInput[0] || (formattedValue && formattedValue[0]) || '',
547
+ this.userInput[1] || (formattedValue && formattedValue[1]) || ''
548
+ ];
549
+ } else if (this.userInput !== null) {
550
+ return this.userInput;
551
+ } else if (formattedValue) {
552
+ return (this.type === 'dates' || this.type === 'years' || this.type === 'months')
553
+ ? formattedValue.join(', ')
554
+ : formattedValue;
555
+ } else {
556
+ return '';
557
+ }
558
+ },
559
+
560
+ parsedValue() {
561
+ if (!this.value) return this.value; // component value is not set
562
+ if (this.type === 'time-select') return this.value; // time-select does not require parsing, this might change in next major version
563
+
564
+ const valueIsDateObject = isDateObject(this.value) || (Array.isArray(this.value) && this.value.every(isDateObject));
565
+ if (valueIsDateObject) {
566
+ return this.value;
567
+ }
568
+
569
+ if (this.valueFormat) {
570
+ return parseAsFormatAndType(this.value, this.valueFormat, this.type, this.rangeSeparator) || this.value;
571
+ }
572
+
573
+ // NOTE: deal with common but incorrect usage, should remove in next major version
574
+ // user might provide string / timestamp without value-format, coerce them into date (or array of date)
575
+ return Array.isArray(this.value) ? this.value.map(val => new Date(val)) : new Date(this.value);
576
+ },
577
+
578
+ _elFormItemSize() {
579
+ return (this.elFormItem || {}).elFormItemSize;
580
+ },
581
+
582
+ pickerSize() {
583
+ return this.size || this._elFormItemSize || (this.$ELEMENT || {}).size;
584
+ },
585
+
586
+ pickerDisabled() {
587
+ return this.disabled || (this.elForm || {}).disabled;
588
+ },
589
+
590
+ firstInputId() {
591
+ const obj = {};
592
+ let id;
593
+ if (this.ranged) {
594
+ id = this.id && this.id[0];
595
+ } else {
596
+ id = this.id;
597
+ }
598
+ if (id) obj.id = id;
599
+ return obj;
600
+ },
601
+
602
+ secondInputId() {
603
+ const obj = {};
604
+ let id;
605
+ if (this.ranged) {
606
+ id = this.id && this.id[1];
607
+ }
608
+ if (id) obj.id = id;
609
+ return obj;
610
+ }
611
+ },
612
+
613
+ created() {
614
+ // vue-popper
615
+ this.popperOptions = {
616
+ boundariesPadding: 0,
617
+ gpuAcceleration: false
618
+ };
619
+ this.placement = PLACEMENT_MAP[this.align] || PLACEMENT_MAP.left;
620
+
621
+ this.$on('fieldReset', this.handleFieldReset);
622
+ },
623
+
624
+ methods: {
625
+ focus() {
626
+ if (!this.ranged) {
627
+ this.$refs.reference.focus();
628
+ } else {
629
+ this.handleFocus();
630
+ }
631
+ },
632
+
633
+ blur() {
634
+ this.refInput.forEach(input => input.blur());
635
+ },
636
+
637
+ // {parse, formatTo} Value deals maps component value with internal Date
638
+ parseValue(value) {
639
+ const isParsed = isDateObject(value) || (Array.isArray(value) && value.every(isDateObject));
640
+ if (this.valueFormat && !isParsed) {
641
+ return parseAsFormatAndType(value, this.valueFormat, this.type, this.rangeSeparator) || value;
642
+ } else {
643
+ return value;
644
+ }
645
+ },
646
+
647
+ formatToValue(date) {
648
+ const isFormattable = isDateObject(date) || (Array.isArray(date) && date.every(isDateObject));
649
+ if (this.valueFormat && isFormattable) {
650
+ return formatAsFormatAndType(date, this.valueFormat, this.type, this.rangeSeparator);
651
+ } else {
652
+ return date;
653
+ }
654
+ },
655
+
656
+ // {parse, formatTo} String deals with user input
657
+ parseString(value) {
658
+ const type = Array.isArray(value) ? this.type : this.type.replace('range', '');
659
+ return parseAsFormatAndType(value, this.format, type);
660
+ },
661
+
662
+ formatToString(value) {
663
+ const type = Array.isArray(value) ? this.type : this.type.replace('range', '');
664
+ return formatAsFormatAndType(value, this.format, type);
665
+ },
666
+
667
+ handleMouseEnter() {
668
+ if (this.readonly || this.pickerDisabled) return;
669
+ if (!this.valueIsEmpty && this.clearable) {
670
+ this.showClose = true;
671
+ }
672
+ },
673
+
674
+ handleChange() {
675
+ if (this.userInput) {
676
+ const value = this.parseString(this.displayValue);
677
+ if (value) {
678
+ this.picker.value = value;
679
+ if (this.isValidValue(value)) {
680
+ this.emitInput(value);
681
+ this.userInput = null;
682
+ }
683
+ }
684
+ }
685
+ if (this.userInput === '') {
686
+ this.emitInput(null);
687
+ this.emitChange(null);
688
+ this.userInput = null;
689
+ }
690
+ },
691
+
692
+ handleStartInput(event) {
693
+ if (this.userInput) {
694
+ this.userInput = [event.target.value, this.userInput[1]];
695
+ } else {
696
+ this.userInput = [event.target.value, null];
697
+ }
698
+ },
699
+
700
+ handleEndInput(event) {
701
+ if (this.userInput) {
702
+ this.userInput = [this.userInput[0], event.target.value];
703
+ } else {
704
+ this.userInput = [null, event.target.value];
705
+ }
706
+ },
707
+
708
+ handleStartChange(event) {
709
+ const value = this.parseString(this.userInput && this.userInput[0]);
710
+ if (value) {
711
+ this.userInput = [this.formatToString(value), this.displayValue[1]];
712
+ const newValue = [value, this.picker.value && this.picker.value[1]];
713
+ this.picker.value = newValue;
714
+ if (this.isValidValue(newValue)) {
715
+ this.emitInput(newValue);
716
+ this.userInput = null;
717
+ }
718
+ }
719
+ },
720
+
721
+ handleEndChange(event) {
722
+ const value = this.parseString(this.userInput && this.userInput[1]);
723
+ if (value) {
724
+ this.userInput = [this.displayValue[0], this.formatToString(value)];
725
+ const newValue = [this.picker.value && this.picker.value[0], value];
726
+ this.picker.value = newValue;
727
+ if (this.isValidValue(newValue)) {
728
+ this.emitInput(newValue);
729
+ this.userInput = null;
730
+ }
731
+ }
732
+ },
733
+
734
+ handleClickIcon(event) {
735
+ if (this.readonly || this.pickerDisabled) return;
736
+ if (this.showClose) {
737
+ this.valueOnOpen = this.value;
738
+ event.stopPropagation();
739
+ this.emitInput(null);
740
+ this.emitChange(null);
741
+ this.showClose = false;
742
+ if (this.picker && typeof this.picker.handleClear === 'function') {
743
+ this.picker.handleClear();
744
+ }
745
+ } else {
746
+ this.pickerVisible = !this.pickerVisible;
747
+ }
748
+ },
749
+
750
+ handleClose() {
751
+ if (!this.pickerVisible) return;
752
+ this.pickerVisible = false;
753
+
754
+ if (this.type === 'dates' || this.type === 'years' || this.type === 'months') {
755
+ // restore to former value
756
+ const oldValue = parseAsFormatAndType(this.valueOnOpen, this.valueFormat, this.type, this.rangeSeparator) || this.valueOnOpen;
757
+ this.emitInput(oldValue);
758
+ }
759
+ },
760
+
761
+ handleFieldReset(initialValue) {
762
+ this.userInput = initialValue === '' ? null : initialValue;
763
+ },
764
+
765
+ handleFocus() {
766
+ const type = this.type;
767
+
768
+ if (HAVE_TRIGGER_TYPES.indexOf(type) !== -1 && !this.pickerVisible) {
769
+ this.pickerVisible = true;
770
+ }
771
+ this.$emit('focus', this);
772
+ },
773
+
774
+ handleKeydown(event) {
775
+ const keyCode = event.keyCode;
776
+
777
+ // ESC
778
+ if (keyCode === 27) {
779
+ this.pickerVisible = false;
780
+ event.stopPropagation();
781
+ return;
782
+ }
783
+
784
+ // Tab
785
+ if (keyCode === 9) {
786
+ if (!this.ranged) {
787
+ this.handleChange();
788
+ this.pickerVisible = this.picker.visible = false;
789
+ this.blur();
790
+ event.stopPropagation();
791
+ } else {
792
+ // user may change focus between two input
793
+ setTimeout(() => {
794
+ if (this.refInput.indexOf(document.activeElement) === -1) {
795
+ this.pickerVisible = false;
796
+ this.blur();
797
+ event.stopPropagation();
798
+ }
799
+ }, 0);
800
+ }
801
+ return;
802
+ }
803
+
804
+ // Enter
805
+ if (keyCode === 13) {
806
+ if (this.userInput === '' || this.isValidValue(this.parseString(this.displayValue))) {
807
+ this.handleChange();
808
+ this.pickerVisible = this.picker.visible = false;
809
+ this.blur();
810
+ }
811
+ event.stopPropagation();
812
+ return;
813
+ }
814
+
815
+ // if user is typing, do not let picker handle key input
816
+ if (this.userInput) {
817
+ event.stopPropagation();
818
+ return;
819
+ }
820
+
821
+ // delegate other keys to panel
822
+ if (this.picker && this.picker.handleKeydown) {
823
+ this.picker.handleKeydown(event);
824
+ }
825
+ },
826
+
827
+ handleRangeClick() {
828
+ const type = this.type;
829
+
830
+ if (HAVE_TRIGGER_TYPES.indexOf(type) !== -1 && !this.pickerVisible) {
831
+ this.pickerVisible = true;
832
+ }
833
+ this.$emit('focus', this);
834
+ },
835
+
836
+ hidePicker() {
837
+ if (this.picker) {
838
+ this.picker.resetView && this.picker.resetView();
839
+ this.pickerVisible = this.picker.visible = false;
840
+ this.destroyPopper();
841
+ }
842
+ },
843
+
844
+ showPicker() {
845
+ if (this.$isServer) return;
846
+ if (!this.picker) {
847
+ this.mountPicker();
848
+ }
849
+ this.pickerVisible = this.picker.visible = true;
850
+
851
+ this.updatePopper();
852
+
853
+ this.picker.value = this.parsedValue;
854
+ this.picker.resetView && this.picker.resetView();
855
+
856
+ this.$nextTick(() => {
857
+ this.picker.adjustSpinners && this.picker.adjustSpinners();
858
+ });
859
+ },
860
+
861
+ mountPicker() {
862
+ this.picker = new Vue(this.panel).$mount();
863
+ this.picker.defaultValue = this.defaultValue;
864
+ this.picker.defaultTime = this.defaultTime;
865
+ this.picker.popperClass = this.popperClass;
866
+ this.popperElm = this.picker.$el;
867
+ this.picker.width = this.reference.getBoundingClientRect().width;
868
+ this.picker.showTime = this.type === 'datetime' || this.type === 'datetimerange';
869
+ this.picker.selectionMode = this.selectionMode;
870
+ this.picker.unlinkPanels = this.unlinkPanels;
871
+ this.picker.arrowControl = this.arrowControl || this.timeArrowControl || false;
872
+ this.$watch('format', (format) => {
873
+ this.picker.format = format;
874
+ });
875
+
876
+ const updateOptions = () => {
877
+ const options = this.pickerOptions;
878
+
879
+ if (options && options.selectableRange) {
880
+ let ranges = options.selectableRange;
881
+ const parser = TYPE_VALUE_RESOLVER_MAP.datetimerange.parser;
882
+ const format = DEFAULT_FORMATS.timerange;
883
+
884
+ ranges = Array.isArray(ranges) ? ranges : [ranges];
885
+ this.picker.selectableRange = ranges.map(range => parser(range, format, this.rangeSeparator));
886
+ }
887
+
888
+ for (const option in options) {
889
+ if (options.hasOwnProperty(option) &&
890
+ // 忽略 time-picker 的该配置项
891
+ option !== 'selectableRange') {
892
+ this.picker[option] = options[option];
893
+ }
894
+ }
895
+
896
+ // main format must prevail over undocumented pickerOptions.format
897
+ if (this.format) {
898
+ this.picker.format = this.format;
899
+ }
900
+ };
901
+ updateOptions();
902
+ this.unwatchPickerOptions = this.$watch('pickerOptions', () => updateOptions(), { deep: true });
903
+ this.$el.appendChild(this.picker.$el);
904
+ this.picker.resetView && this.picker.resetView();
905
+
906
+ this.picker.$on('dodestroy', this.doDestroy);
907
+ this.picker.$on('pick', (date = '', visible = false) => {
908
+ this.userInput = null;
909
+ this.pickerVisible = this.picker.visible = visible;
910
+ this.emitInput(date);
911
+ this.picker.resetView && this.picker.resetView();
912
+ });
913
+
914
+ this.picker.$on('select-range', (start, end, pos) => {
915
+ if (this.refInput.length === 0) return;
916
+ if (!pos || pos === 'min') {
917
+ this.refInput[0].setSelectionRange(start, end);
918
+ this.refInput[0].focus();
919
+ } else if (pos === 'max') {
920
+ this.refInput[1].setSelectionRange(start, end);
921
+ this.refInput[1].focus();
922
+ }
923
+ });
924
+ },
925
+
926
+ unmountPicker() {
927
+ if (this.picker) {
928
+ this.picker.$destroy();
929
+ this.picker.$off();
930
+ if (typeof this.unwatchPickerOptions === 'function') {
931
+ this.unwatchPickerOptions();
932
+ }
933
+ this.picker.$el.parentNode.removeChild(this.picker.$el);
934
+ }
935
+ },
936
+
937
+ emitChange(val) {
938
+ // determine user real change only
939
+ if (!valueEquals(val, this.valueOnOpen)) {
940
+ this.$emit('change', val);
941
+ this.valueOnOpen = val;
942
+ if (this.validateEvent) {
943
+ this.dispatch('ElFormItem', 'el.form.change', val);
944
+ }
945
+ }
946
+ },
947
+
948
+ emitInput(val) {
949
+ const formatted = this.formatToValue(val);
950
+ if (!valueEquals(this.value, formatted)) {
951
+ this.$emit('input', formatted);
952
+ }
953
+ },
954
+
955
+ isValidValue(value) {
956
+ if (!this.picker) {
957
+ this.mountPicker();
958
+ }
959
+ if (this.picker.isValidValue) {
960
+ return value && this.picker.isValidValue(value);
961
+ } else {
962
+ return true;
963
+ }
964
+ }
965
+ }
966
+ };
967
+ </script>