1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- const app = getApp();
- const util = require("../../../utils/util.js")
- const md5 = require('../../../utils/md5.js');
- Page({
- data: {
- hidden: true,
- },
- wxLogin( e ){
- let {avatarUrl} = e.detail.userInfo;
- let that = this
- wx.login({
- success(wxres) {
- if( !wxres.code){
- util.showMsg("登入失败")
- }else{
- that.doLoginByCode( wxres.code, avatarUrl )
- }
- }
- })
- },
- doLoginByCode( code, avatarUrl ){
- app.formPost( "base/wxLogin", {code, avatarUrl}).then( (res)=>{
- if( res.code == 200){
- app.setUserInfo( res.data )
- util.showSuccess("登入成功")
- wx.navigateBack({
- delta: 1,
- })
- }
- })
- },
- doIdentify( e ){
- let {username, nickname, password} = e.detail.value;
- if( !username || !nickname || !password ){
- return;
- }
- let param = {username, nickname}
- console.log("param",{username, nickname, password} )
- param.password = md5.md5( password ).toLocaleLowerCase();
- let that = this
- wx.login({
- success(wxres) {
- if (wxres.code) {
- param.code = wxres.code
- that.doRegister( param )
- }
- }
- })
- },
- doRegister( param ){
- app.formPost( 'base/register', param).then( res =>{
- if( res.code == 200 ){
- console.log( "register", res)
- app.setUserInfo( res.data )
- util.showSuccess("绑定成功")
- wx.navigateBack({
- delta: 1,
- })
- }else{
- util.showMsg( res.msg )
- }
- })
- }
- })
|