Skip to content

Commit

Permalink
fix(h5): h5的chooseImage在count设置为1时取消了multiple属性, fix #3401
Browse files Browse the repository at this point in the history
  • Loading branch information
Littly committed Jun 27, 2019
1 parent 3b18f85 commit 08aa12d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions packages/taro-h5/src/api/image/chooseImage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
import { shouleBeObject, getParameterError } from '../utils'

export default function chooseImage (options) {
/**
* 从本地相册选择图片或使用相机拍照。
* @param {Object} object 参数
* @param {string[]} [object.sourceType=['album', 'camera']] 选择图片的来源(h5端未实现)
* @param {string[]} [object.sizeType=['original', 'compressed']] 所选的图片的尺寸(h5端未实现)
* @param {number} [object.count=9] 最多可以选择的图片张数
* @param {function} [object.success] 接口调用成功的回调函数
* @param {function} [object.fail] 接口调用失败的回调函数
* @param {function} [object.complete] 接口调用结束的回调函数(调用成功、失败都会执行)
* @param {string} [object.imageId] 用来上传的input元素ID(仅h5端)
*/
const chooseImage = function (options) {
// options must be an Object
const isObject = shouleBeObject(options)
if (!isObject.res) {
Expand Down Expand Up @@ -34,7 +45,9 @@ export default function chooseImage (options) {
let obj = document.createElement('input')
obj.setAttribute('type', 'file')
obj.setAttribute('id', imageId)
obj.setAttribute('multiple', 'multiple')
if (count > 1) {
obj.setAttribute('multiple', 'multiple')
}
obj.setAttribute('accept', 'image/*')
obj.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;')
document.body.appendChild(obj)
Expand All @@ -61,3 +74,5 @@ export default function chooseImage (options) {
}
return taroChooseImagePromise
}

export default chooseImage

0 comments on commit 08aa12d

Please sign in to comment.