index.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. //index.js
  2. //获取应用实例
  3. const app = getApp()
  4. var utils = require('../../utils/utils.js');
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. imgList: [
  11. '/image/ad1.jpg',
  12. '/image/ad2.jpg',
  13. '/image/ad3.jpg',
  14. '/image/ad4.jpg',
  15. '/image/ad5.jpg',
  16. '/image/ad6.jpg',
  17. '/image/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. var that = this;
  47. var url = 'http://mobile.ximalaya.com/mobile/discovery/v3/recommend/hotAndGuess?code=43_310000_3100&device=android&version=5.4.45';
  48. // 调用的是自己封装的工具函数,在utils中
  49. utils.myRequest({
  50. url: url,
  51. methods: 'GET',
  52. success: function (result) {
  53. that.setData({
  54. showitem: true,
  55. guess: result.data.paidArea.list,
  56. xiaoshuocontent: result.data.hotRecommends.list[0].list,
  57. xiangshengcontent: result.data.hotRecommends.list[2].list,
  58. tuokocontent: result.data.hotRecommends.list[4].list
  59. })
  60. },
  61. fail: function () {
  62. that.setData({
  63. showitem: false
  64. })
  65. }
  66. });
  67. },
  68. //轮播图改变事件
  69. swiperChange: function (e) {
  70. this.setData({
  71. swiperCurrent: e.detail.current
  72. })
  73. },
  74. goToBangDan: function () {
  75. wx.navigateTo({
  76. url: '/pages/index/bangdan/bangdan',
  77. })
  78. },
  79. gotoDetails(e) {
  80. var url = e.currentTarget.dataset.coverimg;
  81. var title = e.currentTarget.dataset.title;
  82. wx.navigateTo({
  83. url: '/pages/details/details?url=' + url + '&title=' + title,
  84. })
  85. }
  86. })