uploadCutImageToUnicloud.vue 1.1 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
			@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
14
		console.log('path-path-path-path',path);
芊里 已提交
15 16 17 18 19 20 21
		if(options){
			this.options = JSON.parse(options)
		}
	},
	methods:{
		successFn(e){
			this.uploadImgToUnicloud(e.url,(url)=>{
22
				this.getOpenerEventChannel().emit('uploadAvatarAfter', {url})
芊里 已提交
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
				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>