index.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // miniprogram/pages/provincialArea/index.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. playIndex: 0,
  7. data: {
  8. tabs: [],
  9. playStatus: true,
  10. activeTab: 0,
  11. },
  12. /**
  13. * 生命周期函数--监听页面加载
  14. */
  15. onLoad: async function (options) {
  16. wx.setNavigationBarTitle({
  17. title: "红色文物会发声-" + options.title
  18. })
  19. const db = wx.cloud.database();
  20. const _ = db.command;
  21. let list = await db.collection('data_news').where({
  22. type: _.eq(3),
  23. provincial: _.eq(options.title)
  24. }).get();
  25. wx.playBackgroundAudio({
  26. dataUrl: list.data[this.playIndex].music
  27. })
  28. this.setData({
  29. playStatus: true,
  30. tabs: list.data || []
  31. })
  32. },
  33. isPlay(){
  34. let playStatus = !this.data.playStatus;
  35. console.log(playStatus)
  36. if(playStatus){
  37. wx.playBackgroundAudio({
  38. dataUrl: this.data.tabs[this.playIndex].music
  39. })
  40. }else{
  41. wx.pauseBackgroundAudio()
  42. }
  43. this.setData({
  44. playStatus
  45. })
  46. },
  47. pageChange(e){
  48. this.playIndex = e.detail.current || 0;
  49. wx.playBackgroundAudio({
  50. dataUrl: this.data.tabs[this.playIndex].music
  51. })
  52. },
  53. /**
  54. * 生命周期函数--监听页面初次渲染完成
  55. */
  56. onReady: function () {
  57. },
  58. /**
  59. * 生命周期函数--监听页面显示
  60. */
  61. onShow: function () {
  62. },
  63. /**
  64. * 生命周期函数--监听页面隐藏
  65. */
  66. onHide: function () {
  67. },
  68. /**
  69. * 生命周期函数--监听页面卸载
  70. */
  71. onUnload: function () {
  72. wx.stopBackgroundAudio()
  73. },
  74. /**
  75. * 页面相关事件处理函数--监听用户下拉动作
  76. */
  77. onPullDownRefresh: function () {
  78. },
  79. /**
  80. * 页面上拉触底事件的处理函数
  81. */
  82. onReachBottom: function () {
  83. },
  84. /**
  85. * 用户点击右上角分享
  86. */
  87. onShareAppMessage: function () {
  88. }
  89. })