Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
genary
uni-app
提交
e91807da
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,发现更多精彩内容 >>
提交
e91807da
编写于
8月 18, 2020
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'feat-auto-blur' into dev
上级
83559f88
5b5ef1ee
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
128 addition
and
99 deletion
+128
-99
src/core/view/components/input/index.vue
src/core/view/components/input/index.vue
+1
-2
src/core/view/components/textarea/index.vue
src/core/view/components/textarea/index.vue
+1
-2
src/core/view/mixins/keyboard.js
src/core/view/mixins/keyboard.js
+125
-78
src/platforms/app-plus/service/framework/plugins/keyboard.js
src/platforms/app-plus/service/framework/plugins/keyboard.js
+1
-17
未找到文件。
src/core/view/components/input/index.vue
浏览文件 @
e91807da
...
...
@@ -18,6 +18,7 @@
<input
ref=
"input"
v-model=
"valueSync"
v-keyboard
:disabled=
"disabled"
:type=
"inputType"
:maxlength=
"maxlength"
...
...
@@ -153,8 +154,6 @@ export default {
}
$vm
=
$vm
.
$parent
}
this
.
initKeyboard
(
this
.
$refs
.
input
)
},
beforeDestroy
()
{
this
.
$dispatch
(
'
Form
'
,
'
uni-form-group-update
'
,
{
...
...
src/core/view/components/textarea/index.vue
浏览文件 @
e91807da
...
...
@@ -31,6 +31,7 @@
<textarea
ref=
"textarea"
v-model=
"valueSync"
v-keyboard
:disabled=
"disabled"
:maxlength=
"maxlengthNumber"
:autofocus=
"autoFocus || focus"
...
...
@@ -199,8 +200,6 @@ export default {
}
$vm
=
$vm
.
$parent
}
this
.
initKeyboard
(
this
.
$refs
.
textarea
)
},
beforeDestroy
()
{
this
.
$dispatch
(
'
Form
'
,
'
uni-form-group-update
'
,
{
...
...
src/core/view/mixins/keyboard.js
浏览文件 @
e91807da
...
...
@@ -2,14 +2,73 @@ import {
plusReady
}
from
'
uni-shared
'
function
hideKeyboard
()
{
document
.
activeElement
.
blur
()
}
/**
* 保证iOS点击输入框外隐藏键盘
*/
function
iosHideKeyboard
()
{
}
function
showSoftKeybord
()
{
plusReady
(()
=>
{
plus
.
key
.
showSoftKeybord
()
})
}
function
setSoftinputTemporary
(
vm
)
{
plusReady
(()
=>
{
const
currentWebview
=
plus
.
webview
.
currentWebview
()
const
style
=
currentWebview
.
getStyle
()
||
{}
const
rect
=
vm
.
$el
.
getBoundingClientRect
()
currentWebview
.
setSoftinputTemporary
&&
currentWebview
.
setSoftinputTemporary
({
mode
:
style
.
softinputMode
===
'
adjustResize
'
?
'
adjustResize
'
:
(
vm
.
adjustPosition
?
'
adjustPan
'
:
'
nothing
'
),
position
:
{
top
:
rect
.
top
,
height
:
rect
.
height
+
(
Number
(
vm
.
cursorSpacing
)
||
0
)
}
})
})
}
function
setSoftinputNavBar
(
vm
)
{
if
(
vm
.
showConfirmBar
===
'
auto
'
)
{
delete
vm
.
__softinputNavBar
return
}
plusReady
(()
=>
{
const
currentWebview
=
plus
.
webview
.
currentWebview
()
const
{
softinputNavBar
}
=
currentWebview
.
getStyle
()
||
{}
const
showConfirmBar
=
softinputNavBar
!==
'
none
'
if
(
showConfirmBar
!==
vm
.
showConfirmBar
)
{
vm
.
__softinputNavBar
=
softinputNavBar
||
'
auto
'
currentWebview
.
setStyle
({
softinputNavBar
:
vm
.
showConfirmBar
?
'
auto
'
:
'
none
'
})
}
else
{
delete
vm
.
__softinputNavBar
}
})
}
function
resetSoftinputNavBar
(
vm
)
{
const
softinputNavBar
=
vm
.
__softinputNavBar
if
(
softinputNavBar
)
{
plusReady
(()
=>
{
const
currentWebview
=
plus
.
webview
.
currentWebview
()
currentWebview
.
setStyle
({
softinputNavBar
})
})
}
}
let
isAndroid
let
osVersion
if
(
__PLATFORM__
===
'
app-plus
'
)
{
plusReady
(()
=>
{
isAndroid
=
plus
.
os
.
name
.
toLowerCase
()
===
'
android
'
osVersion
=
plus
.
os
.
version
})
}
export
default
{
name
:
'
Keyboard
'
,
props
:
{
...
...
@@ -22,103 +81,91 @@ export default {
default
:
'
auto
'
},
adjustPosition
:
{
type
:
Boolean
,
type
:
[
Boolean
,
String
],
default
:
true
},
autoBlur
:
{
type
:
[
Boolean
,
String
],
default
:
true
}
},
watch
:
{
focus
(
val
)
{
if
(
val
)
{
this
.
showSoftKeybord
()
if
(
val
&&
__PLATFORM__
===
'
app-plus
'
)
{
showSoftKeybord
()
}
}
},
mounted
()
{
if
(
this
.
autoFocus
||
this
.
focus
)
{
this
.
showSoftKeybord
()
directives
:
{
keyboard
:
{
inserted
(
el
,
binding
,
vnode
)
{
vnode
.
context
.
initKeyboard
(
el
)
}
}
},
beforeDestroy
()
{
this
.
onKeyboardHide
()
mounted
()
{
if
((
this
.
autoFocus
||
this
.
focus
)
&&
__PLATFORM__
===
'
app-plus
'
)
{
showSoftKeybord
()
}
},
methods
:
{
initKeyboard
(
el
)
{
el
.
addEventListener
(
'
focus
'
,
()
=>
{
this
.
hideKeyboardTemp
=
function
()
{
hideKeyboard
()
let
focus
let
keyboardHeight
const
keyboardChange
=
(
event
)
=>
{
keyboardHeight
=
event
.
height
// 安卓切换不同键盘类型时会导致键盘收回,需重新设置
if
(
focus
&&
keyboardHeight
===
0
)
{
setSoftinputTemporary
(
this
)
}
// 安卓/iOS13收起键盘时主动失去焦点
if
(
this
.
autoBlur
&&
focus
&&
keyboardHeight
===
0
&&
(
isAndroid
||
parseInt
(
osVersion
)
>=
13
))
{
document
.
activeElement
.
blur
()
}
UniViewJSBridge
.
subscribe
(
'
hideKeyboard
'
,
this
.
hideKeyboardTemp
)
}
el
.
addEventListener
(
'
focus
'
,
()
=>
{
focus
=
true
document
.
addEventListener
(
'
click
'
,
iosHideKeyboard
,
false
)
this
.
setSoftinputNavBar
()
this
.
setSoftinputTemporary
()
})
el
.
addEventListener
(
'
blur
'
,
this
.
onKeyboardHide
.
bind
(
this
))
},
showSoftKeybord
()
{
if
(
__PLATFORM__
===
'
app-plus
'
)
{
plusReady
(()
=>
{
plus
.
key
.
showSoftKeybord
(
)
}
)
document
.
addEventListener
(
'
keyboardchange
'
,
keyboardChange
,
false
)
setSoftinputNavBar
(
this
)
setSoftinputTemporary
(
this
)
}
},
setSoftinputTemporary
()
{
if
(
__PLATFORM__
===
'
app-plus
'
)
{
plusReady
(()
=>
{
const
currentWebview
=
plus
.
webview
.
currentWebview
()
const
style
=
currentWebview
.
getStyle
()
||
{}
const
rect
=
this
.
$el
.
getBoundingClientRect
()
currentWebview
.
setSoftinputTemporary
&&
currentWebview
.
setSoftinputTemporary
({
mode
:
style
.
softinputMode
===
'
adjustResize
'
?
'
adjustResize
'
:
(
this
.
adjustPosition
?
'
adjustPan
'
:
'
nothing
'
),
position
:
{
top
:
rect
.
top
,
height
:
rect
.
height
+
(
Number
(
this
.
cursorSpacing
)
||
0
)
}
})
})
}
},
setSoftinputNavBar
()
{
if
(
__PLATFORM__
===
'
app-plus
'
)
{
if
(
this
.
showConfirmBar
===
'
auto
'
)
{
delete
this
.
__softinputNavBar
return
el
.
addEventListener
(
'
click
'
,
()
=>
{
if
(
focus
&&
keyboardHeight
===
0
)
{
setSoftinputTemporary
(
this
)
}
plusReady
(()
=>
{
const
currentWebview
=
plus
.
webview
.
currentWebview
()
const
{
softinputNavBar
}
=
currentWebview
.
getStyle
()
||
{}
const
showConfirmBar
=
softinputNavBar
!==
'
none
'
if
(
showConfirmBar
!==
this
.
showConfirmBar
)
{
this
.
__softinputNavBar
=
softinputNavBar
||
'
auto
'
currentWebview
.
setStyle
({
softinputNavBar
:
this
.
showConfirmBar
?
'
auto
'
:
'
none
'
})
}
else
{
delete
this
.
__softinputNavBar
}
})
}
},
resetSoftinputNavBar
()
{
const
onKeyboardHide
=
()
=>
{
document
.
removeEventListener
(
'
click
'
,
iosHideKeyboard
,
false
)
if
(
__PLATFORM__
===
'
app-plus
'
)
{
const
softinputNavBar
=
this
.
__softinputNavBar
if
(
softinputNavBar
)
{
plusReady
(()
=>
{
const
currentWebview
=
plus
.
webview
.
currentWebview
()
currentWebview
.
setStyle
({
softinputNavBar
})
})
document
.
removeEventListener
(
'
keyboardchange
'
,
keyboardChange
,
false
)
resetSoftinputNavBar
(
this
)
}
}
},
onKeyboardHide
()
{
UniViewJSBridge
.
unsubscribe
(
'
hideKeyboard
'
,
this
.
hideKeyboardTemp
)
document
.
removeEventListener
(
'
click
'
,
iosHideKeyboard
,
false
)
this
.
resetSoftinputNavBar
()
// 修复ios端显示与点击位置错位的Bug by:wyq
if
(
String
(
navigator
.
vendor
).
indexOf
(
'
Apple
'
)
===
0
)
{
document
.
documentElement
.
scrollTo
(
document
.
documentElement
.
scrollLeft
,
document
.
documentElement
.
scrollTop
)
}
}
el
.
addEventListener
(
'
blur
'
,
()
=>
{
focus
=
false
onKeyboardHide
()
})
this
.
$on
(
'
hook:beforeDestroy
'
,
()
=>
{
onKeyboardHide
()
})
}
}
}
src/platforms/app-plus/service/framework/plugins/keyboard.js
浏览文件 @
e91807da
import
{
onMethod
,
getCurrentPageId
onMethod
}
from
'
../../../../../core/service/platform
'
const
isAndroid
=
plus
.
os
.
name
.
toLowerCase
()
===
'
android
'
const
FOCUS_TIMEOUT
=
isAndroid
?
300
:
700
const
HIDE_TIMEOUT
=
isAndroid
?
800
:
300
let
keyboardHeight
=
0
let
onKeyboardShow
let
focusTimer
let
hideKeyboardTimeout
export
function
hookKeyboardEvent
(
event
,
callback
)
{
onKeyboardShow
=
null
...
...
@@ -37,18 +34,5 @@ onMethod('onKeyboardHeightChange', res => {
keyboardHeight
=
res
.
height
if
(
keyboardHeight
>
0
)
{
onKeyboardShow
&&
onKeyboardShow
()
if
(
hideKeyboardTimeout
)
{
clearTimeout
(
hideKeyboardTimeout
)
hideKeyboardTimeout
=
null
}
}
else
{
// 安卓/iOS13收起键盘时通知view层失去焦点
if
(
isAndroid
||
parseInt
(
plus
.
os
.
version
)
>=
13
)
{
hideKeyboardTimeout
=
setTimeout
(
function
()
{
hideKeyboardTimeout
=
null
var
pageId
=
getCurrentPageId
()
UniServiceJSBridge
.
publishHandler
(
'
hideKeyboard
'
,
{},
pageId
)
},
HIDE_TIMEOUT
)
}
}
})
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录