bangdan.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. const app = getApp();
  2. var utils = require('../../../utils/utils.js')
  3. // 定义一个全局变量保存从接口获取到的数据,以免重复请求接口
  4. var resut;
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. showCover:false,
  11. currentTab:0,
  12. navTitle:[
  13. {title:'经典必听'},
  14. {title:'优质专辑'},
  15. {title:'有声小说'},
  16. {title:'儿童教育'},
  17. {title:'人文历史'},
  18. {title:'最潮外语'},
  19. {title:'商业财经'},
  20. {title:'热门新闻'}
  21. ]
  22. },
  23. /**
  24. * 生命周期函数--监听页面加载
  25. */
  26. onLoad: function (options) {
  27. var that = this;
  28. var url = 'http://mobile.ximalaya.com/mobile/discovery/v3/recommend/hotAndGuess?code=43_310000_3100&device=android&version=5.4.45'
  29. utils.myRequest({
  30. url:url,
  31. methods:'GET',
  32. success:function(res){
  33. console.log(res);
  34. resut = res;
  35. that.setData({
  36. list: res.data.hotRecommends.list[0].list
  37. })
  38. },
  39. fail:function(){
  40. }
  41. })
  42. },
  43. handleClick(e) {
  44. let currentTab = e.currentTarget.dataset.index;
  45. // 实现每一个tabbar切换对应内容的原理,根据每一个tabbar的index对应数组中的数据
  46. this.setData({
  47. currentTab,
  48. list: resut.data.hotRecommends.list[currentTab].list
  49. })
  50. },
  51. pullDown:function(){
  52. var that = this;
  53. that.setData({
  54. showCover:true
  55. })
  56. },
  57. closeCover:function(){
  58. var that = this;
  59. that.setData({
  60. showCover:false
  61. })
  62. },
  63. CoverCheck:function(e){
  64. let currentTab = e.currentTarget.dataset.index;
  65. // 实现每一个tabbar切换对应内容的原理,根据每一个tabbar的index对应数组中的数据
  66. this.setData({
  67. currentTab,
  68. list: resut.data.hotRecommends.list[currentTab].list
  69. })
  70. this.closeCover()
  71. }
  72. })