提交 29ea5065 编写于 作者: D DCloud_LXH

feat: picker mode="date" 初始化时范围包含用户传入的 start.year、end.year question/131332

上级 75dc84da
......@@ -259,6 +259,16 @@ function usePickerColumnScroll(
) {
let scrollToElementTime: number
function setDomScrollToElement(_current: number, animated: boolean = true) {
dom.scrollToElement(contentRef.value, {
offset: _current * indicatorHeight.value,
animated,
})
if (animated) {
scrollToElementTime = Date.now()
}
}
watch(
() => props.length,
() => {
......@@ -267,29 +277,14 @@ function usePickerColumnScroll(
}, 150)
}
)
watch(
() => current.value,
(_current) => {
dom.scrollToElement(contentRef.value, {
offset: _current * indicatorHeight.value,
animated: true,
})
scrollToElementTime = Date.now()
}
)
watch(current, (val) => setDomScrollToElement(val))
const setCurrent = (_current: number, animated = true, force: Boolean) => {
if (current.value === _current && !force) {
return
}
dom.scrollToElement(contentRef.value, {
offset: _current * indicatorHeight.value,
animated,
})
current.value = _current
if (animated) {
scrollToElementTime = Date.now()
}
if (isAndroid) setDomScrollToElement(_current, animated)
}
const onScrollend = (event: {
detail: {
......
......@@ -9,6 +9,7 @@ import {
provide,
ExtractPropTypes,
Comment,
nextTick,
} from 'vue'
import { extend } from '@vue/shared'
import {
......@@ -130,10 +131,13 @@ function useState(props: Props) {
() => props.value,
(val) => {
state.value.length = val.length
val.forEach((val, index) => {
if (val !== state.value[index]) {
state.value.splice(index, 1, val)
}
// fixed by lxh 解决 picker 组件滑动出范围不重定向回 end
nextTick(() => {
val.forEach((val, index) => {
if (val !== state.value[index]) {
state.value.splice(index, 1, val)
}
})
})
}
)
......
......@@ -42,7 +42,7 @@ function getDefaultStartValue(props: Props) {
return '00:00'
}
if (props.mode === mode.DATE) {
const year = new Date().getFullYear() - 100
const year = new Date().getFullYear() - 150
switch (props.fields) {
case fields.YEAR:
return year.toString()
......@@ -59,7 +59,7 @@ function getDefaultEndValue(props: Props) {
return '23:59'
}
if (props.mode === mode.DATE) {
const year = new Date().getFullYear() + 100
const year = new Date().getFullYear() + 150
switch (props.fields) {
case fields.YEAR:
return year.toString()
......@@ -584,10 +584,33 @@ function usePickerMethods(
}
;(state.timeArray as TwoDimensionArray).push(hours, minutes)
}
function getYearStartEnd() {
let year = new Date().getFullYear()
let start = year - 150
let end = year + 150
if (props.start) {
const _year = new Date(props.start).getFullYear()
if (!isNaN(_year) && _year < start) {
start = _year
}
}
if (props.end) {
const _year = new Date(props.start).getFullYear()
if (!isNaN(_year) && _year > end) {
end = _year
}
}
return {
start,
end,
}
}
function _createDate() {
let years: string[] = []
let year = new Date().getFullYear()
for (let i = year - 150, end = year + 150; i <= end; i++) {
const year = getYearStartEnd()
for (let i = year.start, end = year.end; i <= end; i++) {
years.push(String(i))
}
let months: string[] = []
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册