|
@@ -1,240 +1,251 @@
|
|
|
import {
|
|
|
- getMyActivity,
|
|
|
- getOneActivity,
|
|
|
- thumbsUp,
|
|
|
- deleteActivity,
|
|
|
- getShareText,
|
|
|
- playAudioEvent
|
|
|
+ getMyActivity,
|
|
|
+ getOneActivity,
|
|
|
+ thumbsUp,
|
|
|
+ deleteActivity,
|
|
|
+ getShareText,
|
|
|
+ playAudioEvent
|
|
|
} from '~/api/activity'
|
|
|
import {
|
|
|
- actionRecord
|
|
|
+ actionRecord
|
|
|
} from '~/api/global'
|
|
|
Page({
|
|
|
- /**
|
|
|
- * 页面的初始数据
|
|
|
- */
|
|
|
- data: {
|
|
|
- isMy: false,
|
|
|
- pageNo: 1,
|
|
|
- totalSize: 0,
|
|
|
- list: [],
|
|
|
- // 当前用户id
|
|
|
- uid: '',
|
|
|
- // 贺卡作者id
|
|
|
- userId: '',
|
|
|
- playAudioId: null,
|
|
|
- // 当前音频播放时长
|
|
|
- playTime: '00:00',
|
|
|
- endTime: '00:00',
|
|
|
- vProgress: 0,
|
|
|
- userAudioState: false,
|
|
|
- },
|
|
|
+ /**
|
|
|
+ * 页面的初始数据
|
|
|
+ */
|
|
|
+ data: {
|
|
|
+ isMy: false,
|
|
|
+ pageNo: 1,
|
|
|
+ totalSize: 0,
|
|
|
+ list: [],
|
|
|
+ // 当前用户id
|
|
|
+ uid: '',
|
|
|
+ // 贺卡作者id
|
|
|
+ userId: '',
|
|
|
+ playAudioId: null,
|
|
|
+ // 当前音频播放时长
|
|
|
+ playTime: '00:00',
|
|
|
+ endTime: '00:00',
|
|
|
+ vProgress: 0,
|
|
|
+ userAudioState: false,
|
|
|
+ },
|
|
|
|
|
|
- /**
|
|
|
- * 生命周期函数--监听页面加载
|
|
|
- */
|
|
|
- async onLoad(options) {
|
|
|
- console.log(options);
|
|
|
- this.setData({
|
|
|
- uid: wx.getStorageSync('uid')
|
|
|
- })
|
|
|
- if (options.cardId) {
|
|
|
- let oneCard = await getOneActivity(options.cardId)
|
|
|
- this.setData({
|
|
|
- list: oneCard ? [oneCard] : [],
|
|
|
- userId: options.uid
|
|
|
- })
|
|
|
- await actionRecord({
|
|
|
- action: 'NEW_YEAR_ACTIVITY_APP_LINK',
|
|
|
- })
|
|
|
- }
|
|
|
- this.getMyActivity()
|
|
|
- this.innerAudioContext = wx.createInnerAudioContext();
|
|
|
- this.innerAudioContext.onTimeUpdate(() => {
|
|
|
- this.setDuration('playTime', this.innerAudioContext.currentTime)
|
|
|
- this.setData({
|
|
|
- vProgress: Math.ceil((Math.ceil(this.innerAudioContext.currentTime) / this.innerAudioContext.duration) * 100)
|
|
|
- })
|
|
|
- })
|
|
|
- this.innerAudioContext.onEnded((res) => {
|
|
|
- this.clearAudio()
|
|
|
- });
|
|
|
- },
|
|
|
- async getMyActivity() {
|
|
|
- let {
|
|
|
- list,
|
|
|
- totalSize
|
|
|
- } = await getMyActivity({
|
|
|
- userUid: this.data.userId ? this.data.userId : this.data.uid,
|
|
|
- pageNo: this.data.pageNo,
|
|
|
- pageSize: 6
|
|
|
- })
|
|
|
- if (this.data.userId) {
|
|
|
- let firstCard = this.data.list.length > 0 ? this.data.list[0] : ''
|
|
|
- console.log(firstCard);
|
|
|
- list = list.filter(item => {
|
|
|
- return item.id != firstCard.id
|
|
|
- })
|
|
|
- }
|
|
|
- list = [...this.data.list, ...list]
|
|
|
- let isMy = false
|
|
|
- console.log(list);
|
|
|
- if (list.length > 0) {
|
|
|
- isMy = list[0].uid == wx.getStorageSync('uid')
|
|
|
- }
|
|
|
- this.setData({
|
|
|
- isMy,
|
|
|
- list,
|
|
|
- totalSize
|
|
|
- })
|
|
|
- },
|
|
|
- onReachBottom() {
|
|
|
- if (this.data.totalSize > this.data.list.length) {
|
|
|
- this.setData({
|
|
|
- pageNo: this.data.pageNo + 1
|
|
|
- })
|
|
|
- this.getMyActivity()
|
|
|
- }
|
|
|
- },
|
|
|
- async playAudio({
|
|
|
- currentTarget
|
|
|
- }) {
|
|
|
- let item = currentTarget.dataset.item
|
|
|
- if (this.data.userAudioState) {
|
|
|
- if (this.data.playAudioId == item.id) {
|
|
|
- return this.clearAudio()
|
|
|
- }
|
|
|
- this.clearAudio()
|
|
|
- }
|
|
|
- this.innerAudioContext.src = item.audioPath;
|
|
|
- this.innerAudioContext.play();
|
|
|
- this.setDuration('endTime', item.duration)
|
|
|
- this.setData({
|
|
|
- playAudioId: item.id,
|
|
|
- userAudioState: true
|
|
|
- })
|
|
|
- await playAudioEvent(item.id)
|
|
|
- },
|
|
|
- clearAudio() {
|
|
|
- this.setData({
|
|
|
- playAudioId: null,
|
|
|
- userAudioState: false,
|
|
|
- playTime: '00:00',
|
|
|
- endTime: '00:00',
|
|
|
- vProgress: 0,
|
|
|
- })
|
|
|
- this.innerAudioContext.stop();
|
|
|
- },
|
|
|
- delete({
|
|
|
- currentTarget
|
|
|
- }) {
|
|
|
- wx.showModal({
|
|
|
- title: '确认删除吗?',
|
|
|
- content: '作品将被永久删除,无法找回。',
|
|
|
- confirmText: '确认',
|
|
|
- cancelText: '取消',
|
|
|
- success: async (res) => {
|
|
|
- if (res.confirm) {
|
|
|
- await deleteActivity(currentTarget.dataset.id)
|
|
|
- let beforeList = this.data.list.filter(item => {
|
|
|
- return item.id != currentTarget.dataset.id
|
|
|
- })
|
|
|
- this.setData({
|
|
|
- list: beforeList
|
|
|
- })
|
|
|
- wx.showToast({
|
|
|
- title: '删除成功!',
|
|
|
- icon: "none"
|
|
|
- })
|
|
|
- this.clearAudio()
|
|
|
+ /**
|
|
|
+ * 生命周期函数--监听页面加载
|
|
|
+ */
|
|
|
+ async onLoad(options) {
|
|
|
+ console.log(options, '分享');
|
|
|
+ this.setData({
|
|
|
+ uid: wx.getStorageSync('uid')
|
|
|
+ })
|
|
|
+ if (options.uid) {
|
|
|
+ this.setData({
|
|
|
+ userId: options.uid
|
|
|
+ })
|
|
|
+ }
|
|
|
+ if (options.cardId) {
|
|
|
+ let oneCard = await getOneActivity(options.cardId)
|
|
|
+ this.setData({
|
|
|
+ list: oneCard ? [oneCard] : [],
|
|
|
+ })
|
|
|
+ await actionRecord({
|
|
|
+ action: 'NEW_YEAR_ACTIVITY_APP_LINK',
|
|
|
+ })
|
|
|
+ }
|
|
|
+ this.getMyActivity()
|
|
|
+ this.innerAudioContext = wx.createInnerAudioContext();
|
|
|
+ this.innerAudioContext.onTimeUpdate(() => {
|
|
|
+ this.setDuration('playTime', this.innerAudioContext.currentTime)
|
|
|
+ this.setData({
|
|
|
+ vProgress: Math.ceil((Math.ceil(this.innerAudioContext.currentTime) / this.innerAudioContext.duration) * 100)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ this.innerAudioContext.onEnded((res) => {
|
|
|
+ this.clearAudio()
|
|
|
+ });
|
|
|
+ },
|
|
|
+ async getMyActivity() {
|
|
|
+ let {
|
|
|
+ list,
|
|
|
+ totalSize
|
|
|
+ } = await getMyActivity({
|
|
|
+ userUid: this.data.userId ? this.data.userId : this.data.uid,
|
|
|
+ pageNo: this.data.pageNo,
|
|
|
+ pageSize: 6
|
|
|
+ })
|
|
|
+ if (this.data.userId) {
|
|
|
+ let firstCard = this.data.list.length > 0 ? this.data.list[0] : ''
|
|
|
+ console.log(firstCard);
|
|
|
+ list = list.filter(item => {
|
|
|
+ return item.id != firstCard.id
|
|
|
+ })
|
|
|
+ }
|
|
|
+ list = [...this.data.list, ...list]
|
|
|
+ let isMy = false
|
|
|
+ console.log(list);
|
|
|
+ if (list.length > 0) {
|
|
|
+ isMy = list[0].uid == wx.getStorageSync('uid')
|
|
|
+ }
|
|
|
+ this.setData({
|
|
|
+ isMy,
|
|
|
+ list,
|
|
|
+ totalSize
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onReachBottom() {
|
|
|
+ if (this.data.totalSize > this.data.list.length) {
|
|
|
+ this.setData({
|
|
|
+ pageNo: this.data.pageNo + 1
|
|
|
+ })
|
|
|
+ this.getMyActivity()
|
|
|
+ }
|
|
|
+ },
|
|
|
+ async playAudio({
|
|
|
+ currentTarget
|
|
|
+ }) {
|
|
|
+ let item = currentTarget.dataset.item
|
|
|
+ if (this.data.userAudioState) {
|
|
|
+ if (this.data.playAudioId == item.id) {
|
|
|
+ return this.clearAudio()
|
|
|
+ }
|
|
|
+ this.clearAudio()
|
|
|
+ }
|
|
|
+ this.innerAudioContext.src = item.audioPath;
|
|
|
+ this.innerAudioContext.play();
|
|
|
+ this.setDuration('endTime', item.duration)
|
|
|
+ this.setData({
|
|
|
+ playAudioId: item.id,
|
|
|
+ userAudioState: true
|
|
|
+ })
|
|
|
+ await playAudioEvent(item.id)
|
|
|
+ },
|
|
|
+ clearAudio() {
|
|
|
+ this.setData({
|
|
|
+ playAudioId: null,
|
|
|
+ userAudioState: false,
|
|
|
+ playTime: '00:00',
|
|
|
+ endTime: '00:00',
|
|
|
+ vProgress: 0,
|
|
|
+ })
|
|
|
+ this.innerAudioContext.stop();
|
|
|
+ },
|
|
|
+ delete({
|
|
|
+ currentTarget
|
|
|
+ }) {
|
|
|
+ wx.showModal({
|
|
|
+ title: '确认删除吗?',
|
|
|
+ content: '作品将被永久删除,无法找回。',
|
|
|
+ confirmText: '确认',
|
|
|
+ cancelText: '取消',
|
|
|
+ success: async (res) => {
|
|
|
+ if (res.confirm) {
|
|
|
+ await deleteActivity(currentTarget.dataset.id)
|
|
|
+ let beforeList = this.data.list.filter(item => {
|
|
|
+ return item.id != currentTarget.dataset.id
|
|
|
+ })
|
|
|
+ this.setData({
|
|
|
+ list: beforeList
|
|
|
+ })
|
|
|
+ wx.showToast({
|
|
|
+ title: '删除成功!',
|
|
|
+ icon: "none"
|
|
|
+ })
|
|
|
+ this.clearAudio()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
+ async setLike({
|
|
|
+ currentTarget
|
|
|
+ }) {
|
|
|
+ if (currentTarget.dataset.item.isLike) {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ let index = currentTarget.dataset.index
|
|
|
+ await thumbsUp(currentTarget.dataset.item.id)
|
|
|
+ this.setData({
|
|
|
+ [`list[${index}].isLike`]: true,
|
|
|
+ [`list[${index}].likeAmount`]: ++this.data.list[index].likeAmount
|
|
|
+ })
|
|
|
+ },
|
|
|
+ async jump() {
|
|
|
+ await actionRecord({
|
|
|
+ action: 'NEW_YEAR_ACTIVITY_PLAY_TOO',
|
|
|
+ })
|
|
|
+ wx.navigateTo({
|
|
|
+ url: '/pages/activityList/index',
|
|
|
+ })
|
|
|
+ }, // 设置时间文案
|
|
|
+ setDuration(label, s) {
|
|
|
+ let t = '';
|
|
|
+ s = Math.ceil(s);
|
|
|
+ if (s > -1) {
|
|
|
+ let min = Math.floor(s / 60) % 60;
|
|
|
+ let sec = s % 60;
|
|
|
+ if (min < 10) {
|
|
|
+ t += "0";
|
|
|
+ }
|
|
|
+ t += min + ":";
|
|
|
+ if (sec < 10) {
|
|
|
+ t += "0";
|
|
|
+ }
|
|
|
+ t += sec;
|
|
|
}
|
|
|
- }
|
|
|
- })
|
|
|
- },
|
|
|
- async setLike({
|
|
|
- currentTarget
|
|
|
- }) {
|
|
|
- if (currentTarget.dataset.item.isLike) {
|
|
|
- return
|
|
|
- }
|
|
|
- let index = currentTarget.dataset.index
|
|
|
- await thumbsUp(currentTarget.dataset.item.id)
|
|
|
- this.setData({
|
|
|
- [`list[${index}].isLike`]: true,
|
|
|
- [`list[${index}].likeAmount`]: ++this.data.list[index].likeAmount
|
|
|
- })
|
|
|
- },
|
|
|
- async jump() {
|
|
|
- await actionRecord({
|
|
|
- action: 'NEW_YEAR_ACTIVITY_PLAY_TOO',
|
|
|
- })
|
|
|
- wx.navigateTo({
|
|
|
- url: '/pages/activityList/index',
|
|
|
- })
|
|
|
- }, // 设置时间文案
|
|
|
- setDuration(label, s) {
|
|
|
- let t = '';
|
|
|
- s = Math.ceil(s);
|
|
|
- if (s > -1) {
|
|
|
- let min = Math.floor(s / 60) % 60;
|
|
|
- let sec = s % 60;
|
|
|
- if (min < 10) {
|
|
|
- t += "0";
|
|
|
- }
|
|
|
- t += min + ":";
|
|
|
- if (sec < 10) {
|
|
|
- t += "0";
|
|
|
- }
|
|
|
- t += sec;
|
|
|
- }
|
|
|
|
|
|
- this.setData({
|
|
|
- [label]: t,
|
|
|
- })
|
|
|
- },
|
|
|
- createActivityImg(imageUrl, cardReadId) {
|
|
|
- return new Promise(async (resolve, reject) => {
|
|
|
- let title = await getShareText({
|
|
|
- cardReadId
|
|
|
- })
|
|
|
- resolve({
|
|
|
- title,
|
|
|
- path: `/pages/greeting/index?&uid=${wx.getStorageSync('uid')}`,
|
|
|
- imageUrl
|
|
|
- })
|
|
|
- })
|
|
|
- },
|
|
|
- onShareAppMessage({
|
|
|
- target,
|
|
|
- from,
|
|
|
- }) {
|
|
|
- if (from == 'button') {
|
|
|
- const promise = new Promise(resolve => {
|
|
|
- this.createActivityImg(target.dataset.item.cardUrl, target.dataset.item.id).then(res => {
|
|
|
- resolve(res)
|
|
|
+ this.setData({
|
|
|
+ [label]: t,
|
|
|
})
|
|
|
- })
|
|
|
- actionRecord({
|
|
|
- action: 'NEW_YEAR_ACTIVITY_SHARE',
|
|
|
- })
|
|
|
- return {
|
|
|
- title: '',
|
|
|
- path: `/pages/greeting/index?&uid=${wx.getStorageSync('uid')}`,
|
|
|
- imageUrl: target.dataset.img,
|
|
|
- promise
|
|
|
- }
|
|
|
- } else {
|
|
|
- return {
|
|
|
- title: '课文朗读,从未如此有趣。',
|
|
|
- path: `/pages/index/index?&uid=${wx.getStorageSync('uid')}`,
|
|
|
- imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/shareContent.png'
|
|
|
- }
|
|
|
+ },
|
|
|
+ createActivityImg(imageUrl, cardReadId) {
|
|
|
+ return new Promise(async (resolve, reject) => {
|
|
|
+ let title = await getShareText({
|
|
|
+ cardReadId
|
|
|
+ })
|
|
|
+ resolve({
|
|
|
+ title,
|
|
|
+ path: `/pages/greeting/index?uid=${wx.getStorageSync('uid')}`,
|
|
|
+ imageUrl
|
|
|
+ })
|
|
|
+ })
|
|
|
+ },
|
|
|
+ onShareAppMessage({
|
|
|
+ target,
|
|
|
+ from,
|
|
|
+ }) {
|
|
|
+ if (from == 'button') {
|
|
|
+ const promise = new Promise(resolve => {
|
|
|
+ this.createActivityImg(target.dataset.item.cardUrl, target.dataset.item.id).then(res => {
|
|
|
+ resolve(res)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ actionRecord({
|
|
|
+ action: 'NEW_YEAR_ACTIVITY_SHARE',
|
|
|
+ })
|
|
|
+ return {
|
|
|
+ title: '',
|
|
|
+ path: `/pages/greeting/index?uid=${wx.getStorageSync('uid')}`,
|
|
|
+ imageUrl: target.dataset.img,
|
|
|
+ promise
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ return {
|
|
|
+ title: '课文朗读,从未如此有趣。',
|
|
|
+ path: `/pages/index/index?uid=${wx.getStorageSync('uid')}`,
|
|
|
+ imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/shareContent.png'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onShareTimeline() {
|
|
|
+ return {
|
|
|
+ title: '这吉祥话说得太溜了,快来听听吧!',
|
|
|
+ query: `uid=${wx.getStorageSync('uid')}`,
|
|
|
+ imageUrl: 'http://reader-wx.ai160.com/images/reader/v3/xkx_logo.jpg'
|
|
|
+ }
|
|
|
+ },
|
|
|
+ onHide() {
|
|
|
+ this.clearAudio()
|
|
|
+ },
|
|
|
+ onUnload() {
|
|
|
+ this.clearAudio()
|
|
|
}
|
|
|
- },
|
|
|
- onHide() {
|
|
|
- this.clearAudio()
|
|
|
- },
|
|
|
- onUnload() {
|
|
|
- this.clearAudio()
|
|
|
- }
|
|
|
})
|