当检测图片不违规后。拿到上传图片的临时路径,就可以携带临时路径跳到剪裁页
uni.$off('src')
uni.navigateTo({
url: "/pages/路径?path=" + url[0]
})
<template>
<view class="content">
<image @load="loadImage" class="bg" src="" mode="widthFix"</image>
//裁剪的部分的四个剪头 一个方向的就行
<view class="corner" :style="{top:cropperOpt.cut.y+'px',width:cropperOpt.cut.width+'px',height:cropperOpt.cut.height+'px'}">
<image class="corner_border1" src=""></image>
<image class="corner_border2" src=""></image>
<image class="corner_border3" src=""></image>
<image class="corner_border4" src=""></image>
</view>
//裁剪
<view class="Tailoring">
<view class="cropper-wrapper1">
<canvas class="cropper" :style="{width:cropperOpt.width+'px',height:cropperOpt.height+'px'}"
disable-scroll="true" @touchstart="touchStart" @touchmove="touchMove" @touchend="touchEnd"
canvas-id="cropper"></canvas>
</view>
</view>
// 裁剪按钮
<image @click="getCropperImage" class="btn"
src="" mode="widthFix"></image>
</view>
</template>
<script>
import WeCropper from '@/common/weCropper.js'
const device = tt.getSystemInfoSync()
const width = device.windowWidth
const height = device.windowHeight;
const app = getApp();
export default {
data() {
return {
cropperOpt: {
id: 'cropper',
targetId: 'targetCropper',
pixelRatio: device.pixelRatio,
width,
height,
scale: 2.5,
zoom: 8,
cut: {
x: (width - uni.upx2px(495)) / 2,
y: (height - uni.upx2px(530)) / 2+40,
width: uni.upx2px(495),
height: uni.upx2px(530)
}
},
cropper: ''
}
},
onLoad(options) {
this.path = options.path;
this.cropperOpt.src = this.path;
this.cropper = new WeCropper(this.cropperOpt)
.on('ready', (ctx) => {
console.log(`wecropper is ready for work!`)
})
.on('beforeImageLoad', (ctx) => {
uni.showToast({
title: '上传中',
icon: 'loading',
duration: 20000
})
})
.on('imageLoad', (ctx) => {
uni.hideToast()
})
},
methods: {
touchStart(e) {
this.cropper.touchStart(e)
},
touchMove(e) {
this.cropper.touchMove(e)
},
touchEnd(e) {
this.cropper.touchEnd(e)
},
getCropperImage() {
var that = this
that.cropper.getCropperImage((tempFilePath) => {
if (tempFilePath) {
let arr = tempFilePath.split("?")
tempFilePath = arr[0]
uni.getFileSystemManager().readFile({
filePath: tempFilePath,
encoding: 'base64',
success: function(base64_str) {
let data = {
base64:`${base64_str.data}`,
src:tempFilePath
}
uni.redirectTo({
url: `/pages/路径`
})
},
fail(e) {
console.log('失败了1', e)
}
})
} else {
console.log('获取图片地址失败,请稍后重试')
}
})
}
}
}
</script>
<style scoped lang="scss">
.content {
width: 100%;
min-height: 100vh;
position: relative;
overflow: hidden;
background-color: #0A0432;
}
.bg {
display: block;
position: fixed;
top: 0;
left: 0;
width: 750rpx;
height: 1624rpx;
}
.cropper-wrapper1 {
width: 100%;
height: 100%;
position: relative;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
background: url('') no-repeat;
background-size: 100% 100%;
}
.cropper {
position: absolute;
top: 0;
left: 0;
width: 100%;
min-height: 100%;
}
.bg-dera{
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 120rpx;
background: rgba($color: #000000, $alpha: 0.3);
z-index: 88;
}
.corner{
position: absolute;
z-index: 6;
// top: 214px;
left: 50%;
transform: translate(-50%,0);
// border: 1px solid red;
pointer-events:none;
}
.corner_border1{
position: absolute;
width: 73rpx;
height: 74rpx;
top: -5rpx;
left: -5rpx;
}
.corner_border2{
position: absolute;
width: 73rpx;
height: 74rpx;
top: -5rpx;
right: -5rpx;
transform:rotate(90deg);
}
.corner_border3{
position: absolute;
width: 73rpx;
height: 74rpx;
bottom: -5rpx;
left: -5rpx;
transform:rotate(270deg);
}
.corner_border4{
position: absolute;
width: 73rpx;
height: 74rpx;
bottom: -5rpx;
right: -5rpx;
transform:rotate(180deg);
}
.btn {
width: 452rpx;
height: 130rpx;
position: absolute;
top: 1202rpx;
left: 50%;
transform: translateX(-50%);
z-index: 999;
}
.eg-img {
width: 738rpx;
height: 389rpx;
z-index: 999;
position: absolute;
top: 0;
left: 50%;
transform: translateX(-50%);
}
.loading{
position: fixed;
top: 0rpx;
left: 0;
float: left;
width: 100vw;
height: 100vh;
background-color: #FFFFFF;
z-index: 99999;
display: flex;
justify-content: center;
align-items: center;
}
</style>