Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DiDi
cube-ui
提交
4e743247
C
cube-ui
项目概览
DiDi
/
cube-ui
12 个月 前同步成功
通知
34
Star
9078
Fork
1508
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
C
cube-ui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4e743247
编写于
12月 01, 2017
作者:
A
AmyFoxFN
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update date-picker
上级
26462f66
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
79 addition
and
46 deletion
+79
-46
example/components/date-picker.vue
example/components/date-picker.vue
+79
-46
未找到文件。
example/components/date-picker.vue
浏览文件 @
4e743247
...
...
@@ -39,68 +39,45 @@
},
data
()
{
return
{
dateData
:
[],
tempIndex
:
[
0
,
0
,
0
],
values
:
[
0
,
0
,
0
]
}
},
mounted
()
{
this
.
values
=
[
this
.
years
[
this
.
selectedIndex
[
0
]],
this
.
month
[
this
.
selectedIndex
[
1
]],
this
.
day
[
this
.
selectedIndex
[
2
]]]
this
.
tempIndex
=
this
.
selectedIndex
},
computed
:
{
years
()
{
return
range
(
this
.
min
[
0
],
this
.
max
[
0
],
false
,
'
年
'
)
},
months
()
{
let
minMonth
=
!
this
.
tempIndex
[
0
]
?
this
.
min
[
1
]
:
1
let
maxMonth
=
this
.
tempIndex
[
0
]
===
this
.
years
.
length
-
1
?
this
.
max
[
1
]
:
12
return
range
(
minMonth
,
maxMonth
,
false
,
'
月
'
)
},
days
()
{
const
currentYear
=
this
.
years
[
this
.
tempIndex
[
0
]].
value
const
currentMonth
=
this
.
months
[
this
.
tempIndex
[
1
]].
value
let
day
=
30
if
([
1
,
3
,
5
,
7
,
8
,
10
,
12
].
includes
(
currentMonth
))
{
day
=
31
}
else
{
if
(
currentMonth
===
2
)
{
day
=
!
(
currentYear
%
400
)
||
(
!
(
currentYear
%
4
)
&&
currentYear
%
100
)
?
29
:
28
}
}
let
minDay
=
!
this
.
tempIndex
[
0
]
&&
!
this
.
tempIndex
[
1
]
?
this
.
min
[
2
]
:
1
let
maxDay
=
this
.
tempIndex
[
0
]
===
this
.
years
.
length
-
1
&&
this
.
tempIndex
[
1
]
===
this
.
months
.
length
-
1
?
this
.
max
[
2
]
:
day
let
days
=
range
(
minDay
,
maxDay
,
false
,
'
日
'
)
this
.
$refs
.
picker
.
setData
([
this
.
years
,
this
.
months
,
this
.
days
],
this
.
tempIndex
)
return
days
},
dateData
()
{
return
[
this
.
years
,
this
.
months
,
this
.
days
]
years
:
[],
months
:
[],
days
:
[],
year
:
0
,
month
:
0
,
day
:
0
}
},
watch
:
{
days
()
{
this
.
$refs
.
picker
.
setData
(
this
.
dateData
,
[
this
.
yearIndex
,
this
.
monthIndex
,
this
.
dayIndex
])
this
.
$refs
.
picker
.
refresh
()
year
()
{
this
.
updateMonths
()
},
month
()
{
this
.
updateDays
()
}
},
methods
:
{
show
()
{
this
.
$refs
.
picker
.
show
()
this
.
years
=
range
(
this
.
min
[
0
],
this
.
max
[
0
],
false
,
'
年
'
)
this
.
year
=
this
.
years
[
this
.
selectedIndex
[
0
]].
value
this
.
updateMonths
()
this
.
month
=
this
.
months
[
this
.
selectedIndex
[
1
]].
value
this
.
updateDays
()
this
.
day
=
this
.
days
[
this
.
selectedIndex
[
2
]].
value
this
.
tempIndex
=
this
.
selectedIndex
},
hide
()
{
this
.
$refs
.
picker
.
hide
()
},
change
(
i
,
newIndex
)
{
if
(
newIndex
!==
this
.
tempIndex
[
i
])
{
this
.
tempIndex
.
splice
(
i
,
1
,
newIndex
)
this
.
tempIndex
[
i
]
=
newIndex
}
if
(
this
.
dateData
[
i
][
newIndex
]
!==
this
.
value
[
i
])
{
this
.
values
.
splice
(
i
,
1
,
this
.
dateData
[
i
][
newIndex
])
const
keyMap
=
[
'
year
'
,
'
month
'
,
'
day
'
]
if
(
this
.
dateData
[
i
][
newIndex
]
!==
this
[
keyMap
[
i
]])
{
this
[
keyMap
[
i
]]
=
this
.
dateData
[
i
][
newIndex
].
value
}
},
select
(
selectedVal
,
selectedIndex
,
selectedText
)
{
...
...
@@ -108,6 +85,62 @@
},
cancel
()
{
this
.
$emit
(
EVENT_CANCEL
)
},
updateMonths
()
{
let
minMonth
=
this
.
year
===
this
.
min
[
0
]
?
this
.
min
[
1
]
:
1
let
maxMonth
=
this
.
year
===
this
.
max
[
0
]
?
this
.
max
[
1
]
:
12
this
.
months
=
range
(
minMonth
,
maxMonth
,
false
,
'
月
'
)
/* Try to keep the same month */
const
findIndex
=
this
.
months
.
findIndex
((
item
)
=>
{
return
item
.
value
===
this
.
month
})
if
(
findIndex
!==
-
1
)
{
this
.
tempIndex
.
splice
(
1
,
1
,
findIndex
)
this
.
updateDays
()
}
else
{
if
(
this
.
month
<
this
.
months
[
0
].
value
)
{
this
.
month
=
this
.
months
[
0
].
value
this
.
tempIndex
[
1
]
=
0
}
else
{
this
.
month
=
this
.
months
[
this
.
months
.
length
-
1
].
value
this
.
tempIndex
[
1
]
=
this
.
months
.
length
-
1
}
}
},
updateDays
()
{
let
day
=
30
if
([
1
,
3
,
5
,
7
,
8
,
10
,
12
].
includes
(
this
.
month
))
{
day
=
31
}
else
{
if
(
this
.
month
===
2
)
{
day
=
!
(
this
.
year
%
400
)
||
(
!
(
this
.
year
%
4
)
&&
this
.
year
%
100
)
?
29
:
28
}
}
let
minDay
=
this
.
year
===
this
.
min
[
0
]
&&
this
.
month
===
this
.
min
[
1
]
?
this
.
min
[
2
]
:
1
let
maxDay
=
this
.
year
===
this
.
max
[
0
]
&&
this
.
month
===
this
.
max
[
1
]
?
this
.
max
[
2
]
:
day
this
.
days
=
range
(
minDay
,
maxDay
,
false
,
'
日
'
)
/* Try to keep the same day */
const
self
=
this
const
findIndex
=
this
.
days
.
findIndex
((
item
)
=>
{
return
item
.
value
===
self
.
day
})
if
(
findIndex
!==
-
1
)
{
this
.
tempIndex
[
2
]
=
findIndex
}
else
{
this
.
day
=
this
.
day
<
this
.
days
[
0
].
value
?
this
.
days
[
0
].
value
:
this
.
days
[
this
.
days
.
length
-
1
].
value
}
this
.
dateData
=
[
this
.
years
,
this
.
months
,
this
.
days
]
// make sure picker render before call refillColumn
this
.
$nextTick
(()
=>
{
this
.
$refs
.
picker
.
scrollTo
(
1
,
this
.
tempIndex
[
1
])
this
.
$refs
.
picker
.
scrollTo
(
2
,
this
.
tempIndex
[
2
])
})
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录