me.js 3.4 KB

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