小程序-app.js
// app.js
const config = require('/config.js');
const util = require('/utils/util.js');
App({
onLaunch() {
// 展示本地存储能力
const logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
const self = this
// 登录
wx.login({
success: res => {
console.log(res)
// 发送 res.code 到后台换取 openId, sessionKey, unionId
if (res.code) {
//发起网络请求
util.requestWithSess({
method: 'POST',
url: self.globalData.apiBaseUrl + '/onlogin',
data: {
code: res.code
},
success: res => {
wx.showToast({
icon: 'none',
title: '登陆成功',
})
self.globalData.userInfo.uuid = res.data.data.uuid;
self.globalData.userInfo.nickName = res.data.data.nickName;
if (this.onLanchCallbackFn) {
// 如果有说明,onLoad中没有拿到值,把结果当参数再传入回调中
this.onLanchCallbackFn(res.data.data);
}
}
})
} else {
console.log('登录失败!' + res.errMsg)
}
}
})
},
globalData: {
cookie: null,
userInfo: {uuid : null, nickName:null},
resBaseUrl: config.baseUrl + '/asssets',
apiBaseUrl: config.baseUrl,
},
})
网友评论