index.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. const app = getApp();
  2. const util = require("../../../utils/util.js")
  3. const md5 = require('../../../utils/md5.js');
  4. Page({
  5. data: {
  6. hidden: true,
  7. },
  8. wxLogin( e ){
  9. let {avatarUrl} = e.detail.userInfo;
  10. let that = this
  11. wx.login({
  12. success(wxres) {
  13. if( !wxres.code){
  14. util.showMsg("登入失败")
  15. }else{
  16. that.doLoginByCode( wxres.code, avatarUrl )
  17. }
  18. }
  19. })
  20. },
  21. doLoginByCode( code, avatarUrl ){
  22. app.formPost( "base/wxLogin", {code, avatarUrl}).then( (res)=>{
  23. if( res.code == 200){
  24. app.setUserInfo( res.data )
  25. util.showSuccess("登入成功")
  26. wx.navigateBack({
  27. delta: 1,
  28. })
  29. }
  30. })
  31. },
  32. doIdentify( e ){
  33. let {username, nickname, password} = e.detail.value;
  34. if( !username || !nickname || !password ){
  35. return;
  36. }
  37. let param = {username, nickname}
  38. console.log("param",{username, nickname, password} )
  39. param.password = md5.md5( password ).toLocaleLowerCase();
  40. let that = this
  41. wx.login({
  42. success(wxres) {
  43. if (wxres.code) {
  44. param.code = wxres.code
  45. that.doRegister( param )
  46. }
  47. }
  48. })
  49. },
  50. doRegister( param ){
  51. app.formPost( 'base/register', param).then( res =>{
  52. if( res.code == 200 ){
  53. console.log( "register", res)
  54. app.setUserInfo( res.data )
  55. util.showSuccess("绑定成功")
  56. wx.navigateBack({
  57. delta: 1,
  58. })
  59. }else{
  60. util.showMsg( res.msg )
  61. }
  62. })
  63. }
  64. })