4 Star 2 Fork 1

BlankSpace1 / 打卡小程序界面

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
app.js 3.43 KB
一键复制 编辑 原始数据 按行查看 历史
BlankSpace1 提交于 2018-11-24 15:19 . loc kaoqin
/**
* App() 函数
*
* 用来注册一个小程序。接受一个 object 参数,其指定小程序的生命周期函数等。
*
* @param onLaunch // 当小程序初始化完成时,会触发 onLaunch(全局只触发一次)
* @param onShow // 当小程序启动,或从后台进入前台显示,会触发 onShow
* @param onHide // 当小程序从前台进入后台,会触发 onHide
* @param getUserInfo // 获取用户信息
*/
App({
onLaunch: function() {
// 获取用户信息
// wx.getSetting({
// success: res => {
// if (res.authSetting['scope.userInfo']) {
// // 已经授权,可以直接调用 getUserInfo 获取头像昵称,不会弹框
// wx.getUserInfo({
// success: res => {
// // 可以将 res 发送给后台解码出 unionId
// this.globalData.userInfo = res.userInfo
// // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
// // 所以此处加入 callback 以防止这种情况
// if (this.userInfoReadyCallback) {
// this.userInfoReadyCallback(res)
// }
// }
// })
// }
// }
// })
//测试
console.log('APP-onLaunch 生命周期函数--监听小程序初始化');
},
onShow: function() {
console.log('App-onShow 生命周期函数--监听小程序显示');
},
onHide: function() {
console.log('App-onHide 生命周期函数--监听小程序隐藏');
},
getUserInfo: function(cb) {
var that = this
if (this.globalData.userInfo) {
typeof cb == "function" && cb(this.globalData.userInfo)
} else {
//调用登录接口
wx.login({
success: function(r) {
console.log('Login-----------------------------');
// 获取用户信息
// wx.getUserInfo({
// success: function(res) {
// that.globalData.userInfo = res.userInfo
// typeof cb == "function" && cb(that.globalData.userInfo)
// }
// })
// 查看是否授权
wx.getSetting({
success: function (res) {
if (res.authSetting['scope.userInfo']) {
// 已经授权,可以直接调用 getUserInfo 获取头像昵称
wx.getUserInfo({
success: function (res) {
that.globalData.userInfo = res.userInfo
typeof cb == "function" && cb(that.globalData.userInfo)
//console.log(res.userInfo)
// that.setData({
// userInfo: res.userInfo
// });
// console.log(canIUse)
}
})
} else {
wx.navigateTo({
url: '../../pages/authority/authority'
});
}
}
})
// 获取用户openid
wx.request({
url: 'http://118.24.156.136:8080/attendance/getOpenId',
data: {
'code': r.code
},
method: 'GET',
success: function(res) {
console.log('---code 换取 openid---' + that.globalData.openId);
//wx.setStorageSync('openId', res.data.openid);
wx.setStorageSync('openId', that.globalData.openId);
},
fail:function(){
console.log("fail");
}
})
}
})
}
},
//全局变量
globalData: {
userInfo: null,
openId: 'stu1'
}
})
1
https://gitee.com/BlankSpace1/card_applet_interface.git
git@gitee.com:BlankSpace1/card_applet_interface.git
BlankSpace1
card_applet_interface
打卡小程序界面
master

搜索帮助