Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(taro-h5): 修复h5的chooseImage API无法动态设置souceType的问题,对齐小程序端 #6101

Merged
merged 1 commit into from
Apr 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions packages/taro-h5/src/api/image/chooseImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const chooseImage = function (options) {
tempFilePaths: [],
tempFiles: []
}
const sourceTypeString = sourceType && sourceType.toString()
const acceptableSourceType = ['user', 'environment', 'camera']

if (count && typeof count !== 'number') {
res.errMsg = getParameterError({
Expand All @@ -43,8 +45,6 @@ const chooseImage = function (options) {
let taroChooseImageId = document.getElementById(imageId)
if (!taroChooseImageId) {
let obj = document.createElement('input')
const sourceTypeString = sourceType && sourceType.toString()
const acceptableSourceType = ['user', 'environment', 'camera']
obj.setAttribute('type', 'file')
obj.setAttribute('id', imageId)
if (count > 1) {
Expand All @@ -57,6 +57,12 @@ const chooseImage = function (options) {
obj.setAttribute('style', 'position: fixed; top: -4000px; left: -3000px; z-index: -300;')
document.body.appendChild(obj)
taroChooseImageId = document.getElementById(imageId)
} else {
if (acceptableSourceType.indexOf(sourceTypeString) > -1) {
taroChooseImageId.setAttribute('capture', sourceTypeString)
} else {
taroChooseImageId.removeAttribute('capture')
}
}
let taroChooseImageCallback
const taroChooseImagePromise = new Promise(resolve => {
Expand All @@ -67,7 +73,7 @@ const chooseImage = function (options) {
taroChooseImageId.dispatchEvent(TaroMouseEvents)
taroChooseImageId.onchange = function (e) {
let arr = [...e.target.files]
arr=arr.splice(0,count)
arr = arr.splice(0, count)
arr && arr.forEach(item => {
let blob = new Blob([item], {
type: item.type
Expand Down