Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
qianlong66
uni-app
提交
e06a7021
U
uni-app
项目概览
qianlong66
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
e06a7021
编写于
9月 17, 2021
作者:
D
DCloud_LXH
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
chore(App): chooseImage、chooseVideo optimize
上级
453b3fe2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
101 deletion
+30
-101
packages/uni-app-plus/src/service/api/media/chooseImage.ts
packages/uni-app-plus/src/service/api/media/chooseImage.ts
+9
-55
packages/uni-app-plus/src/service/api/media/chooseVideo.ts
packages/uni-app-plus/src/service/api/media/chooseVideo.ts
+21
-46
未找到文件。
packages/uni-app-plus/src/service/api/media/chooseImage.ts
浏览文件 @
e06a7021
import
{
TEMP_PATH
}
from
'
../constants
'
import
{
TEMP_PATH
}
from
'
../constants
'
import
{
warpPlusErrorCallback
}
from
'
../../../helpers/plus
'
import
{
warpPlusErrorCallback
}
from
'
../../../helpers/plus
'
import
{
getFileName
}
from
'
../../../helpers/file
'
import
{
import
{
API_TYPE_CHOOSE_IMAGE
,
API_TYPE_CHOOSE_IMAGE
,
API_CHOOSE_IMAGE
,
API_CHOOSE_IMAGE
,
...
@@ -27,30 +26,6 @@ function getFileInfo(filePath: string): Promise<PlusIoMetadata> {
...
@@ -27,30 +26,6 @@ function getFileInfo(filePath: string): Promise<PlusIoMetadata> {
})
})
}
}
function
compressImage
(
tempFilePath
:
string
):
Promise
<
string
>
{
const
dst
=
`
${
TEMP_PATH
}
/compressed/
${
Date
.
now
()}
_
${
getFileName
(
tempFilePath
)}
`
return
new
Promise
((
resolve
)
=>
{
plus
.
nativeUI
.
showWaiting
()
plus
.
zip
.
compressImage
(
{
src
:
tempFilePath
,
dst
,
overwrite
:
true
,
},
()
=>
{
plus
.
nativeUI
.
closeWaiting
()
resolve
(
dst
)
},
()
=>
{
plus
.
nativeUI
.
closeWaiting
()
resolve
(
tempFilePath
)
}
)
})
}
type
File
=
{
type
File
=
{
path
:
string
path
:
string
size
:
number
size
:
number
...
@@ -58,7 +33,7 @@ type File = {
...
@@ -58,7 +33,7 @@ type File = {
export
const
chooseImage
=
defineAsyncApi
<
API_TYPE_CHOOSE_IMAGE
>
(
export
const
chooseImage
=
defineAsyncApi
<
API_TYPE_CHOOSE_IMAGE
>
(
API_CHOOSE_IMAGE
,
API_CHOOSE_IMAGE
,
// @ts-
ignore
crop 属性App特有
// @ts-
expect-error
crop 属性App特有
({
count
,
sizeType
,
sourceType
,
crop
}
=
{},
{
resolve
,
reject
})
=>
{
({
count
,
sizeType
,
sourceType
,
crop
}
=
{},
{
resolve
,
reject
})
=>
{
initI18nChooseImageMsgsOnce
()
initI18nChooseImageMsgsOnce
()
const
{
t
}
=
useI18n
()
const
{
t
}
=
useI18n
()
...
@@ -86,38 +61,17 @@ export const chooseImage = defineAsyncApi<API_TYPE_CHOOSE_IMAGE>(
...
@@ -86,38 +61,17 @@ export const chooseImage = defineAsyncApi<API_TYPE_CHOOSE_IMAGE>(
function
openCamera
()
{
function
openCamera
()
{
const
camera
=
plus
.
camera
.
getCamera
()
const
camera
=
plus
.
camera
.
getCamera
()
camera
.
captureImage
(
camera
.
captureImage
((
path
)
=>
successCallback
([
path
]),
errorCallback
,
{
(
path
)
=>
{
filename
:
TEMP_PATH
+
'
/camera/
'
,
// fix By Lxh 暂时添加拍照压缩逻辑,等客户端增加逻辑后修改
resolution
:
'
high
'
,
// 判断是否需要压缩
crop
,
if
(
sizeType
&&
sizeType
.
includes
(
'
compressed
'
))
{
// @ts-expect-error
return
getFileInfo
(
path
)
sizeType
,
.
then
(({
size
})
=>
{
})
// 压缩阈值 0.5 兆
const
THRESHOLD
=
1024
*
1024
*
0.5
return
size
&&
size
>
THRESHOLD
?
compressImage
(
path
).
then
((
dstPath
)
=>
successCallback
([
dstPath
])
)
:
successCallback
([
path
])
})
.
catch
(
errorCallback
)
}
return
successCallback
([
path
])
},
errorCallback
,
{
filename
:
TEMP_PATH
+
'
/camera/
'
,
resolution
:
'
high
'
,
crop
,
}
)
}
}
function
openAlbum
()
{
function
openAlbum
()
{
// NOTE 5+此API分单选和多选,多选返回files:string[]
// @ts-ignore 5+此API分单选和多选,多选返回files:string[]
// @ts-ignore
plus
.
gallery
.
pick
(({
files
})
=>
successCallback
(
files
),
errorCallback
,
{
plus
.
gallery
.
pick
(({
files
})
=>
successCallback
(
files
),
errorCallback
,
{
maximum
:
count
,
maximum
:
count
,
multiple
:
true
,
multiple
:
true
,
...
...
packages/uni-app-plus/src/service/api/media/chooseVideo.ts
浏览文件 @
e06a7021
import
{
TEMP_PATH
}
from
'
../constants
'
import
{
TEMP_PATH
}
from
'
../constants
'
import
{
warpPlusErrorCallback
}
from
'
../../../helpers/plus
'
import
{
warpPlusErrorCallback
}
from
'
../../../helpers/plus
'
import
{
getFileName
}
from
'
../../../helpers/file
'
import
{
initI18nChooseVideoMsgsOnce
,
useI18n
}
from
'
@dcloudio/uni-core
'
import
{
initI18nChooseVideoMsgsOnce
,
useI18n
}
from
'
@dcloudio/uni-core
'
import
{
import
{
API_TYPE_CHOOSE_VIDEO
,
API_TYPE_CHOOSE_VIDEO
,
...
@@ -17,56 +16,28 @@ export const chooseVideo = defineAsyncApi<API_TYPE_CHOOSE_VIDEO>(
...
@@ -17,56 +16,28 @@ export const chooseVideo = defineAsyncApi<API_TYPE_CHOOSE_VIDEO>(
const
{
t
}
=
useI18n
()
const
{
t
}
=
useI18n
()
const
errorCallback
=
warpPlusErrorCallback
(
reject
)
const
errorCallback
=
warpPlusErrorCallback
(
reject
)
function
successCallback
(
tempFilePath
:
string
=
''
)
{
function
successCallback
(
tempFilePath
:
string
)
{
const
filename
=
`
${
TEMP_PATH
}
/compressed/
${
Date
.
now
()}
_
${
getFileName
(
plus
.
io
.
getVideoInfo
({
tempFilePath
filePath
:
tempFilePath
,
)}
`
success
(
videoInfo
)
{
const
compressVideo
:
Promise
<
string
>
=
compressed
const
result
=
{
?
new
Promise
((
resolve
)
=>
{
errMsg
:
'
chooseVideo:ok
'
,
plus
.
zip
.
compressVideo
(
tempFilePath
:
tempFilePath
,
{
size
:
videoInfo
.
size
,
src
:
tempFilePath
,
duration
:
videoInfo
.
duration
,
filename
,
width
:
videoInfo
.
width
,
quality
:
'
medium
'
,
height
:
videoInfo
.
height
,
},
}
({
tempFilePath
}:
{
tempFilePath
:
string
})
=>
{
// @ts-expect-error tempFile、name 仅H5支持
resolve
(
tempFilePath
)
resolve
(
result
)
},
},
()
=>
{
fail
:
errorCallback
,
resolve
(
tempFilePath
)
}
)
})
:
Promise
.
resolve
(
tempFilePath
)
if
(
compressed
)
{
plus
.
nativeUI
.
showWaiting
()
}
compressVideo
.
then
((
tempFilePath
:
string
)
=>
{
if
(
compressed
)
{
plus
.
nativeUI
.
closeWaiting
()
}
plus
.
io
.
getVideoInfo
({
filePath
:
tempFilePath
,
success
(
videoInfo
)
{
const
result
=
{
errMsg
:
'
chooseVideo:ok
'
,
tempFilePath
:
tempFilePath
,
size
:
videoInfo
.
size
,
duration
:
videoInfo
.
duration
,
width
:
videoInfo
.
width
,
height
:
videoInfo
.
height
,
}
resolve
(
result
as
any
)
},
fail
:
errorCallback
,
})
})
})
}
}
function
openAlbum
()
{
function
openAlbum
()
{
plus
.
gallery
.
pick
(
plus
.
gallery
.
pick
(
// NOTE 5+此API分单选和多选,多选返回files:string[]
// @ts-ignore 5+此API分单选和多选,多选返回files:string[]
// @ts-ignore
({
files
})
=>
successCallback
(
files
[
0
]),
({
files
})
=>
successCallback
(
files
[
0
]),
errorCallback
,
errorCallback
,
{
{
...
@@ -77,6 +48,8 @@ export const chooseVideo = defineAsyncApi<API_TYPE_CHOOSE_VIDEO>(
...
@@ -77,6 +48,8 @@ export const chooseVideo = defineAsyncApi<API_TYPE_CHOOSE_VIDEO>(
maximum
:
1
,
maximum
:
1
,
filename
:
TEMP_PATH
+
'
/gallery/
'
,
filename
:
TEMP_PATH
+
'
/gallery/
'
,
permissionAlert
:
true
,
permissionAlert
:
true
,
// @ts-expect-error 新增参数,用于视频压缩
videoCompress
:
compressed
,
}
}
)
)
}
}
...
@@ -87,6 +60,8 @@ export const chooseVideo = defineAsyncApi<API_TYPE_CHOOSE_VIDEO>(
...
@@ -87,6 +60,8 @@ export const chooseVideo = defineAsyncApi<API_TYPE_CHOOSE_VIDEO>(
index
:
camera
===
'
front
'
?
'
2
'
:
'
1
'
,
index
:
camera
===
'
front
'
?
'
2
'
:
'
1
'
,
videoMaximumDuration
:
maxDuration
,
videoMaximumDuration
:
maxDuration
,
filename
:
TEMP_PATH
+
'
/camera/
'
,
filename
:
TEMP_PATH
+
'
/camera/
'
,
// @ts-expect-error 新增参数,用于视频压缩
videoCompress
:
compressed
,
})
})
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录