|
|
@@ -1,15 +1,16 @@
|
|
|
<template>
|
|
|
- <view class="content" v-if="isShow" >
|
|
|
+ <view class="content" v-if="isShow">
|
|
|
<view style="position: relative;">
|
|
|
- <image :src="img" style="height: 950rpx;width: 550rpx;" @load="load"></image>
|
|
|
- <image @click.stop="isShow=false" style="position: absolute;right: -50rpx;top: -60rpx;width: 50rpx;height: 50rpx;" src="@/static/icon/close.png" mode=""></image>
|
|
|
+ <image :src="img" style="height: 950rpx;width: 550rpx;" @load="load"></image>
|
|
|
+ <image @click.stop="isShow=false"
|
|
|
+ style="position: absolute;right: -50rpx;top: -60rpx;width: 50rpx;height: 50rpx;"
|
|
|
+ src="@/static/icon/close.png" mode=""></image>
|
|
|
</view>
|
|
|
|
|
|
<view class="btn" v-if="imgLoad">
|
|
|
<view class="save-btn" @click.stop="saveImage">保存图片</view>
|
|
|
<!-- <view class="save-btn" @click.stop="goLottery" v-if="subTitle"> 去抽奖 </view> -->
|
|
|
</view>
|
|
|
-
|
|
|
<canvas style="position: fixed;top: 999999999rpx;" @click.stop=""
|
|
|
:style="{ width: canvasW + 'px', height: canvasH + 'px' }" canvas-id="my-canvas"></canvas>
|
|
|
</view>
|
|
|
@@ -18,9 +19,9 @@
|
|
|
<script>
|
|
|
export default {
|
|
|
props: {
|
|
|
- headerImg: {
|
|
|
- type: String,
|
|
|
- default: 'https://vote.guosen-fumao.cn/obsfile/fa4631ad16f64357a4ec84c81064102d-%E5%88%86%E4%BA%AB%E6%B5%B7%E6%8A%A5.jpg'
|
|
|
+ activeId:{
|
|
|
+ type:String,
|
|
|
+ default:''
|
|
|
},
|
|
|
avatar: {
|
|
|
type: String,
|
|
|
@@ -41,6 +42,18 @@
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
+ posterParams:{
|
|
|
+ //背景图
|
|
|
+ bgImg:"https://vote-obs.guosen-fumao.cn/ce6e19c78f1b4220b4716ea11af960f5-z70fIvNXVEQ11b0ee4e6d35913e6f22391705967fe3f.jpg",
|
|
|
+ //头像大小
|
|
|
+ avatarSize:160,
|
|
|
+ //头像的Y坐标
|
|
|
+ avatarY:500,
|
|
|
+ //标题的y坐标
|
|
|
+ titleY:80,
|
|
|
+ //副标题的y坐标
|
|
|
+ subTitleY:130
|
|
|
+ },
|
|
|
imgLoad: false,
|
|
|
img: '',
|
|
|
canvasW: 0,
|
|
|
@@ -50,18 +63,39 @@
|
|
|
qrcode: '',
|
|
|
}
|
|
|
},
|
|
|
+ created() {
|
|
|
+ this.initParams()
|
|
|
+ },
|
|
|
methods: {
|
|
|
- saveImage(){
|
|
|
-
|
|
|
+ initParams(){
|
|
|
+ let params={
|
|
|
+ activeId:this.activeId
|
|
|
+ }
|
|
|
+ this.$api.poster.detail(params).then(res=>{
|
|
|
+ if (this.$isNotEmpty(res.data.data)) {
|
|
|
+ this.posterParams=res.data.data
|
|
|
+ }
|
|
|
+ })
|
|
|
},
|
|
|
- goLottery(){
|
|
|
+ goLottery() {
|
|
|
uni.navigateTo({
|
|
|
- url:"/pages/webview/webview?url= "+encodeURIComponent('https://api.jijipai.cn/h5/#/pages/activity/lottery?drawId=12')
|
|
|
+ url: "/pages/webview/webview?url= " + encodeURIComponent(
|
|
|
+ 'https://api.jijipai.cn/h5/#/pages/activity/lottery?drawId=12')
|
|
|
})
|
|
|
},
|
|
|
load() {
|
|
|
this.imgLoad = true
|
|
|
},
|
|
|
+ chkstrlen(str) {
|
|
|
+ var strlen = 0;
|
|
|
+ for (var i = 0; i < str.length; i++) {
|
|
|
+ if (str.charCodeAt(i) > 255) //如果是汉字,则字符串长度加2
|
|
|
+ strlen += 2;
|
|
|
+ else
|
|
|
+ strlen++;
|
|
|
+ }
|
|
|
+ return strlen;
|
|
|
+ },
|
|
|
//显示
|
|
|
showCanvas() {
|
|
|
this.isShow = true
|
|
|
@@ -83,37 +117,39 @@
|
|
|
//绘制圆角背景
|
|
|
this.drawRoundRect(this.ctx, 0, 0, this.canvasW, this.canvasH, 0, '#f82001')
|
|
|
//绘制标题图
|
|
|
- let headerImg = await this.getImageInfo(this.headerImg)
|
|
|
+ let bgImg = await this.getImageInfo(this.posterParams.bgImg)
|
|
|
let hW = uni.upx2px(750);
|
|
|
let hH = uni.upx2px(1333);
|
|
|
- this.drawRoundImg(this.ctx, headerImg.path, ((this.canvasW - hW) / 2), ((this.canvasW - hW) / 2), hW,
|
|
|
+ this.drawRoundImg(this.ctx, bgImg.path, ((this.canvasW - hW) / 2), ((this.canvasW - hW) / 2), hW,
|
|
|
hH, 0)
|
|
|
//绘制头像
|
|
|
- const userInfo = uni.getStorageSync("userInfo");
|
|
|
- let avatar = await this.getImageInfo( userInfo.avatar ||this.avatar)
|
|
|
- let avatarW = 290
|
|
|
- let aW = uni.upx2px(avatarW);
|
|
|
- this.drawRoundImg(this.ctx, avatar.path, (hW - aW) / 2, uni.upx2px(222), aW, aW, uni.upx2px(avatarW /
|
|
|
+ const userInfo = uni.getStorageSync("userInfo");
|
|
|
+ let avatar = await this.getImageInfo(userInfo.avatar || this.avatar)
|
|
|
+ let aW = uni.upx2px(this.posterParams.avatarSize);
|
|
|
+ this.drawRoundImg(this.ctx, avatar.path, (hW - aW) / 2, uni.upx2px(this.posterParams.avatarY), aW, aW, uni.upx2px(this.posterParams.avatarSize /
|
|
|
2))
|
|
|
//绘制标题
|
|
|
let titleSize = 20
|
|
|
+ let titleLen=this.chkstrlen(this.title) / 2
|
|
|
let titleParams = {
|
|
|
color: '#fff',
|
|
|
- x: (hW / 2) - (this.title.length * titleSize / 2) - 10,
|
|
|
- y: (hH / 2) + uni.upx2px(110)
|
|
|
+ x: (hW / 2) - ( titleLen * titleSize / 2),
|
|
|
+ y: (hH / 2) + uni.upx2px(this.posterParams.titleY)
|
|
|
}
|
|
|
this.ctx.font = "19px 华文楷体"
|
|
|
this.ctx.setFontSize(titleSize); //设置标题字体大小
|
|
|
this.ctx.setFillStyle('#fff'); //设置标题文本颜色
|
|
|
this.ctx.fillText(this.title, titleParams.x, titleParams.y)
|
|
|
//绘制副标题
|
|
|
+ let subTitleLen=this.chkstrlen(this.subTitle) / 2
|
|
|
let subTitleParams = {
|
|
|
color: '#fff',
|
|
|
- y: (hH / 2) + uni.upx2px(170)
|
|
|
+ x:(hW / 2) - ( subTitleLen * titleSize / 2),
|
|
|
+ y: (hH / 2) + uni.upx2px(this.posterParams.subTitleY)
|
|
|
}
|
|
|
this.ctx.setFontSize(titleSize); //设置标题字体大小
|
|
|
this.ctx.setFillStyle('#fff'); //设置标题文本颜色
|
|
|
- this.ctx.fillText(this.subTitle, titleParams.x, subTitleParams.y)
|
|
|
+ this.ctx.fillText(this.subTitle, subTitleParams.x, subTitleParams.y)
|
|
|
//小程序码
|
|
|
// let qrSize = uni.upx2px(200)
|
|
|
// let qrcodeImg = await this.getImageInfo(this.qrcode)
|