|
@@ -42,75 +42,131 @@ Component({
|
|
|
return false
|
|
|
},
|
|
|
poster: function () {
|
|
|
- const that = this;
|
|
|
const ctx = wx.createCanvasContext('myCanvas');
|
|
|
- // 先画背景
|
|
|
- this.drawBg(ctx)
|
|
|
- .then(() => {
|
|
|
- // 下载保存图片
|
|
|
- console.log('背景画完');
|
|
|
- return this.saveImg(ctx);
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- // 画头像和作者||发起者
|
|
|
- console.log('头像画完');
|
|
|
- return this.drawAuthor(ctx);
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- console.log(this.data.shareType)
|
|
|
- if (this.data.shareType === 'works') {
|
|
|
- // 分享作品的主题内容
|
|
|
- console.log('主题画完');
|
|
|
- return this.drawWorksGut(ctx)
|
|
|
- } else {
|
|
|
- return this.drawGroupGut(ctx)
|
|
|
+ const that = this;
|
|
|
+ wx.showLoading({
|
|
|
+ title: '海报生成中',
|
|
|
+ // mask: true
|
|
|
+ })
|
|
|
+ httpRequestApi.createQRCode(this.data.QRData).success(res => {
|
|
|
+ // 下载二维码
|
|
|
+ wx.downloadFile({
|
|
|
+ url: res.data.data,
|
|
|
+ success: res => {
|
|
|
+ this.setData({
|
|
|
+ QRCodeImagePath: res.tempFilePath
|
|
|
+ })
|
|
|
}
|
|
|
- })
|
|
|
- .then(() => {
|
|
|
- wx.getImageInfo({
|
|
|
- src: this.data.QRCodeImagePath, //服务器返回的图片地址
|
|
|
- success: function (res) {
|
|
|
- console.log('下载content成功1')
|
|
|
- console.log(res.path)
|
|
|
- //res.path是网络图片的本地地址
|
|
|
- ctx.drawImage(res.path, 35, 358, 90, 90);
|
|
|
- console.log('下载content成功2')
|
|
|
- ctx.draw(true, function (res) {
|
|
|
- setTimeout(() => {
|
|
|
- wx.canvasToTempFilePath({
|
|
|
- x: 0,
|
|
|
- y: 0,
|
|
|
- width: 300,
|
|
|
- height: 525,
|
|
|
- // destWidth: 370,
|
|
|
- destWidth: 1200,
|
|
|
- // destHeight: 507,
|
|
|
- destHeight: 2100,
|
|
|
- canvasId: 'myCanvas',
|
|
|
- success: (res) => {
|
|
|
- console.log(res.tempFilePath)
|
|
|
- that.setData({
|
|
|
- imgUrls: res.tempFilePath
|
|
|
- }, () => {
|
|
|
- wx.hideLoading();
|
|
|
- })
|
|
|
- },
|
|
|
- fail: (res) => {
|
|
|
- console.log(res)
|
|
|
- }
|
|
|
- })
|
|
|
- }, 200)
|
|
|
+ });
|
|
|
+ wx.downloadFile({
|
|
|
+ url: that.data.avatar,
|
|
|
+ success: res => {
|
|
|
+ this.setData({
|
|
|
+ avatar: res.tempFilePath
|
|
|
+ })
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 下载icon
|
|
|
+ if (this.data.shareType === 'works') {
|
|
|
+ wx.downloadFile({
|
|
|
+ url: that.data.iconImg,
|
|
|
+ success: res => {
|
|
|
+ this.setData({
|
|
|
+ iconImg: res.tempFilePath
|
|
|
})
|
|
|
- },
|
|
|
- fail: function (res) {
|
|
|
- //失败回调
|
|
|
- console.log(res)
|
|
|
}
|
|
|
});
|
|
|
+ }
|
|
|
+ this.makeImage(ctx);
|
|
|
+ })
|
|
|
+ },
|
|
|
+ makeImage: function (ctx) {
|
|
|
+ // 画出背景和相同内容
|
|
|
+ if (this.data.shareType === 'works') {
|
|
|
+ ctx.drawImage('../../../static/image/works_poster.jpg', 0, 0, 1200, 2100, 0, 0, 600, 1050); //插入图片
|
|
|
+ } else {
|
|
|
+ ctx.drawImage('../../../static/image/group_poster.jpg', 0, 0, 1200, 2100, 0, 0, 600, 1050); //插入图片
|
|
|
+ }
|
|
|
+ ctx.save()
|
|
|
+ ctx.beginPath()
|
|
|
+ ctx.fill()
|
|
|
+ ctx.setFontSize(25)
|
|
|
+ ctx.setFillStyle('#fff')
|
|
|
+ ctx.fillText('课文朗读 每天5分钟', (300 - ctx.measureText('课文朗读 每天5分钟').width) / 2, 54.5)
|
|
|
+ ctx.setFontSize(16)
|
|
|
+ ctx.fillText('大声朗读是语感形成的必走之路', (300 - ctx.measureText('大声朗读是语感形成的必走之路').width) / 2, 75.5)
|
|
|
+ ctx.setFontSize(15)
|
|
|
+ ctx.setFillStyle('#838383')
|
|
|
+ ctx.fillText('长按识别二维码', 130.5, 391)
|
|
|
+ ctx.setFontSize(12)
|
|
|
+ ctx.setFillStyle('#838383')
|
|
|
+ ctx.fillText('接收邀请,获得你的课程吧', 130.5, 409.5) /* */
|
|
|
+ // 头像
|
|
|
+ console.log('画头像')
|
|
|
+ if (this.data.shareType === 'works') {
|
|
|
+ ctx.arc(150, 160, 36, 0, 2 * Math.PI, true)
|
|
|
+ ctx.clip(); //剪切头像区域
|
|
|
+ ctx.drawImage(this.data.avatar, 116, 126, 68, 68);
|
|
|
+ ctx.arc(150, 160, 34, 0, 2 * Math.PI, false)
|
|
|
+ ctx.setFillStyle('#ff6f42')
|
|
|
+ ctx.fill();
|
|
|
+ ctx.clip(); //剪切头像区域
|
|
|
+ ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 可以继续绘制
|
|
|
+ ctx.setFontSize(15)
|
|
|
+ ctx.setFillStyle('#ff6f42')
|
|
|
+ ctx.fillText(this.data.author, (300 - ctx.measureText(this.data.author).width) / 2, 220)
|
|
|
+ ctx.setFillStyle('#434343')
|
|
|
+ ctx.fillText('播音主持特长生', (300 - ctx.measureText('播音主持特长生').width) / 2, 243)
|
|
|
+ ctx.setFontSize(15)
|
|
|
+ ctx.setFillStyle('#434343')
|
|
|
+ ctx.fillText('使出洪荒之力,声情并茂地朗诵了', (300 - ctx.measureText('使出洪荒之力,声情并茂地朗诵了').width) / 2, 262)
|
|
|
+ ctx.fillText(`《${this.data.title}》`, (300 - ctx.measureText(`《${this.data.title}》`).width) / 2, 284)
|
|
|
+ } else {
|
|
|
+ ctx.arc(64, 146, 29, 0, 2 * Math.PI, true)
|
|
|
+ ctx.clip(); //剪切头像区域
|
|
|
+ ctx.drawImage(this.data.avatar, 37, 119, 54, 54);
|
|
|
+ ctx.arc(64, 146, 27, 0, 2 * Math.PI, false)
|
|
|
+ ctx.setFillStyle('#ff6f42')
|
|
|
+ ctx.fill();
|
|
|
+ ctx.clip(); //剪切头像区域
|
|
|
+ //插入图片
|
|
|
+ ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 可以继续绘制
|
|
|
+ ctx.setFontSize(18)
|
|
|
+ ctx.setFillStyle('#ff6f42')
|
|
|
+ ctx.fillText(this.data.author, 100, 143.5)
|
|
|
+ ctx.setFontSize(16)
|
|
|
+ ctx.setFillStyle('#434343')
|
|
|
+ ctx.fillText('邀您和我一起大声朗读', 100, 167.5)
|
|
|
+ ctx.drawImage(this.data.iconImg, 27, 194, 247, 103.5);
|
|
|
+ ctx.setFontSize(15)
|
|
|
+ ctx.setFillStyle('#434343')
|
|
|
+ ctx.fillText('朗朗读书声,是世界上最美妙的声音', (300 - ctx.measureText('朗朗读书声,是世界上最美妙的声音').width) / 2, 327.5)
|
|
|
+ }
|
|
|
+ console.log('花二维码')
|
|
|
+ console.log(this.data.QRCodeImagePath)
|
|
|
+ ctx.drawImage(this.data.QRCodeImagePath, 35, 353, 90, 90);
|
|
|
+ ctx.draw();
|
|
|
+ setTimeout(() => {
|
|
|
+ wx.canvasToTempFilePath({
|
|
|
+ x: 0,
|
|
|
+ y: 0,
|
|
|
+ width: 300,
|
|
|
+ height: 525,
|
|
|
+ destWidth: 1200,
|
|
|
+ destHeight: 2100,
|
|
|
+ canvasId: 'myCanvas',
|
|
|
+ success: (res) => {
|
|
|
+ this.setData({
|
|
|
+ imgUrls: res.tempFilePath
|
|
|
+ })
|
|
|
+ wx.hideLoading()
|
|
|
+ },
|
|
|
+ fail: (res) => {
|
|
|
+ console.log(res)
|
|
|
+ wx.hideLoading();
|
|
|
+ }
|
|
|
})
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ }, 200)
|
|
|
|
|
|
},
|
|
|
share: function (data) {
|
|
@@ -150,8 +206,8 @@ Component({
|
|
|
groupPurchaseInfo: data.groupPurchaseInfo,
|
|
|
groupType: data.groupType
|
|
|
})
|
|
|
- this.poster();
|
|
|
}
|
|
|
+ this.poster();
|
|
|
|
|
|
if (this.data.shareType === 'class') {
|
|
|
console.log('课程分享')
|
|
@@ -188,205 +244,10 @@ Component({
|
|
|
this.triggerEvent('ShareDialogClose', {})
|
|
|
}, 200)
|
|
|
})
|
|
|
-
|
|
|
-
|
|
|
},
|
|
|
nothing: function (e) {
|
|
|
return
|
|
|
},
|
|
|
- // 保存图片到本地
|
|
|
- saveImg: function () {
|
|
|
- console.log('yibuububu')
|
|
|
- let download = new Promise((resolve, reject) => {
|
|
|
- let QRCode = () => {
|
|
|
- // 生成二维码并下载
|
|
|
- httpRequestApi.createQRCode(this.data.QRData).success(res => {
|
|
|
- console.log(this.data.QRData);
|
|
|
- this.setData({
|
|
|
- QRCodeImagePath: res.data.data
|
|
|
- })
|
|
|
- // wx.downloadFile({
|
|
|
- // url: res,
|
|
|
- // success: (res) => {
|
|
|
- // console.log(res)
|
|
|
- // console.log('下载二维码成功')
|
|
|
- // // this.setData({
|
|
|
- // // avatar: res.tempFilePath
|
|
|
- // // }, () => {
|
|
|
-
|
|
|
- // // })
|
|
|
-
|
|
|
- // }
|
|
|
- // });
|
|
|
- resolve();
|
|
|
- })
|
|
|
- }
|
|
|
- let downAvatar = () => {
|
|
|
- wx.downloadFile({
|
|
|
- url: this.data.avatar,
|
|
|
- success: (res) => {
|
|
|
- console.log('下载头像成功')
|
|
|
- console.log(this.data.avatar)
|
|
|
- this.setData({
|
|
|
- avatar: res.tempFilePath
|
|
|
- }, () => {
|
|
|
- QRCode();
|
|
|
- })
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- // resolve(()=>{
|
|
|
- // 下载icon
|
|
|
- wx.downloadFile({
|
|
|
- url: this.data.iconImg,
|
|
|
- success: (res) => {
|
|
|
- console.log('下载icon成功')
|
|
|
- console.log(this.data.iconImg)
|
|
|
- this.setData({
|
|
|
- iconImg: res.tempFilePath
|
|
|
- }, () => {
|
|
|
- // 下载头像
|
|
|
- downAvatar();
|
|
|
- })
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- })
|
|
|
- return download;
|
|
|
- },
|
|
|
- // 先画出背景
|
|
|
- drawBg: function (ctx) {
|
|
|
- let background = new Promise((resolve, reject) => {
|
|
|
- wx.showLoading({
|
|
|
- title: '海报生成中',
|
|
|
- // mask: true
|
|
|
- })
|
|
|
- if (this.data.shareType === 'works') {
|
|
|
- ctx.drawImage('../../../static/image/works_poster.jpg', 0, 0, 1200, 2100, 0, 0, 600, 1050); //插入图片
|
|
|
- } else {
|
|
|
- ctx.drawImage('../../../static/image/group_poster.jpg', 0, 0, 1200, 2100, 0, 0, 600, 1050); //插入图片
|
|
|
- }
|
|
|
- ctx.save()
|
|
|
- ctx.beginPath()
|
|
|
- ctx.fill()
|
|
|
- resolve();
|
|
|
- });
|
|
|
- return background;
|
|
|
- },
|
|
|
- // 画头像和作者||发起者
|
|
|
- drawAuthor: function (ctx) {
|
|
|
- let author = new Promise((resolve, reject) => {
|
|
|
- if (this.data.shareType === 'works') {
|
|
|
- ctx.arc(187.5, 171, 36, 0, 2 * Math.PI, false)
|
|
|
- ctx.clip(); //剪切头像区域
|
|
|
- ctx.fill('red')
|
|
|
- ctx.drawImage(this.data.avatar, 152, 135, 72, 72); //插入图片
|
|
|
- ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 可以继续绘制
|
|
|
- ctx.setFontSize(18)
|
|
|
- ctx.setFillStyle('#444444')
|
|
|
- ctx.fillText(this.data.author, (300 - ctx.measureText(this.data.author).width) / 2, 232)
|
|
|
- ctx.setFontSize(16)
|
|
|
- ctx.setFillStyle('#ff9209')
|
|
|
- ctx.fillText('播音主持特长生', (300 - ctx.measureText('播音主持特长生').width) / 2, 253)
|
|
|
- } else {
|
|
|
- ctx.arc(64, 146, 29, 0, 2 * Math.PI, true)
|
|
|
- ctx.clip(); //剪切头像区域
|
|
|
- ctx.drawImage(this.data.avatar, 37, 119, 54, 54);
|
|
|
- ctx.arc(64, 146, 27, 0, 2 * Math.PI, false)
|
|
|
- ctx.setFillStyle('#ff6f42')
|
|
|
- ctx.fill();
|
|
|
- ctx.clip(); //剪切头像区域
|
|
|
- //插入图片
|
|
|
- ctx.restore(); //恢复之前保存的绘图上下文 恢复之前保存的绘图上下午即状态 可以继续绘制
|
|
|
- ctx.setFontSize(18)
|
|
|
- ctx.setFillStyle('#ff6f42')
|
|
|
- ctx.fillText(this.data.author, 100, 143.5)
|
|
|
- ctx.setFontSize(16)
|
|
|
- ctx.setFillStyle('#434343')
|
|
|
- ctx.fillText('邀您和我一起大声朗读', 100, 167.5)
|
|
|
- }
|
|
|
- resolve();
|
|
|
- })
|
|
|
- return author;
|
|
|
- },
|
|
|
- // 分享作品的主题内容
|
|
|
- drawWorksGut: function (ctx) {
|
|
|
- let works = new Promise((resolve, reject) => {
|
|
|
- // resolve(() => {
|
|
|
- console.log('开始画内容')
|
|
|
- ctx.setFillStyle('#fff')
|
|
|
- ctx.setFontSize(18)
|
|
|
- ctx.fillText('小学语文 最新全国统一教材', (300 - ctx.measureText('小学语文 最新全国统一教材').width) / 2, 55);
|
|
|
- ctx.setFontSize(30)
|
|
|
- ctx.fillText('课文朗读 从未如此有趣', (300 - ctx.measureText('课文朗读 从未如此有趣').width) / 2, 103);
|
|
|
- ctx.setFontSize(16)
|
|
|
- ctx.setFillStyle('#444')
|
|
|
- ctx.fillText('使出洪荒之力,声情并茂地朗诵了', (300 - ctx.measureText('使出洪荒之力,声情并茂地朗诵了').width) / 2, 297)
|
|
|
- // ctx.fillText(`配了一段惊世之作`, 90, 240)
|
|
|
- // ctx.setFontSize(16)
|
|
|
- // ctx.setFillStyle('red')
|
|
|
- ctx.fillText(`《${this.data.title}》`, (300 - ctx.measureText(`《${this.data.title}》`).width) / 2, 322)
|
|
|
-
|
|
|
- ctx.setFontSize(16)
|
|
|
- ctx.setFillStyle('#000')
|
|
|
- // ctx.setFillStyle('#000')
|
|
|
- ctx.setFontSize(16)
|
|
|
- // ctx.setFillStyle('#c90000')
|
|
|
- ctx.setFillStyle('#ff9209')
|
|
|
- ctx.fillText('为TA疯狂打CALL 快去听听', (300 - ctx.measureText('为TA疯狂打CALL 快去听听').width) / 2, 401)
|
|
|
- ctx.setFontSize(12)
|
|
|
- ctx.setFillStyle('#666666')
|
|
|
- ctx.fillText('长按识别二维码', (300 - ctx.measureText('长按识别二维码').width) / 2, 574)
|
|
|
- // })
|
|
|
- resolve();
|
|
|
- })
|
|
|
- return works;
|
|
|
- },
|
|
|
-
|
|
|
- // 分享团购的主体内容
|
|
|
- drawGroupGut: function (ctx) {
|
|
|
- let group = new Promise((resolve, reject) => {
|
|
|
- ctx.setFontSize(25)
|
|
|
- ctx.setFillStyle('#fff')
|
|
|
- ctx.fillText('课文朗读 每天5分钟', (300 - ctx.measureText('课文朗读 每天5分钟').width) / 2, 54.5)
|
|
|
- ctx.setFontSize(16)
|
|
|
- ctx.fillText('大声朗读是语感形成的必走之路', (300 - ctx.measureText('大声朗读是语感形成的必走之路').width) / 2, 75.5)
|
|
|
- ctx.drawImage(this.data.iconImg, 27, 194, 247, 103.5);
|
|
|
-
|
|
|
- ctx.setFontSize(15)
|
|
|
- ctx.setFillStyle('#434343')
|
|
|
- ctx.fillText('朗朗读书声,是世界上最美妙的声音', (300 - ctx.measureText('朗朗读书声,是世界上最美妙的声音').width) / 2, 327.5)
|
|
|
- // if(this.data.groupType === 'IOS'){
|
|
|
- // ctx.setFillStyle('#ff670d')
|
|
|
- // ctx.fillText(`助力成功,您还可以获得本课程7天VIP`, (300 - ctx.measureText('助力成功,您还可以获得本课程7天VIP').width) / 2, 412)
|
|
|
-
|
|
|
-
|
|
|
- // } else {
|
|
|
- // ctx.setFillStyle('#A95A00')
|
|
|
- // ctx.fillText(`${this.data.groupPurchaseInfo.headcount}人团`, 96, 412)
|
|
|
- // ctx.setFontSize(19)
|
|
|
- // ctx.fillText('每人仅需', 151, 412)
|
|
|
- // // ctx.fillText('元', 120, 495)
|
|
|
- // ctx.setFontSize(28)
|
|
|
- // ctx.setStrokeStyle('red')
|
|
|
- // ctx.setFillStyle('red')
|
|
|
- // ctx.fillText(`${parseFloat(this.data.groupPurchaseInfo.price / 100).toFixed(2)}元`, 235, 415)
|
|
|
- // }
|
|
|
-
|
|
|
- ctx.setFontSize(15)
|
|
|
- ctx.setFillStyle('#838383')
|
|
|
- ctx.fillText('长按识别二维码', 130.5, 391)
|
|
|
- ctx.setFontSize(12)
|
|
|
- ctx.setFillStyle('#838383')
|
|
|
- ctx.fillText('接收邀请,获得你的课程吧', 130.5, 409.5)
|
|
|
- //})
|
|
|
- resolve();
|
|
|
- })
|
|
|
- return group;
|
|
|
- },
|
|
|
-
|
|
|
// 保存最终图片
|
|
|
PreservationImg: function () {
|
|
|
// this.getImgAuthorize()
|