You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

login.js 4.0KB

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