collection.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // pages/collection/collection.js
  2. const app = getApp()
  3. let userInfo = app.globalData.userInfo;
  4. let height = app.globalData.phoneHeight
  5. Page({
  6. /**
  7. * 页面的初始数据
  8. */
  9. data: {
  10. currentIndex:0,
  11. height:height,
  12. content: [
  13. {text: "我的收藏"},
  14. {text: "我的已购"},
  15. {text: "收听历史"},
  16. {text: "我的礼包"}
  17. ]
  18. },
  19. /**
  20. * 生命周期函数--监听页面加载
  21. */
  22. onLoad: function (options) {
  23. var that = this;
  24. var height;
  25. wx.getSystemInfo({
  26. success (res) {
  27. console.log(res.windowHeight);
  28. height = res.windowHeight
  29. }
  30. })
  31. if (app.globalData.userInfo === null){
  32. that.setData({
  33. login:true
  34. })
  35. }else{
  36. that.setData({
  37. login: false,
  38. height:height
  39. })
  40. }
  41. },
  42. /**
  43. * 用户点击右上角分享
  44. */
  45. onShareAppMessage: function () {
  46. },
  47. // 点击获取头像和昵称
  48. bindGetUserInfo(e) {
  49. var that = this;
  50. wx.getUserInfo({
  51. success: function (res) {
  52. app.globalData.userInfo = e.detail.userInfo;
  53. console.log(e.detail.userInfo);
  54. that.setData({
  55. login: false,
  56. })
  57. }
  58. })
  59. },
  60. checkItem(e){
  61. var that = this;
  62. if (this.data.currentIndex === e.target.dataset.current) {
  63. return false;
  64. } else {
  65. that.setData({
  66. currentIndex: e.target.dataset.index
  67. })
  68. }
  69. },
  70. // 滑动切换tab
  71. changeTab:function(e){
  72. var that = this;
  73. console.log(e.detail.current)
  74. that.setData({
  75. currentIndex:e.detail.current
  76. })
  77. }
  78. })