@94ai/nf-timezone-picker 5.0.0
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.
- package/.eslintrc.cjs +49 -0
- package/README.md +17 -0
- package/components.d.ts +8 -0
- package/lib/basic/date-table.vue.d.ts +86 -0
- package/lib/basic/month-table.vue.d.ts +51 -0
- package/lib/basic/time-spinner.vue.d.ts +42 -0
- package/lib/basic/year-table.vue.d.ts +26 -0
- package/lib/index.d.ts +333 -0
- package/lib/nf-timezone-picker.cjs.js +5984 -0
- package/lib/nf-timezone-picker.esm-bundler.js +5984 -0
- package/lib/nf-timezone-picker.vue.d.ts +157 -0
- package/lib/panel/date-range.vue.d.ts +55 -0
- package/lib/panel/date.vue.d.ts +35 -0
- package/lib/panel/month-range.vue.d.ts +30 -0
- package/lib/panel/time.vue.d.ts +27 -0
- package/lib/picker.vue.d.ts +142 -0
- package/lib/style/css.d.ts +1 -0
- package/lib/style/css.js +1 -0
- package/lib/style/index.d.ts +1 -0
- package/lib/style/index.js +1 -0
- package/package/basic/date-table.vue +448 -0
- package/package/basic/month-table.vue +253 -0
- package/package/basic/time-spinner.vue +316 -0
- package/package/basic/year-table.vue +101 -0
- package/package/index.ts +7 -0
- package/package/nf-timezone-picker.vue +50 -0
- package/package/panel/date-range.vue +700 -0
- package/package/panel/date.vue +607 -0
- package/package/panel/month-range.vue +293 -0
- package/package/panel/time-range.vue +254 -0
- package/package/panel/time-select.vue +178 -0
- package/package/panel/time.vue +189 -0
- package/package/picker/date-picker.js +43 -0
- package/package/picker/time-picker.js +39 -0
- package/package/picker/time-select.js +21 -0
- package/package/picker.vue +943 -0
- package/package/popper.js +1276 -0
- package/package/style/css.ts +1 -0
- package/package/style/index.ts +1 -0
- package/package.json +34 -0
- package/postcss.config.js +8 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<transition name="el-zoom-in-top" @before-enter="handleMenuEnter" @after-leave="$emit('dodestroy')">
|
|
3
|
+
<div
|
|
4
|
+
v-show="visible"
|
|
5
|
+
ref="popper"
|
|
6
|
+
:style="{ width: width + 'px' }"
|
|
7
|
+
:class="popperClass"
|
|
8
|
+
class="el-picker-panel time-select el-popper"
|
|
9
|
+
>
|
|
10
|
+
<el-scrollbar noresize wrap-class="el-picker-panel__content">
|
|
11
|
+
<div
|
|
12
|
+
v-for="item in items"
|
|
13
|
+
:key="item.value"
|
|
14
|
+
class="time-select-item"
|
|
15
|
+
:class="{ selected: value === item.value, disabled: item.disabled, default: item.value === defaultValue }"
|
|
16
|
+
:disabled="item.disabled"
|
|
17
|
+
@click="handleClick(item)"
|
|
18
|
+
>{{ item.value }}</div>
|
|
19
|
+
</el-scrollbar>
|
|
20
|
+
</div>
|
|
21
|
+
</transition>
|
|
22
|
+
</template>
|
|
23
|
+
|
|
24
|
+
<script type="text/babel">
|
|
25
|
+
import scrollIntoView from 'element-ui/src/utils/scroll-into-view'
|
|
26
|
+
|
|
27
|
+
const parseTime = function(time) {
|
|
28
|
+
const values = (time || '').split(':')
|
|
29
|
+
if (values.length >= 2) {
|
|
30
|
+
const hours = parseInt(values[0], 10)
|
|
31
|
+
const minutes = parseInt(values[1], 10)
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
hours,
|
|
35
|
+
minutes
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/* istanbul ignore next */
|
|
39
|
+
return null
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const compareTime = function(time1, time2) {
|
|
43
|
+
const value1 = parseTime(time1)
|
|
44
|
+
const value2 = parseTime(time2)
|
|
45
|
+
|
|
46
|
+
const minutes1 = value1.minutes + value1.hours * 60
|
|
47
|
+
const minutes2 = value2.minutes + value2.hours * 60
|
|
48
|
+
|
|
49
|
+
if (minutes1 === minutes2) {
|
|
50
|
+
return 0
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return minutes1 > minutes2 ? 1 : -1
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const formatTime = function(time) {
|
|
57
|
+
return (time.hours < 10 ? '0' + time.hours : time.hours) + ':' + (time.minutes < 10 ? '0' + time.minutes : time.minutes)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const nextTime = function(time, step) {
|
|
61
|
+
const timeValue = parseTime(time)
|
|
62
|
+
const stepValue = parseTime(step)
|
|
63
|
+
|
|
64
|
+
const next = {
|
|
65
|
+
hours: timeValue.hours,
|
|
66
|
+
minutes: timeValue.minutes
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
next.minutes += stepValue.minutes
|
|
70
|
+
next.hours += stepValue.hours
|
|
71
|
+
|
|
72
|
+
next.hours += Math.floor(next.minutes / 60)
|
|
73
|
+
next.minutes = next.minutes % 60
|
|
74
|
+
|
|
75
|
+
return formatTime(next)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export default {
|
|
79
|
+
data() {
|
|
80
|
+
return {
|
|
81
|
+
popperClass: '',
|
|
82
|
+
start: '09:00',
|
|
83
|
+
end: '18:00',
|
|
84
|
+
step: '00:30',
|
|
85
|
+
value: '',
|
|
86
|
+
defaultValue: '',
|
|
87
|
+
visible: false,
|
|
88
|
+
minTime: '',
|
|
89
|
+
maxTime: '',
|
|
90
|
+
width: 0
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
|
|
94
|
+
computed: {
|
|
95
|
+
items() {
|
|
96
|
+
const start = this.start
|
|
97
|
+
const end = this.end
|
|
98
|
+
const step = this.step
|
|
99
|
+
|
|
100
|
+
const result = []
|
|
101
|
+
|
|
102
|
+
if (start && end && step) {
|
|
103
|
+
let current = start
|
|
104
|
+
while (compareTime(current, end) <= 0) {
|
|
105
|
+
result.push({
|
|
106
|
+
value: current,
|
|
107
|
+
disabled: compareTime(current, this.minTime || '-1:-1') <= 0 ||
|
|
108
|
+
compareTime(current, this.maxTime || '100:100') >= 0
|
|
109
|
+
})
|
|
110
|
+
current = nextTime(current, step)
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return result
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
|
|
118
|
+
watch: {
|
|
119
|
+
value(val) {
|
|
120
|
+
if (!val) return
|
|
121
|
+
this.$nextTick(() => this.scrollToOption())
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
|
|
125
|
+
methods: {
|
|
126
|
+
handleClick(item) {
|
|
127
|
+
if (!item.disabled) {
|
|
128
|
+
this.$emit('pick', item.value)
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
handleClear() {
|
|
133
|
+
this.$emit('pick', null)
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
scrollToOption(selector = '.selected') {
|
|
137
|
+
const menu = this.$refs.popper.querySelector('.el-picker-panel__content')
|
|
138
|
+
scrollIntoView(menu, menu.querySelector(selector))
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
handleMenuEnter() {
|
|
142
|
+
const selected = this.items.map(item => item.value).indexOf(this.value) !== -1
|
|
143
|
+
const hasDefault = this.items.map(item => item.value).indexOf(this.defaultValue) !== -1
|
|
144
|
+
const option = (selected && '.selected') || (hasDefault && '.default') || '.time-select-item:not(.disabled)'
|
|
145
|
+
this.$nextTick(() => this.scrollToOption(option))
|
|
146
|
+
},
|
|
147
|
+
|
|
148
|
+
scrollDown(step) {
|
|
149
|
+
const items = this.items
|
|
150
|
+
const length = items.length
|
|
151
|
+
let total = items.length
|
|
152
|
+
let index = items.map(item => item.value).indexOf(this.value)
|
|
153
|
+
while (total--) {
|
|
154
|
+
index = (index + step + length) % length
|
|
155
|
+
if (!items[index].disabled) {
|
|
156
|
+
this.$emit('pick', items[index].value, true)
|
|
157
|
+
return
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
isValidValue(date) {
|
|
163
|
+
return this.items.filter(item => !item.disabled).map(item => item.value).indexOf(date) !== -1
|
|
164
|
+
},
|
|
165
|
+
|
|
166
|
+
handleKeydown(event) {
|
|
167
|
+
const keyCode = event.keyCode
|
|
168
|
+
if (keyCode === 38 || keyCode === 40) {
|
|
169
|
+
const mapping = { 40: 1, 38: -1 }
|
|
170
|
+
const offset = mapping[keyCode.toString()]
|
|
171
|
+
this.scrollDown(offset)
|
|
172
|
+
event.stopPropagation()
|
|
173
|
+
return
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
</script>
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<transition name="el-zoom-in-top" @after-leave="$emit('dodestroy')">
|
|
3
|
+
<div
|
|
4
|
+
v-show="visible"
|
|
5
|
+
class="el-time-panel el-popper"
|
|
6
|
+
:class="popperClass"
|
|
7
|
+
>
|
|
8
|
+
<div class="el-time-panel__content" :class="{ 'has-seconds': showSeconds }">
|
|
9
|
+
<time-spinner
|
|
10
|
+
ref="spinner"
|
|
11
|
+
:arrow-control="useArrow"
|
|
12
|
+
:show-seconds="showSeconds"
|
|
13
|
+
:am-pm-mode="amPmMode"
|
|
14
|
+
:date="date"
|
|
15
|
+
@change="handleChange"
|
|
16
|
+
@select-range="setSelectionRange"
|
|
17
|
+
/>
|
|
18
|
+
</div>
|
|
19
|
+
<div class="el-time-panel__footer">
|
|
20
|
+
<button
|
|
21
|
+
type="button"
|
|
22
|
+
class="el-time-panel__btn cancel"
|
|
23
|
+
@click="handleCancel"
|
|
24
|
+
>{{ t('el.datepicker.cancel') }}</button>
|
|
25
|
+
<button
|
|
26
|
+
type="button"
|
|
27
|
+
class="el-time-panel__btn"
|
|
28
|
+
:class="{confirm: !disabled}"
|
|
29
|
+
@click="handleConfirm()"
|
|
30
|
+
>{{ t('el.datepicker.confirm') }}</button>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
</transition>
|
|
34
|
+
</template>
|
|
35
|
+
|
|
36
|
+
<script type="text/babel">
|
|
37
|
+
import { limitTimeRange, isDate, clearMilliseconds, timeWithinRange } from 'element-ui/src/utils/date-util'
|
|
38
|
+
import Locale from 'element-ui/src/mixins/locale'
|
|
39
|
+
import TimeSpinner from '../basic/time-spinner.vue'
|
|
40
|
+
|
|
41
|
+
export default {
|
|
42
|
+
|
|
43
|
+
components: {
|
|
44
|
+
TimeSpinner
|
|
45
|
+
},
|
|
46
|
+
mixins: [Locale],
|
|
47
|
+
|
|
48
|
+
props: {
|
|
49
|
+
visible: Boolean,
|
|
50
|
+
timeArrowControl: Boolean
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
data() {
|
|
54
|
+
return {
|
|
55
|
+
popperClass: '',
|
|
56
|
+
format: 'HH:mm:ss',
|
|
57
|
+
value: '',
|
|
58
|
+
defaultValue: null,
|
|
59
|
+
date: new Date(),
|
|
60
|
+
oldValue: new Date(),
|
|
61
|
+
selectableRange: [],
|
|
62
|
+
selectionRange: [0, 2],
|
|
63
|
+
disabled: false,
|
|
64
|
+
arrowControl: false,
|
|
65
|
+
needInitAdjust: true
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
computed: {
|
|
70
|
+
showSeconds() {
|
|
71
|
+
return (this.format || '').indexOf('ss') !== -1
|
|
72
|
+
},
|
|
73
|
+
useArrow() {
|
|
74
|
+
return this.arrowControl || this.timeArrowControl || false
|
|
75
|
+
},
|
|
76
|
+
amPmMode() {
|
|
77
|
+
if ((this.format || '').indexOf('A') !== -1) return 'A'
|
|
78
|
+
if ((this.format || '').indexOf('a') !== -1) return 'a'
|
|
79
|
+
return ''
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
|
|
83
|
+
watch: {
|
|
84
|
+
visible(val) {
|
|
85
|
+
if (val) {
|
|
86
|
+
this.oldValue = this.value
|
|
87
|
+
this.$nextTick(() => this.$refs.spinner.emitSelectRange('hours'))
|
|
88
|
+
} else {
|
|
89
|
+
this.needInitAdjust = true
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
value(newVal) {
|
|
94
|
+
let date
|
|
95
|
+
if (newVal instanceof Date) {
|
|
96
|
+
date = limitTimeRange(newVal, this.selectableRange, this.format)
|
|
97
|
+
} else if (!newVal) {
|
|
98
|
+
date = this.defaultValue ? new Date(this.defaultValue) : new Date()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
this.date = date
|
|
102
|
+
if (this.visible && this.needInitAdjust) {
|
|
103
|
+
this.$nextTick(_ => this.adjustSpinners())
|
|
104
|
+
this.needInitAdjust = false
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
selectableRange(val) {
|
|
109
|
+
this.$refs.spinner.selectableRange = val
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
defaultValue(val) {
|
|
113
|
+
if (!isDate(this.value)) {
|
|
114
|
+
this.date = val ? new Date(val) : new Date()
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
|
|
119
|
+
mounted() {
|
|
120
|
+
this.$nextTick(() => this.handleConfirm(true, true))
|
|
121
|
+
this.$emit('mounted')
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
methods: {
|
|
125
|
+
handleCancel() {
|
|
126
|
+
this.$emit('pick', this.oldValue, false)
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
handleChange(date) {
|
|
130
|
+
// this.visible avoids edge cases, when use scrolls during panel closing animation
|
|
131
|
+
if (this.visible) {
|
|
132
|
+
this.date = clearMilliseconds(date)
|
|
133
|
+
// if date is out of range, do not emit
|
|
134
|
+
if (this.isValidValue(this.date)) {
|
|
135
|
+
this.$emit('pick', this.date, true)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
setSelectionRange(start, end) {
|
|
141
|
+
this.$emit('select-range', start, end)
|
|
142
|
+
this.selectionRange = [start, end]
|
|
143
|
+
},
|
|
144
|
+
|
|
145
|
+
handleConfirm(visible = false, first) {
|
|
146
|
+
if (first) return
|
|
147
|
+
const date = clearMilliseconds(limitTimeRange(this.date, this.selectableRange, this.format))
|
|
148
|
+
this.$emit('pick', date, visible, first)
|
|
149
|
+
},
|
|
150
|
+
|
|
151
|
+
handleKeydown(event) {
|
|
152
|
+
const keyCode = event.keyCode
|
|
153
|
+
const mapping = { 38: -1, 40: 1, 37: -1, 39: 1 }
|
|
154
|
+
|
|
155
|
+
// Left or Right
|
|
156
|
+
if (keyCode === 37 || keyCode === 39) {
|
|
157
|
+
const step = mapping[keyCode]
|
|
158
|
+
this.changeSelectionRange(step)
|
|
159
|
+
event.preventDefault()
|
|
160
|
+
return
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Up or Down
|
|
164
|
+
if (keyCode === 38 || keyCode === 40) {
|
|
165
|
+
const step = mapping[keyCode]
|
|
166
|
+
this.$refs.spinner.scrollDown(step)
|
|
167
|
+
event.preventDefault()
|
|
168
|
+
return
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
|
|
172
|
+
isValidValue(date) {
|
|
173
|
+
return timeWithinRange(date, this.selectableRange, this.format)
|
|
174
|
+
},
|
|
175
|
+
|
|
176
|
+
adjustSpinners() {
|
|
177
|
+
return this.$refs.spinner.adjustSpinners()
|
|
178
|
+
},
|
|
179
|
+
|
|
180
|
+
changeSelectionRange(step) {
|
|
181
|
+
const list = [0, 3].concat(this.showSeconds ? [6] : [])
|
|
182
|
+
const mapping = ['hours', 'minutes'].concat(this.showSeconds ? ['seconds'] : [])
|
|
183
|
+
const index = list.indexOf(this.selectionRange[0])
|
|
184
|
+
const next = (index + step + list.length) % list.length
|
|
185
|
+
this.$refs.spinner.emitSelectRange(mapping[next])
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
</script>
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import Picker from '../picker'
|
|
2
|
+
import DatePanel from '../panel/date'
|
|
3
|
+
import DateRangePanel from '../panel/date-range'
|
|
4
|
+
import MonthRangePanel from '../panel/month-range'
|
|
5
|
+
|
|
6
|
+
const getPanel = function(type) {
|
|
7
|
+
if (type === 'daterange' || type === 'datetimerange') {
|
|
8
|
+
return DateRangePanel
|
|
9
|
+
} else if (type === 'monthrange') {
|
|
10
|
+
return MonthRangePanel
|
|
11
|
+
}
|
|
12
|
+
return DatePanel
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
mixins: [Picker],
|
|
17
|
+
|
|
18
|
+
name: 'ElDatePicker',
|
|
19
|
+
|
|
20
|
+
props: {
|
|
21
|
+
type: {
|
|
22
|
+
type: String,
|
|
23
|
+
default: 'date'
|
|
24
|
+
},
|
|
25
|
+
timeArrowControl: Boolean
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
watch: {
|
|
29
|
+
type(type) {
|
|
30
|
+
if (this.picker) {
|
|
31
|
+
this.unmountPicker()
|
|
32
|
+
this.panel = getPanel(type)
|
|
33
|
+
this.mountPicker()
|
|
34
|
+
} else {
|
|
35
|
+
this.panel = getPanel(type)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
|
|
40
|
+
created() {
|
|
41
|
+
this.panel = getPanel(this.type)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import Picker from '../picker'
|
|
2
|
+
import TimePanel from '../panel/time'
|
|
3
|
+
import TimeRangePanel from '../panel/time-range'
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
mixins: [Picker],
|
|
7
|
+
|
|
8
|
+
name: 'ElTimePicker',
|
|
9
|
+
|
|
10
|
+
props: {
|
|
11
|
+
isRange: Boolean,
|
|
12
|
+
arrowControl: Boolean
|
|
13
|
+
},
|
|
14
|
+
|
|
15
|
+
data() {
|
|
16
|
+
return {
|
|
17
|
+
type: ''
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
watch: {
|
|
22
|
+
isRange(isRange) {
|
|
23
|
+
if (this.picker) {
|
|
24
|
+
this.unmountPicker()
|
|
25
|
+
this.type = isRange ? 'timerange' : 'time'
|
|
26
|
+
this.panel = isRange ? TimeRangePanel : TimePanel
|
|
27
|
+
this.mountPicker()
|
|
28
|
+
} else {
|
|
29
|
+
this.type = isRange ? 'timerange' : 'time'
|
|
30
|
+
this.panel = isRange ? TimeRangePanel : TimePanel
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
|
|
35
|
+
created() {
|
|
36
|
+
this.type = this.isRange ? 'timerange' : 'time'
|
|
37
|
+
this.panel = this.isRange ? TimeRangePanel : TimePanel
|
|
38
|
+
}
|
|
39
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import Picker from '../picker'
|
|
2
|
+
import Panel from '../panel/time-select'
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
mixins: [Picker],
|
|
6
|
+
|
|
7
|
+
name: 'ElTimeSelect',
|
|
8
|
+
|
|
9
|
+
componentName: 'ElTimeSelect',
|
|
10
|
+
|
|
11
|
+
props: {
|
|
12
|
+
type: {
|
|
13
|
+
type: String,
|
|
14
|
+
default: 'time-select'
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
|
|
18
|
+
beforeCreate() {
|
|
19
|
+
this.panel = Panel
|
|
20
|
+
}
|
|
21
|
+
}
|