collection.js 1.6 KB

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