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 @@
:type=
"inputType"
:maxlength=
"maxlength"
:step=
"step"
:autofocus=
"focus"
class=
"uni-input-input"
autocomplete=
"off"
@
focus=
"_onFocus"
...
...
@@ -50,13 +49,13 @@
</
template
>
<
script
>
import
{
baseInput
field
}
from
'
uni-mixins
'
const
INPUT_TYPES
=
[
'
text
'
,
'
number
'
,
'
idcard
'
,
'
digit
'
,
'
password
'
]
const
NUMBER_TYPES
=
[
'
number
'
,
'
digit
'
]
export
default
{
name
:
'
Input
'
,
mixins
:
[
baseInput
],
mixins
:
[
field
],
props
:
{
name
:
{
type
:
String
,
...
...
@@ -90,10 +89,6 @@ export default {
type
:
[
Number
,
String
],
default
:
140
},
focus
:
{
type
:
[
Boolean
,
String
],
default
:
false
},
confirmType
:
{
type
:
String
,
default
:
'
done
'
...
...
@@ -134,9 +129,6 @@ export default {
}
},
watch
:
{
focus
(
val
)
{
this
.
$refs
.
input
&&
this
.
$refs
.
input
[
val
?
'
focus
'
:
'
blur
'
]()
},
maxlength
(
value
)
{
const
realValue
=
this
.
valueSync
.
slice
(
0
,
parseInt
(
value
,
10
))
realValue
!==
this
.
valueSync
&&
(
this
.
valueSync
=
realValue
)
...
...
@@ -168,6 +160,8 @@ export default {
}
$vm
=
$vm
.
$parent
}
this
.
_initField
(
'
input
'
)
},
beforeDestroy
()
{
this
.
$dispatch
(
'
Form
'
,
'
uni-form-group-update
'
,
{
...
...
src/core/view/components/textarea/index.vue
浏览文件 @
a67363f1
...
...
@@ -35,16 +35,15 @@
v-keyboard
:disabled=
"disabled"
:maxlength=
"maxlengthNumber"
:autofocus=
"autoFocus || focus"
:class=
"
{ 'uni-textarea-textarea-fix-margin': fixMargin }"
:style="{ 'overflow-y': autoHeight ? 'hidden' : 'auto' }"
class="uni-textarea-textarea"
@compositionstart="_
c
ompositionstart"
@compositionend="_
c
ompositionend"
@input.stop="_
i
nput"
@focus="_
f
ocus"
@blur="_
b
lur"
@touchstart.passive="_
t
ouchstart"
@compositionstart="_
onC
ompositionstart"
@compositionend="_
onC
ompositionend"
@input.stop="_
onI
nput"
@focus="_
onF
ocus"
@blur="_
onB
lur"
@touchstart.passive="_
onT
ouchstart"
/>
<textarea
v-if=
"disabled && fixColor"
...
...
@@ -62,12 +61,12 @@
</
template
>
<
script
>
import
{
baseInput
field
}
from
'
uni-mixins
'
const
DARK_TEST_STRING
=
'
(prefers-color-scheme: dark)
'
export
default
{
name
:
'
Textarea
'
,
mixins
:
[
baseInput
],
mixins
:
[
field
],
props
:
{
name
:
{
type
:
String
,
...
...
@@ -85,14 +84,6 @@ export default {
type
:
[
Boolean
,
String
],
default
:
false
},
focus
:
{
type
:
[
Boolean
,
String
],
default
:
false
},
autoFocus
:
{
type
:
[
Boolean
,
String
],
default
:
false
},
placeholderClass
:
{
type
:
String
,
default
:
'
textarea-placeholder
'
...
...
@@ -156,13 +147,6 @@ export default {
focus
(
val
)
{
if
(
val
)
{
this
.
focusChangeSource
=
'
focus
'
if
(
this
.
$refs
.
textarea
)
{
this
.
$refs
.
textarea
.
focus
()
}
}
else
{
if
(
this
.
$refs
.
textarea
)
{
this
.
$refs
.
textarea
.
blur
()
}
}
},
focusSync
(
val
)
{
...
...
@@ -214,6 +198,8 @@ export default {
}
$vm
=
$vm
.
$parent
}
this
.
_initField
(
'
textarea
'
)
},
beforeDestroy
()
{
this
.
$dispatch
(
'
Form
'
,
'
uni-form-group-update
'
,
{
...
...
@@ -222,7 +208,7 @@ export default {
})
},
methods
:
{
_
f
ocus
:
function
(
$event
)
{
_
onF
ocus
:
function
(
$event
)
{
this
.
focusSync
=
true
this
.
$trigger
(
'
focus
'
,
$event
,
{
value
:
this
.
valueSync
...
...
@@ -239,20 +225,20 @@ export default {
this
.
$refs
.
textarea
.
selectionEnd
=
this
.
$refs
.
textarea
.
selectionStart
=
this
.
cursorNumber
}
},
_
b
lur
:
function
(
$event
)
{
_
onB
lur
:
function
(
$event
)
{
this
.
focusSync
=
false
this
.
$trigger
(
'
blur
'
,
$event
,
{
value
:
this
.
valueSync
,
cursor
:
this
.
$refs
.
textarea
.
selectionEnd
})
},
_
c
ompositionstart
(
$event
)
{
_
onC
ompositionstart
(
$event
)
{
this
.
composition
=
true
},
_
c
ompositionend
(
$event
)
{
_
onC
ompositionend
(
$event
)
{
this
.
composition
=
false
// 部分输入法 compositionend 事件可能晚于 input
this
.
_
i
nput
(
$event
)
this
.
_
onI
nput
(
$event
)
},
// 暂无完成按钮,此功能未实现
_confirm
(
$event
)
{
...
...
@@ -265,13 +251,13 @@ export default {
value
:
this
.
valueSync
})
},
_
t
ouchstart
()
{
_
onT
ouchstart
()
{
this
.
focusChangeSource
=
'
touch
'
},
_resize
({
height
})
{
this
.
height
=
height
},
_
i
nput
(
$event
)
{
_
onI
nput
(
$event
)
{
if
(
this
.
composition
)
{
this
.
valueComposition
=
$event
.
target
.
value
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
},
pageId
)
})
// App 延迟获取焦点
const
FOCUS_DELAY
=
200
let
startTime
export
default
{
name
:
'
BaseInput
'
,
mixins
:
[
emitter
,
keyboard
],
...
...
@@ -34,6 +38,17 @@ export default {
value
:
{
type
:
[
String
,
Number
],
default
:
''
},
/**
* 已废弃属性,用于历史兼容
*/
autoFocus
:
{
type
:
[
Boolean
,
String
],
default
:
false
},
focus
:
{
type
:
[
Boolean
,
String
],
default
:
false
}
},
data
()
{
...
...
@@ -41,6 +56,20 @@ export default {
valueSync
:
this
.
_getValueString
(
this
.
value
)
}
},
watch
:
{
focus
(
val
)
{
if
(
val
)
{
this
.
_focus
()
}
else
{
this
.
_blur
()
}
}
},
computed
:
{
needFocus
()
{
return
this
.
autoFocus
||
this
.
focus
}
},
created
()
{
const
valueChange
=
this
.
__valueChange
=
debounce
((
val
)
=>
{
this
.
valueSync
=
this
.
_getValueString
(
val
)
...
...
@@ -62,6 +91,38 @@ export default {
methods
:
{
_getValueString
(
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 {
from
'
./keyboard
'
export
{
default
as
baseInput
default
as
field
}
from
'
./
base-input
'
from
'
./
field
'
export
{
default
as
interact
...
...
src/core/view/mixins/keyboard.js
浏览文件 @
a67363f1
...
...
@@ -7,12 +7,6 @@ import {
*/
function
iosHideKeyboard
()
{
}
function
showSoftKeybord
()
{
plusReady
(()
=>
{
plus
.
key
.
showSoftKeybord
()
})
}
function
setSoftinputTemporary
(
vm
,
reset
)
{
plusReady
(()
=>
{
const
MODE_ADJUSTRESIZE
=
'
adjustResize
'
...
...
@@ -98,13 +92,6 @@ export default {
default
:
true
}
},
watch
:
{
focus
(
val
)
{
if
(
val
&&
__PLATFORM__
===
'
app-plus
'
)
{
showSoftKeybord
()
}
}
},
directives
:
{
keyboard
:
{
inserted
(
el
,
binding
,
vnode
)
{
...
...
@@ -112,11 +99,6 @@ export default {
}
}
},
mounted
()
{
if
((
this
.
autoFocus
||
this
.
focus
)
&&
__PLATFORM__
===
'
app-plus
'
)
{
showSoftKeybord
()
}
},
methods
:
{
initKeyboard
(
el
)
{
let
focus
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录