1. Registration Authority
Where needed query is logged, and I was here in the home of onready
the onReady: function () { // if the authorization wx.getSetting ({ Success: RES => { IF (res.authSetting [ 'scope.userInfo']) { // has authorized, can directly call getUserInfo nickname acquisition head, not playing block console.log ( "has authorized"); wx.getUserInfo ({ Success: function (RES) { app.globalData.userInfo res.userInfo = } }) } the else { console.log ( "Jump unauthorized login" ); wx.navigateTo ({ URL: '/ Pages / Login / Login', }) } } }) },
// I do not have personal information stored in the cache, the cache can be stored and then be judged by whether a user is authorized to cache information
Login interface has a login button
<button class='login-btn' open-type='getUserInfo' lang='zh_CN' bindgetuserinfo='onGotUserInfo' hover-class='btn-hover' >微信登录</button>
Click method:
onGotUserInfo: function (E) { the console.log ( 'errMsg An:' + e.detail.errMsg) the console.log (+ e.detail.userInfo) the console.log ( 'the rawData:' + e.detail.rawData) IF ( e.detail.userInfo) { the console.log ( 'clicked authorization') app.globalData.userInfo = e.detail.userInfo wx.login ({ Success: function (RES) { the console.log (RES) // temporary return certificate acquisition code passed back and openid session_key of wx.request ({ URL: 'testurl', Data: { code: res.code }, Method: 'the POST', header: { 'Content-type': 'application / json '// Default }, Success:function(res){ the console.log (RES) } }) } }) } {the else the console.log ( 'rejected authorization') } wx.navigateBack ({ }) },
2. The use of sound
URL directly innerAudioContext play will be delayed, experience is poor, resources can be stored in the cache, to play by PATH
globaldata in:
home_btn:'', next_question:'', wrong_1:'', wrong_2: '', right_1:'', right_2:'', unit_pass_1:'', unit_pass_2:'', unit_pass_3:'', unit_fail:'', game_pass_1:'', game_pass_2:'', game_pass_3:'', game_fail:'',
onLaunch in:
self.saveAudioFile('home_btn') self.saveAudioFile('next_question')
saveAuidoFile method:
saveAudioFile: function (fileName) { var = Self the this; // first determine whether there is a cache wx.getStorage ({ Key: fileName, Success: function (RES) { // exists directly assigned to GlobalData self.globalData [fileName] res.data = }, Fail: function (RES) { // do not exist, the tone into the local cache wx.downloadFile ({ URL: self.globalData.audioHeader + + fileName '.mp3', Success (RES) { wx.saveFile ({ the Tempfilepath: res.tempFilePath, Success (RES) { wx.setStorage ({ Key: fileName, Data: res.savedFilePath, }) //赋值给globaldata self.globalData[fileName] = res.savedFilePath }, fail(res) { console.log(res) } }) } }) } }) },
Play:
pointAudioPlay: function (name){ innerAudioContext.src = app.globalData.home_btn innerAudioContext.play() },
Very convenient also very effective!