uploadCutImageToUnicloud.vue 1.2 KB
Newer Older
芊里 已提交
1 2
<template>
	<view class="content" >
L
21  
linju 已提交
3
		<limeClipper :width="options.width" :scale-ratio="2" :is-lock-width="false" :is-lock-height="false" :height="options.height" :image-url="path"  
芊里 已提交
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
			@success="successFn" @cancel="cancel"  />
	</view>
</template>
<script>
import limeClipper from './limeClipper/limeClipper.vue';
export default {
	components: {limeClipper},
	data() {return {path: '',options:{"width":600,"height":600}}},
	onLoad({path,options}) {
		this.path = path
		if(options){
			this.options = JSON.parse(options)
		}
	},
	methods:{
		successFn(e){
20 21 22 23 24 25
			// uni.getImageInfo({
			// 	src:e.url,
			// 	complete: (e) => {
			// 		console.log(e);
			// 	}
			// })
芊里 已提交
26 27
			this.uploadImgToUnicloud(e.url,(url)=>{
				//console.log(url);
28
				this.getOpenerEventChannel().emit('uploadAvatarAfter', {url})
芊里 已提交
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
				uni.navigateBack()
			})
		},
		uploadImgToUnicloud(url,callback){
			uni.showLoading()
			uniCloud.uploadFile({
				cloudPath:Math.ceil((Math.random()+Math.random()+Math.random()+1)*1000000)+Date.now()+".png",
				filePath:url
			})
			.then(res=>{
				//console.log(res);
				callback(res.fileID)
				uni.hideLoading()
			})
		},
		cancel(){
			uni.navigateBack()
		}
	}
}
</script>

<style>
	.box{
		width: 400rpx;
	}
	.mt{
		margin-top: -10px;
	}
</style>