var postsData = require('../../../data/posts-data.js')
//获取全局变量
var app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
isPlayingMusic:false
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
// var globalData = app.globalData;
var postId=options.id;
this.data.currentPostId = postId;
var postData = postsData.postList[postId];
this.setData({
postData: postData
})
// var postsCollected ={
// 1:"true",
// 2:"false"
// }
//wx.clearStorage();
var postsCollected = wx.getStorageSync('posts_Collected');
if(postsCollected){
var postCollected = postsCollected[postId];
if (!postCollected){
postCollected=false;
}
this.setData({
collected: postCollected
})
}else{
var postsCollected={}
postsCollected[postId] = false;
wx.setStorageSync('posts_Collected', postsCollected);
}
if (app.globalData.g_isPlayingMusic && app.globalData.g_currentMusicPostId === postId){
this.setData({
isPlayingMusic : true
})
}
this.setMusicMonitor();
},
setMusicMonitor:function(){
var that = this;
wx.onBackgroundAudioPlay(function () {
that.setData({
isPlayingMusic : true
})
app.globalData.g_isPlayingMusic = true;
app.globalData.g_currentMusicPostId = that.data.currentPostId;
});
wx.onBackgroundAudioPause(function () {
that.setData({
isPlayingMusic : false
})
app.globalData.g_isPlayingMusic = false;
app.globalData.g_currentMusicPostId = null;
});
wx.onBackgroundAudioStop(function () {
that.setData({
isPlayingMusic: false
})
app.globalData.g_isPlayingMusic = false;
app.globalData.g_currentMusicPostId = null;
});
},
onCollectionTap:function(event){
//同步
this.getPostsCollectedSyc();
//异步
// this.getPostsCollectedAsy();
},
getPostsCollectedAsy:function(){
var that = this;
wx.getStorage({
key:"posts_Collected",
success:function(res){
var postsCollected = res.data;
var postCollected = postsCollected[that.data.currentPostId];
//收藏变成未收藏,未收藏变成收藏
postCollected = !postCollected;
postsCollected[that.data.currentPostId] = postCollected;
that.showToast(postsCollected, postCollected);
}
})
},
getPostsCollectedSyc:function(){
var that = this;
var postsCollected = wx.getStorageSync('posts_Collected');
var postCollected = postsCollected[that.data.currentPostId];
//收藏变成未收藏,未收藏变成收藏
postCollected = !postCollected;
postsCollected[that.data.currentPostId] = postCollected;
that.showToast(postsCollected, postCollected);
},
showModal: function (postsCollected,postCollected){
var that = this;
wx.showModal({
title: '收藏',
content: postCollected ?'收藏这篇文章?':'取消收藏这篇文章?',
showCancel: "true",
cancelText: "取消",
cancelColor: "#333",
confirmText: "确认",
confirmColor: "#405f80",
success:function(res){
if (res.confirm){
//更新文章是否收藏
wx.setStorageSync('posts_Collected', postsCollected);
//更新数据绑定变量,从而实现切换图片
// this.showToast();
that.setData({
collected: postCollected
})
}
}
})
},
showToast: function (postsCollected, postCollected){
//更新文章是否收藏
wx.setStorageSync('posts_Collected', postsCollected);
//更新数据绑定变量,从而实现切换图片
this.setData({
collected: postCollected
})
wx.showToast({
title: postCollected?'收藏成功':'取消成功',
duration:1000,
icon:"success",
success:function(){},
fail:function(){},
complete:function(){}
})
},
onShareTap:function(){
var itemList = [
"分享给微信好友",
"分享到朋友圈",
"分享到QQ",
"分享到微博"
]
wx.showActionSheet({
itemList: itemList,
itemColor:"#405f80",
success:function(res){
// res.cancel:用户是不是点击了取消按钮
// res.tapIndex:数组元素的序号,从0开始
wx.showModal({
title: '用户'+itemList[res.tapIndex],
content: '用户是否取消?'+res.cancel+'现在无法实现分享功能,什么时候能支持呢',
})
},
// fail:function(res){
// wx.showToast({
// title: 'test'
// })
// }
})
},
onMusicTap:function(event){
var currentPostId = this.data.currentPostId;
var postData = postsData.postList[currentPostId];
var isPlayingMusic = this.data.isPlayingMusic;
if (isPlayingMusic){
wx.pauseBackgroundAudio();
this.setData({
isPlayingMusic:false
})
}else{
wx.playBackgroundAudio({
dataUrl: postData.music.url, // 设置了 src 之后会自动播放
title: postData.music.title,
coverImgUrl: postData.music.coverImg
})
this.setData({
isPlayingMusic: true
})
}
}
})
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
ReaderMovie.zip (76个子文件)
ReaderMovie
project.config.json 503B
pages
.DS_Store 6KB
welcome
welcome.wxml 308B
welcome.js 153B
welcome.json 47B
welcome.wxss 564B
posts
post-detail
post-detail.wxss 1KB
post-detail.json 40B
post-detail.wxml 997B
post-detail.js 5KB
post.json 78B
post.wxss 152B
post.js 2KB
post.wxml 812B
post-item
post-item-template.wxml 686B
post-item-template.wxss 1KB
test
test.wxss 26B
test.js 3KB
test.wxml 911B
test.json 2B
movies
movie-list
movie-list-template.wxss 588B
movie-list-template.wxml 781B
movies.wxml 959B
movies.wxss 692B
movie
movie-template.wxml 359B
movie-template.wxss 257B
stars
stars-template.wxml 574B
stars-template.wxss 273B
movie-grid
movie-grid-template.wxml 317B
movie-grid-template.wxss 177B
movie-detail
class
Movie.js 1KB
movie-detail.json 2B
movie-detail.wxss 2KB
movie-detail.wxml 2KB
movie-detail.js 982B
movies.js 3KB
movies.json 42B
more-movie
more-movie.wxss 49B
more-movie.js 3KB
more-movie.json 61B
more-movie.wxml 155B
.DS_Store 10KB
utils
util.js 2KB
images
post
.DS_Store 6KB
sky.jpg 31KB
road.jpg 37KB
.DS_Store 14KB
title.jpg 15KB
yourName.png 202KB
2.jpg 33KB
tab
dianying_hl.png 6KB
yuedu_hl.png 25KB
dianying.png 3KB
yuedu.png 13KB
1.jpg 28KB
avatar
a.gif 9KB
.DS_Store 6KB
icon
.DS_Store 6KB
view.png 46KB
share.png 31KB
xx.png 2KB
coll1.png 80KB
chat.png 12KB
music.png 31KB
allow-right.png 395B
star.png 825B
coll.png 77KB
star_hl.png 1KB
pause.png 43KB
chat1.png 12KB
3.jpg 13KB
app.js 683B
data
posts-data.js 2KB
app.wxml 0B
app.json 784B
app.wxss 92B
共 76 条
- 1
资源评论
hanchaojunjava
- 粉丝: 2
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功