Skip to content

选择本地图片 - chooseImage

简介

  • 该任务是一个异步任务,需使用async await / promise结构 获取回调值
  • 该任务用于选择本地图片,返回选择的图片信息
  • 该API最大支持选择9张图片,默认也是9张,若需要限制用户选择最大数量,可针对性控制,见参数说明

环境适配说明

环境名称是否支持jssdk文件最低版本号npm包最低版本号
湘易办APP-小程序1.1.40.0.4
湘易办APP-小程序-webview1.1.80.0.4
湘易办APP-webview2.0.00.0.4
三方H5----
三方小程序-H5--0.0.32

参数

参数名类型必填默认值可选值描述
countNumber91-9最多选择图片数量
sizeTypeArray['original', 'compressed']['original', 'compressed']图片尺寸类型
sourceTypeArray['album']['album', 'camera']图片来源 ⚠️小程序嵌套的webview无法使用camera
isCircleCropBooleanfalsetrue/false是否圆形裁剪

返回值

仅列出返回体内的子参数,整体是一个Array / Object对象

参数名类型描述
fileNameString文件名 (微信/支付宝小程序下此字段无值)
pathStringAPP端本地文件路径
sizeNumber文件大小(字节) (微信/支付宝小程序下此字段无值)
typeString文件类型 (微信/支付宝小程序下此字段无值)

示例

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) {
    // 执行业务代码
  }
})