酷炫小程序

music.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //index.js
  2. //获取应用实例
  3. var app = getApp()
  4. Page({
  5. data: {
  6. userImg: "",
  7. userName: "",
  8. score: 0,
  9. oneScore: 0
  10. },
  11. onLoad: function (options) {
  12. this.checkSession()
  13. },
  14. onShow: function () {
  15. var that = this;
  16. wx.getStorage({
  17. key: 'score',
  18. success: function (res) {
  19. console.log(res)
  20. that.setData({
  21. score: res.data
  22. })
  23. }
  24. })
  25. wx.getStorage({
  26. key: 'oneScore',
  27. success: function (res) {
  28. that.setData({
  29. oneScore: res.data
  30. })
  31. }
  32. })
  33. },
  34. checkSession() {
  35. var that = this;
  36. app.checkSession(() => {
  37. wx.getStorage({
  38. key: 'userInfo',
  39. success: function (res) {
  40. console.log(res)
  41. that.setData({
  42. userImg: res.data.avatarUrl,
  43. userName: res.data.nickName
  44. })
  45. wx.getStorage({
  46. key: 'score',
  47. success: function (res) {
  48. that.setData({
  49. score: res.data
  50. })
  51. }
  52. })
  53. wx.getStorage({
  54. key: 'oneScore',
  55. success: function (res) {
  56. that.setData({
  57. oneScore: res.data
  58. })
  59. }
  60. })
  61. },
  62. fail: function (res) {
  63. console.log('获取用户信息失败')
  64. that.checkSession();
  65. }
  66. })
  67. })
  68. },
  69. startGame: function () {
  70. console.log('按钮点击事件触发,这里跳转到游戏页面')
  71. wx.navigateTo({
  72. url: '/pages/game/game'
  73. })
  74. },
  75. //右上角转发
  76. onShareAppMessage() {
  77. return {
  78. title: '指尖钢琴别踩白块',
  79. path: '/pages/index/index',
  80. }
  81. }
  82. })