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.
58 lines
1.8 KiB
58 lines
1.8 KiB
var api = require('../../utils/api.js')
|
|
var global = require('../../utils/config.js')
|
|
const app = getApp()
|
|
Page({
|
|
data: {
|
|
webUrl: '',
|
|
gid: '' // 网格ID
|
|
},
|
|
onLoad: function (options) {
|
|
//上级页面传递过来的gid
|
|
if(options.gid){
|
|
this.setData({
|
|
gid: options.gid
|
|
})
|
|
}
|
|
this.getUserState()
|
|
},
|
|
// 根据微信code查询用户当前状态
|
|
getUserState: function () {
|
|
let that = this
|
|
wx.login({
|
|
success(res) {
|
|
if (res.code) {
|
|
let code = res.code
|
|
let date = Date.parse(new Date())
|
|
api.getToken(code).then(function(res){
|
|
let state = res.data.userState
|
|
wx.login({
|
|
success(res2) {
|
|
if (state==0) { //已注册,跳转到首页
|
|
that.setData({
|
|
webUrl: global.WEBROOT() + 'home?token='+res.data.token+'&grid='+encodeURIComponent(res.data.grid)+'&t='+date+''
|
|
})
|
|
console.log('webUrl', that.data.webUrl)
|
|
} else if(state==1) { //未注册,跳到我要注册页面
|
|
that.setData({
|
|
webUrl: global.WEBROOT() + 'register/'+res2.code+'/'+that.data.gid+'?t='+date+''
|
|
})
|
|
} else if(state==2) { //注册审核中
|
|
that.setData({
|
|
webUrl: global.WEBROOT() + 'registerAudit?state=2&t='+date+''
|
|
})
|
|
} else if(state==3) { //注册审核失败
|
|
that.setData({
|
|
webUrl: global.WEBROOT() + 'register/'+res2.code+'/'+that.data.gid+'?t='+date+''
|
|
})
|
|
|
|
}
|
|
}
|
|
})
|
|
})
|
|
} else {
|
|
console.log('登录失败' + res.errMsg)
|
|
}
|
|
}
|
|
})
|
|
}
|
|
})
|
|
|