collection.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. const app = getApp()
  2. Page({
  3. data: {
  4. currentIndex:0,
  5. height:0,
  6. login: false,
  7. content: [
  8. {text: "我的收藏"},
  9. {text: "我的已购"},
  10. {text: "收听历史"},
  11. {text: "我的礼包"}
  12. ]
  13. },
  14. onLoad() {
  15. const that = this;
  16. wx.getSystemInfo({
  17. success (res) {
  18. that.setData({
  19. height :res.windowHeight
  20. })
  21. }
  22. })
  23. },
  24. onShow() {
  25. const that = this
  26. if (!that.login) {
  27. wx.getStorage({
  28. key: 'userinfo',
  29. success(res){
  30. that.setData({
  31. login: res.data ? true : false,
  32. })
  33. }
  34. })
  35. }
  36. },
  37. // 点击获取头像和昵称
  38. bindGetUserInfo(e) {
  39. const that = this;
  40. wx.getUserInfo({
  41. success: function (res) {
  42. wx.setStorage({
  43. key: "userinfo",
  44. data: JSON.stringify(res.userInfo)
  45. })
  46. that.setData({
  47. login: true
  48. })
  49. }
  50. })
  51. },
  52. checkItem(e) {
  53. const that = this;
  54. if (this.data.currentIndex === e.target.dataset.current) {
  55. return false;
  56. } else {
  57. that.setData({
  58. currentIndex: e.target.dataset.index
  59. })
  60. }
  61. },
  62. // 滑动切换tab
  63. changeTab(e) {
  64. const that = this;
  65. that.setData({
  66. currentIndex:e.detail.current
  67. })
  68. }
  69. })