@94ai/nf-timezone-picker 6.1.12 → 6.1.14

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.
@@ -1,316 +1,316 @@
1
- <template>
2
- <div class="el-time-spinner" :class="{ 'has-seconds': showSeconds }">
3
- <template v-if="!arrowControl">
4
- <el-scrollbar
5
- ref="hours"
6
- class="el-time-spinner__wrapper"
7
- wrap-style="max-height: inherit;"
8
- view-class="el-time-spinner__list"
9
- noresize
10
- tag="ul"
11
- @mouseenter.native="emitSelectRange('hours')"
12
- @mousemove.native="adjustCurrentSpinner('hours')"
13
- >
14
- <li
15
- v-for="(disabled, hour) in hoursList"
16
- :key="hour"
17
- class="el-time-spinner__item"
18
- :class="{ 'active': hour === hours, 'disabled': disabled }"
19
- @click="handleClick('hours', { value: hour, disabled: disabled })"
20
- >{{ ('0' + (amPmMode ? (hour % 12 || 12) : hour )).slice(-2) }}{{ amPm(hour) }}</li>
21
- </el-scrollbar>
22
- <el-scrollbar
23
- ref="minutes"
24
- class="el-time-spinner__wrapper"
25
- wrap-style="max-height: inherit;"
26
- view-class="el-time-spinner__list"
27
- noresize
28
- tag="ul"
29
- @mouseenter.native="emitSelectRange('minutes')"
30
- @mousemove.native="adjustCurrentSpinner('minutes')"
31
- >
32
- <li
33
- v-for="(enabled, key) in minutesList"
34
- :key="key"
35
- class="el-time-spinner__item"
36
- :class="{ 'active': key === minutes, disabled: !enabled }"
37
- @click="handleClick('minutes', { value: key, disabled: false })"
38
- >{{ ('0' + key).slice(-2) }}</li>
39
- </el-scrollbar>
40
- <el-scrollbar
41
- v-show="showSeconds"
42
- ref="seconds"
43
- class="el-time-spinner__wrapper"
44
- wrap-style="max-height: inherit;"
45
- view-class="el-time-spinner__list"
46
- noresize
47
- tag="ul"
48
- @mouseenter.native="emitSelectRange('seconds')"
49
- @mousemove.native="adjustCurrentSpinner('seconds')"
50
- >
51
- <li
52
- v-for="(second, key) in 60"
53
- :key="key"
54
- class="el-time-spinner__item"
55
- :class="{ 'active': key === seconds }"
56
- @click="handleClick('seconds', { value: key, disabled: false })"
57
- >{{ ('0' + key).slice(-2) }}</li>
58
- </el-scrollbar>
59
- </template>
60
- <template v-if="arrowControl">
61
- <div
62
- class="el-time-spinner__wrapper is-arrow"
63
- @mouseenter="emitSelectRange('hours')"
64
- >
65
- <i v-repeat-click="decrease" class="el-time-spinner__arrow el-icon-arrow-up" />
66
- <i v-repeat-click="increase" class="el-time-spinner__arrow el-icon-arrow-down" />
67
- <ul ref="hours" class="el-time-spinner__list">
68
- <li
69
- v-for="(hour, key) in arrowHourList"
70
- :key="key"
71
- class="el-time-spinner__item"
72
- :class="{ 'active': hour === hours, 'disabled': hoursList[hour] }"
73
- >{{ hour === undefined ? '' : ('0' + (amPmMode ? (hour % 12 || 12) : hour )).slice(-2) + amPm(hour) }}</li>
74
- </ul>
75
- </div>
76
- <div
77
- class="el-time-spinner__wrapper is-arrow"
78
- @mouseenter="emitSelectRange('minutes')"
79
- >
80
- <i v-repeat-click="decrease" class="el-time-spinner__arrow el-icon-arrow-up" />
81
- <i v-repeat-click="increase" class="el-time-spinner__arrow el-icon-arrow-down" />
82
- <ul ref="minutes" class="el-time-spinner__list">
83
- <li
84
- v-for="(minute, key) in arrowMinuteList"
85
- :key="key"
86
- class="el-time-spinner__item"
87
- :class="{ 'active': minute === minutes }"
88
- >
89
- {{ minute === undefined ? '' : ('0' + minute).slice(-2) }}
90
- </li>
91
- </ul>
92
- </div>
93
- <div
94
- v-if="showSeconds"
95
- class="el-time-spinner__wrapper is-arrow"
96
- @mouseenter="emitSelectRange('seconds')"
97
- >
98
- <i v-repeat-click="decrease" class="el-time-spinner__arrow el-icon-arrow-up" />
99
- <i v-repeat-click="increase" class="el-time-spinner__arrow el-icon-arrow-down" />
100
- <ul ref="seconds" class="el-time-spinner__list">
101
- <li
102
- v-for="(second, key) in arrowSecondList"
103
- :key="key"
104
- class="el-time-spinner__item"
105
- :class="{ 'active': second === seconds }"
106
- >
107
- {{ second === undefined ? '' : ('0' + second).slice(-2) }}
108
- </li>
109
- </ul>
110
- </div>
111
- </template>
112
- </div>
113
- </template>
114
-
115
- <script type="text/babel">
116
- import { getRangeHours, getRangeMinutes, modifyTime } from 'element-ui/src/utils/date-util'
117
- // import ElScrollbar from 'element-ui/packages/scrollbar';
118
- import RepeatClick from 'element-ui/src/directives/repeat-click'
119
-
120
- export default {
121
- components: { },
122
-
123
- directives: {
124
- repeatClick: RepeatClick
125
- },
126
-
127
- props: {
128
- date: {},
129
- defaultValue: {}, // reserved for future use
130
- showSeconds: {
131
- type: Boolean,
132
- default: true
133
- },
134
- arrowControl: Boolean,
135
- amPmMode: {
136
- type: String,
137
- default: '' // 'a': am/pm; 'A': AM/PM
138
- }
139
- },
140
-
141
- data() {
142
- return {
143
- selectableRange: [],
144
- currentScrollbar: null
145
- }
146
- },
147
-
148
- computed: {
149
- hours() {
150
- return this.date.getHours()
151
- },
152
- minutes() {
153
- return this.date.getMinutes()
154
- },
155
- seconds() {
156
- return this.date.getSeconds()
157
- },
158
- hoursList() {
159
- return getRangeHours(this.selectableRange)
160
- },
161
- minutesList() {
162
- return getRangeMinutes(this.selectableRange, this.hours)
163
- },
164
- arrowHourList() {
165
- const hours = this.hours
166
- return [
167
- hours > 0 ? hours - 1 : undefined,
168
- hours,
169
- hours < 23 ? hours + 1 : undefined
170
- ]
171
- },
172
- arrowMinuteList() {
173
- const minutes = this.minutes
174
- return [
175
- minutes > 0 ? minutes - 1 : undefined,
176
- minutes,
177
- minutes < 59 ? minutes + 1 : undefined
178
- ]
179
- },
180
- arrowSecondList() {
181
- const seconds = this.seconds
182
- return [
183
- seconds > 0 ? seconds - 1 : undefined,
184
- seconds,
185
- seconds < 59 ? seconds + 1 : undefined
186
- ]
187
- }
188
- },
189
-
190
- mounted() {
191
- this.$nextTick(() => {
192
- !this.arrowControl && this.bindScrollEvent()
193
- })
194
- },
195
-
196
- methods: {
197
- increase() {
198
- this.scrollDown(1)
199
- },
200
-
201
- decrease() {
202
- this.scrollDown(-1)
203
- },
204
-
205
- modifyDateField(type, value) {
206
- switch (type) {
207
- case 'hours': this.$emit('change', modifyTime(this.date, value, this.minutes, this.seconds)); break
208
- case 'minutes': this.$emit('change', modifyTime(this.date, this.hours, value, this.seconds)); break
209
- case 'seconds': this.$emit('change', modifyTime(this.date, this.hours, this.minutes, value)); break
210
- }
211
- },
212
-
213
- handleClick(type, { value, disabled }) {
214
- if (!disabled) {
215
- this.modifyDateField(type, value)
216
- this.emitSelectRange(type)
217
- this.adjustSpinner(type, value)
218
- }
219
- },
220
-
221
- emitSelectRange(type) {
222
- if (type === 'hours') {
223
- this.$emit('select-range', 0, 2)
224
- } else if (type === 'minutes') {
225
- this.$emit('select-range', 3, 5)
226
- } else if (type === 'seconds') {
227
- this.$emit('select-range', 6, 8)
228
- }
229
- this.currentScrollbar = type
230
- },
231
-
232
- bindScrollEvent() {
233
- const bindFuntion = (type) => {
234
- this.$refs[type].wrap.onscroll = (e) => {
235
- // TODO: scroll is emitted when set scrollTop programatically
236
- // should find better solutions in the future!
237
- this.handleScroll(type, e)
238
- }
239
- }
240
- bindFuntion('hours')
241
- bindFuntion('minutes')
242
- bindFuntion('seconds')
243
- },
244
-
245
- handleScroll(type) {
246
- const value = Math.min(Math.round((this.$refs[type].wrap.scrollTop - (this.scrollBarHeight(type) * 0.5 - 10) / this.typeItemHeight(type) + 3) / this.typeItemHeight(type)), (type === 'hours' ? 23 : 59))
247
- this.modifyDateField(type, value)
248
- },
249
-
250
- // NOTE: used by datetime / date-range panel
251
- // renamed from adjustScrollTop
252
- // should try to refactory it
253
- adjustSpinners() {
254
- this.adjustSpinner('hours', this.hours)
255
- this.adjustSpinner('minutes', this.minutes)
256
- this.adjustSpinner('seconds', this.seconds)
257
- },
258
-
259
- adjustCurrentSpinner(type) {
260
- this.adjustSpinner(type, this[type])
261
- },
262
-
263
- adjustSpinner(type, value) {
264
- if (this.arrowControl) return
265
- const el = this.$refs[type].wrap
266
- if (el) {
267
- el.scrollTop = Math.max(0, value * this.typeItemHeight(type))
268
- }
269
- },
270
-
271
- scrollDown(step) {
272
- if (!this.currentScrollbar) {
273
- this.emitSelectRange('hours')
274
- }
275
-
276
- const label = this.currentScrollbar
277
- const hoursList = this.hoursList
278
- let now = this[label]
279
-
280
- if (this.currentScrollbar === 'hours') {
281
- let total = Math.abs(step)
282
- step = step > 0 ? 1 : -1
283
- let length = hoursList.length
284
- while (length-- && total) {
285
- now = (now + step + hoursList.length) % hoursList.length
286
- if (hoursList[now]) {
287
- continue
288
- }
289
- total--
290
- }
291
- if (hoursList[now]) return
292
- } else {
293
- now = (now + step + 60) % 60
294
- }
295
-
296
- this.modifyDateField(label, now)
297
- this.adjustSpinner(label, now)
298
- this.$nextTick(() => this.emitSelectRange(this.currentScrollbar))
299
- },
300
- amPm(hour) {
301
- const shouldShowAmPm = this.amPmMode.toLowerCase() === 'a'
302
- if (!shouldShowAmPm) return ''
303
- const isCapital = this.amPmMode === 'A'
304
- let content = (hour < 12) ? ' am' : ' pm'
305
- if (isCapital) content = content.toUpperCase()
306
- return content
307
- },
308
- typeItemHeight(type) {
309
- return this.$refs[type].$el.querySelector('li').offsetHeight
310
- },
311
- scrollBarHeight(type) {
312
- return this.$refs[type].$el.offsetHeight
313
- }
314
- }
315
- }
316
- </script>
1
+ <template>
2
+ <div class="el-time-spinner" :class="{ 'has-seconds': showSeconds }">
3
+ <template v-if="!arrowControl">
4
+ <el-scrollbar
5
+ ref="hours"
6
+ class="el-time-spinner__wrapper"
7
+ wrap-style="max-height: inherit;"
8
+ view-class="el-time-spinner__list"
9
+ noresize
10
+ tag="ul"
11
+ @mouseenter.native="emitSelectRange('hours')"
12
+ @mousemove.native="adjustCurrentSpinner('hours')"
13
+ >
14
+ <li
15
+ v-for="(disabled, hour) in hoursList"
16
+ :key="hour"
17
+ class="el-time-spinner__item"
18
+ :class="{ 'active': hour === hours, 'disabled': disabled }"
19
+ @click="handleClick('hours', { value: hour, disabled: disabled })"
20
+ >{{ ('0' + (amPmMode ? (hour % 12 || 12) : hour )).slice(-2) }}{{ amPm(hour) }}</li>
21
+ </el-scrollbar>
22
+ <el-scrollbar
23
+ ref="minutes"
24
+ class="el-time-spinner__wrapper"
25
+ wrap-style="max-height: inherit;"
26
+ view-class="el-time-spinner__list"
27
+ noresize
28
+ tag="ul"
29
+ @mouseenter.native="emitSelectRange('minutes')"
30
+ @mousemove.native="adjustCurrentSpinner('minutes')"
31
+ >
32
+ <li
33
+ v-for="(enabled, key) in minutesList"
34
+ :key="key"
35
+ class="el-time-spinner__item"
36
+ :class="{ 'active': key === minutes, disabled: !enabled }"
37
+ @click="handleClick('minutes', { value: key, disabled: false })"
38
+ >{{ ('0' + key).slice(-2) }}</li>
39
+ </el-scrollbar>
40
+ <el-scrollbar
41
+ v-show="showSeconds"
42
+ ref="seconds"
43
+ class="el-time-spinner__wrapper"
44
+ wrap-style="max-height: inherit;"
45
+ view-class="el-time-spinner__list"
46
+ noresize
47
+ tag="ul"
48
+ @mouseenter.native="emitSelectRange('seconds')"
49
+ @mousemove.native="adjustCurrentSpinner('seconds')"
50
+ >
51
+ <li
52
+ v-for="(second, key) in 60"
53
+ :key="key"
54
+ class="el-time-spinner__item"
55
+ :class="{ 'active': key === seconds }"
56
+ @click="handleClick('seconds', { value: key, disabled: false })"
57
+ >{{ ('0' + key).slice(-2) }}</li>
58
+ </el-scrollbar>
59
+ </template>
60
+ <template v-if="arrowControl">
61
+ <div
62
+ class="el-time-spinner__wrapper is-arrow"
63
+ @mouseenter="emitSelectRange('hours')"
64
+ >
65
+ <i v-repeat-click="decrease" class="el-time-spinner__arrow el-icon-arrow-up" />
66
+ <i v-repeat-click="increase" class="el-time-spinner__arrow el-icon-arrow-down" />
67
+ <ul ref="hours" class="el-time-spinner__list">
68
+ <li
69
+ v-for="(hour, key) in arrowHourList"
70
+ :key="key"
71
+ class="el-time-spinner__item"
72
+ :class="{ 'active': hour === hours, 'disabled': hoursList[hour] }"
73
+ >{{ hour === undefined ? '' : ('0' + (amPmMode ? (hour % 12 || 12) : hour )).slice(-2) + amPm(hour) }}</li>
74
+ </ul>
75
+ </div>
76
+ <div
77
+ class="el-time-spinner__wrapper is-arrow"
78
+ @mouseenter="emitSelectRange('minutes')"
79
+ >
80
+ <i v-repeat-click="decrease" class="el-time-spinner__arrow el-icon-arrow-up" />
81
+ <i v-repeat-click="increase" class="el-time-spinner__arrow el-icon-arrow-down" />
82
+ <ul ref="minutes" class="el-time-spinner__list">
83
+ <li
84
+ v-for="(minute, key) in arrowMinuteList"
85
+ :key="key"
86
+ class="el-time-spinner__item"
87
+ :class="{ 'active': minute === minutes }"
88
+ >
89
+ {{ minute === undefined ? '' : ('0' + minute).slice(-2) }}
90
+ </li>
91
+ </ul>
92
+ </div>
93
+ <div
94
+ v-if="showSeconds"
95
+ class="el-time-spinner__wrapper is-arrow"
96
+ @mouseenter="emitSelectRange('seconds')"
97
+ >
98
+ <i v-repeat-click="decrease" class="el-time-spinner__arrow el-icon-arrow-up" />
99
+ <i v-repeat-click="increase" class="el-time-spinner__arrow el-icon-arrow-down" />
100
+ <ul ref="seconds" class="el-time-spinner__list">
101
+ <li
102
+ v-for="(second, key) in arrowSecondList"
103
+ :key="key"
104
+ class="el-time-spinner__item"
105
+ :class="{ 'active': second === seconds }"
106
+ >
107
+ {{ second === undefined ? '' : ('0' + second).slice(-2) }}
108
+ </li>
109
+ </ul>
110
+ </div>
111
+ </template>
112
+ </div>
113
+ </template>
114
+
115
+ <script type="text/babel">
116
+ import { getRangeHours, getRangeMinutes, modifyTime } from 'element-ui/src/utils/date-util'
117
+ // import ElScrollbar from 'element-ui/packages/scrollbar';
118
+ import RepeatClick from 'element-ui/src/directives/repeat-click'
119
+
120
+ export default {
121
+ components: { },
122
+
123
+ directives: {
124
+ repeatClick: RepeatClick
125
+ },
126
+
127
+ props: {
128
+ date: {},
129
+ defaultValue: {}, // reserved for future use
130
+ showSeconds: {
131
+ type: Boolean,
132
+ default: true
133
+ },
134
+ arrowControl: Boolean,
135
+ amPmMode: {
136
+ type: String,
137
+ default: '' // 'a': am/pm; 'A': AM/PM
138
+ }
139
+ },
140
+
141
+ data() {
142
+ return {
143
+ selectableRange: [],
144
+ currentScrollbar: null
145
+ }
146
+ },
147
+
148
+ computed: {
149
+ hours() {
150
+ return this.date.getHours()
151
+ },
152
+ minutes() {
153
+ return this.date.getMinutes()
154
+ },
155
+ seconds() {
156
+ return this.date.getSeconds()
157
+ },
158
+ hoursList() {
159
+ return getRangeHours(this.selectableRange)
160
+ },
161
+ minutesList() {
162
+ return getRangeMinutes(this.selectableRange, this.hours)
163
+ },
164
+ arrowHourList() {
165
+ const hours = this.hours
166
+ return [
167
+ hours > 0 ? hours - 1 : undefined,
168
+ hours,
169
+ hours < 23 ? hours + 1 : undefined
170
+ ]
171
+ },
172
+ arrowMinuteList() {
173
+ const minutes = this.minutes
174
+ return [
175
+ minutes > 0 ? minutes - 1 : undefined,
176
+ minutes,
177
+ minutes < 59 ? minutes + 1 : undefined
178
+ ]
179
+ },
180
+ arrowSecondList() {
181
+ const seconds = this.seconds
182
+ return [
183
+ seconds > 0 ? seconds - 1 : undefined,
184
+ seconds,
185
+ seconds < 59 ? seconds + 1 : undefined
186
+ ]
187
+ }
188
+ },
189
+
190
+ mounted() {
191
+ this.$nextTick(() => {
192
+ !this.arrowControl && this.bindScrollEvent()
193
+ })
194
+ },
195
+
196
+ methods: {
197
+ increase() {
198
+ this.scrollDown(1)
199
+ },
200
+
201
+ decrease() {
202
+ this.scrollDown(-1)
203
+ },
204
+
205
+ modifyDateField(type, value) {
206
+ switch (type) {
207
+ case 'hours': this.$emit('change', modifyTime(this.date, value, this.minutes, this.seconds)); break
208
+ case 'minutes': this.$emit('change', modifyTime(this.date, this.hours, value, this.seconds)); break
209
+ case 'seconds': this.$emit('change', modifyTime(this.date, this.hours, this.minutes, value)); break
210
+ }
211
+ },
212
+
213
+ handleClick(type, { value, disabled }) {
214
+ if (!disabled) {
215
+ this.modifyDateField(type, value)
216
+ this.emitSelectRange(type)
217
+ this.adjustSpinner(type, value)
218
+ }
219
+ },
220
+
221
+ emitSelectRange(type) {
222
+ if (type === 'hours') {
223
+ this.$emit('select-range', 0, 2)
224
+ } else if (type === 'minutes') {
225
+ this.$emit('select-range', 3, 5)
226
+ } else if (type === 'seconds') {
227
+ this.$emit('select-range', 6, 8)
228
+ }
229
+ this.currentScrollbar = type
230
+ },
231
+
232
+ bindScrollEvent() {
233
+ const bindFuntion = (type) => {
234
+ this.$refs[type].wrap.onscroll = (e) => {
235
+ // TODO: scroll is emitted when set scrollTop programatically
236
+ // should find better solutions in the future!
237
+ this.handleScroll(type, e)
238
+ }
239
+ }
240
+ bindFuntion('hours')
241
+ bindFuntion('minutes')
242
+ bindFuntion('seconds')
243
+ },
244
+
245
+ handleScroll(type) {
246
+ const value = Math.min(Math.round((this.$refs[type].wrap.scrollTop - (this.scrollBarHeight(type) * 0.5 - 10) / this.typeItemHeight(type) + 3) / this.typeItemHeight(type)), (type === 'hours' ? 23 : 59))
247
+ this.modifyDateField(type, value)
248
+ },
249
+
250
+ // NOTE: used by datetime / date-range panel
251
+ // renamed from adjustScrollTop
252
+ // should try to refactory it
253
+ adjustSpinners() {
254
+ this.adjustSpinner('hours', this.hours)
255
+ this.adjustSpinner('minutes', this.minutes)
256
+ this.adjustSpinner('seconds', this.seconds)
257
+ },
258
+
259
+ adjustCurrentSpinner(type) {
260
+ this.adjustSpinner(type, this[type])
261
+ },
262
+
263
+ adjustSpinner(type, value) {
264
+ if (this.arrowControl) return
265
+ const el = this.$refs[type].wrap
266
+ if (el) {
267
+ el.scrollTop = Math.max(0, value * this.typeItemHeight(type))
268
+ }
269
+ },
270
+
271
+ scrollDown(step) {
272
+ if (!this.currentScrollbar) {
273
+ this.emitSelectRange('hours')
274
+ }
275
+
276
+ const label = this.currentScrollbar
277
+ const hoursList = this.hoursList
278
+ let now = this[label]
279
+
280
+ if (this.currentScrollbar === 'hours') {
281
+ let total = Math.abs(step)
282
+ step = step > 0 ? 1 : -1
283
+ let length = hoursList.length
284
+ while (length-- && total) {
285
+ now = (now + step + hoursList.length) % hoursList.length
286
+ if (hoursList[now]) {
287
+ continue
288
+ }
289
+ total--
290
+ }
291
+ if (hoursList[now]) return
292
+ } else {
293
+ now = (now + step + 60) % 60
294
+ }
295
+
296
+ this.modifyDateField(label, now)
297
+ this.adjustSpinner(label, now)
298
+ this.$nextTick(() => this.emitSelectRange(this.currentScrollbar))
299
+ },
300
+ amPm(hour) {
301
+ const shouldShowAmPm = this.amPmMode.toLowerCase() === 'a'
302
+ if (!shouldShowAmPm) return ''
303
+ const isCapital = this.amPmMode === 'A'
304
+ let content = (hour < 12) ? ' am' : ' pm'
305
+ if (isCapital) content = content.toUpperCase()
306
+ return content
307
+ },
308
+ typeItemHeight(type) {
309
+ return this.$refs[type].$el.querySelector('li').offsetHeight
310
+ },
311
+ scrollBarHeight(type) {
312
+ return this.$refs[type].$el.offsetHeight
313
+ }
314
+ }
315
+ }
316
+ </script>