|
|
@ -1,26 +1,40 @@
|
|
|
|
<template>
|
|
|
|
<template>
|
|
|
|
|
|
|
|
<navigation-general title="头像修改">
|
|
|
|
<view class="container">
|
|
|
|
<view class="container">
|
|
|
|
<view class="page-body uni-content-info">
|
|
|
|
<view class="page-body uni-content-info">
|
|
|
|
<view class='cropper-content'>
|
|
|
|
<view class='cropper-content'>
|
|
|
|
<view v-if="isShowImg" class="uni-corpper" :style="'width:'+cropperInitW+'px;height:'+cropperInitH+'px;background:#000'">
|
|
|
|
<view v-if="isShowImg" class="uni-corpper"
|
|
|
|
<view class="uni-corpper-content" :style="'width:'+cropperW+'px;height:'+cropperH+'px;left:'+cropperL+'px;top:'+cropperT+'px'">
|
|
|
|
:style="'width:'+cropperInitW+'px;height:'+cropperInitH+'px;background:#000'">
|
|
|
|
|
|
|
|
<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>
|
|
|
|
<image :src="imageSrc" :style="'width:'+cropperW+'px;height:'+cropperH+'px'"></image>
|
|
|
|
<view class="uni-corpper-crop-box" @touchstart.stop="contentStartMove" @touchmove.stop="contentMoveing" @touchend.stop="contentTouchEnd"
|
|
|
|
<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'">
|
|
|
|
:style="'left:'+cutL+'px;top:'+cutT+'px;right:'+cutR+'px;bottom:'+cutB+'px'">
|
|
|
|
<view class="uni-cropper-view-box">
|
|
|
|
<view class="uni-cropper-view-box">
|
|
|
|
<view class="uni-cropper-dashed-h"></view>
|
|
|
|
<view class="uni-cropper-dashed-h"></view>
|
|
|
|
<view class="uni-cropper-dashed-v"></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-t" data-drag="top" @touchstart.stop="dragStart"
|
|
|
|
<view class="uni-cropper-line-r" data-drag="right" @touchstart.stop="dragStart" @touchmove.stop="dragMove"></view>
|
|
|
|
@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-r" data-drag="right" @touchstart.stop="dragStart"
|
|
|
|
<view class="uni-cropper-line-l" data-drag="left" @touchstart.stop="dragStart" @touchmove.stop="dragMove"></view>
|
|
|
|
@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-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-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-r" data-drag="right"
|
|
|
|
<view class="uni-cropper-point point-rb" data-drag="rightBottom" @touchstart.stop="dragStart" @touchmove.stop="dragMove"></view>
|
|
|
|
@touchstart.stop="dragStart" @touchmove.stop="dragMove"></view>
|
|
|
|
<view class="uni-cropper-point point-b" data-drag="bottom" @touchstart.stop="dragStart" @touchmove.stop="dragMove" @touchend.stop="dragEnd"></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"
|
|
|
|
|
|
|
|
@touchend.stop="dragEnd"></view>
|
|
|
|
<view class="uni-cropper-point point-bl" data-drag="bottomLeft"></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-l" data-drag="left"
|
|
|
|
|
|
|
|
@touchstart.stop="dragStart" @touchmove.stop="dragMove"></view>
|
|
|
|
<view class="uni-cropper-point point-lt" data-drag="leftTop"></view>
|
|
|
|
<view class="uni-cropper-point point-lt" data-drag="leftTop"></view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
@ -31,15 +45,19 @@
|
|
|
|
<button type="primary reverse" @click="getImage" style='margin-top: 30rpx;'> 选择头像 </button>
|
|
|
|
<button type="primary reverse" @click="getImage" style='margin-top: 30rpx;'> 选择头像 </button>
|
|
|
|
<button type="warn" @click="getImageInfo" style='margin-top: 30rpx;'> 提交 </button>
|
|
|
|
<button type="warn" @click="getImageInfo" style='margin-top: 30rpx;'> 提交 </button>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
<canvas canvas-id="myCanvas" :style="'position:absolute;border: 1px solid red; width:'+imageW+'px;height:'+imageH+'px;top:-9999px;left:-9999px;'"></canvas>
|
|
|
|
<canvas canvas-id="myCanvas"
|
|
|
|
|
|
|
|
:style="'position:absolute;border: 1px solid red; width:'+imageW+'px;height:'+imageH+'px;top:-9999px;left:-9999px;'"></canvas>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
</view>
|
|
|
|
|
|
|
|
</navigation-general>
|
|
|
|
</template>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
<script>
|
|
|
|
import config from '@/config'
|
|
|
|
import config from '@/config'
|
|
|
|
import store from "@/store"
|
|
|
|
import store from "@/store"
|
|
|
|
import { uploadAvatar } from "@/api/system/user"
|
|
|
|
import {
|
|
|
|
|
|
|
|
uploadAvatar
|
|
|
|
|
|
|
|
} from "@/api/system/user"
|
|
|
|
|
|
|
|
|
|
|
|
const baseUrl = config.baseUrl
|
|
|
|
const baseUrl = config.baseUrl
|
|
|
|
let sysInfo = uni.getSystemInfoSync()
|
|
|
|
let sysInfo = uni.getSystemInfoSync()
|
|
|
@ -100,20 +118,20 @@
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
* 生命周期函数--监听页面初次渲染完成
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
onReady: function () {
|
|
|
|
onReady: function() {
|
|
|
|
this.loadImage()
|
|
|
|
this.loadImage()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
methods: {
|
|
|
|
setData: function (obj) {
|
|
|
|
setData: function(obj) {
|
|
|
|
let that = this
|
|
|
|
let that = this
|
|
|
|
Object.keys(obj).forEach(function (key) {
|
|
|
|
Object.keys(obj).forEach(function(key) {
|
|
|
|
that.$set(that.$data, key, obj[key])
|
|
|
|
that.$set(that.$data, key, obj[key])
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
getImage: function () {
|
|
|
|
getImage: function() {
|
|
|
|
var _this = this
|
|
|
|
var _this = this
|
|
|
|
uni.chooseImage({
|
|
|
|
uni.chooseImage({
|
|
|
|
success: function (res) {
|
|
|
|
success: function(res) {
|
|
|
|
_this.setData({
|
|
|
|
_this.setData({
|
|
|
|
imageSrc: res.tempFilePaths[0],
|
|
|
|
imageSrc: res.tempFilePaths[0],
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -121,7 +139,7 @@
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
},
|
|
|
|
},
|
|
|
|
loadImage: function () {
|
|
|
|
loadImage: function() {
|
|
|
|
var _this = this
|
|
|
|
var _this = this
|
|
|
|
|
|
|
|
|
|
|
|
uni.getImageInfo({
|
|
|
|
uni.getImageInfo({
|
|
|
@ -139,7 +157,8 @@
|
|
|
|
INIT_DRAG_POSITION = minRange > INIT_DRAG_POSITION ? INIT_DRAG_POSITION : minRange
|
|
|
|
INIT_DRAG_POSITION = minRange > INIT_DRAG_POSITION ? INIT_DRAG_POSITION : minRange
|
|
|
|
// 根据图片的宽高显示不同的效果 保证图片可以正常显示
|
|
|
|
// 根据图片的宽高显示不同的效果 保证图片可以正常显示
|
|
|
|
if (IMG_RATIO >= 1) {
|
|
|
|
if (IMG_RATIO >= 1) {
|
|
|
|
let cutT = Math.ceil((SCREEN_WIDTH / IMG_RATIO - (SCREEN_WIDTH / IMG_RATIO - INIT_DRAG_POSITION)) / 2)
|
|
|
|
let cutT = Math.ceil((SCREEN_WIDTH / IMG_RATIO - (SCREEN_WIDTH / IMG_RATIO -
|
|
|
|
|
|
|
|
INIT_DRAG_POSITION)) / 2)
|
|
|
|
let cutB = cutT
|
|
|
|
let cutB = cutT
|
|
|
|
let cutL = Math.ceil((SCREEN_WIDTH - SCREEN_WIDTH + INIT_DRAG_POSITION) / 2)
|
|
|
|
let cutL = Math.ceil((SCREEN_WIDTH - SCREEN_WIDTH + INIT_DRAG_POSITION) / 2)
|
|
|
|
let cutR = cutL
|
|
|
|
let cutR = cutL
|
|
|
@ -161,7 +180,8 @@
|
|
|
|
innerAspectRadio: IMG_RATIO
|
|
|
|
innerAspectRadio: IMG_RATIO
|
|
|
|
})
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let cutL = Math.ceil((SCREEN_WIDTH * IMG_RATIO - (SCREEN_WIDTH * IMG_RATIO)) / 2)
|
|
|
|
let cutL = Math.ceil((SCREEN_WIDTH * IMG_RATIO - (SCREEN_WIDTH * IMG_RATIO)) /
|
|
|
|
|
|
|
|
2)
|
|
|
|
let cutR = cutL
|
|
|
|
let cutR = cutL
|
|
|
|
let cutT = Math.ceil((SCREEN_WIDTH - INIT_DRAG_POSITION) / 2)
|
|
|
|
let cutT = Math.ceil((SCREEN_WIDTH - INIT_DRAG_POSITION) / 2)
|
|
|
|
let cutB = cutT
|
|
|
|
let cutB = cutT
|
|
|
@ -253,12 +273,18 @@
|
|
|
|
destHeight: canvasH,
|
|
|
|
destHeight: canvasH,
|
|
|
|
quality: 0.5,
|
|
|
|
quality: 0.5,
|
|
|
|
canvasId: 'myCanvas',
|
|
|
|
canvasId: 'myCanvas',
|
|
|
|
success: function (res) {
|
|
|
|
success: function(res) {
|
|
|
|
uni.hideLoading()
|
|
|
|
uni.hideLoading()
|
|
|
|
let data = {name: 'avatarfile', filePath: res.tempFilePath}
|
|
|
|
let data = {
|
|
|
|
|
|
|
|
name: 'avatarfile',
|
|
|
|
|
|
|
|
filePath: res.tempFilePath
|
|
|
|
|
|
|
|
}
|
|
|
|
uploadAvatar(data).then(response => {
|
|
|
|
uploadAvatar(data).then(response => {
|
|
|
|
store.commit('SET_AVATAR', baseUrl + response.imgUrl)
|
|
|
|
store.commit('SET_AVATAR', baseUrl + response.imgUrl)
|
|
|
|
uni.showToast({ title: "修改成功", icon: 'success' })
|
|
|
|
uni.showToast({
|
|
|
|
|
|
|
|
title: "修改成功",
|
|
|
|
|
|
|
|
icon: 'success'
|
|
|
|
|
|
|
|
})
|
|
|
|
uni.navigateBack()
|
|
|
|
uni.navigateBack()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -290,7 +316,8 @@
|
|
|
|
case 'left':
|
|
|
|
case 'left':
|
|
|
|
var dragLength = (T_PAGE_X - e.touches[0].pageX) * DRAFG_MOVE_RATIO
|
|
|
|
var dragLength = (T_PAGE_X - e.touches[0].pageX) * DRAFG_MOVE_RATIO
|
|
|
|
if (CUT_L - dragLength < 0) dragLength = CUT_L
|
|
|
|
if (CUT_L - dragLength < 0) dragLength = CUT_L
|
|
|
|
if ((CUT_L - dragLength) > (this.cropperW - this.cutR)) dragLength = CUT_L - (this.cropperW - this.cutR)
|
|
|
|
if ((CUT_L - dragLength) > (this.cropperW - this.cutR)) dragLength = CUT_L - (this.cropperW - this
|
|
|
|
|
|
|
|
.cutR)
|
|
|
|
this.setData({
|
|
|
|
this.setData({
|
|
|
|
cutL: CUT_L - dragLength
|
|
|
|
cutL: CUT_L - dragLength
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -298,7 +325,8 @@
|
|
|
|
case 'top':
|
|
|
|
case 'top':
|
|
|
|
var dragLength = (T_PAGE_Y - e.touches[0].pageY) * DRAFG_MOVE_RATIO
|
|
|
|
var dragLength = (T_PAGE_Y - e.touches[0].pageY) * DRAFG_MOVE_RATIO
|
|
|
|
if (CUT_T - dragLength < 0) dragLength = CUT_T
|
|
|
|
if (CUT_T - dragLength < 0) dragLength = CUT_T
|
|
|
|
if ((CUT_T - dragLength) > (this.cropperH - this.cutB)) dragLength = CUT_T - (this.cropperH - this.cutB)
|
|
|
|
if ((CUT_T - dragLength) > (this.cropperH - this.cutB)) dragLength = CUT_T - (this.cropperH - this
|
|
|
|
|
|
|
|
.cutB)
|
|
|
|
this.setData({
|
|
|
|
this.setData({
|
|
|
|
cutT: CUT_T - dragLength
|
|
|
|
cutT: CUT_T - dragLength
|
|
|
|
})
|
|
|
|
})
|
|
|
@ -382,6 +410,7 @@
|
|
|
|
image-orientation: 0deg !important;
|
|
|
|
image-orientation: 0deg !important;
|
|
|
|
margin: 0 auto;
|
|
|
|
margin: 0 auto;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 移动图片效果 */
|
|
|
|
/* 移动图片效果 */
|
|
|
|
|
|
|
|
|
|
|
|
.uni-cropper-drag-box {
|
|
|
|
.uni-cropper-drag-box {
|
|
|
@ -394,6 +423,7 @@
|
|
|
|
background: rgba(0, 0, 0, 0.6);
|
|
|
|
background: rgba(0, 0, 0, 0.6);
|
|
|
|
z-index: 1;
|
|
|
|
z-index: 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 内部的信息 */
|
|
|
|
/* 内部的信息 */
|
|
|
|
|
|
|
|
|
|
|
|
.uni-corpper-crop-box {
|
|
|
|
.uni-corpper-crop-box {
|
|
|
@ -411,6 +441,7 @@
|
|
|
|
outline: 1rpx solid #69f;
|
|
|
|
outline: 1rpx solid #69f;
|
|
|
|
outline-color: rgba(102, 153, 255, .75)
|
|
|
|
outline-color: rgba(102, 153, 255, .75)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 横向虚线 */
|
|
|
|
/* 横向虚线 */
|
|
|
|
|
|
|
|
|
|
|
|
.uni-cropper-dashed-h {
|
|
|
|
.uni-cropper-dashed-h {
|
|
|
@ -422,6 +453,7 @@
|
|
|
|
border-top: 1rpx dashed rgba(255, 255, 255, 0.5);
|
|
|
|
border-top: 1rpx dashed rgba(255, 255, 255, 0.5);
|
|
|
|
border-bottom: 1rpx dashed rgba(255, 255, 255, 0.5);
|
|
|
|
border-bottom: 1rpx dashed rgba(255, 255, 255, 0.5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 纵向虚线 */
|
|
|
|
/* 纵向虚线 */
|
|
|
|
|
|
|
|
|
|
|
|
.uni-cropper-dashed-v {
|
|
|
|
.uni-cropper-dashed-v {
|
|
|
@ -433,6 +465,7 @@
|
|
|
|
border-left: 1rpx dashed rgba(255, 255, 255, 0.5);
|
|
|
|
border-left: 1rpx dashed rgba(255, 255, 255, 0.5);
|
|
|
|
border-right: 1rpx dashed rgba(255, 255, 255, 0.5);
|
|
|
|
border-right: 1rpx dashed rgba(255, 255, 255, 0.5);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 四个方向的线 为了之后的拖动事件*/
|
|
|
|
/* 四个方向的线 为了之后的拖动事件*/
|
|
|
|
|
|
|
|
|
|
|
|
.uni-cropper-line-t {
|
|
|
|
.uni-cropper-line-t {
|
|
|
@ -615,6 +648,7 @@
|
|
|
|
margin-top: -3rpx;
|
|
|
|
margin-top: -3rpx;
|
|
|
|
cursor: n-resize;
|
|
|
|
cursor: n-resize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* 裁剪框预览内容 */
|
|
|
|
/* 裁剪框预览内容 */
|
|
|
|
|
|
|
|
|
|
|
|
.uni-cropper-viewer {
|
|
|
|
.uni-cropper-viewer {
|
|
|
|