index.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //index.js
  2. const util = require("../../utils/util")
  3. const md5 = require("../../utils/md5")
  4. //获取应用实例
  5. const app = getApp()
  6. Page({
  7. data: {
  8. buyModel:false,
  9. system: "",
  10. username:'',
  11. password:'',
  12. userInfo:{},
  13. },
  14. onLoad: function(){
  15. let that = this
  16. app.checkLogin(res=>{
  17. console.log("login", res)
  18. })
  19. },
  20. wxLogin(){
  21. let that = this
  22. wx.login({
  23. success(wxres) {
  24. if( !wxres.code){
  25. util.showMsg("登入失败")
  26. }else{
  27. that.doLoginByCode( wxres.code )
  28. }
  29. }
  30. })
  31. },
  32. doLoginByCode( code ){
  33. app.formPost( "Auth.WxLogin", {code}).then( (res)=>{
  34. if( res.code == 200){
  35. this.setData( {userInfo: res.data})
  36. app.setUserInfo( res.data )
  37. this.goDefaultPage()
  38. }
  39. })
  40. },
  41. register( e ){
  42. let that = this
  43. wx.login({
  44. success(wxres) {
  45. if (wxres.code) {
  46. that.doRegister( wxres.code, e.detail.value )
  47. }
  48. }
  49. })
  50. },
  51. doRegister( code, info ){
  52. let param = {
  53. code: code,
  54. username: info.username,
  55. password: md5.md5(info.password).toLowerCase(),
  56. }
  57. app.formPost( 'Auth.Register', param).then( res =>{
  58. if( res.code == 200 ){
  59. let studyUser= res.data
  60. app.setUserInfo( studyUser )
  61. util.showSuccess("实名认证成功")
  62. this.goDefaultPage()
  63. this.setData({studyUser})
  64. }else{
  65. util.showMsg( res.msg )
  66. }
  67. })
  68. },
  69. onPullDownRefresh() {
  70. if (!this.loading) {
  71. this.indexLoad( this.stopPullDownRefresh )
  72. }
  73. },
  74. goDefaultPage(){
  75. wx.switchTab({
  76. url: '/pages/rili/index',
  77. })
  78. },
  79. onShareAppMessage: function(){
  80. }
  81. })