Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
良好的行为成为习惯
uni-app
提交
a67363f1
U
uni-app
项目概览
良好的行为成为习惯
/
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,发现更多精彩内容 >>
提交
a67363f1
编写于
10月 29, 2020
作者:
Q
qiang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: App 端延迟获取焦点 question/107820
上级
88ef44bb
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
84 addition
and
61 deletion
+84
-61
src/core/view/components/input/index.vue
src/core/view/components/input/index.vue
+4
-10
src/core/view/components/textarea/index.vue
src/core/view/components/textarea/index.vue
+17
-31
src/core/view/mixins/field.js
src/core/view/mixins/field.js
+61
-0
src/core/view/mixins/index.js
src/core/view/mixins/index.js
+2
-2
src/core/view/mixins/keyboard.js
src/core/view/mixins/keyboard.js
+0
-18
未找到文件。
src/core/view/components/input/index.vue
浏览文件 @
a67363f1
...
@@ -24,7 +24,6 @@
...
@@ -24,7 +24,6 @@
:type=
"inputType"
:type=
"inputType"
:maxlength=
"maxlength"
:maxlength=
"maxlength"
:step=
"step"
:step=
"step"
:autofocus=
"focus"
class=
"uni-input-input"
class=
"uni-input-input"
autocomplete=
"off"
autocomplete=
"off"
@
focus=
"_onFocus"
@
focus=
"_onFocus"
...
@@ -50,13 +49,13 @@
...
@@ -50,13 +49,13 @@
</
template
>
</
template
>
<
script
>
<
script
>
import
{
import
{
baseInput
field
}
from
'
uni-mixins
'
}
from
'
uni-mixins
'
const
INPUT_TYPES
=
[
'
text
'
,
'
number
'
,
'
idcard
'
,
'
digit
'
,
'
password
'
]
const
INPUT_TYPES
=
[
'
text
'
,
'
number
'
,
'
idcard
'
,
'
digit
'
,
'
password
'
]
const
NUMBER_TYPES
=
[
'
number
'
,
'
digit
'
]
const
NUMBER_TYPES
=
[
'
number
'
,
'
digit
'
]
export
default
{
export
default
{
name
:
'
Input
'
,
name
:
'
Input
'
,
mixins
:
[
baseInput
],
mixins
:
[
field
],
props
:
{
props
:
{
name
:
{
name
:
{
type
:
String
,
type
:
String
,
...
@@ -90,10 +89,6 @@ export default {
...
@@ -90,10 +89,6 @@ export default {
type
:
[
Number
,
String
],
type
:
[
Number
,
String
],
default
:
140
default
:
140
},
},
focus
:
{
type
:
[
Boolean
,
String
],
default
:
false
},
confirmType
:
{
confirmType
:
{
type
:
String
,
type
:
String
,
default
:
'
done
'
default
:
'
done
'
...
@@ -134,9 +129,6 @@ export default {
...
@@ -134,9 +129,6 @@ export default {
}
}
},
},
watch
:
{
watch
:
{
focus
(
val
)
{
this
.
$refs
.
input
&&
this
.
$refs
.
input
[
val
?
'
focus
'
:
'
blur
'
]()
},
maxlength
(
value
)
{
maxlength
(
value
)
{
const
realValue
=
this
.
valueSync
.
slice
(
0
,
parseInt
(
value
,
10
))
const
realValue
=
this
.
valueSync
.
slice
(
0
,
parseInt
(
value
,
10
))
realValue
!==
this
.
valueSync
&&
(
this
.
valueSync
=
realValue
)
realValue
!==
this
.
valueSync
&&
(
this
.
valueSync
=
realValue
)
...
@@ -168,6 +160,8 @@ export default {
...
@@ -168,6 +160,8 @@ export default {
}
}
$vm
=
$vm
.
$parent
$vm
=
$vm
.
$parent
}
}
this
.
_initField
(
'
input
'
)
},
},
beforeDestroy
()
{
beforeDestroy
()
{
this
.
$dispatch
(
'
Form
'
,
'
uni-form-group-update
'
,
{
this
.
$dispatch
(
'
Form
'
,
'
uni-form-group-update
'
,
{
...
...
src/core/view/components/textarea/index.vue
浏览文件 @
a67363f1
...
@@ -35,16 +35,15 @@
...
@@ -35,16 +35,15 @@
v-keyboard
v-keyboard
:disabled=
"disabled"
:disabled=
"disabled"
:maxlength=
"maxlengthNumber"
:maxlength=
"maxlengthNumber"
:autofocus=
"autoFocus || focus"
:class=
"
{ 'uni-textarea-textarea-fix-margin': fixMargin }"
:class=
"
{ 'uni-textarea-textarea-fix-margin': fixMargin }"
:style="{ 'overflow-y': autoHeight ? 'hidden' : 'auto' }"
:style="{ 'overflow-y': autoHeight ? 'hidden' : 'auto' }"
class="uni-textarea-textarea"
class="uni-textarea-textarea"
@compositionstart="_
c
ompositionstart"
@compositionstart="_
onC
ompositionstart"
@compositionend="_
c
ompositionend"
@compositionend="_
onC
ompositionend"
@input.stop="_
i
nput"
@input.stop="_
onI
nput"
@focus="_
f
ocus"
@focus="_
onF
ocus"
@blur="_
b
lur"
@blur="_
onB
lur"
@touchstart.passive="_
t
ouchstart"
@touchstart.passive="_
onT
ouchstart"
/>
/>
<textarea
<textarea
v-if=
"disabled && fixColor"
v-if=
"disabled && fixColor"
...
@@ -62,12 +61,12 @@
...
@@ -62,12 +61,12 @@
</
template
>
</
template
>
<
script
>
<
script
>
import
{
import
{
baseInput
field
}
from
'
uni-mixins
'
}
from
'
uni-mixins
'
const
DARK_TEST_STRING
=
'
(prefers-color-scheme: dark)
'
const
DARK_TEST_STRING
=
'
(prefers-color-scheme: dark)
'
export
default
{
export
default
{
name
:
'
Textarea
'
,
name
:
'
Textarea
'
,
mixins
:
[
baseInput
],
mixins
:
[
field
],
props
:
{
props
:
{
name
:
{
name
:
{
type
:
String
,
type
:
String
,
...
@@ -85,14 +84,6 @@ export default {
...
@@ -85,14 +84,6 @@ export default {
type
:
[
Boolean
,
String
],
type
:
[
Boolean
,
String
],
default
:
false
default
:
false
},
},
focus
:
{
type
:
[
Boolean
,
String
],
default
:
false
},
autoFocus
:
{
type
:
[
Boolean
,
String
],
default
:
false
},
placeholderClass
:
{
placeholderClass
:
{
type
:
String
,
type
:
String
,
default
:
'
textarea-placeholder
'
default
:
'
textarea-placeholder
'
...
@@ -156,13 +147,6 @@ export default {
...
@@ -156,13 +147,6 @@ export default {
focus
(
val
)
{
focus
(
val
)
{
if
(
val
)
{
if
(
val
)
{
this
.
focusChangeSource
=
'
focus
'
this
.
focusChangeSource
=
'
focus
'
if
(
this
.
$refs
.
textarea
)
{
this
.
$refs
.
textarea
.
focus
()
}
}
else
{
if
(
this
.
$refs
.
textarea
)
{
this
.
$refs
.
textarea
.
blur
()
}
}
}
},
},
focusSync
(
val
)
{
focusSync
(
val
)
{
...
@@ -214,6 +198,8 @@ export default {
...
@@ -214,6 +198,8 @@ export default {
}
}
$vm
=
$vm
.
$parent
$vm
=
$vm
.
$parent
}
}
this
.
_initField
(
'
textarea
'
)
},
},
beforeDestroy
()
{
beforeDestroy
()
{
this
.
$dispatch
(
'
Form
'
,
'
uni-form-group-update
'
,
{
this
.
$dispatch
(
'
Form
'
,
'
uni-form-group-update
'
,
{
...
@@ -222,7 +208,7 @@ export default {
...
@@ -222,7 +208,7 @@ export default {
})
})
},
},
methods
:
{
methods
:
{
_
f
ocus
:
function
(
$event
)
{
_
onF
ocus
:
function
(
$event
)
{
this
.
focusSync
=
true
this
.
focusSync
=
true
this
.
$trigger
(
'
focus
'
,
$event
,
{
this
.
$trigger
(
'
focus
'
,
$event
,
{
value
:
this
.
valueSync
value
:
this
.
valueSync
...
@@ -239,20 +225,20 @@ export default {
...
@@ -239,20 +225,20 @@ export default {
this
.
$refs
.
textarea
.
selectionEnd
=
this
.
$refs
.
textarea
.
selectionStart
=
this
.
cursorNumber
this
.
$refs
.
textarea
.
selectionEnd
=
this
.
$refs
.
textarea
.
selectionStart
=
this
.
cursorNumber
}
}
},
},
_
b
lur
:
function
(
$event
)
{
_
onB
lur
:
function
(
$event
)
{
this
.
focusSync
=
false
this
.
focusSync
=
false
this
.
$trigger
(
'
blur
'
,
$event
,
{
this
.
$trigger
(
'
blur
'
,
$event
,
{
value
:
this
.
valueSync
,
value
:
this
.
valueSync
,
cursor
:
this
.
$refs
.
textarea
.
selectionEnd
cursor
:
this
.
$refs
.
textarea
.
selectionEnd
})
})
},
},
_
c
ompositionstart
(
$event
)
{
_
onC
ompositionstart
(
$event
)
{
this
.
composition
=
true
this
.
composition
=
true
},
},
_
c
ompositionend
(
$event
)
{
_
onC
ompositionend
(
$event
)
{
this
.
composition
=
false
this
.
composition
=
false
// 部分输入法 compositionend 事件可能晚于 input
// 部分输入法 compositionend 事件可能晚于 input
this
.
_
i
nput
(
$event
)
this
.
_
onI
nput
(
$event
)
},
},
// 暂无完成按钮,此功能未实现
// 暂无完成按钮,此功能未实现
_confirm
(
$event
)
{
_confirm
(
$event
)
{
...
@@ -265,13 +251,13 @@ export default {
...
@@ -265,13 +251,13 @@ export default {
value
:
this
.
valueSync
value
:
this
.
valueSync
})
})
},
},
_
t
ouchstart
()
{
_
onT
ouchstart
()
{
this
.
focusChangeSource
=
'
touch
'
this
.
focusChangeSource
=
'
touch
'
},
},
_resize
({
height
})
{
_resize
({
height
})
{
this
.
height
=
height
this
.
height
=
height
},
},
_
i
nput
(
$event
)
{
_
onI
nput
(
$event
)
{
if
(
this
.
composition
)
{
if
(
this
.
composition
)
{
this
.
valueComposition
=
$event
.
target
.
value
this
.
valueComposition
=
$event
.
target
.
value
return
return
...
...
src/core/view/mixins/
base-input
.js
→
src/core/view/mixins/
field
.js
浏览文件 @
a67363f1
...
@@ -23,6 +23,10 @@ UniViewJSBridge.subscribe('getSelectedTextRange', function ({ pageId, callbackId
...
@@ -23,6 +23,10 @@ UniViewJSBridge.subscribe('getSelectedTextRange', function ({ pageId, callbackId
},
pageId
)
},
pageId
)
})
})
// App 延迟获取焦点
const
FOCUS_DELAY
=
200
let
startTime
export
default
{
export
default
{
name
:
'
BaseInput
'
,
name
:
'
BaseInput
'
,
mixins
:
[
emitter
,
keyboard
],
mixins
:
[
emitter
,
keyboard
],
...
@@ -34,6 +38,17 @@ export default {
...
@@ -34,6 +38,17 @@ export default {
value
:
{
value
:
{
type
:
[
String
,
Number
],
type
:
[
String
,
Number
],
default
:
''
default
:
''
},
/**
* 已废弃属性,用于历史兼容
*/
autoFocus
:
{
type
:
[
Boolean
,
String
],
default
:
false
},
focus
:
{
type
:
[
Boolean
,
String
],
default
:
false
}
}
},
},
data
()
{
data
()
{
...
@@ -41,6 +56,20 @@ export default {
...
@@ -41,6 +56,20 @@ export default {
valueSync
:
this
.
_getValueString
(
this
.
value
)
valueSync
:
this
.
_getValueString
(
this
.
value
)
}
}
},
},
watch
:
{
focus
(
val
)
{
if
(
val
)
{
this
.
_focus
()
}
else
{
this
.
_blur
()
}
}
},
computed
:
{
needFocus
()
{
return
this
.
autoFocus
||
this
.
focus
}
},
created
()
{
created
()
{
const
valueChange
=
this
.
__valueChange
=
debounce
((
val
)
=>
{
const
valueChange
=
this
.
__valueChange
=
debounce
((
val
)
=>
{
this
.
valueSync
=
this
.
_getValueString
(
val
)
this
.
valueSync
=
this
.
_getValueString
(
val
)
...
@@ -62,6 +91,38 @@ export default {
...
@@ -62,6 +91,38 @@ export default {
methods
:
{
methods
:
{
_getValueString
(
value
)
{
_getValueString
(
value
)
{
return
value
===
null
?
''
:
String
(
value
)
return
value
===
null
?
''
:
String
(
value
)
},
_initField
(
ref
)
{
this
.
_fieldRef
=
ref
startTime
=
startTime
||
Date
.
now
()
if
(
this
.
needFocus
)
{
this
.
_focus
()
}
},
_focus
()
{
if
(
!
this
.
needFocus
)
{
return
}
const
field
=
this
.
$refs
[
this
.
_fieldRef
]
if
(
!
field
||
(
__PLATFORM__
===
'
app-plus
'
&&
!
window
.
plus
))
{
setTimeout
(
this
.
_focus
.
bind
(
this
),
100
)
return
}
if
(
__PLATFORM__
===
'
h5
'
)
{
field
.
focus
()
}
else
{
const
timeout
=
FOCUS_DELAY
-
(
Date
.
now
()
-
startTime
)
if
(
timeout
>
0
)
{
setTimeout
(
this
.
_focus
.
bind
(
this
),
timeout
)
return
}
field
.
focus
()
plus
.
key
.
showSoftKeybord
()
}
},
_blur
()
{
const
field
=
this
.
$refs
[
this
.
_fieldRef
]
field
&&
field
.
blur
()
}
}
}
}
}
}
src/core/view/mixins/index.js
浏览文件 @
a67363f1
...
@@ -24,9 +24,9 @@ export {
...
@@ -24,9 +24,9 @@ export {
from
'
./keyboard
'
from
'
./keyboard
'
export
{
export
{
default
as
baseInput
default
as
field
}
}
from
'
./
base-input
'
from
'
./
field
'
export
{
export
{
default
as
interact
default
as
interact
...
...
src/core/view/mixins/keyboard.js
浏览文件 @
a67363f1
...
@@ -7,12 +7,6 @@ import {
...
@@ -7,12 +7,6 @@ import {
*/
*/
function
iosHideKeyboard
()
{
}
function
iosHideKeyboard
()
{
}
function
showSoftKeybord
()
{
plusReady
(()
=>
{
plus
.
key
.
showSoftKeybord
()
})
}
function
setSoftinputTemporary
(
vm
,
reset
)
{
function
setSoftinputTemporary
(
vm
,
reset
)
{
plusReady
(()
=>
{
plusReady
(()
=>
{
const
MODE_ADJUSTRESIZE
=
'
adjustResize
'
const
MODE_ADJUSTRESIZE
=
'
adjustResize
'
...
@@ -98,13 +92,6 @@ export default {
...
@@ -98,13 +92,6 @@ export default {
default
:
true
default
:
true
}
}
},
},
watch
:
{
focus
(
val
)
{
if
(
val
&&
__PLATFORM__
===
'
app-plus
'
)
{
showSoftKeybord
()
}
}
},
directives
:
{
directives
:
{
keyboard
:
{
keyboard
:
{
inserted
(
el
,
binding
,
vnode
)
{
inserted
(
el
,
binding
,
vnode
)
{
...
@@ -112,11 +99,6 @@ export default {
...
@@ -112,11 +99,6 @@ export default {
}
}
}
}
},
},
mounted
()
{
if
((
this
.
autoFocus
||
this
.
focus
)
&&
__PLATFORM__
===
'
app-plus
'
)
{
showSoftKeybord
()
}
},
methods
:
{
methods
:
{
initKeyboard
(
el
)
{
initKeyboard
(
el
)
{
let
focus
let
focus
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录