//index.js const util = require("../../utils/util") const md5 = require("../../utils/md5") //获取应用实例 const app = getApp() Page({ data: { buyModel:false, system: "", username:'', password:'', userInfo:{}, }, onLoad: function(){ let that = this app.checkLogin(res=>{ console.log("login", res) }) }, wxLogin(){ let that = this wx.login({ success(wxres) { if( !wxres.code){ util.showMsg("登入失败") }else{ that.doLoginByCode( wxres.code ) } } }) }, doLoginByCode( code ){ app.formPost( "Auth.WxLogin", {code}).then( (res)=>{ if( res.code == 200){ this.setData( {userInfo: res.data}) app.setUserInfo( res.data ) this.goDefaultPage() } }) }, register( e ){ let that = this wx.login({ success(wxres) { if (wxres.code) { that.doRegister( wxres.code, e.detail.value ) } } }) }, doRegister( code, info ){ let param = { code: code, username: info.username, password: md5.md5(info.password).toLowerCase(), } app.formPost( 'Auth.Register', param).then( res =>{ if( res.code == 200 ){ let studyUser= res.data app.setUserInfo( studyUser ) util.showSuccess("实名认证成功") this.goDefaultPage() this.setData({studyUser}) }else{ util.showMsg( res.msg ) } }) }, onPullDownRefresh() { if (!this.loading) { this.indexLoad( this.stopPullDownRefresh ) } }, goDefaultPage(){ wx.switchTab({ url: '/pages/rili/index', }) }, onShareAppMessage: function(){ } })