日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學(xué)無(wú)先后,達(dá)者為師

網(wǎng)站首頁(yè) 編程語(yǔ)言 正文

uniapp上傳圖片視頻uniapp上傳圖片視頻

作者:L、yan 更新時(shí)間: 2022-03-04 編程語(yǔ)言
<template>
	<view>
		<!-- 評(píng)分 -->	
		<view class="grade" v-for="(item,index) in talk" :key="index">
			<view>
				<view>{{item.title}}</view>
				<view>
					<uni-rate v-model="item.value" @change="(e)=>{onChange(e,item,index)}" activeColor="red" />
				</view>
			</view>
			<view>1.0分</view>
		</view>
		
		<!-- 評(píng)價(jià) -->
		<view class="discuss">
			<view>評(píng)價(jià)</view>
			<view>
				<textarea value="" placeholder="" />
			</view>
		</view>
		
		<!-- 上傳 -->
		<view class="up_photo_video">
			<view class="up_photo_video_m_b">
				<view class="up_photo_video_m" @tap="chooseVideoImage(1)">
					<view>
						<image src="../../static/icon/up.png"></image>
					</view>
					<view>上傳圖片</view>
				</view>
				<view class="up_photo_video_m" style="margin-left: 20rpx;" @tap="chooseVideoImage(2)">
					<view>
						<image src="../../static/icon/up.png"></image>
					</view>
					<view>上傳視頻</view>
				</view>
			</view>
			<view class="burst-wrap-bg">
			    <view>
			        <!-- 信息提交 -->
			        <view class="burst-info">
			            <view class="uni-uploader-body">
			                <view class="uni-uploader__files">
			                    <!-- 圖片 -->
			                   <view class="image_b">
								   <block v-for="(image,index) in imageList" :key="index">
								        <view class="uni-uploader__file">
								            <view class="delete_x" @click.stop="delect(index)">X</view>
								            <image class="uni-uploader__img" :src="image" :data-src="image" @tap="previewImage"></image>
								        </view>
								    </block>
							   </view>
			                    <!-- 視頻 -->
			                    <view class="uni-uploader__file" v-if="src">
			                        <view class="uploader_video">
			                            <view class="icon iconfont icon-cuo" @tap="delectVideo"></view>
			                            <video :src="src" class="video"></video>
			                        </view>
			                    </view>
			                    <view class="uni-uploader__input-box" v-if="VideoOfImagesShow">
			                        <view class="uni-uploader__input" @tap="chooseVideoImage"></view>
			                    </view>
			                </view>
			            </view>
			
			
			        </view>
			    </view>
			</view>
		</view>
		
		
		
		
		
		
	</view>
</template>

<script>
	import uRate from '@/uni_modules/uni-rate/components/uni-rate/uni-rate.vue'
	export default {
		data() {
			return {
				talk: [
					{
						id: 1,
						title: '態(tài)度',
						value: 5
					},
					{
						id: 2,
						title: '服務(wù)',
						value: 5
					},
					{
						id: 3,
						title: '性價(jià)比',
						value: 5
					},
					{
						id: 4,
						title: '環(huán)境',
						value: 5
					},
				], // 評(píng)論數(shù)據(jù)
				feedback: '',// 反饋
				iphone: '',// 聯(lián)系方式
				gradeArr: [
					{
						id: 1,
						title: '態(tài)度',
						value: 5
					},
					{
						id: 2,
						title: '服務(wù)',
						value: 5
					},
					{
						id: 3,
						title: '性價(jià)比',
						value: 5
					},
					{
						id: 4,
						title: '環(huán)境',
						value: 5
					},
				], // 評(píng)級(jí)的數(shù)據(jù) 
				suid: 0, // 客服id	
				// 上傳
				imageList:[],//圖片
				src:"",//視頻存放
				sourceTypeIndex: 2,
				checkedValue:true,
				checkedIndex:0,
				sourceType: ['拍攝', '相冊(cè)', '拍攝或相冊(cè)'],
				cameraList: [{
				        value: 'back',
				        name: '后置攝像頭',
				        checked: 'true'
				    },
				    {
				        value: 'front',
				        name: '前置攝像頭'
				    },
				],
				cameraIndex: 0,
				VideoOfImagesShow:true,
			};
		},
		components: {
			uRate
		},
		onUnload() {
		    this.src = '',
		    this.sourceTypeIndex = 2,
		    this.sourceType = ['拍攝', '相冊(cè)', '拍攝或相冊(cè)'];
		},
		methods:{
			// 星星評(píng)級(jí)
			onChange(d,title,index) {
			  console.log(d)
			  let obj ={
			    id: title.id,
			    star:d.value,
			    title:title.title
			  }
			  this.$set(this.gradeArr,index,obj)
			  console.log(this.gradeArr)
			},
			// 上傳
			chooseVideoImage(msg){
				console.log(msg)
				if(msg == 1){
					this.chooseImages()
				}else{
					this.chooseVideo()
				}
			    // uni.showActionSheet({
			    //     title:"選擇上傳類型",
			    //     itemList: ['圖片','視頻'],
			    //     success: (res) => {
			    //         console.log(res)
			    //         if(res.tapIndex == 0){
			    //             this.chooseImages()
			    //         } else {
			    //             this.chooseVideo()
			    //         }
			    //     }
			    // })
			},
			chooseImages(){
			    // 上傳圖片
			    uni.chooseImage({
			        count: 9, //默認(rèn)9
			        sizeType: ['original', 'compressed'], //可以指定是原圖還是壓縮圖,默認(rèn)二者都有
			        sourceType: ['album','camera'], //從相冊(cè)選擇
			        success:(res)=> {
			            this.imageList = this.imageList.concat(res.tempFilePaths);
			            
			            if(this.imageList.length == 4) {
			                this.VideoOfImagesShow = false
			            }
			        }
			    });
			},
			chooseVideo(){
			    // 上傳視頻
			    console.log('上傳視頻')
			    uni.chooseVideo({
			        maxDuration:10,
			        count: 1,
			        camera: this.cameraList[this.cameraIndex].value,
			        sourceType: ['album','camera'],
			        success: (res) => {
			            console.log(JSON.stringify(res.tempFilePath),'視頻')
			            this.src = res.tempFilePath;
			            console.log(this.src)
			        }
			    })
			},
			previewImage: function(e) {
			    //預(yù)覽圖片
			    var current = e.target.dataset.src
			    uni.previewImage({
			        current: current,
			        urls: this.imageList
			    })
			},
			delect(index){
			    uni.showModal({
			        title: "提示",
			        content: "是否要?jiǎng)h除該圖片",
			        success: (res) => {
			            if (res.confirm) {
			                this.imageList.splice(index, 1)
			            }
			        }
			    })
			},
			delectVideo(){
			    uni.showModal({
			        title:"提示",
			        content:"是否要?jiǎng)h除此視頻",
			        success:(res) =>{
			            if(res.confirm){
			                this.src = ''
			            }
			        }
			    })
			}
		}
	}
</script>

<style lang="less" scoped>
* {
		margin: 0;
		padding: 0;
	}

	page {
		background: #F5F7F9;
	}

	.flex {
		display: flex;
		justify-content: space-between;
		align-items: center;
	}

	.hidden {
		white-space: nowrap;
		text-overflow: ellipsis;
		overflow: hidden;
	}


	// 評(píng)分
	.grade{
		height: 52rpx;
		width: 92%;
		margin: 0 auto;
		margin-top: 50rpx;
		.flex;
		>view:first-child{
			height: 52rpx;
			width: 80%;
			display: flex;
			align-items: center;
			>view:first-child{
				height: 52rpx;
				width: 25%;
				font-size: 28rpx;
				font-weight: 550;
				line-height: 52rpx;
			}
			>view:last-child{
				height: 52rpx;
				width: 100%;
			}
			
		}
		>view:last-child{
			height: 52rpx;
			width: 18%;
			line-height: 52rpx;
			text-align: right;
			font-size: 24rpx;
			color: #1D1D2C;
		}
	}

	// 評(píng)價(jià)
	.discuss{
		height: 232rpx;
		width: 92%;
		margin: 0 auto;
		margin-top: 80rpx;
		>view:first-child{
			height: 40rpx;
			width: 100%;
			font-size: 24rpx;
			color: #767783;
		}
		>view:last-child{
			height: 160rpx;
			width: 100%;
			margin-top: 34rpx;
			background: #FFFFFF;
			border-radius: 4px;
			>textarea{
				height: 160rpx;
				width: 100%;
				font-size: 24rpx;
			}
		}
	}
	
	// 上傳
	.up_photo_video{
		width: 92%;
		margin: 0 auto;
		margin-top: 30rpx;
		.up_photo_video_m_b{
			height: 200rpx;
			width: 100%;
			display: flex;
			.up_photo_video_m{
				height: 200rpx;
				width: 200rpx;
				background: #FFFFFF;
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				>view:first-child{
					height: 80rpx;
					width: 80rpx;
					>image{
						height: 80rpx;
						width: 80rpx;
					}
				}
				>view:last-child{
					height: 40rpx;
					width: 100%;
					line-height: 40rpx;
					text-align: center;
					font-size: 24rpx;
				}
			}
		}
	}
	.image_b{
		height: auto;
		width: 100%;
		display: flex;
		flex-wrap: wrap;
		// background: red;
	}
	.uni-uploader__file{
		height: 200rpx;
		width: 200rpx;
		position: relative;
		margin-left: 20rpx;
		margin-top: 20rpx;
	}
	.uni-uploader__img{
		height: 200rpx;
		width: 200rpx;
		
	}
	.delete_x{
		height: 40rpx;
		width: 40rpx;
		position: absolute;
		top: 10rpx;
		right: 4rpx;
		font-size: 28rpx;
		z-index: 9999;
	}





















</style>

原文鏈接:https://blog.csdn.net/weixin_45966782/article/details/121652150

欄目分類
最近更新