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