您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

176 行
3.3KB

  1. // pages/login/login.js
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. showLogin:false,
  9. isLoginIng: false,
  10. canIUse: wx.canIUse('button.open-type.getUserInfo'),
  11. hasUserInfo: false,
  12. },
  13. /**
  14. * 登录
  15. */
  16. checkLogin(e) {
  17. if (this.data.isLoginIng) {
  18. return
  19. }
  20. var data = e.detail.value;
  21. if (data.userName == '') {
  22. wx.showToast({
  23. title: '请先输入账号',
  24. icon: 'none',
  25. duration: 2000
  26. })
  27. } else if (data.password == '') {
  28. wx.showToast({
  29. title: '请先输入密码',
  30. icon: 'none',
  31. duration: 2000
  32. })
  33. } else {
  34. this.setData({
  35. isLoginIng: true
  36. })
  37. this.login(data);
  38. }
  39. },
  40. login(data) {
  41. var data={
  42. account_id: data.userName,
  43. account_password: data.password
  44. }
  45. app.requestPost('register', data,res=>{
  46. this.setData({
  47. isLoginIng: false
  48. })
  49. if(res.code==200){
  50. app.globalData.storeData = res.data;
  51. wx.switchTab({
  52. url: '../home/home'
  53. })
  54. }else{
  55. wx.showToast({
  56. title: res.message,
  57. icon: 'none',
  58. duration: 2000
  59. })
  60. }
  61. })
  62. },
  63. /**
  64. * 生命周期函数--监听页面加载
  65. */
  66. onLoad: function(options) {
  67. var that=this;
  68. wx.hideShareMenu();
  69. if (app.globalData.userInfo) {
  70. this.setData({
  71. hasUserInfo: true
  72. })
  73. } else if (this.data.canIUse) {
  74. // 由于 getUserInfo 是网络请求,可能会在 Page.onLoad 之后才返回
  75. // 所以此处加入 callback 以防止这种情况
  76. app.userInfoReadyCallback = res => {
  77. this.setData({
  78. hasUserInfo: true
  79. })
  80. }
  81. } else {
  82. // 在没有 open-type=getUserInfo 版本的兼容处理
  83. wx.getUserInfo({
  84. success: res => {
  85. app.globalData.userInfo = res.userInfo
  86. this.setData({
  87. hasUserInfo: true
  88. })
  89. }
  90. })
  91. }
  92. if (app.globalData.userState==1){//已注册
  93. wx.switchTab({
  94. url: '../home/home'
  95. })
  96. } else if (app.globalData.userState == -1){
  97. app.userStateReadyCallback = res => {
  98. if(res){
  99. wx.switchTab({
  100. url: '../home/home'
  101. })
  102. }else{
  103. that.setData({
  104. showLogin:true
  105. })
  106. }
  107. }
  108. }
  109. },
  110. /**
  111. * 获取头像昵称
  112. */
  113. getUserInfo: function (e) {
  114. app.globalData.userInfo = e.detail.userInfo
  115. this.setData({
  116. hasUserInfo: true
  117. })
  118. if (e.detail.userInfo){
  119. var userInfo = app.setUserInfo(e.detail.userInfo)
  120. app.requestPost('submit', userInfo,res=>{
  121. console.log(res)
  122. })
  123. }
  124. },
  125. /**
  126. * 生命周期函数--监听页面初次渲染完成
  127. */
  128. onReady: function() {
  129. },
  130. /**
  131. * 生命周期函数--监听页面显示
  132. */
  133. onShow: function() {
  134. },
  135. /**
  136. * 生命周期函数--监听页面隐藏
  137. */
  138. onHide: function() {
  139. },
  140. /**
  141. * 生命周期函数--监听页面卸载
  142. */
  143. onUnload: function() {
  144. },
  145. /**
  146. * 页面相关事件处理函数--监听用户下拉动作
  147. */
  148. onPullDownRefresh: function() {
  149. },
  150. /**
  151. * 页面上拉触底事件的处理函数
  152. */
  153. onReachBottom: function() {
  154. },
  155. /**
  156. * 用户点击右上角分享
  157. */
  158. onShareAppMessage: function() {
  159. }
  160. })