Browse Source

添加图片裁剪

master
unknown 8 months ago
parent
commit
f48be77ee2
  1. 10
      pages.json
  2. 2
      pages/indexEntry/enroll/enroll.vue
  3. 74
      pages/mineEntry/personaInfo/personaInfo.vue
  4. 284
      pages/mineEntry/uAvatarCropper/uAvatarCropper.vue
  5. 1265
      pages/mineEntry/uAvatarCropper/weCropper.js
  6. 23
      pages/tabbar/learnCar/comp/topInfo.vue
  7. 2
      pages/tabbar/mine/index.vue
  8. BIN
      static/images/mineIcon/camera.png
  9. 2
      uni_modules/zeng-calen/components/zeng-calen/zeng-calen.vue

10
pages.json

@ -432,7 +432,6 @@
"path": "personaInfo/personaInfo",
"style": {
"navigationBarTitleText": "个人信息",
"navigationStyle": "custom",
"enablePullDownRefresh": false,
"backgroundTextStyle": "dark"
}
@ -447,6 +446,15 @@
}
},
{
"path": "uAvatarCropper/uAvatarCropper",
"style": {
"navigationBarTitleText": "图像裁剪",
"navigationStyle": "custom",
"enablePullDownRefresh": false,
"backgroundTextStyle": "dark"
}
},
{
"path": "myForecastName/myForecastName",
"style": {
"navigationBarTitleText": "我的报名",

2
pages/indexEntry/enroll/enroll.vue

@ -227,7 +227,7 @@
this.vuex_userInfo.idcard = this.form.idcard
this.vuex_userInfo.nationality = (this.form.value==7||this.form.value==2)?'外国':'中国'
this.vuex_userInfo.cardType = this.form.value
return this.$goPage('/pages/indexEntry/enroll/registInfo/registInfo?realNameNo=1')
return this.$goPage('/pages/indexEntry/enroll/uploadAvatar/uploadAvatar')
}
//

74
pages/mineEntry/personaInfo/personaInfo.vue

@ -1,7 +1,14 @@
<template>
<view class="pageBgImg">
<topNavbar title="人个中心"></topNavbar>
<view class="pageBg">
<view class="pad">
<view class="avatarBox" @click="uploadTap">
<view class="avatar">
<image :src="avatarLink" mode=""></image>
</view>
<view class="phoneIcon">
<image src="@/static/images/mineIcon/camera.png" mode=""></image>
</view>
</view>
<view class="card">
<view class="row">
<view class="lab">手机号</view>
@ -37,7 +44,6 @@
<u-icon name="arrow-right"></u-icon>
</view>
</view>
</view>
</view>
@ -48,25 +54,35 @@
</view>
</view>
<view class="card" v-if="cardType==1">
<view class="card" v-if="vuex_userInfo.cardType==1">
<view class="row">
<view class="lab">拍照&体检&面签</view>
<view class="val">已完成</view>
</view>
</view>
<view class="logout" @click="logOutFn">退出登录</view>
<view class="logout" @click="deleteTestClick" style="margin-top: 40rpx;">删除测试账号开发用的</view>
<!-- <view class="logout" @click="deleteTestClick" style="margin-top: 40rpx;">删除测试账号开发用的</view> -->
</view>
<view class="footerBtn">
<view class="btnBg" @click="logOutFn">退出登录</view>
</view>
</view>
</template>
<script>
import { logOut,deleteTest } from '@/config/api.js'
export default {
data() {
return {
avatarLink: ''
}
},
onLoad() {
uni.$on('uAvatarCropper', (res)=>{
this.avatarLink = res
})
},
methods: {
logOutFn() {
let _this = this
@ -91,7 +107,24 @@
const res = await deleteTest({phone: this.vuex_userInfo.phone})
this.$store.commit('goLogin')
console.log(res)
},
uploadTap() {
// let studentId = uni.getStorageSync('studentId')
// if(!studentId&&!this.havePay) return false
const _this = this;
uni.chooseImage({
count: 1, // 9
sizeType: ['original', 'compressed'], //
sourceType: ['album', 'camera'], //
success: (res) => {
let url = res.tempFilePaths[0];
// datasrc
uni.navigateTo({
url: '/pages/indexEntry/enroll/uploadAvatar/uAvatarCropper/uAvatarCropper?url=' + encodeURIComponent(url)
})
}
});
},
}
}
</script>
@ -101,7 +134,30 @@
padding: 6rpx;
margin-bottom: 20rpx;
}
.pad {
overflow: hidden;
}
.avatarBox {
width: 175rpx;
height: 175rpx;
margin: 50rpx auto 50rpx auto;
position: relative;
.avatar {
width: 100%;
height: 100%;
border-radius: 50%;
overflow: hidden;
background-color: #E8E9EC;
}
.phoneIcon {
width: 46rpx;
height: 46rpx;
position: absolute;
right: 0;
bottom: 0;
z-index: 9;
}
}
.row {
display: flex;
align-items: center;

284
pages/mineEntry/uAvatarCropper/uAvatarCropper.vue

@ -0,0 +1,284 @@
<template>
<view class="content">
<view class="cropper-wrapper" :style="{ height: cropperOpt.height + 'px' }">
<canvas
class="cropper"
:disable-scroll="true"
@touchstart="touchStart"
@touchmove="touchMove"
@touchend="touchEnd"
:style="{ width: cropperOpt.width, height: cropperOpt.height, backgroundColor: 'rgba(0, 0, 0, 0.8)' }"
canvas-id="cropper"
id="cropper"
></canvas>
<canvas
class="cropper"
:disable-scroll="true"
:style="{
position: 'fixed',
top: `-${cropperOpt.width * cropperOpt.pixelRatio}px`,
left: `-${cropperOpt.height * cropperOpt.pixelRatio}px`,
width: `${cropperOpt.width * cropperOpt.pixelRatio}px`,
height: `${cropperOpt.height * cropperOpt.pixelRatio}`
}"
canvas-id="targetId"
id="targetId"
></canvas>
</view>
<view class="cropper-buttons safe-area-padding" :style="{ height: bottomNavHeight + 'px' }">
<view class="upload" @click="uploadTap">取消</view>
<view class="getCropperImage" @click="getCropperImage(false)">完成</view>
</view>
</view>
</template>
<script>
import WeCropper from './weCropper.js';
export default {
props: {
// lineWidth-(rpx)color:
// mask-rgba"rgba(0, 0, 0, 0.35)"
boundStyle: {
type: Object,
default() {
return {
lineWidth: 4,
borderColor: 'rgb(245, 245, 245)',
mask: 'rgba(0, 0, 0, 0.35)'
};
}
},
avatarSrc: {
type: String,
default: ''
}
// // rpx
// rectWidth: {
// type: [String, Number],
// default: 400
// },
// // rpx
// rectHeight: {
// type: [String, Number],
// default: 400
// },
// // rpx
// destWidth: {
// type: [String, Number],
// default: 400
// },
// // rpx
// destHeight: {
// type: [String, Number],
// default: 400
// },
// // "png""jpg"
// fileType: {
// type: String,
// default: 'jpg',
// },
// //
// // H5使
// quality: {
// type: [Number, String],
// default: 1
// }
},
data() {
return {
//
bottomNavHeight: 50,
originWidth: 200,
width: 0,
height: 0,
cropperOpt: {
id: 'cropper',
targetId: 'targetCropper',
pixelRatio: 1,
width: 0,
height: 0,
scale: 2.5,
zoom: 8,
cut: {
x: (this.width - this.originWidth) / 2,
y: (this.height - this.originWidth) / 2,
width: this.originWidth,
height: this.originWidth
},
boundStyle: {
lineWidth: uni.upx2px(this.boundStyle.lineWidth),
mask: this.boundStyle.mask,
color: this.boundStyle.borderColor
}
},
//
// px
destWidth: 200,
// px
rectWidth: 350,
// 'png'"jpg"
fileType: 'png',
src: '', //
};
},
onLoad(options) {
let rectInfo = uni.getSystemInfoSync();
this.width = rectInfo.windowWidth;
this.height = rectInfo.windowHeight - this.bottomNavHeight;
this.cropperOpt.width = this.width;
this.cropperOpt.height = this.height;
this.cropperOpt.pixelRatio = rectInfo.pixelRatio;
if (this.destWidth) this.destWidth = this.destWidth;
if (this.rectWidth) {
let rectWidth = Number(this.rectWidth);
this.cropperOpt.cut = {
x: (this.width - rectWidth) / 2,
y: (this.height - rectWidth) / 2,
width: rectWidth,
height: rectWidth
};
}
this.rectWidth = this.rectWidth;
if (this.fileType) this.fileType = this.fileType;
//
this.cropper = new WeCropper(this.cropperOpt)
.on('ready', ctx => {
// wecropper is ready for work!
})
.on('beforeImageLoad', ctx => {
// before picture loaded, i can do something
})
.on('imageLoad', ctx => {
// picture loaded
})
.on('beforeDraw', (ctx, instance) => {
// before canvas draw,i can do something
});
// page.json
uni.setNavigationBarColor({
frontColor: '#ffffff',
backgroundColor: '#000000'
});
this.src = encodeURI(options.url)
// datasrc
this.cropper.pushOrign(this.src);
},
methods: {
touchStart(e) {
this.cropper.touchStart(e);
},
touchMove(e) {
this.cropper.touchMove(e);
},
touchEnd(e) {
this.cropper.touchEnd(e);
},
getCropperImage(isPre = false) {
if(!this.src) return this.$u.toast('请先选择图片再裁剪');
let cropper_opt = {
destHeight: Number(this.destWidth), // uni.canvasToTempFilePath
destWidth: Number(this.destWidth),
fileType: this.fileType
};
this.cropper.getCropperImage(cropper_opt, (path, err) => {
if (err) {
uni.showModal({
title: '温馨提示',
content: err.message
});
} else {
if (isPre) {
uni.previewImage({
current: '', // http
urls: [path] // http
});
} else {
uni.$emit('uAvatarCropper', path);
// console.log(path)
uni.navigateBack()
}
}
});
},
uploadTap() {
uni.navigateBack()
return
const self = this;
uni.chooseImage({
count: 1, // 9
sizeType: ['original', 'compressed'], //
sourceType: ['album', 'camera'], //
success: (res) => {
self.src = res.tempFilePaths[0];
// datasrc
self.cropper.pushOrign(this.src);
}
});
}
}
};
</script>
<style scoped lang="scss">
@import '@/uni_modules/uview-ui/libs/css/components.scss';
.content {
background: rgba(255, 255, 255, 1);
}
.cropper {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 11;
}
.cropper-buttons {
background-color: #000000;
color: #eee;
}
.cropper-wrapper {
position: relative;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
width: 100%;
background-color: #000;
}
.cropper-buttons {
width: 100vw;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
position: fixed;
bottom: 0;
left: 0;
font-size: 28rpx;
}
.cropper-buttons .upload,
.cropper-buttons .getCropperImage {
width: 50%;
text-align: center;
}
.cropper-buttons .upload {
text-align: left;
padding-left: 50rpx;
}
.cropper-buttons .getCropperImage {
text-align: right;
padding-right: 50rpx;
}
</style>

1265
pages/mineEntry/uAvatarCropper/weCropper.js
File diff suppressed because it is too large
View File

23
pages/tabbar/learnCar/comp/topInfo.vue

@ -4,10 +4,10 @@
<view class="avatar">
<image src="@/static/images/mineIcon/emtryIcon (1).png" mode=""></image>
</view>
<view class="rightTxt">
<view class="rightTxt" @click="showType=true">
<view class="name">JOE宝宝</view>
<view class="btn_row">
<view class="txt">科目四</view>
<view class="txt">{{ carType }}</view>
<u-icon name="arrow-down-fill" color="#fff" size="10"></u-icon>
</view>
</view>
@ -47,6 +47,7 @@
</view>
</view>
</view>
<u-picker :show="showType" :columns="typeArr" keyName="name" @confirm="confirmType" @cancel="showType=false"></u-picker>
</view>
</template>
@ -54,7 +55,23 @@
export default {
data() {
return {
showType: false,
typeArr: [
[
{name: '科目一', id: 1},
{name: '科目二', id: 2},
{name: '科目三', id: 3},
]
],
carType: '科目一'
}
},
methods: {
confirmType(val) {
console.log(val)
let item = val.value[0]
this.carType = item.name
this.showType = false
}
}
}

2
pages/tabbar/mine/index.vue

@ -66,7 +66,7 @@
{name: '退款申请', icon: require('@/static/images/mineIcon/minIcon (3).png'),url: '/pages/mineEntry/refund/refund'},
{name: '变更车型', icon: require('@/static/images/mineIcon/minIcon (7).png'),url: '/pages/mineEntry/modelChange/modelChange'},
{name: '同城转校', icon: require('@/static/images/mineIcon/minIcon (5).png'),url: '/pages/mineEntry/schoolTransfer/schoolTransfer'},
{name: '退款申请记录', icon: require('@/static/images/mineIcon/minIcon (6).png'),url: ''},
// {name: '退', icon: require('@/static/images/mineIcon/minIcon (6).png'),url: ''},
{name: '关于我们', icon: require('@/static/images/mineIcon/minIcon (2).png'),url: ''},
]
}

BIN
static/images/mineIcon/camera.png

After

Width: 46  |  Height: 46  |  Size: 1.3 KiB

2
uni_modules/zeng-calen/components/zeng-calen/zeng-calen.vue

@ -30,7 +30,7 @@
}">
{{Number(item.date)}}
</view>
<view class="dian" v-if="getChoose(`${item.year}-${item.month}-${item.date}`)" :class="{red: getChooseLack(`${item.year}-${item.month}-${item.date}`)}"></view>
<view class="dian" v-if="getChoose(`${item.year}-${item.month}-${item.date}`)&&item.isCurM" :class="{red: getChooseLack(`${item.year}-${item.month}-${item.date}`)}"></view>
</view>
</view>
</view>

Loading…
Cancel
Save