// miniprogram/pages/provincialArea/index.js Page({ /** * 页面的初始数据 */ playIndex: 0, data: { tabs: [], playStatus: true, activeTab: 0, }, /** * 生命周期函数--监听页面加载 */ onLoad: async function (options) { wx.setNavigationBarTitle({ title: "红色文物会发声-" + options.title }) const db = wx.cloud.database(); const _ = db.command; let list = await db.collection('data_news').where({ type: _.eq(3), provincial: _.eq(options.title) }).get(); wx.playBackgroundAudio({ dataUrl: list.data[this.playIndex].music }) this.setData({ playStatus: true, tabs: list.data || [] }) }, isPlay(){ let playStatus = !this.data.playStatus; console.log(playStatus) if(playStatus){ wx.playBackgroundAudio({ dataUrl: this.data.tabs[this.playIndex].music }) }else{ wx.pauseBackgroundAudio() } this.setData({ playStatus }) }, pageChange(e){ this.playIndex = e.detail.current || 0; wx.playBackgroundAudio({ dataUrl: this.data.tabs[this.playIndex].music }) }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () { }, /** * 生命周期函数--监听页面显示 */ onShow: function () { }, /** * 生命周期函数--监听页面隐藏 */ onHide: function () { }, /** * 生命周期函数--监听页面卸载 */ onUnload: function () { wx.stopBackgroundAudio() }, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () { }, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () { }, /** * 用户点击右上角分享 */ onShareAppMessage: function () { } })