123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- //index.js
- //获取应用实例
- var app = getApp()
- Page({
- data: {
- userImg: "",
- userName: "",
- score: 0,
- oneScore: 0
- },
- onLoad: function (options) {
- this.checkSession()
- },
- onShow: function () {
- var that = this;
- wx.getStorage({
- key: 'score',
- success: function (res) {
- console.log(res)
- that.setData({
- score: res.data
- })
- }
- })
- wx.getStorage({
- key: 'oneScore',
- success: function (res) {
- that.setData({
- oneScore: res.data
- })
- }
- })
- },
- checkSession() {
- var that = this;
- app.checkSession(() => {
- wx.getStorage({
- key: 'userInfo',
- success: function (res) {
- console.log(res)
- that.setData({
- userImg: res.data.avatarUrl,
- userName: res.data.nickName
- })
- wx.getStorage({
- key: 'score',
- success: function (res) {
- that.setData({
- score: res.data
- })
- }
- })
- wx.getStorage({
- key: 'oneScore',
- success: function (res) {
- that.setData({
- oneScore: res.data
- })
- }
- })
- },
- fail: function (res) {
- console.log('获取用户信息失败')
- that.checkSession();
- }
- })
- })
- },
- startGame: function () {
- console.log('按钮点击事件触发,这里跳转到游戏页面')
- wx.navigateTo({
- url: '/pages/game/game'
- })
- },
- //右上角转发
- onShareAppMessage() {
- return {
- title: '指尖钢琴别踩白块',
- path: '/pages/index/index',
- }
- }
- })
|