第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

微信小程序收藏功能,出去后進來圖標會自動重置,但數(shù)值正常,無報錯

微信小程序收藏功能,出去后進來圖標會自動重置,但數(shù)值正常,無報錯

var postsData = require('../../../data/posts-data.js')var app = getApp();Page({data: {//isPlayingMusic: flase},onLoad: function(option) {var postId = option.id;//url: "post-detail/post-detail?id=" + postId;?后面的id=option.id里的idthis.data.currentPostId = postId;var postData = postsData.postList[postId];// this.setData({//postData: postData//})this.postData = postsData.postList[postId]var postsCollected = wx.getStorageSync('posts_collected')if (postsCollected) {var postCollected = postsCollected[postId]this.setData({postData: postData//將data上的數(shù)據(jù)傳送到頁面})}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() {//點擊播放圖標和總控開關(guān)都會觸發(fā)這個函數(shù)var that = this;wx.onBackgroundAudioPlay(function(event) {var pages = getCurrentPages();var currentPage = pages[pages.length - 1];if (currentPage.data.currentPostId === that.data.currentPostId) {// 打開多個post-detail頁面后,每個頁面不會關(guān)閉,只會隱藏。通過頁面棧拿到到// 當前頁面的postid,只處理當前頁面的音樂播放。if (app.globalData.g_currentMusicPostId == that.data.currentPostId) {// 播放當前頁面音樂才改變圖標that.setData({isPlayingMusic: true})}// if(app.globalData.g_currentMusicPostId == that.data.currentPostId )// app.globalData.g_currentMusicPostId = that.data.currentPostId;}app.globalData.g_isPlayingMusic = true;});wx.onBackgroundAudioPause(function() {var pages = getCurrentPages();var currentPage = pages[pages.length - 1];if (currentPage.data.currentPostId === that.data.currentPostId) {if (app.globalData.g_currentMusicPostId == that.data.currentPostId) {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.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 postsCollected = wx.getStorageSync('posts_collected');var postCollected = postsCollected[this.data.currentPostId];// 收藏變成未收藏,未收藏變成收藏postCollected = !postCollected;postsCollected[this.data.currentPostId] = postCollected;this.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);// 更新數(shù)據(jù)綁定變量,從而實現(xiàn)切換圖片that.setData({collected: postCollected})}}})},showToast: function(postsCollected, postCollected) {// 更新文章是否的緩存值wx.setStorageSync('posts_collected', postsCollected);// 更新數(shù)據(jù)綁定變量,從而實現(xiàn)切換圖片this.setData({collected: postCollected})wx.showToast({title: postCollected ? "收藏成功" : "取消成功",duration: 1000,icon: "success"})},onShareTap: function(event) {var itemList = ["分享給微信好友","分享到朋友圈","分享到QQ","分享到微博"];wx.showActionSheet({itemList: itemList,itemColor: "#405f80",success: function(res) {// res.cancel 用戶是不是點擊了取消按鈕// res.tapIndex 數(shù)組元素的序號,從0開始wx.showModal({title: "用戶 " + itemList[res.tapIndex],content: "用戶是否取消?" + res.cancel + "現(xiàn)在無法實現(xiàn)分享功能,什么時候能支持呢"})}})},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})// app.globalData.g_currentMusicPostId = null;app.globalData.g_isPlayingMusic = false;} else {wx.playBackgroundAudio({dataUrl: postData.music.url,title: postData.music.title,coverImgUrl: postData.music.coverImg,})this.setData({isPlayingMusic: true})app.globalData.g_currentMusicPostId = this.data.currentPostId;app.globalData.g_isPlayingMusic = true;}}})上面的這是post-detail.js里的代碼。<!--pages/posts/post-detail/post-detail.wxml--><view class="container"><image class="head-image" src="{{isPlayingMusic?postData.music.coverImg:postData.headImgSrc}}"></image><image catchtap="onMusicTap" class="audio"src="{{isPlayingMusic?'/images/music/music-stop.png': '/images/music/music-start.png'}}"></image><view class="author-date"><image class="avatar" src="{{postData.avatar}}"></image><text class="author">{{postData.author}}</text><text class="const-text">發(fā)表于</text><text class="date">{{postData.dateTime}}</text></view><text class="title">{{postData.title}}</text><view class="tool"><view class="circle-img"><image wx:if="{{collected}}" catchtap="onCollectionTap"src="/images/icon/collection.png"></image><image wx:else catchtap="onCollectionTap"src="/images/icon/collection-anti.png"></image><image catchtap="onShareTap" class="share-img"src="/images/icon/share.png"></image></view><view class="horizon"></view></view><text class="detail">{{postData.detail}}</text></view>上面的這是post-detail.wxml里的代碼。麻煩各位大神了,微信小程序收藏功能,收藏然后出去后進來圖標會自動重置,但數(shù)值正常,無報錯。
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 1956 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號