bangdan.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. const app = getApp();
  2. let myRequest = require('../../../api/index.js')
  3. // 定义一个全局变量保存从接口获取到的数据,以免重复请求接口
  4. let 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. let that = this;
  28. myRequest.getData().then(res => {
  29. resut = res;
  30. that.setData({
  31. list: res.data.hotRecommends.list[0].list
  32. })
  33. }).catch(err => {
  34. console.log(err);
  35. })
  36. },
  37. handleClick(e) {
  38. let currentTab = e.currentTarget.dataset.index;
  39. // 实现每一个tabbar切换对应内容的原理,根据每一个tabbar的index对应数组中的数据
  40. this.setData({
  41. currentTab,
  42. list: resut.data.hotRecommends.list[currentTab].list
  43. })
  44. },
  45. pullDown:function(){
  46. let that = this;
  47. that.setData({
  48. showCover:true
  49. })
  50. },
  51. closeCover:function(){
  52. let that = this;
  53. that.setData({
  54. showCover:false
  55. })
  56. },
  57. coverCheck:function(e){
  58. let currentTab = e.currentTarget.dataset.index;
  59. // 实现每一个tabbar切换对应内容的原理,根据每一个tabbar的index对应数组中的数据
  60. this.setData({
  61. currentTab,
  62. list: resut.data.hotRecommends.list[currentTab].list
  63. })
  64. this.closeCover()
  65. }
  66. })