Appearance
选择本地图片 - chooseImage
简介
- 该任务是一个异步任务,需使用async await / promise结构 获取回调值
- 该任务用于选择本地图片,返回选择的图片信息
- 该API最大支持选择9张图片,默认也是9张,若需要限制用户选择最大数量,可针对性控制,见参数说明
环境适配说明
| 环境名称 | 是否支持 | jssdk文件最低版本号 | npm包最低版本号 |
|---|---|---|---|
| 湘易办APP-小程序 | ✅ | 1.1.4 | 0.0.4 |
| 湘易办APP-小程序-webview | ✅ | 1.1.8 | 0.0.4 |
| 湘易办APP-webview | ✅ | 2.0.0 | 0.0.4 |
| 三方H5 | ❌ | -- | -- |
| 三方小程序-H5 | ✅ | -- | 0.0.32 |
参数
| 参数名 | 类型 | 必填 | 默认值 | 可选值 | 描述 |
|---|---|---|---|---|---|
| count | Number | 否 | 9 | 1-9 | 最多选择图片数量 |
| sizeType | Array | 否 | ['original', 'compressed'] | ['original', 'compressed'] | 图片尺寸类型 |
| sourceType | Array | 否 | ['album'] | ['album', 'camera'] | 图片来源 ⚠️小程序嵌套的webview无法使用camera |
| isCircleCrop | Boolean | 否 | false | true/false | 是否圆形裁剪 |
返回值
仅列出返回体内的子参数,整体是一个
Array / Object对象
| 参数名 | 类型 | 描述 |
|---|---|---|
| fileName | String | 文件名 (微信/支付宝小程序下此字段无值) |
| path | String | APP端本地文件路径 |
| size | Number | 文件大小(字节) (微信/支付宝小程序下此字段无值) |
| type | String | 文件类型 (微信/支付宝小程序下此字段无值) |
示例
javascript
// exp.1 不更改参数
const res = await this.$xybAgent.chooseImage();
if (res) {
// 执行业务代码
}
// exp.2 改变参数-最大可选数量
const res = await this.$xybAgent.chooseImage({
count: 1
});
if (res) {
// 执行业务代码
}
// exp.3 改变参数-图片尺寸类型
const res = await this.$xybAgent.chooseImage({
sizeType: ['original']
});
if (res) {
// 执行业务代码
}
// exp.4 改变参数-图片来源
const res = await this.$xybAgent.chooseImage({
sourceType: ['camera']
});
if (res) {
// 执行业务代码
}
// exp.5 改变参数-圆形裁剪
const res = await this.$xybAgent.chooseImage({
isCircleCrop: true
});
if (res) {
// 执行业务代码
}javascript
// exp.1 不更改参数
this.$xybAgent.chooseImage().then(res => {
if (res) {
// 执行业务代码
}
});
// exp.2 改变参数-最大可选数量
this.$xybAgent.chooseImage({
count: 1
}).then(res => {
if (res) {
// 执行业务代码
}
})
// exp.3 改变参数-图片尺寸类型
this.$xybAgent.chooseImage({
sizeType: ['original']
}).then(res => {
if (res) {
// 执行业务代码
}
})
// exp.4 改变参数-图片来源
this.$xybAgent.chooseImage({
sourceType: ['camera']
}).then(res => {
if (res) {
// 执行业务代码
}
});
// exp.5 改变参数-圆形裁剪
this.$xybAgent.chooseImage({
isCircleCrop: true
}).then(res => {
if (res) {
// 执行业务代码
}
})