123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- //app.js
- var server = require('/libs/config.js');
- App({
- onLaunch: function () {
- // 展示本地存储能力
- var logs = wx.getStorageSync('logs') || []
- logs.unshift(Date.now())
- wx.setStorageSync('logs', logs)
-
- // 登录
- wx.login({
- success: res => {
- console.info(server.Server.url)
- // 发送 res.code 到后台换取 openId, sessionKey, unionId
- this.globalData.code=res.code
-
- wx.request({
- url: server.Server.url +'/api/user/checkOpenId',
- //url: 'https://www.easy-mock.com/mock/59c0bb01e0dc663341af8b9f/gugnv/userInfo',
- data:{
- code:res.code
- },
- success: function (res) {
-
- console.log(res);
- if (res.statusCode=='404'){//如果验证已经注册过,免登录进入
- wx.showToast({
- title: '服务器中断',
- icon: 'success',
- duration: 2000
- })
- }else if(res.data.errorCode=='60001'){//进入注册页面
- wx.redirectTo({
- url: '/pages/index/index',
- })
- } else if (res.data.errorCode == '0'){//已经注册过
- //保存用户id到全局变量
-
- wx.redirectTo({
- url: '/pages/txmap/index?userId=' + res.data.data.userId,
- })
- }else{
- wx.showToast({
- title: 'Bad:'+res.statusCode,
- icon: 'success',
- duration: 2000
- })
- }
-
-
- }
- })
-
- }
- })
- // 获取用户信息
- 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)
- }
- }
- })
- }
- }
- })
- },
- globalData: {
- userInfo: null,
- server:server,
- userId:'',
- deptData:null,
- code:'',
- nwUserid:''
- }
- })
|