|
@@ -10,7 +10,8 @@ Page({
|
|
|
* 页面的初始数据
|
|
|
*/
|
|
|
data: {
|
|
|
- state: false,
|
|
|
+ // 'before录制前, process 录制中,after录制后'
|
|
|
+ state: 'before',
|
|
|
tens: 3,
|
|
|
bits: 0,
|
|
|
fromWidth: 100,
|
|
@@ -28,6 +29,8 @@ Page({
|
|
|
greeting: [],
|
|
|
// 是否更改过头像
|
|
|
changeAvatarFlag: false,
|
|
|
+ greetingCard: null,
|
|
|
+ userAudioState: false
|
|
|
},
|
|
|
async onLoad(options) {
|
|
|
let configure = await getActivityInfo(options.id)
|
|
@@ -59,12 +62,18 @@ Page({
|
|
|
})
|
|
|
},
|
|
|
play() {
|
|
|
- if (!this.data.state) {
|
|
|
+ if (this.data.state == 'before') {
|
|
|
this.innerAudioContext = wx.createInnerAudioContext();
|
|
|
this.innerAudioContext.src = this.data.configure.bgMusic; // 这里可以是录音的临时路径
|
|
|
this.innerAudioContext.play();
|
|
|
+ this.innerAudioContext.onEnded((res) => {
|
|
|
+ console.log('音频播放完毕');
|
|
|
+ this.setData({
|
|
|
+ userAudioState: false
|
|
|
+ })
|
|
|
+ });
|
|
|
this.setData({
|
|
|
- state: true
|
|
|
+ state: 'process'
|
|
|
})
|
|
|
let countDown = Number(this.data.configure.bgMusicLength)
|
|
|
// 倒计时
|
|
@@ -111,7 +120,7 @@ Page({
|
|
|
this.innerAudioContext.stop();
|
|
|
recorderManager.stop();
|
|
|
this.setData({
|
|
|
- state: false,
|
|
|
+ state: 'after',
|
|
|
tens: this.data.configure.bgMusicLength[0],
|
|
|
bits: this.data.configure.bgMusicLength[1]
|
|
|
})
|
|
@@ -130,7 +139,6 @@ Page({
|
|
|
success: (res) => {
|
|
|
const formateRes = JSON.parse(res.data);
|
|
|
let audioPath = formateRes.data;
|
|
|
- console.log(formateRes);
|
|
|
this.setData({
|
|
|
audioPath
|
|
|
})
|
|
@@ -146,7 +154,6 @@ Page({
|
|
|
// 上传贺卡
|
|
|
async uploadActivity() {
|
|
|
this.createActivityImg('upload').then(async res => {
|
|
|
- console.log(res);
|
|
|
let cardUrl = await this.uploadFile(res)
|
|
|
let data = {
|
|
|
audioPath: this.data.audioPath,
|
|
@@ -154,16 +161,33 @@ Page({
|
|
|
cardUrl,
|
|
|
templateId: this.data.id
|
|
|
}
|
|
|
- console.log(data,'data');
|
|
|
- let hk = await saveActivity(data)
|
|
|
- console.log(hk, '贺卡生成');
|
|
|
+ console.log(data, 'data');
|
|
|
+ let greetingCard = await saveActivity(data)
|
|
|
+ console.log('贺卡生成', greetingCard);
|
|
|
this.setData({
|
|
|
+ greetingCard,
|
|
|
uploadState: false
|
|
|
})
|
|
|
})
|
|
|
},
|
|
|
+ playUserAudio() {
|
|
|
+ if (!this.innerAudioContext) {
|
|
|
+ this.innerAudioContext = wx.createInnerAudioContext();
|
|
|
+ }
|
|
|
+ if (this.data.userAudioState) {
|
|
|
+ this.innerAudioContext.stop();
|
|
|
+ this.setData({
|
|
|
+ userAudioState: false
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ this.innerAudioContext.src = this.data.tempFilePath;
|
|
|
+ this.innerAudioContext.play();
|
|
|
+ this.setData({
|
|
|
+ userAudioState: true
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
bindKeyInput(e) {
|
|
|
- console.log(e);
|
|
|
if (e.currentTarget.dataset.type == 'from') {
|
|
|
this.setData({
|
|
|
fromWidth: e.detail.cursor * this.data.configure.fromFontSize,
|
|
@@ -175,14 +199,10 @@ Page({
|
|
|
'configure.toText': e.detail.value
|
|
|
})
|
|
|
}
|
|
|
- /* this.setData({
|
|
|
- inputValue: e.detail.value
|
|
|
- }) */
|
|
|
},
|
|
|
// 上传图片
|
|
|
uploadFile(filePath) {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
-
|
|
|
wx.uploadFile({
|
|
|
url: 'https://reader-api.ai160.com/file/upload',
|
|
|
filePath,
|
|
@@ -192,7 +212,6 @@ Page({
|
|
|
},
|
|
|
success: (res) => {
|
|
|
const result = JSON.parse(res.data).data;
|
|
|
- console.log(result, res, 'rrrr');
|
|
|
resolve(result)
|
|
|
}
|
|
|
})
|
|
@@ -201,6 +220,14 @@ Page({
|
|
|
// 生成活动图片
|
|
|
createActivityImg(createType = 'share') {
|
|
|
return new Promise((resolve, reject) => {
|
|
|
+ let cardUrl = !this.data.greetingCard ? '' : this.data.greetingCard.cardUrl
|
|
|
+ if (cardUrl) {
|
|
|
+ resolve({
|
|
|
+ title: '请欣赏我的课文朗读作品,点赞+评论。',
|
|
|
+ path: `/pages/index/index`,
|
|
|
+ imageUrl: cardUrl
|
|
|
+ })
|
|
|
+ }
|
|
|
let context = wx.createSelectorQuery();
|
|
|
context
|
|
|
.select('#share')
|
|
@@ -215,22 +242,11 @@ Page({
|
|
|
canvas.height = res[0].height * dpr;
|
|
|
ctx.scale(dpr, dpr);
|
|
|
let avatar = canvas.createImage();
|
|
|
- wx.getImageInfo({
|
|
|
- src: this.data.avatar,
|
|
|
- success: function (res) {
|
|
|
- console.log(res);
|
|
|
- avatar.src = res.path
|
|
|
- },
|
|
|
- });
|
|
|
+ avatar.src = this.data.avatar
|
|
|
avatar.onload = () => {
|
|
|
ctx.drawImage(avatar, this.data.configure.templateBase.photoLeft / 2, this.data.configure.templateBase.photoTop / 2, this.data.configure.templateBase.photoWidth / 2, this.data.configure.templateBase.photoHeight / 2);
|
|
|
let bgImg = canvas.createImage();
|
|
|
- wx.getImageInfo({
|
|
|
- src: this.data.configure.bgImg,
|
|
|
- success: function (res) {
|
|
|
- bgImg.src = res.path
|
|
|
- },
|
|
|
- });
|
|
|
+ bgImg.src = this.data.configure.bgImg
|
|
|
bgImg.onload = () => {
|
|
|
ctx.drawImage(bgImg, 0, 0, 375, 300);
|
|
|
ctx.font = `${this.data.configure.fromFontSize/2}px PingFang`;
|
|
@@ -238,29 +254,28 @@ Page({
|
|
|
ctx.fillText(this.data.configure.fromText, this.data.configure.templateBase.fromLeft / 2, this.data.configure.templateBase.fromTop / 2 + this.data.configure.toFontSize / 2)
|
|
|
console.log(this.data.configure.toText, this.data.configure.templateBase.toLeft / 2, this.data.configure.templateBase.toTop / 2);
|
|
|
console.log(this.data.configure.fromText, this.data.configure.templateBase.fromLeft / 2, this.data.configure.templateBase.fromTop / 2);
|
|
|
+ setTimeout(() => {
|
|
|
+ wx.canvasToTempFilePath({
|
|
|
+ canvas: canvas,
|
|
|
+ success(res) {
|
|
|
+ console.log('9');
|
|
|
+ if (createType == 'share') {
|
|
|
+ resolve({
|
|
|
+ title: '请欣赏我的课文朗读作品,点赞+评论。',
|
|
|
+ path: `/pages/index/index`,
|
|
|
+ imageUrl: res.tempFilePath
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ resolve(res.tempFilePath)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ fail(res) {
|
|
|
+ reject()
|
|
|
+ }
|
|
|
+ }, this)
|
|
|
+ }, 1000)
|
|
|
}
|
|
|
}
|
|
|
- setTimeout(() => {
|
|
|
- wx.canvasToTempFilePath({
|
|
|
- canvas: canvas,
|
|
|
- success(res) {
|
|
|
- console.log(res);
|
|
|
- if (createType == 'share') {
|
|
|
- resolve({
|
|
|
- title: '请欣赏我的课文朗读作品,点赞+评论。',
|
|
|
- path: `/pages/index/index`,
|
|
|
- imageUrl: res.tempFilePath
|
|
|
- })
|
|
|
- } else {
|
|
|
- resolve(res.tempFilePath)
|
|
|
- }
|
|
|
-
|
|
|
- },
|
|
|
- fail(res) {
|
|
|
- reject()
|
|
|
- }
|
|
|
- }, this)
|
|
|
- }, 1000)
|
|
|
})
|
|
|
})
|
|
|
},
|