login.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. // pages/login/login.js
  2. Page({
  3. /**
  4. * 页面的初始数据
  5. */
  6. data: {
  7. openid:'',
  8. username:'',
  9. password:'',
  10. userInfo: {},
  11. // hasUserInfo: false,
  12. // canIUse: wx.canIUse('button.open-type.getUserInfo'),
  13. // canIUseGetUserProfile: false,
  14. // canIUseOpenData: wx.canIUse('open-data.type.userAvatarUrl') && wx.canIUse('open-data.type.userNickName') // 如需尝试获取用户信息可改为false
  15. },
  16. onClickIcon(){
  17. },
  18. async handleLogin () {
  19. let app = getApp();
  20. let openid = app.globalData.openID;
  21. await wx.p.request({
  22. url: `${app.globalData.url}wx/wxLogin`,
  23. method:'POST',
  24. data:{account: this.data.username,
  25. password:this.data.password,
  26. openid
  27. }
  28. }).then(res=>{
  29. if(res.data.code==200){
  30. wx.showToast({
  31. title:res.data.msg ,
  32. })
  33. wx.redirectTo({
  34. url: '../zero/zero',
  35. })
  36. }else{
  37. wx.showModal({
  38. content: res.data.msg,
  39. showCancel:false,
  40. confirmText:'返回'
  41. })
  42. }
  43. })
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad(options) {
  49. },
  50. /**
  51. * 生命周期函数--监听页面初次渲染完成
  52. */
  53. onReady() {
  54. let app = getApp();
  55. this.setData({
  56. username:app.globalData.phoneNumber
  57. })
  58. },
  59. /**
  60. * 生命周期函数--监听页面显示
  61. */
  62. onShow() {
  63. },
  64. /**
  65. * 生命周期函数--监听页面隐藏
  66. */
  67. onHide() {
  68. },
  69. /**
  70. * 生命周期函数--监听页面卸载
  71. */
  72. onUnload() {
  73. },
  74. /**
  75. * 页面相关事件处理函数--监听用户下拉动作
  76. */
  77. onPullDownRefresh() {
  78. },
  79. /**
  80. * 页面上拉触底事件的处理函数
  81. */
  82. onReachBottom() {
  83. },
  84. /**
  85. * 用户点击右上角分享
  86. */
  87. onShareAppMessage() {
  88. },
  89. // getUserProfile(e) {
  90. // // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  91. // wx.getUserProfile({
  92. // desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  93. // success: (res) => {
  94. // console.log(res)
  95. // this.setData({
  96. // userInfo: res.userInfo,
  97. // hasUserInfo: true
  98. // })
  99. // }
  100. // })
  101. // },
  102. // getUserInfo(e) {
  103. // // 不推荐使用getUserInfo获取用户信息,预计自2021年4月13日起,getUserInfo将不再弹出弹窗,并直接返回匿名的用户个人信息
  104. // console.log(e)
  105. // this.setData({
  106. // userInfo: e.detail.userInfo,
  107. // hasUserInfo: true
  108. // })
  109. // }
  110. })