提交 39ec2b8e 编写于 作者: X xiaoyucoding

fix: 解决低版本 safari 浏览器中 chooseImage/chooseVideo 方法无效的问题

上级 67af900e
import { fileToUrl } from 'uni-platform/helpers/file' import { fileToUrl } from 'uni-platform/helpers/file'
import { updateElementStyle } from 'uni-shared'
const { const {
invokeCallbackHandler: invoke invokeCallbackHandler: invoke
...@@ -9,7 +10,14 @@ let imageInput = null ...@@ -9,7 +10,14 @@ let imageInput = null
const _createInput = function (options) { const _createInput = function (options) {
let inputEl = document.createElement('input') let inputEl = document.createElement('input')
inputEl.type = 'file' inputEl.type = 'file'
inputEl.style = 'position: absolute;visibility: hidden;z-index: -999;width: 0;height: 0;' updateElementStyle(inputEl, {
'position': 'absolute',
'visibility': 'hidden',
'z-index': -999,
'width': 0,
'height': 0
})
// inputEl.style = 'position: absolute;visibility: hidden;z-index: -999;width: 0;height: 0;'
inputEl.accept = 'image/*' inputEl.accept = 'image/*'
if (options.count > 1) { if (options.count > 1) {
inputEl.multiple = 'multiple' inputEl.multiple = 'multiple'
......
import { fileToUrl } from 'uni-platform/helpers/file' import { fileToUrl } from 'uni-platform/helpers/file'
import { updateElementStyle } from 'uni-shared'
const { const {
invokeCallbackHandler: invoke invokeCallbackHandler: invoke
...@@ -9,7 +10,14 @@ let videoInput = null ...@@ -9,7 +10,14 @@ let videoInput = null
const _createInput = function (options) { const _createInput = function (options) {
let inputEl = document.createElement('input') let inputEl = document.createElement('input')
inputEl.type = 'file' inputEl.type = 'file'
inputEl.style = 'position: absolute;visibility: hidden;z-index: -999;width: 0;height: 0;' updateElementStyle(inputEl, {
'position': 'absolute',
'visibility': 'hidden',
'z-index': -999,
'width': 0,
'height': 0
})
// inputEl.style = 'position: absolute;visibility: hidden;z-index: -999;width: 0;height: 0;'
inputEl.accept = 'video/*' inputEl.accept = 'video/*'
// 经过测试,仅能限制只通过相机拍摄,不能限制只允许从相册选择。 // 经过测试,仅能限制只通过相机拍摄,不能限制只允许从相册选择。
if (options.sourceType.length === 1 && options.sourceType[0] === 'camera') { if (options.sourceType.length === 1 && options.sourceType[0] === 'camera') {
......
...@@ -50,3 +50,9 @@ export function formatDateTime ({ ...@@ -50,3 +50,9 @@ export function formatDateTime ({
return date.getFullYear() + '-' + _completeValue(date.getMonth() + 1) + '-' + _completeValue(date.getDate()) return date.getFullYear() + '-' + _completeValue(date.getMonth() + 1) + '-' + _completeValue(date.getDate())
} }
} }
export function updateElementStyle (element, styles) {
for (let attrName in styles) {
element.style[attrName] = styles[attrName]
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册