collection.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. // pages/collection/collection.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. content: [
  8. {
  9. text: "我的收藏"
  10. },
  11. {
  12. text: "我的已购"
  13. },
  14. {
  15. text: "收听历史"
  16. },
  17. {
  18. text: "我的礼包"
  19. }
  20. ]
  21. },
  22. /**
  23. * 生命周期函数--监听页面加载
  24. */
  25. onLoad: function (options) {
  26. var that = this;
  27. wx.getSetting({
  28. success(res) {
  29. if (res.authSetting['scope.userInfo']) {
  30. // 已经授权,可以直接调用 getUserInfo 获取头像昵称
  31. that.setData({
  32. login: false
  33. })
  34. } else {
  35. that.setData({
  36. login: true
  37. })
  38. }
  39. }
  40. })
  41. },
  42. /**
  43. * 生命周期函数--监听页面显示
  44. */
  45. onShow: function () {
  46. },
  47. /**
  48. * 用户点击右上角分享
  49. */
  50. onShareAppMessage: function () {
  51. },
  52. bindGetUserInfo(e) {
  53. var that = this;
  54. wx.getUserInfo({
  55. success: function (res) {
  56. console.log(e.detail.userInfo);
  57. that.setData({
  58. login: false,
  59. })
  60. // 存缓存
  61. wx.setStorage({
  62. key: 'avatarUrl',
  63. data: e.detail.userInfo.avatarUrl,
  64. success: (result) => {
  65. console.log('缓存成功');
  66. },
  67. });
  68. wx.setStorage({
  69. key: 'nickName',
  70. data: e.detail.userInfo.nickName,
  71. success: (result) => {
  72. console.log('缓存成功');
  73. },
  74. });
  75. }
  76. })
  77. },
  78. })