You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
76 lines
2.0 KiB
76 lines
2.0 KiB
var util = require('./utils/util.js');
|
|
var api = require('./config/api.js');
|
|
var user = require('./services/user.js');
|
|
|
|
App({
|
|
onLaunch: function () {
|
|
|
|
// 获取用户信息
|
|
wx.getSetting({
|
|
success: res => {
|
|
if (res.authSetting['scope.userInfo']) {
|
|
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
|
|
wx.getUserInfo({
|
|
success: res => {
|
|
console.log('success');
|
|
// 可以将 res 发送给后台解码出 unionId
|
|
this.globalData.userInfo = res.userInfo
|
|
|
|
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
|
|
// 所以此处加入 callback 以防止这种情况
|
|
if (this.userInfoReadyCallback) {
|
|
this.userInfoReadyCallback(res)
|
|
}
|
|
},
|
|
fail: error => {
|
|
console.log('error:');
|
|
}
|
|
})
|
|
}
|
|
}
|
|
});
|
|
|
|
wx.login({
|
|
success: function (res) {
|
|
console.log('登录成功' + res);
|
|
if (res.code) {
|
|
//发起网络请求
|
|
wx.request({
|
|
url: 'https://mp.fengyuexingzi.top/api/login',
|
|
data: {
|
|
code: res.code
|
|
},
|
|
success: res => {
|
|
console.log(res);
|
|
},
|
|
fail: error => {
|
|
console.log(error)
|
|
}
|
|
})
|
|
} else {
|
|
console.log('登录失败!' + res.errMsg)
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
// //获取用户的登录信息
|
|
// user.checkLogin().then(res => {
|
|
// console.log('app login')
|
|
// this.globalData.userInfo = wx.getStorageSync('userInfo');
|
|
// this.globalData.token = wx.getStorageSync('token');
|
|
// }).catch(() => {
|
|
|
|
// });
|
|
|
|
},
|
|
|
|
globalData: {
|
|
userInfo: {
|
|
nickname: '游客',
|
|
username: '去登录',
|
|
avatar: 'http://mp.fengyuexingzi.top/images/default_head.png'
|
|
},
|
|
token: '',
|
|
}
|
|
}) |