|
|
@ -2,23 +2,17 @@ |
|
|
|
<view class="promotion"> |
|
|
|
|
|
|
|
<navbar title="二维码" |
|
|
|
bgColor="#E3441A" |
|
|
|
bgColor="rgb(235, 51, 0)" |
|
|
|
color="#fff" |
|
|
|
leftClick @leftClick="$utils.navigateBack" /> |
|
|
|
|
|
|
|
<view class="promotion-card"> |
|
|
|
|
|
|
|
<image :src="userInfo.headImage" mode="aspectFill" |
|
|
|
class="headImage"></image> |
|
|
|
|
|
|
|
<image style="width: 100%;" :src="imagePath" mode="widthFix"></image> |
|
|
|
|
|
|
|
<!-- <view class="invitation-code">加油站: {{ title }}</view> --> |
|
|
|
<canvas id="myCanvas" type="2d" canvas-id="firstCanvas1"></canvas> |
|
|
|
|
|
|
|
<view class="uni-color-btn" |
|
|
|
@click="preservationImg(imagePath)">保存二维码</view> |
|
|
|
</view> |
|
|
|
|
|
|
|
<image |
|
|
|
class="image" |
|
|
|
:src="imagePath" mode="aspectFill"></image> |
|
|
|
|
|
|
|
<canvas id="myCanvas" type="2d" canvas-id="firstCanvas1"></canvas> |
|
|
|
|
|
|
|
</view> |
|
|
|
</template> |
|
|
|
|
|
|
@ -27,7 +21,7 @@ |
|
|
|
export default { |
|
|
|
name: 'Promotion', |
|
|
|
computed: { |
|
|
|
...mapState(['userInfo']), |
|
|
|
...mapState(['userInfo', 'promotionUrl']), |
|
|
|
}, |
|
|
|
data() { |
|
|
|
return { |
|
|
@ -39,7 +33,11 @@ |
|
|
|
} |
|
|
|
}, |
|
|
|
onShow() { |
|
|
|
this.getQrCode() |
|
|
|
if(this.promotionUrl){ |
|
|
|
this.imagePath = this.promotionUrl |
|
|
|
}else{ |
|
|
|
this.getQrCode() |
|
|
|
} |
|
|
|
this.$store.commit('getUserInfo') |
|
|
|
}, |
|
|
|
methods: { |
|
|
@ -71,73 +69,73 @@ |
|
|
|
// Canvas 画布的实际绘制宽高 |
|
|
|
const width = res[0].width |
|
|
|
const height = res[0].height |
|
|
|
|
|
|
|
console.log(width, height); |
|
|
|
// 初始化画布大小 |
|
|
|
const dpr = wx.getWindowInfo().pixelRatio |
|
|
|
|
|
|
|
|
|
|
|
//根据dpr调整 |
|
|
|
// dpr 2 4 |
|
|
|
// 3 6 |
|
|
|
let Ratio = dpr * 2 |
|
|
|
console.log("bug", dpr) |
|
|
|
|
|
|
|
canvas.width = width * dpr |
|
|
|
canvas.height = height * dpr |
|
|
|
|
|
|
|
|
|
|
|
this.canvas = canvas |
|
|
|
ctx.scale(dpr, dpr) |
|
|
|
ctx.clearRect(0, 0, width, height) |
|
|
|
|
|
|
|
ctx.fillStyle = '#fff' |
|
|
|
ctx.fillRect(0, 0, canvas.width, canvas.height) |
|
|
|
|
|
|
|
//用户图片 |
|
|
|
// const image = canvas.createImage() |
|
|
|
// image.onload = () => { |
|
|
|
// ctx.drawImage(image, 30, 18, 40, 40) |
|
|
|
// } |
|
|
|
// image.src = '/public/img/wechar_1.png' |
|
|
|
// image.src = this.userInfo.headImage |
|
|
|
ctx.fillStyle = 'black' |
|
|
|
ctx.font = '22px PingFangSC-regular'; |
|
|
|
|
|
|
|
// 绘制用户姓名 |
|
|
|
// let nickName = this.userInfo.nickName || '绘制用户姓名' |
|
|
|
// ctx.fillText(nickName, canvas.width / Ratio - nickName.length * 11, 40); |
|
|
|
|
|
|
|
// ctx.font = '18px PingFangSC-regular'; |
|
|
|
// ctx.fillStyle = '#fff' |
|
|
|
// ctx.fillRect(0, 0, canvas.width, canvas.height) |
|
|
|
|
|
|
|
|
|
|
|
//图片 |
|
|
|
const bgImage = canvas.createImage() |
|
|
|
bgImage.src = this.configList.qr_code |
|
|
|
|
|
|
|
// 绘制欢迎语 |
|
|
|
let s = this.title || '' |
|
|
|
ctx.fillText(s, canvas.width / Ratio - s.length * 11, 50); |
|
|
|
|
|
|
|
//二维码图片 |
|
|
|
const coderImage = canvas.createImage() |
|
|
|
coderImage.src = this.baseUrl + this.url |
|
|
|
coderImage.onload = () => { |
|
|
|
ctx.drawImage(coderImage, |
|
|
|
canvas.width / Ratio - 240 / 2, 100, 240, 240) |
|
|
|
|
|
|
|
|
|
|
|
bgImage.onload = () => { |
|
|
|
canvas.width = bgImage.width |
|
|
|
canvas.height = bgImage.height |
|
|
|
ctx.drawImage(bgImage, |
|
|
|
0, 0, bgImage.width, bgImage.height) |
|
|
|
|
|
|
|
coderImage.onload = () => { |
|
|
|
ctx.drawImage(coderImage, |
|
|
|
canvas.width / 2 - 175, canvas.height / 2 - 100, 350, 350) |
|
|
|
this.canvasToTempFilePath() |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 绘制完成后存储路径 |
|
|
|
|
|
|
|
setTimeout(() => { |
|
|
|
wx.canvasToTempFilePath({ |
|
|
|
x: 0, |
|
|
|
y: 0, |
|
|
|
width: this.canvas.width, |
|
|
|
height: this.canvas.height, |
|
|
|
canvas, |
|
|
|
success: (res) => { |
|
|
|
var tempFilePath = res.tempFilePath; |
|
|
|
this.imagePath = tempFilePath |
|
|
|
uni.hideLoading() |
|
|
|
} |
|
|
|
}); |
|
|
|
}, 600); |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
}, |
|
|
|
canvasToTempFilePath(){ |
|
|
|
// 绘制完成后存储路径 |
|
|
|
setTimeout(() => { |
|
|
|
wx.canvasToTempFilePath({ |
|
|
|
x: 0, |
|
|
|
y: 0, |
|
|
|
width: this.canvas.width, |
|
|
|
height: this.canvas.height, |
|
|
|
canvas : this.canvas, |
|
|
|
success: (res) => { |
|
|
|
var tempFilePath = res.tempFilePath; |
|
|
|
this.imagePath = tempFilePath |
|
|
|
|
|
|
|
this.$store.commit('setPromotionUrl', res.tempFilePath) |
|
|
|
|
|
|
|
uni.hideLoading() |
|
|
|
this.load = false |
|
|
|
} |
|
|
|
}); |
|
|
|
}, 200); |
|
|
|
}, |
|
|
|
back() { |
|
|
|
uni.navigateBack(-1) |
|
|
|
}, |
|
|
@ -176,28 +174,10 @@ |
|
|
|
width: 100%; |
|
|
|
height: 100vh; |
|
|
|
background-color: $uni-color; |
|
|
|
.promotion-card { |
|
|
|
width: 90%; |
|
|
|
margin: 140rpx auto 0rpx auto; |
|
|
|
box-shadow: 0rpx 0rpx 15rpx rgba(0, 0, 0, .2); |
|
|
|
border-radius: 40rpx; |
|
|
|
padding: 40rpx 30rpx; |
|
|
|
box-sizing: border-box; |
|
|
|
background-color: #fff; |
|
|
|
position: relative; |
|
|
|
padding-top: 100rpx; |
|
|
|
.headImage{ |
|
|
|
position: absolute; |
|
|
|
height: 180rpx; |
|
|
|
width: 180rpx; |
|
|
|
border-radius: 50%; |
|
|
|
top: -80rpx; |
|
|
|
left: 50%; |
|
|
|
transform: translate(-50%); |
|
|
|
border: 10rpx solid #fff; |
|
|
|
box-shadow: 0 0 10rpx 10rpx #00000013; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
.image{ |
|
|
|
width: 100%; |
|
|
|
height: calc(100vh - 200rpx); |
|
|
|
} |
|
|
|
|
|
|
|
#myCanvas { |
|
|
@ -206,9 +186,8 @@ |
|
|
|
/* visibility: hidden */ |
|
|
|
/* visibility: hidden; */ |
|
|
|
/* margin-top: 100rpx; */ |
|
|
|
margin: 68rpx auto; |
|
|
|
width: 750rpx; |
|
|
|
height: 750rpx; |
|
|
|
height: calc(100vh - 120rpx); |
|
|
|
/* line-height: 20px; */ |
|
|
|
background-color: rgba(255, 255, 255, 1); |
|
|
|
text-align: center; |
|
|
|