# choosePhoto
选择相册照片,并返回相片数据
# 调用方式
choosePhoto(params)
1
返回 Promise,使用 then/catch 或 await 处理结果。 接收单个业务参数;是否需要传参按下方参数表约定,无业务参数时可省略。具体字段及返回数据由宿主原生约定。
# 请求参数
| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
param | Object | Y | {}属性: compressRage:{Type: Number, Default: 100,Description: 返回照片的压缩率,范围为 0~100(只是针对jpg格式的图片,png格式没有压缩率),数值越高保真率越高} type:{Type: String, Default: jpg,Description: 指定返回相片的格式(值为 jpg或png} isNeedBase64:{Type: Boolean, Default: true, Description: 是否需要返回相片base64数据: true是 / false否} | 请求参数 |
参数对象示例(数值为示例值,不代表默认值):
const params = {
compressRage: 70,
type: 'jpg',
isNeedBase64: false,
crop: false,
scale: 1,
maxWidthHeight: 1500
}
1
2
3
4
5
6
7
8
2
3
4
5
6
7
8
补充参数(来自旧 intl 文档,示例值不是默认值):
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| params.crop | Boolean | 宿主约定 | 未说明 | 旧文档的裁剪配置,具体行为由原生决定 |
| params.scale | Number | 宿主约定 | 未说明 | 旧示例中的 scale 配置,含义和取值范围以宿主为准 |
| params.maxWidthHeight | Number | 宿主约定 | 未说明 | 旧示例中的尺寸限制配置,单位及行为以宿主为准 |
# 接口调用示例
this.$bridge.choosePhoto(params)
1
# 返回参数
- 成功时返回
| Prop | Type | Default | Description |
|---|---|---|---|
status | Number | 0/1 | 0 拍照成功 /1 取消拍照 |
type | String | N/A | 指定返回相片的格式(值为jpg或png) |
data | String | N/A | 如果isNeedBase64为true,则返回相片的base64字符串 |
filePath | String | N/A | 返回相片保存的文件路径 |
fileName | String | N/A | 保存的文件名 |
size | Number | N/A | 返回相片的文件大小,带小数,单位为Kb |
- 失败时返回
| Prop | Type | Default | Description |
|---|---|---|---|
errorCode | Number | N/A | 请求失败错误码:-1 没有权限 |
# 接口返回示例
this.$bridge.choosePhoto(params)
.then((res) => {
this.emitUploadFile('photo', res);
})
.catch((error) => {
this.$bridge.log('choosePhoto error', error);
});
1
2
3
4
5
6
7
2
3
4
5
6
7
# 注意事项
crop、scale、maxWidthHeight 来自旧 intl 文档;示例数值不代表默认值。参数对象会转发给原生,裁剪行为和字段支持情况取决于宿主。