使用H5轻应用JSAPI需要引用资源,查看详细文档
HWH5.chooseImage
从本地相册选择图片或使用相机拍照
请求参数
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
flag | Number | 否 | 1:访问本地相册;2:拍照;3:录像,默认为1 |
imagePickerMode | String | 否 | 相册展示资源类型。All :图片、视频 IMAGE :只显示图片 VIDEO :只显示视频,默认为All |
maxSelectedCount | Number | 否 | 最多选取资源数。默认为9 |
showOrigin | Bool | 否 | 是否可以选择原图。true:可以选择原图,false:原图按钮隐藏。默认为true |
btntxtEN | String | 否 | 结束按钮文案,英文 |
btntxtCN | String | 否 | 结束按钮文案,中文 |
cameraFacing | Number | 否 | 0:后置摄像头,1:前置摄像头。默认为0 |
showShadow | String | 否 | flag:2时才起作用。不传或是为 '0',不显示相框。 '1': 显示人头框 ,'2': 身份证正面(国徽面),'3': 身份证反面,'4': 证件 |
返回结果
参数 | 说明 |
---|---|
url | 本地上传后的临时路径 |
请求示例
本地相册选择
ES6版本
HWH5.chooseImage({ flag: 1, imagePickerMode: 'All', maxSelectedCount: 12, showOrigin: false, btntxtEN: 'Done', btntxtCN: '完成', cameraFacing: 0, compress: '0.25' }).then(data => { console.log(data); }).catch(error => { console.log('访问相册异常', error); });
ES5版本
HWH5.chooseImage({ flag: 1, imagePickerMode: 'All', maxSelectedCount: 12, showOrigin: false, btntxtEN: 'Done', btntxtCN: '完成', cameraFacing: 0, compress: '0.25' }).then(function (data) { console.log(data); }).catch(function (error) { console.log('访问相册异常', error); });
拍照
ES6版本
HWH5.chooseImage({ flag: 2, showShadow: '0', }).then(data => { console.log('data:', data); }).catch(error => { console.log('拍照异常', error); });
ES5版本
HWH5.chooseImage({ flag: 2, showShadow: '0', }).then(function (data) { console.log('data:', data); }).catch(function (error) { console.log('拍照异常', error); });
HWH5.previewImage
打开在线图片预览界面
请求参数
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
index | String | 是 | 类型,图片索引 |
imageArray | String | 是 | 预览的在线图片列表 |
watermark | boolean | 否 | 图片预览页面添加水印 |
返回结果
无。
请求示例
const images = [
'http://xxx.xxx.com/xxx/xxx1.jpg',
'http://xxx.xxx.com/xxx/xxx2.jpg',
'http://xxx.xxx.com/xxx/xxx3.jpg'
];
HWH5.previewImage({
index: '0',
imageArray: JSON.stringify(images),
watermark: true
}).catch(error => {
console.log('打开失败', error);
});
const images = [
'http://xxx.xxx.com/xxx/xxx1.jpg',
'http://xxx.xxx.com/xxx/xxx2.jpg',
'http://xxx.xxx.com/xxx/xxx3.jpg'
];
HWH5.previewImage({
index: '0',
imageArray: JSON.stringify(images),
watermark: true
}).catch(function (error) {
console.log('获取失败', error);
});