Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
uni-app
提交
79dd3b16
U
uni-app
项目概览
DCloud
/
uni-app
3 个月 前同步成功
通知
720
Star
38705
Fork
3642
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
7
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
7
Issue
7
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
79dd3b16
编写于
10月 26, 2021
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat(H5): judge user activation when choose file
上级
c45634db
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
40 addition
and
15 deletion
+40
-15
src/core/view/mixins/interact.js
src/core/view/mixins/interact.js
+12
-11
src/platforms/h5/service/api/media/choose-file.js
src/platforms/h5/service/api/media/choose-file.js
+8
-1
src/platforms/h5/service/api/media/choose-image.js
src/platforms/h5/service/api/media/choose-image.js
+8
-2
src/platforms/h5/service/api/media/choose-video.js
src/platforms/h5/service/api/media/choose-video.js
+8
-1
src/platforms/h5/service/api/media/create_input.js
src/platforms/h5/service/api/media/create_input.js
+4
-0
未找到文件。
src/core/view/mixins/interact.js
浏览文件 @
79dd3b16
...
...
@@ -9,21 +9,17 @@ const passiveOptions = supportsPassive ? {
const
vms
=
[]
let
userInteract
=
0
let
inited
function
addInteractListener
(
vm
)
{
function
addInteractListener
(
vm
=
{}
)
{
if
(
!
inited
)
{
const
eventNames
=
[
'
touchstart
'
,
'
touchmove
'
,
'
touchend
'
,
'
mousedown
'
,
'
mouseup
'
]
eventNames
.
forEach
(
eventName
=>
{
document
.
addEventListener
(
eventName
,
function
()
{
vms
.
forEach
(
vm
=>
{
vm
.
userInteract
=
true
userInteract
++
setTimeout
(()
=>
{
userInteract
--
if
(
!
userInteract
)
{
vm
.
userInteract
=
false
}
},
0
)
})
!
userInteract
&&
vms
.
forEach
(
vm
=>
(
vm
.
userInteract
=
true
))
userInteract
++
setTimeout
(()
=>
{
!--
userInteract
&&
vms
.
forEach
(
vm
=>
(
vm
.
userInteract
=
false
))
},
0
)
},
passiveOptions
)
})
inited
=
true
...
...
@@ -51,5 +47,10 @@ export default {
},
beforeDestroy
()
{
removeInteractListener
(
this
)
},
addInteractListener
,
// true -> interact
getStatus
()
{
return
!!
userInteract
}
}
src/platforms/h5/service/api/media/choose-file.js
浏览文件 @
79dd3b16
import
{
fileToUrl
}
from
'
uni-platform/helpers/file
'
import
_createInput
from
'
./create_input
'
import
{
interact
}
from
'
uni-mixins
'
const
{
invokeCallbackHandler
:
invoke
...
...
@@ -55,5 +56,11 @@ export function chooseFile ({
// TODO 用户取消选择时,触发 fail,目前尚未找到合适的方法。
})
fileInput
.
click
()
if
(
interact
.
getStatus
())
{
fileInput
.
click
()
}
else
{
invoke
(
callbackId
,
{
errMsg
:
'
chooseFile:fail File chooser dialog can only be shown with a user activation.
'
})
}
}
src/platforms/h5/service/api/media/choose-image.js
浏览文件 @
79dd3b16
import
{
fileToUrl
}
from
'
uni-platform/helpers/file
'
import
_createInput
from
'
./create_input
'
import
{
interact
}
from
'
uni-mixins
'
const
{
invokeCallbackHandler
:
invoke
...
...
@@ -27,7 +28,6 @@ export function chooseImage ({
type
:
'
image
'
})
document
.
body
.
appendChild
(
imageInput
)
imageInput
.
addEventListener
(
'
change
'
,
function
(
event
)
{
const
tempFiles
=
[]
const
fileCount
=
event
.
target
.
files
.
length
...
...
@@ -54,5 +54,11 @@ export function chooseImage ({
// TODO 用户取消选择时,触发 fail,目前尚未找到合适的方法。
})
imageInput
.
click
()
if
(
interact
.
getStatus
())
{
imageInput
.
click
()
}
else
{
invoke
(
callbackId
,
{
errMsg
:
'
chooseImage:fail File chooser dialog can only be shown with a user activation.
'
})
}
}
src/platforms/h5/service/api/media/choose-video.js
浏览文件 @
79dd3b16
import
{
fileToUrl
,
revokeObjectURL
}
from
'
uni-platform/helpers/file
'
import
_createInput
from
'
./create_input
'
import
{
interact
}
from
'
uni-mixins
'
const
{
invokeCallbackHandler
:
invoke
...
...
@@ -67,5 +68,11 @@ export function chooseVideo ({
// TODO 用户取消选择时,触发 fail,目前尚未找到合适的方法。
})
videoInput
.
click
()
if
(
interact
.
getStatus
())
{
videoInput
.
click
()
}
else
{
invoke
(
callbackId
,
{
errMsg
:
'
chooseVideo:fail File chooser dialog can only be shown with a user activation.
'
})
}
}
src/platforms/h5/service/api/media/create_input.js
浏览文件 @
79dd3b16
import
{
updateElementStyle
}
from
'
uni-shared
'
import
MIMEType
from
'
./MIMEType
'
import
{
interact
}
from
'
uni-mixins
'
interact
.
addInteractListener
()
const
ALL
=
'
*
'
function
isWXEnv
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录