欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

uniapp組件uni-file-picker中設(shè)置使用照相機和相冊權(quán)限的操作方法

 更新時間:2022年11月14日 11:00:31   作者:youmi_sunshine  
這篇文章主要介紹了uniapp組件uni-file-picker中設(shè)置使用照相機和相冊的權(quán)限,在uniapp中,我們通常會使用uni-file-picker這個組件,但是這個組件中,有點缺陷,就是沒有對這個功能的傳值設(shè)置,這里就要給組件進行修改了,需要的朋友可以參考下

在寫uniapp項目中,對于上傳圖片有時會有這樣的需求:只可使用照相機拍攝上傳,不可使用相冊。

在uniapp中,我們通常會使用uni-file-picker這個組件,但是這個組件中,有點缺陷,就是沒有對這個功能的傳值設(shè)置,這里就要給組件進行修改了。

1、在uni-file-picker組件中的uni-file-picker.vue中的js部分,找到props添加一個變量,如下:

props: {
		....以上省略	
			sizeType: {
				type: Array,
				default () {
					return ['original', 'compressed']
				}
			},
 
            //這是新加的變量,默認值是相冊和照相機都有的
			sourceType: {
				type: Array,
				default () {
					return ['camera','album']
				}
			}
},

2、在uni-file-picker組件中的uni-file-picker.vue中的js部分,找到chooseFiles()函數(shù),添加sourceType的傳值,如下:

/**
 * 選擇文件并上傳
*/
chooseFiles() {		
	const _extname = get_extname(this.fileExtname)
	// 獲取后綴
	uniCloud
		.chooseAndUploadFile({
				type: this.fileMediatype,
				compressed: false,
                //sourceType為新添加的控制照相機與相冊的傳值變量
				sourceType: this.sourceType,
				sizeType: this.sizeType,
				// TODO 如果為空,video 有問題
				extension: _extname.length > 0 ? _extname : undefined,
				count: this.limitLength - this.files.length, //默認9
				onChooseFile: this.chooseFileCallback,
				onUploadProgress: progressEvent => {
					this.setProgress(progressEvent, progressEvent.index)
				}
		})
		.then(result => {
			this.setSuccessAndError(result.tempFiles)
		})
		.catch(err => {
			console.log('選擇失敗', err)
		})
},

3、在頁面調(diào)用模板中使用改組件,使用 :sourceType或者 :source-type來控制照相機與相冊的使用權(quán)限,如下:

<template>
	<view class="container">
        <!--設(shè)置只能使用照相機  :sourceType="sourceType1" -->
        <view class="upload-box">
			<view class="pic-desc">照片1</view>
			<uni-file-picker  v-model="mentouValue" return-type="object" fileMediatype="image" mode="grid" :sourceType="sourceType1" :auto-upload="false"  @select="mentouSelect" @delete="mentouDelete"/>	
		</view>
        <!--設(shè)置只能使用照相機 則 :sourceType="sourceType2" -->
        <!--若都可以使用,則不用此變量,默認都可以使用的-->
    </view>
<template>

4、js部分寫法如下:

<script>
export default {
	data() {
		return{
           mentouValue:'',
           sourceType1:['camera'], 
           sourceType2:['album'], 
        }
    },
    methods:{
        //選擇圖片
        mentouSelect(e){
			console.log("選擇圖片",e)
		},
 
        //刪除圖片
        mentouDelete(){
			this.mentouValue = ''
		},
    }
}
</script>

到此這篇關(guān)于uniapp組件uni-file-picker中設(shè)置使用照相機和相冊的權(quán)限的文章就介紹到這了,更多相關(guān)uniapp組件uni-file-picker相冊權(quán)限內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論