From 38090099676a585393eac008b04b883c42a4c300 Mon Sep 17 00:00:00 2001 From: jackie-gan Date: Fri, 24 Apr 2020 23:52:50 +0800 Subject: [PATCH] =?UTF-8?q?fix(taro-h5):=20=E4=BF=AE=E5=A4=8Dh5=E7=9A=84ch?= =?UTF-8?q?ooseImage=20API=E6=97=A0=E6=B3=95=E5=8A=A8=E6=80=81=E8=AE=BE?= =?UTF-8?q?=E7=BD=AEsouceType=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=8C=E5=AF=B9?= =?UTF-8?q?=E9=BD=90=E5=B0=8F=E7=A8=8B=E5=BA=8F=E7=AB=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-h5/src/api/image/chooseImage.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/taro-h5/src/api/image/chooseImage.js b/packages/taro-h5/src/api/image/chooseImage.js index 6b15c77fff51..addab7b4ffab 100644 --- a/packages/taro-h5/src/api/image/chooseImage.js +++ b/packages/taro-h5/src/api/image/chooseImage.js @@ -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({ @@ -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) { @@ -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 => { @@ -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