提交 3c820822 编写于 作者: D DCloud_LXH

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

上级 da58fd56
......@@ -129,7 +129,7 @@ function getDefaultStartValue () {
return '00:00'
}
if (this.mode === mode.DATE) {
const year = new Date().getFullYear() - 100
const year = new Date().getFullYear() - 150
switch (this.fields) {
case fields.YEAR:
return year.toString()
......@@ -147,7 +147,7 @@ function getDefaultEndValue () {
return '23:59'
}
if (this.mode === mode.DATE) {
const year = new Date().getFullYear() + 100
const year = new Date().getFullYear() + 150
switch (this.fields) {
case fields.YEAR:
return year.toString()
......@@ -160,6 +160,29 @@ function getDefaultEndValue () {
return ''
}
function getYearStartEnd (props) {
const year = new Date().getFullYear()
let start = year - 61
let end = year + 61
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
}
}
const mode = {
SELECTOR: 'selector',
MULTISELECTOR: 'multiSelector',
......@@ -427,8 +450,8 @@ export default {
},
_createDate () {
var years = []
var year = new Date().getFullYear()
for (let i = year - 150, end = year + 150; i <= end; i++) {
var year = getYearStartEnd(this)
for (let i = year.start, end = year.end; i <= end; i++) {
years.push(String(i))
}
var months = []
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册