-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
112 lines (109 loc) · 3.36 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const { getOpenId, getRecord } = require('./request/request');
const {mockData} =require('./utils/utils')
App({
onLaunch: function () {
//云开发初始化
wx.cloud.init({
env: 'yuan-1bd01',
traceUser: true
})
// 展示本地存储能力
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
// 登录
wx.login({
success: res => {
// 发送 res.code 到后台换取 openId, sessionKey, unionId
// 获取到用户的 code 之后:res.code
console.log("用户的code:" + res.code);
// 或者可以直接使用微信的提供的接口直接获取 openid ,方法如下:
// wx.request({
// // 自行补上自己的 APPID 和 SECRET
// url: 'https://api.weixin.qq.com/sns/jscode2session?appid=wx779e535c408fadbd&secret=7bce4a89821f3ae45b1a17e572287dd6&js_code=' + res.code + '&grant_type=authorization_code',
// success: res => {
// // 获取到用户的 openid
// console.log("用户的openid:" + res.data.openid);
// this.globalData.openid = res.data.openid
// }
// });
}
})
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
this.globalData.nickName = res.userInfo.nickName
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
this.startAudio();
},
stopAudio: function () {
this.globalData.audio = false;
this.buttonAudio.destroy();
this.clickAudio.destroy();
this.clockAudio.destroy();
this.successAudio.destroy();
},
startAudio: function () {
this.globalData.audio = true;
this.buttonAudio = wx.createInnerAudioContext()
this.clickAudio = wx.createInnerAudioContext()
this.clockAudio = wx.createInnerAudioContext()
this.successAudio = wx.createInnerAudioContext()
this.buttonAudio.src = '/img/button.mp3'
this.clickAudio.src='/img/click.mp3'
this.clockAudio.src='/img/clock1.mp3'
this.successAudio.src= '/img/success.mp3'
this.clockAudio.loop = true;
},
globalData: {
//index
userInfo: null,
oepnid: null,
nickName: '',
gameId: 9,
gameInfo: null,
sex: 2,
level: 1, //1-低级;2-高级
practice: false,
//wjl
// 测试年龄段
young: [1, 2, 2, 3, 4, 4],
old: [2, 3, 3, 4, 4, 5],
time1: 0,
time2: 0,
error: 0,
//记录题目难度序列,便于生成题目
level2: [
[1, 2],
[3, 4, 5],
[6, 7, 8],
[9, 10, 11, 12],
[13, 14, 15]
],
// 进入游戏根据年龄随机生成的题库,记录题目id
current: [],
scoreList: [6, 6, 8, 8, 11, 11],
//第一关的分数
A1score: 50,
//第二关分数
A2score: 50,
//skd
authorize:false,
...mockData()
}
})