index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. onLoad: function (options) {
  43. const that = this
  44. myRequest.getData().then(res => {
  45. const {guess,hotRecommends} = res.data
  46. that.setData({
  47. showitem: true,
  48. guess: guess.list.slice(0, 3),
  49. xiaoshuocontent: hotRecommends.list[0].list,
  50. xiangshengcontent: hotRecommends.list[2].list,
  51. tuokocontent: hotRecommends.list[4].list
  52. })
  53. }).catch(err => {
  54. console.log('error :>> ', err);
  55. that.setData({
  56. showitem: false
  57. })
  58. })
  59. },
  60. //轮播图改变事件
  61. swiperChange: function (e) {
  62. this.setData({
  63. swiperCurrent: e.detail.current
  64. })
  65. },
  66. goToBangDan: function () {
  67. wx.navigateTo({
  68. url: '/pages/index/bangdan/bangdan',
  69. })
  70. },
  71. gotoDetails(e) {
  72. const url = e.currentTarget.dataset.coverimg;
  73. const title = e.currentTarget.dataset.title;
  74. wx.navigateTo({
  75. // 页面传参
  76. url: '/pages/details/details?url=' + url + '&title=' + title,
  77. })
  78. }
  79. })