赞
踩
一、子组件,通过插件更改的头像裁剪 头像上传裁切/剪切组件 - DCloud 插件市场
- <template>
- <view class="container">
- <view class="page-body uni-content-info">
- <view class='cropper-content'>
- <view v-if="isShowImg" class="uni-corpper" :style="'width:'+cropperInitW+'px;height:'+cropperInitH+'px;'">
- <view class="cropper-modal" :style="'width:'+cropperInitW+'px;height:'+cropperInitH+'px;'"></view>
- <view class="uni-corpper-content" :style="'width:'+cropperW+'px;height:'+cropperH+'px;left:'+cropperL+'px;top:'+cropperT+'px'">
- <image :src="imageSrc" :style="'width:'+cropperW+'px;height:'+cropperH+'px'"></image>
- <view class="cropper-modal-box" :style="'left:'+cutL+'px;top:'+cutT+'px;right:'+cutR+'px;bottom:'+cutB+'px'">
- <img :src="imageSrc" :style="'width:'+cropperW+'px;height:'+cropperH+'px;transform:translate3d('+cutL*-1+'px, '+cutT*-1+'px, 0px) '" />
- </view>
- <view class="uni-corpper-crop-box" @touchstart.stop="contentStartMove" @touchmove.stop="contentMoveing" @touchend.stop="contentTouchEnd"
- :style="'left:'+cutL+'px;top:'+cutT+'px;right:'+cutR+'px;bottom:'+cutB+'px'">
- <view class="uni-cropper-view-box">
- <view class="uni-cropper-dashed-h"></view>
- <view class="uni-cropper-dashed-v"></view>
- <view class="uni-cropper-line-t" data-drag="top" @touchstart.stop="dragStart" @touchmove.stop="dragMove"></view>
- <view class="uni-cropper-line-r" data-drag="right" @touchstart.stop="dragStart" @touchmove.stop="dragMove"></view>
- <view class="uni-cropper-line-b" data-drag="bottom" @touchstart.stop="dragStart" @touchmove.stop="dragMove"></view>
- <view class="uni-cropper-line-l" data-drag="left" @touchstart.stop="dragStart" @touchmove.stop="dragMove"></view>
- <view class="uni-cropper-point point-t" data-drag="top" @touchstart.stop="dragStart" @touchmove.stop="dragMove"></view>
- <view class="uni-cropper-point point-tr" data-drag="topTight"></view>
- <view class="uni-cropper-point point-r" data-drag="right" @touchstart.stop="dragStart" @touchmove.stop="dragMove"></view>
- <view class="uni-cropper-point point-rb" data-drag="rightBottom" @touchstart.stop="dragStart" @touchmove.stop="dragMove"></view>
- <view class="uni-cropper-point point-b" data-drag="bottom" @touchstart.stop="dragStart" @touchmove.stop="dragMove"></view>
- <view class="uni-cropper-point point-bl" data-drag="bottomLeft"></view>
- <view class="uni-cropper-point point-l" data-drag="left" @touchstart.stop="dragStart" @touchmove.stop="dragMove"></view>
- <view class="uni-cropper-point point-lt" data-drag="leftTop"></view>
- </view>
- </view>
- </view>
- </view>
- </view>
- <view class='cropper-config'>
- <!-- :style="'background-color: '+selectButtonBackgroundColor+';color: '+selectButtonColor+';'" -->
- <view class="cropper-choose" @click="getImage">{
- { selectButtonText }}</view>
- <!-- :style="'background-color: '+saveButtonBackgroundColor+';color: '+saveButtonColor+';'" -->
- <view class="cropper-confirm" @click="getImageInfo">{
- { isShowImg ? '上传' : '取消' }}</view>
- </view>
- <canvas canvas-id="myCanvas" v-if="originalW>0 && originalH>0" :style="'position:absolute;border: 1px solid red; width:'+(original?originalW:imageW)+'px;height:'+(original?originalH:imageH)+'px;top:-9999px;left:-9999px;'"></canvas>
- </view>
- </view>
- </template>
-
- <script>
- let sysInfo = uni.getSystemInfoSync();
- let SCREEN_WIDTH = sysInfo.screenWidth
- let PAGE_X, // 手按下的x位置
- PAGE_Y, // 手按下y的位置
- PR = sysInfo.pixelRatio, // dpi
- T_PAGE_X, // 手移动的时候x的位置
- T_PAGE_Y, // 手移动的时候Y的位置
- CUT_L, // 初始化拖拽元素的left值
- CUT_T, // 初始化拖拽元素的top值
- CUT_R, // 初始化拖拽元素的
- CUT_B, // 初始化拖拽元素的
- CUT_W, // 初始化拖拽元素的宽度
- CUT_H, // 初始化拖拽元素的高度
- IMG_RATIO, // 图片比例
- IMG_REAL_W, // 图片实际的宽度
- IMG_REAL_H, // 图片实际的高度
- DRAFG_MOVE_RATIO = 1, //移动时候的比例,
- INIT_DRAG_POSITION = 200, // 初始化屏幕宽度和裁剪区域的宽度之差,用于设置初始化裁剪的宽度
- ORIGINAL_W, //原始图片宽度
- ORIGINAL_H, //原始图片高度
- DRAW_IMAGE_W = sysInfo.screenWidth // 设置生成的图片宽度
-
- export default {
- name:'OkingtzCropper',
- props:{
- //是否显示头像裁剪
- is_avatar:{
- type:Boolean,
- default:false
- },
- original:{
- // 是否按照原始大小返回
- type:Boolean,
- default:true
- },
- fixed:{
- // 优先级比较
- type:Boolean,
- default:true
- },
- fixedNumber:{
- type:Array,
-
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。