me.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. import http from '../../base/httputil'
  2. const app = getApp()
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. isShowAccoutDialog : false,
  9. isBindSuccess : false,
  10. userInfo:null,
  11. userName :"点击登录",
  12. password: null,
  13. openid: null
  14. },
  15. inputUserName(e){
  16. this.userName = e.detail.value
  17. },
  18. inputPassword(e){
  19. this.password = e.detail.value
  20. },
  21. init_userInfo() {
  22. let that = this
  23. if (app.globalToken == null) {
  24. wx.getUserProfile({
  25. desc: 'desc',
  26. success: (res) => {
  27. this.getSysUserInfo(res.userInfo)
  28. that.setData({
  29. userInfo : res.userInfo
  30. })
  31. },
  32. fail: res => {
  33. console.log(res)
  34. },
  35. })
  36. }
  37. },
  38. getSysUserInfo(info) {
  39. let that = this
  40. wx.login({
  41. success(res) {
  42. var code = res.code
  43. var data = {
  44. wxCode: code,
  45. wxNickName: info.nickName,
  46. wxAvatarUrl: info.avatarUrl
  47. }
  48. http.send_post("/auth/applogin", data, that.loginSuccess)
  49. },
  50. fail(res) {
  51. console.log("ffff", res)
  52. }
  53. })
  54. },
  55. loginSuccess(res) {
  56. let that = this
  57. if (res.code != 200) {
  58. that.openid = res.openid
  59. wx.showToast({
  60. title: res.msg,
  61. icon: "none"
  62. })
  63. // http.hideLoading()
  64. that.setData({
  65. isShowAccoutDialog : true
  66. })
  67. } else {
  68. app.globalToken = res.data.access_token
  69. console.log("登陆成功的令牌:",app.globalToken )
  70. //登录成功,获取首页数据
  71. // http.hideLoading()
  72. this.setData({
  73. isBindSuccess : true
  74. })
  75. }
  76. },
  77. clear(){
  78. wx.clearStorage({
  79. success: (res) => {
  80. wx.showToast({
  81. title: '清理成功',
  82. })
  83. wx.removeStorageSync('userInfo');
  84. wx.removeStorageSync('openid');
  85. app.globalToken=null;
  86. this.setData({
  87. isShowAccoutDialog : false,
  88. isBindSuccess : false,
  89. userInfo:null,
  90. userName :"游客",
  91. password: null,
  92. openid: null
  93. })
  94. wx.reLaunch({
  95. url: '../denglu/denglu'
  96. })
  97. },
  98. })
  99. },
  100. modalCancel(){
  101. this.setData({
  102. isShowAccoutDialog : false
  103. })
  104. },
  105. modalSubmit(){
  106. let obj = new Object()
  107. obj.openid = this.openid
  108. obj.userName = this.userName
  109. obj.password = this.password
  110. http.send_post("/system/minapp/AppLoginController/bindWxUser",obj,this.modalSubmitSuccess)
  111. },
  112. modalSubmitSuccess(res){
  113. wx.showToast({
  114. title: res.msg,
  115. icon: "none"
  116. })
  117. if (res.code == 200) {
  118. this.setData({
  119. isShowAccoutDialog : false,
  120. isBindSuccess : true
  121. })
  122. }
  123. },
  124. /**
  125. * 生命周期函数--监听页面加载
  126. */
  127. onLoad(options) {
  128. },
  129. /**
  130. * 生命周期函数--监听页面初次渲染完成
  131. */
  132. onReady() {
  133. },
  134. /**
  135. * 生命周期函数--监听页面显示
  136. */
  137. onShow() {
  138. },
  139. /**
  140. * 生命周期函数--监听页面隐藏
  141. */
  142. onHide() {
  143. },
  144. /**
  145. * 生命周期函数--监听页面卸载
  146. */
  147. onUnload() {
  148. },
  149. /**
  150. * 页面相关事件处理函数--监听用户下拉动作
  151. */
  152. onPullDownRefresh() {
  153. },
  154. /**
  155. * 页面上拉触底事件的处理函数
  156. */
  157. onReachBottom() {
  158. },
  159. /**
  160. * 用户点击右上角分享
  161. */
  162. onShareAppMessage() {
  163. }
  164. })