Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
genary
uni-app
提交
59c88b61
U
uni-app
项目概览
genary
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
59c88b61
编写于
12月 10, 2018
作者:
X
xiaoyucoding
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: 修复 picker 未设置 value 值时报错的问题
上级
cf84fd78
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
159 addition
and
119 deletion
+159
-119
src/core/view/components/picker/index.vue
src/core/view/components/picker/index.vue
+1
-1
src/platforms/h5/components/app/popup/picker.vue
src/platforms/h5/components/app/popup/picker.vue
+143
-118
src/shared/util.js
src/shared/util.js
+15
-0
未找到文件。
src/core/view/components/picker/index.vue
浏览文件 @
59c88b61
...
@@ -48,7 +48,7 @@ export default {
...
@@ -48,7 +48,7 @@ export default {
},
},
value
:
{
value
:
{
type
:
[
Number
,
String
,
Array
],
type
:
[
Number
,
String
,
Array
],
default
:
''
default
:
0
},
},
mode
:
{
mode
:
{
type
:
String
,
type
:
String
,
...
...
src/platforms/h5/components/app/popup/picker.vue
浏览文件 @
59c88b61
<
template
>
<
template
>
<uni-picker
@
touchmove.prevent
>
<uni-picker
@
touchmove.prevent
>
<transition
<transition
name=
"uni-fade"
>
name=
"uni-fade"
>
<div
<div
v-show=
"visible"
v-show=
"visible"
class=
"uni-mask"
class=
"uni-mask"
...
@@ -40,6 +39,10 @@
...
@@ -40,6 +39,10 @@
</uni-picker>
</uni-picker>
</
template
>
</
template
>
<
script
>
<
script
>
import
{
formatDateTime
}
from
'
uni-shared
'
const
mode
=
{
const
mode
=
{
SELECTOR
:
'
selector
'
,
SELECTOR
:
'
selector
'
,
MULTISELECTOR
:
'
multiSelector
'
,
MULTISELECTOR
:
'
multiSelector
'
,
...
@@ -151,7 +154,8 @@ export default {
...
@@ -151,7 +154,8 @@ export default {
return
val
return
val
case
mode
.
TIME
:
case
mode
.
TIME
:
return
this
.
timeArray
return
this
.
timeArray
case
mode
.
DATE
:
{
case
mode
.
DATE
:
{
let
dateArray
=
this
.
dateArray
let
dateArray
=
this
.
dateArray
switch
(
this
.
fields
)
{
switch
(
this
.
fields
)
{
case
fields
.
YEAR
:
case
fields
.
YEAR
:
...
@@ -166,11 +170,13 @@ export default {
...
@@ -166,11 +170,13 @@ export default {
},
},
startArray
()
{
startArray
()
{
var
splitStr
=
this
.
mode
===
mode
.
DATE
?
'
-
'
:
'
:
'
var
splitStr
=
this
.
mode
===
mode
.
DATE
?
'
-
'
:
'
:
'
return
this
.
start
.
split
(
splitStr
).
map
((
val
,
i
)
=>
(
this
.
mode
===
mode
.
DATE
?
this
.
dateArray
:
this
.
timeArray
)[
i
].
indexOf
(
val
))
return
this
.
start
.
split
(
splitStr
).
map
((
val
,
i
)
=>
(
this
.
mode
===
mode
.
DATE
?
this
.
dateArray
:
this
.
timeArray
)[
i
].
indexOf
(
val
))
},
},
endArray
()
{
endArray
()
{
var
splitStr
=
this
.
mode
===
mode
.
DATE
?
'
-
'
:
'
:
'
var
splitStr
=
this
.
mode
===
mode
.
DATE
?
'
-
'
:
'
:
'
return
this
.
end
.
split
(
splitStr
).
map
((
val
,
i
)
=>
(
this
.
mode
===
mode
.
DATE
?
this
.
dateArray
:
this
.
timeArray
)[
i
].
indexOf
(
val
))
return
this
.
end
.
split
(
splitStr
).
map
((
val
,
i
)
=>
(
this
.
mode
===
mode
.
DATE
?
this
.
dateArray
:
this
.
timeArray
)[
i
].
indexOf
(
val
))
},
},
units
()
{
units
()
{
switch
(
this
.
mode
)
{
switch
(
this
.
mode
)
{
...
@@ -211,7 +217,7 @@ export default {
...
@@ -211,7 +217,7 @@ export default {
created
()
{
created
()
{
this
.
_createTime
()
this
.
_createTime
()
this
.
_createDate
()
this
.
_createDate
()
this
.
_setValue
(
this
.
value
)
this
.
_setValue
()
this
.
$watch
(
'
value
'
,
this
.
_setValue
)
this
.
$watch
(
'
value
'
,
this
.
_setValue
)
this
.
$watch
(
'
mode
'
,
this
.
_setValue
)
this
.
$watch
(
'
mode
'
,
this
.
_setValue
)
},
},
...
@@ -270,9 +276,21 @@ export default {
...
@@ -270,9 +276,21 @@ export default {
valueArray
=
[...
val
]
valueArray
=
[...
val
]
break
break
case
mode
.
TIME
:
case
mode
.
TIME
:
// 处理默认值为当前时间
if
(
this
.
value
===
0
)
{
val
=
formatDateTime
({
mode
:
mode
.
TIME
})
}
valueArray
=
val
.
split
(
'
:
'
).
map
((
val
,
i
)
=>
this
.
timeArray
[
i
].
indexOf
(
val
))
valueArray
=
val
.
split
(
'
:
'
).
map
((
val
,
i
)
=>
this
.
timeArray
[
i
].
indexOf
(
val
))
break
break
case
mode
.
DATE
:
case
mode
.
DATE
:
// 处理默认值为当前日期
if
(
this
.
value
===
0
)
{
val
=
formatDateTime
({
mode
:
mode
.
DATE
})
}
valueArray
=
val
.
split
(
'
-
'
).
map
((
val
,
i
)
=>
this
.
dateArray
[
i
].
indexOf
(
val
))
valueArray
=
val
.
split
(
'
-
'
).
map
((
val
,
i
)
=>
this
.
dateArray
[
i
].
indexOf
(
val
))
break
break
}
}
...
@@ -316,12 +334,12 @@ export default {
...
@@ -316,12 +334,12 @@ export default {
}
}
</
script
>
</
script
>
<
style
>
<
style
>
uni-picker
{
uni-picker
{
display
:
block
;
display
:
block
;
box-sizing
:
border-box
;
box-sizing
:
border-box
;
}
}
uni-picker
.uni-picker
{
uni-picker
.uni-picker
{
position
:
fixed
;
position
:
fixed
;
left
:
0
;
left
:
0
;
bottom
:
0
;
bottom
:
0
;
...
@@ -331,17 +349,17 @@ uni-picker .uni-picker {
...
@@ -331,17 +349,17 @@ uni-picker .uni-picker {
width
:
100%
;
width
:
100%
;
background-color
:
#efeff4
;
background-color
:
#efeff4
;
transition
:
transform
0.3s
;
transition
:
transform
0.3s
;
}
}
uni-picker
.uni-picker.uni-picker_toggle
{
uni-picker
.uni-picker.uni-picker_toggle
{
transform
:
translate
(
0
,
0
);
transform
:
translate
(
0
,
0
);
}
}
uni-picker
.uni-picker
*
{
uni-picker
.uni-picker
*
{
box-sizing
:
border-box
;
box-sizing
:
border-box
;
}
}
uni-picker
.uni-picker
{
uni-picker
.uni-picker
{
position
:
fixed
;
position
:
fixed
;
left
:
0
;
left
:
0
;
bottom
:
0
;
bottom
:
0
;
...
@@ -352,16 +370,17 @@ uni-picker .uni-picker {
...
@@ -352,16 +370,17 @@ uni-picker .uni-picker {
background-color
:
#efeff4
;
background-color
:
#efeff4
;
transition
:
transform
0.3s
;
transition
:
transform
0.3s
;
transition
:
transform
0.3s
;
transition
:
transform
0.3s
;
}
}
uni-picker
.uni-picker-content
{
uni-picker
.uni-picker-content
{
position
:
relative
;
position
:
relative
;
display
:
block
;
display
:
block
;
width
:
100%
;
width
:
100%
;
height
:
238px
;
height
:
238px
;
background-color
:
white
;
background-color
:
white
;
}
}
uni-picker
.uni-picker-item
{
uni-picker
.uni-picker-item
{
padding
:
0
;
padding
:
0
;
height
:
34px
;
height
:
34px
;
line-height
:
34px
;
line-height
:
34px
;
...
@@ -370,16 +389,18 @@ uni-picker .uni-picker-item {
...
@@ -370,16 +389,18 @@ uni-picker .uni-picker-item {
text-overflow
:
ellipsis
;
text-overflow
:
ellipsis
;
white-space
:
nowrap
;
white-space
:
nowrap
;
overflow
:
hidden
;
overflow
:
hidden
;
}
}
uni-picker
.uni-picker-header
{
uni-picker
.uni-picker-header
{
display
:
block
;
display
:
block
;
position
:
relative
;
position
:
relative
;
text-align
:
center
;
text-align
:
center
;
width
:
100%
;
width
:
100%
;
height
:
45px
;
height
:
45px
;
background-color
:
#fff
;
background-color
:
#fff
;
}
}
uni-picker
.uni-picker-header
:after
{
uni-picker
.uni-picker-header
:after
{
content
:
""
;
content
:
""
;
position
:
absolute
;
position
:
absolute
;
left
:
0
;
left
:
0
;
...
@@ -391,8 +412,9 @@ uni-picker .uni-picker-header:after {
...
@@ -391,8 +412,9 @@ uni-picker .uni-picker-header:after {
color
:
#e5e5e5
;
color
:
#e5e5e5
;
transform-origin
:
0
100%
;
transform-origin
:
0
100%
;
transform
:
scaleY
(
0.5
);
transform
:
scaleY
(
0.5
);
}
}
uni-picker
.uni-picker-action
{
uni-picker
.uni-picker-action
{
display
:
block
;
display
:
block
;
max-width
:
50%
;
max-width
:
50%
;
top
:
0
;
top
:
0
;
...
@@ -402,16 +424,19 @@ uni-picker .uni-picker-action {
...
@@ -402,16 +424,19 @@ uni-picker .uni-picker-action {
font-size
:
17px
;
font-size
:
17px
;
line-height
:
45px
;
line-height
:
45px
;
overflow
:
hidden
;
overflow
:
hidden
;
}
}
uni-picker
.uni-picker-action.uni-picker-action-cancel
{
uni-picker
.uni-picker-action.uni-picker-action-cancel
{
float
:
left
;
float
:
left
;
color
:
#888
;
color
:
#888
;
}
}
uni-picker
.uni-picker-action.uni-picker-action-confirm
{
uni-picker
.uni-picker-action.uni-picker-action-confirm
{
float
:
right
;
float
:
right
;
color
:
#007aff
;
color
:
#007aff
;
}
}
/* .uni-picker {
/* .uni-picker {
position: relative;
position: relative;
}
}
.uni-picker-units {
.uni-picker-units {
...
...
src/shared/util.js
浏览文件 @
59c88b61
const
_toString
=
Object
.
prototype
.
toString
const
_toString
=
Object
.
prototype
.
toString
const
hasOwnProperty
=
Object
.
prototype
.
hasOwnProperty
const
hasOwnProperty
=
Object
.
prototype
.
hasOwnProperty
const
_completeValue
=
value
=>
{
return
value
>
9
?
value
:
(
'
0
'
+
value
)
}
export
function
isFn
(
fn
)
{
export
function
isFn
(
fn
)
{
return
typeof
fn
===
'
function
'
return
typeof
fn
===
'
function
'
}
}
...
@@ -35,3 +39,14 @@ export function getLen (str = '') {
...
@@ -35,3 +39,14 @@ export function getLen (str = '') {
/* eslint-disable no-control-regex */
/* eslint-disable no-control-regex */
return
(
''
+
str
).
replace
(
/
[^\x
00-
\x
ff
]
/g
,
'
**
'
).
length
return
(
''
+
str
).
replace
(
/
[^\x
00-
\x
ff
]
/g
,
'
**
'
).
length
}
}
export
function
formatDateTime
({
date
=
new
Date
(),
mode
=
'
date
'
})
{
if
(
mode
===
'
time
'
)
{
return
_completeValue
(
date
.
getHours
())
+
'
:
'
+
_completeValue
(
date
.
getMinutes
())
}
else
{
return
date
.
getFullYear
()
+
'
-
'
+
_completeValue
(
date
.
getMonth
()
+
1
)
+
'
-
'
+
_completeValue
(
date
.
getDate
())
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录