1 Star 0 Fork 10

刘春光 / wx-spark-shop

forked from polaris.wang / wx-spark-shop 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
app.js 1.57 KB
一键复制 编辑 原始数据 按行查看 历史
polaris.wang 提交于 2021-01-27 18:02 . 完善代码
var http = require('utils/http.js');
App({
onLaunch: function () {
http.getToken();
// 获取用户信息
wx.getSetting({
success: res => {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
wx.getUserInfo({
success: res => {
// 可以将 res 发送给后台解码出 unionId
this.globalData.userInfo = res.userInfo
var ths = this;
var params = {
url: "/userApi",
method: "POST",
data:{
id: wx.getStorageSync('userId'),
nickname: ths.globalData.userInfo.nickname,
avatar: ths.globalData.userInfo.avatarUrl
},
callBack: function (res) {
ths.globalData.userInfo['userTypeName'] = res.data.userTypeName
ths.globalData.userInfo['createDate'] = res.data.createDate
}
};
http.request(params);
// 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// 所以此处加入 callback 以防止这种情况
if (this.userInfoReadyCallback) {
this.userInfoReadyCallback(res)
}
}
})
}
}
})
},
globalData: {
appId: 'wx28480e43e3e8636f',
// 定义全局请求队列
requestQueue: [],
// 是否正在进行登陆
isLanding: false,
userInfo: null
}
})
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/liuchunguang72_admin/wx-spark-shop.git
git@gitee.com:liuchunguang72_admin/wx-spark-shop.git
liuchunguang72_admin
wx-spark-shop
wx-spark-shop
master

搜索帮助

344bd9b3 5694891 D2dac590 5694891