index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. const myRequest = require('../../api/index.js');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. imgList: [
  11. '/image/swiper/ad1.jpg',
  12. '/image/swiper/ad2.jpg',
  13. '/image/swiper/ad3.jpg',
  14. '/image/swiper/ad4.jpg',
  15. '/image/swiper/ad5.jpg',
  16. '/image/swiper/ad6.jpg',
  17. '/image/swiper/ad7.jpg'
  18. ],
  19. navList: [{
  20. icon: '/image/nav-icon/diantai.png',
  21. events: 'goToBangDan',
  22. text: '榜单'
  23. },
  24. {
  25. icon: '/image/nav-icon/diantai.png',
  26. events: 'goToBangDan',
  27. text: '听小说'
  28. },
  29. {
  30. icon: '/image/nav-icon/diantai.png',
  31. events: 'goToBangDan',
  32. text: '情感电台'
  33. },
  34. {
  35. icon: '/image/nav-icon/diantai.png',
  36. events: 'goToBangDan',
  37. text: '听知识'
  38. },
  39. ],
  40. swiperCurrent: 0,
  41. },
  42. /**
  43. * 生命周期函数--监听页面加载
  44. */
  45. onLoad: function (options) {
  46. const that = this
  47. myRequest.getData().then(res => {
  48. that.setData({
  49. showitem: true,
  50. guess: res.data.guess.list.slice(0, 3),
  51. xiaoshuocontent: res.data.hotRecommends.list[0].list,
  52. xiangshengcontent: res.data.hotRecommends.list[2].list,
  53. tuokocontent: res.data.hotRecommends.list[4].list
  54. })
  55. }).catch(err => {
  56. that.setData({
  57. showitem: false
  58. })
  59. })
  60. },
  61. //轮播图改变事件
  62. swiperChange: function (e) {
  63. this.setData({
  64. swiperCurrent: e.detail.current
  65. })
  66. },
  67. goToBangDan: function () {
  68. wx.navigateTo({
  69. url: '/pages/index/bangdan/bangdan',
  70. })
  71. },
  72. gotoDetails(e) {
  73. const url = e.currentTarget.dataset.coverimg;
  74. const title = e.currentTarget.dataset.title;
  75. wx.navigateTo({
  76. // 页面传参
  77. url: '/pages/details/details?url=' + url + '&title=' + title,
  78. })
  79. }
  80. })