|
@@ -1,18 +1,10 @@
|
|
|
<template>
|
|
|
- <view class="avatar-container">
|
|
|
- <u-navbar :titleStyle="{ color: '#fff' }" :autoBack="true" title="修改头像" :placeholder="true" :safeAreaInsetTop="true" :bgColor="proxy.$settingStore.themeColor.color">
|
|
|
- <template #left>
|
|
|
- <view class="u-nav-slot">
|
|
|
- <u-icon name="arrow-left" size="19" color="#fff"></u-icon>
|
|
|
- </view>
|
|
|
- </template>
|
|
|
- </u-navbar>
|
|
|
-
|
|
|
+ <view class="avatar-container" :data-theme="'theme-' + proxy.$settingStore.themeColor.name">
|
|
|
<view class="uni-content-header"></view>
|
|
|
<view class="page-body uni-content-info">
|
|
|
<view class="cropper-content">
|
|
|
- <view ref="uniCorpper" v-if="isShowImg" class="uni-corpper" :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'">
|
|
|
+ <view ref="uniCorpper" v-if="isShowImg" class="uni-corpper" :style="'display: flex;' + 'width:' + cropperInitW + 'px;height:' + cropperInitH + 'px;'">
|
|
|
+ <view class="uni-corpper-content" :style="'margin: auto;' + '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="uni-corpper-crop-box"
|
|
@@ -42,9 +34,13 @@
|
|
|
</view>
|
|
|
</view>
|
|
|
</view>
|
|
|
- <view class="padding-sm">
|
|
|
- <button type="default" class="margin-top-sm round text-dfl" @click="getImage" style="border: 1px rgb(0, 0, 0, 0.1) solid">选择头像</button>
|
|
|
- <button type="primary" class="margin-top-sm round text-dfl" @click="getImageInfo">提交</button>
|
|
|
+
|
|
|
+ <view class="app-position-fixed">
|
|
|
+ <view class="app-flex">
|
|
|
+ <u-button class="app-buttom" style="margin-right: 15px" @click="getImage" shape="circle"> 选择头像 </u-button>
|
|
|
+
|
|
|
+ <u-button class="app-buttom" type="primary" @click="getImageInfo" shape="circle"> 提交 </u-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>
|
|
|
</view>
|
|
@@ -66,6 +62,7 @@ const { proxy } = getCurrentInstance();
|
|
|
const baseUrl = config.baseUrl;
|
|
|
let sysInfo = uni.getSystemInfoSync();
|
|
|
let SCREEN_WIDTH = sysInfo.screenWidth;
|
|
|
+let SCREEN_HEIGHT = sysInfo.screenHeight - (proxy.$settingStore.StatusBar + 44);
|
|
|
let PAGE_X, // 手按下的x位置
|
|
|
PAGE_Y, // 手按下y的位置
|
|
|
PR = sysInfo.pixelRatio, // dpi
|
|
@@ -92,7 +89,7 @@ const array = reactive({
|
|
|
isShowImg: false,
|
|
|
// 初始化的宽高
|
|
|
cropperInitW: SCREEN_WIDTH,
|
|
|
- cropperInitH: SCREEN_WIDTH,
|
|
|
+ cropperInitH: SCREEN_HEIGHT,
|
|
|
// 动态的宽高
|
|
|
cropperW: SCREEN_WIDTH,
|
|
|
cropperH: SCREEN_WIDTH,
|
|
@@ -157,6 +154,7 @@ function setData(obj) {
|
|
|
*/
|
|
|
function getImage() {
|
|
|
uni.chooseImage({
|
|
|
+ sizeType: "original",
|
|
|
success: function (res) {
|
|
|
setData({
|
|
|
imageSrc: res.tempFilePaths[0],
|
|
@@ -171,13 +169,36 @@ function loadImage() {
|
|
|
src: imageSrc.value,
|
|
|
success: function success(res) {
|
|
|
IMG_RATIO = 1 / 1;
|
|
|
+
|
|
|
if (IMG_RATIO >= 1) {
|
|
|
IMG_REAL_W = SCREEN_WIDTH;
|
|
|
- IMG_REAL_H = SCREEN_WIDTH / IMG_RATIO;
|
|
|
+ IMG_REAL_H = res.height > SCREEN_HEIGHT ? SCREEN_HEIGHT : res.height;
|
|
|
} else {
|
|
|
IMG_REAL_W = SCREEN_WIDTH * IMG_RATIO;
|
|
|
- IMG_REAL_H = SCREEN_WIDTH;
|
|
|
+ IMG_REAL_H = res.height > SCREEN_HEIGHT ? SCREEN_HEIGHT : res.height;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (res.width == res.height) {
|
|
|
+ IMG_REAL_W = res.width > SCREEN_WIDTH ? SCREEN_WIDTH : res.width; //等比例获取宽度
|
|
|
+ IMG_REAL_H = res.width > SCREEN_WIDTH ? SCREEN_WIDTH : res.width;
|
|
|
}
|
|
|
+
|
|
|
+ if (res.width > res.height) {
|
|
|
+ IMG_REAL_W = SCREEN_WIDTH; //等比例获取宽度
|
|
|
+ IMG_REAL_H = (SCREEN_WIDTH / res.width) * res.height; //等比例获取高度
|
|
|
+ }
|
|
|
+
|
|
|
+ if (res.width < res.height) {
|
|
|
+ IMG_REAL_W = res.width / (res.height / SCREEN_HEIGHT);
|
|
|
+ IMG_REAL_H = SCREEN_HEIGHT;
|
|
|
+
|
|
|
+ if (IMG_REAL_W > SCREEN_WIDTH) {
|
|
|
+ IMG_REAL_W = SCREEN_WIDTH; //等比例获取宽度
|
|
|
+ IMG_REAL_H = (SCREEN_WIDTH / res.width) * res.height; //等比例获取高度
|
|
|
+ IMG_REAL_H = IMG_REAL_H > SCREEN_HEIGHT ? SCREEN_HEIGHT : IMG_REAL_H;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
let minRange = IMG_REAL_W > IMG_REAL_H ? IMG_REAL_W : IMG_REAL_H;
|
|
|
INIT_DRAG_POSITION = minRange > INIT_DRAG_POSITION ? INIT_DRAG_POSITION : minRange;
|
|
|
// 根据图片的宽高显示不同的效果 保证图片可以正常显示
|
|
@@ -187,8 +208,8 @@ function loadImage() {
|
|
|
let cutL = Math.ceil((SCREEN_WIDTH - SCREEN_WIDTH + INIT_DRAG_POSITION) / 2);
|
|
|
let cutR = cutL;
|
|
|
setData({
|
|
|
- cropperW: SCREEN_WIDTH,
|
|
|
- cropperH: SCREEN_WIDTH / IMG_RATIO,
|
|
|
+ cropperW: IMG_REAL_W,
|
|
|
+ cropperH: IMG_REAL_H,
|
|
|
// 初始化left right
|
|
|
cropperL: Math.ceil((SCREEN_WIDTH - SCREEN_WIDTH) / 2),
|
|
|
cropperT: Math.ceil((SCREEN_WIDTH - SCREEN_WIDTH / IMG_RATIO) / 2),
|
|
@@ -210,7 +231,7 @@ function loadImage() {
|
|
|
let cutB = cutT;
|
|
|
setData({
|
|
|
cropperW: SCREEN_WIDTH * IMG_RATIO,
|
|
|
- cropperH: SCREEN_WIDTH,
|
|
|
+ cropperH: IMG_REAL_H,
|
|
|
// 初始化left right
|
|
|
cropperL: Math.ceil((SCREEN_WIDTH - SCREEN_WIDTH * IMG_RATIO) / 2),
|
|
|
cropperT: Math.ceil((SCREEN_WIDTH - SCREEN_WIDTH) / 2),
|
|
@@ -305,9 +326,8 @@ function getImageInfo() {
|
|
|
let data = { name: "file", filePath: res.tempFilePath };
|
|
|
uploadAvatar(data).then((response) => {
|
|
|
useStore.$state.avatar = response.data.url;
|
|
|
- updateUserProfile({
|
|
|
- avatar: response.data.url,
|
|
|
- }).then(() => {});
|
|
|
+ useStore.$state.userArr.avatar = response.data.url;
|
|
|
+ updateUserProfile(useStore.$state.userArr).then(() => {});
|
|
|
uni.showToast({ title: "修改成功", icon: "success" });
|
|
|
uni.navigateBack();
|
|
|
});
|
|
@@ -364,20 +384,20 @@ function dragMove(e) {
|
|
|
cutB: CUT_B + dragLength,
|
|
|
});
|
|
|
break;
|
|
|
- case "rightBottom":
|
|
|
- var dragLengthX = (T_PAGE_X - e.touches[0].pageX) * DRAFG_MOVE_RATIO;
|
|
|
- var dragLengthY = (T_PAGE_Y - e.touches[0].pageY) * DRAFG_MOVE_RATIO;
|
|
|
-
|
|
|
- if (CUT_B + dragLengthY < 0) dragLengthY = -CUT_B;
|
|
|
- if (CUT_R + dragLengthX < 0) dragLengthX = -CUT_R;
|
|
|
- let cutB = CUT_B + dragLengthY;
|
|
|
- let cutR = CUT_R + dragLengthX;
|
|
|
-
|
|
|
- setData({
|
|
|
- cutB: cutB,
|
|
|
- cutR: cutR,
|
|
|
- });
|
|
|
- break;
|
|
|
+ // case "rightBottom":
|
|
|
+ // var dragLengthX = (T_PAGE_X - e.touches[0].pageX) * DRAFG_MOVE_RATIO;
|
|
|
+ // var dragLengthY = (T_PAGE_Y - e.touches[0].pageY) * DRAFG_MOVE_RATIO;
|
|
|
+
|
|
|
+ // if (CUT_B + dragLengthY < 0) dragLengthY = -CUT_B;
|
|
|
+ // if (CUT_R + dragLengthX < 0) dragLengthX = -CUT_R;
|
|
|
+ // let cutB = CUT_B + dragLengthY;
|
|
|
+ // let cutR = CUT_R + dragLengthX;
|
|
|
+
|
|
|
+ // setData({
|
|
|
+ // cutB: cutB,
|
|
|
+ // cutR: cutR,
|
|
|
+ // });
|
|
|
+ // break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
@@ -605,8 +625,16 @@ onShow(() => {
|
|
|
.point-t {
|
|
|
top: -3rpx;
|
|
|
left: 50%;
|
|
|
- margin-left: -3rpx;
|
|
|
+ // margin-left: -3rpx;
|
|
|
+ -webkit-transform: translate3d(-50%, -50%, 0);
|
|
|
+ transform: translate3d(-50%, -50%, 0);
|
|
|
cursor: n-resize;
|
|
|
+ width: 36rpx;
|
|
|
+ height: 36rpx;
|
|
|
+ background-color: #69f;
|
|
|
+ position: absolute;
|
|
|
+ z-index: 1112;
|
|
|
+ opacity: 1;
|
|
|
}
|
|
|
|
|
|
.point-tr {
|
|
@@ -619,14 +647,8 @@ onShow(() => {
|
|
|
.point-r {
|
|
|
top: 50%;
|
|
|
left: 100%;
|
|
|
- margin-left: -3rpx;
|
|
|
- margin-top: -3rpx;
|
|
|
- cursor: n-resize;
|
|
|
- }
|
|
|
-
|
|
|
- .point-rb {
|
|
|
- left: 100%;
|
|
|
- top: 100%;
|
|
|
+ // margin-left: -3rpx;
|
|
|
+ // margin-top: -3rpx;
|
|
|
-webkit-transform: translate3d(-50%, -50%, 0);
|
|
|
transform: translate3d(-50%, -50%, 0);
|
|
|
cursor: n-resize;
|
|
@@ -638,12 +660,36 @@ onShow(() => {
|
|
|
opacity: 1;
|
|
|
}
|
|
|
|
|
|
- .point-b {
|
|
|
- left: 50%;
|
|
|
+ .point-rb {
|
|
|
+ left: 100%;
|
|
|
top: 100%;
|
|
|
margin-left: -3rpx;
|
|
|
margin-top: -3rpx;
|
|
|
+ // -webkit-transform: translate3d(-50%, -50%, 0);
|
|
|
+ // transform: translate3d(-50%, -50%, 0);
|
|
|
+ cursor: n-resize;
|
|
|
+ // width: 36rpx;
|
|
|
+ // height: 36rpx;
|
|
|
+ // background-color: #69f;
|
|
|
+ // position: absolute;
|
|
|
+ // z-index: 1112;
|
|
|
+ // opacity: 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ .point-b {
|
|
|
+ left: 50%;
|
|
|
+ top: 100%;
|
|
|
+ // margin-left: -3rpx;
|
|
|
+ // margin-top: -3rpx;
|
|
|
+ -webkit-transform: translate3d(-50%, -50%, 0);
|
|
|
+ transform: translate3d(-50%, -50%, 0);
|
|
|
cursor: n-resize;
|
|
|
+ width: 36rpx;
|
|
|
+ height: 36rpx;
|
|
|
+ background-color: #69f;
|
|
|
+ position: absolute;
|
|
|
+ z-index: 1112;
|
|
|
+ opacity: 1;
|
|
|
}
|
|
|
|
|
|
.point-bl {
|
|
@@ -657,9 +703,17 @@ onShow(() => {
|
|
|
.point-l {
|
|
|
left: 0%;
|
|
|
top: 50%;
|
|
|
- margin-left: -3rpx;
|
|
|
- margin-top: -3rpx;
|
|
|
+ // margin-left: -3rpx;
|
|
|
+ // margin-top: -3rpx;
|
|
|
+ -webkit-transform: translate3d(-50%, -50%, 0);
|
|
|
+ transform: translate3d(-50%, -50%, 0);
|
|
|
cursor: n-resize;
|
|
|
+ width: 36rpx;
|
|
|
+ height: 36rpx;
|
|
|
+ background-color: #69f;
|
|
|
+ position: absolute;
|
|
|
+ z-index: 1112;
|
|
|
+ opacity: 1;
|
|
|
}
|
|
|
|
|
|
.point-lt {
|