denglu.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import http from '../../base/httputil'
  2. const app = getApp()
  3. // pages/denglu/denglu.js
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. userName: "",
  10. password: "",
  11. wxCode: "",
  12. openid: "",
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad(options) {
  18. app.isLoginSuccess = false;
  19. let that = this;
  20. wx.login({
  21. success(res) {
  22. that.data.wxCode = res.code
  23. that.getOpenIdBywxCode()
  24. },
  25. fail(res) {
  26. }
  27. })
  28. },
  29. bindViewlogin() {
  30. if (this.data.userName == null || this.data.userName == '') {
  31. wx.showToast({
  32. title: '请输入用户名',
  33. icon: 'none',
  34. duration: 2000
  35. })
  36. return
  37. }
  38. if (this.data.password == null || this.data.password == '') {
  39. wx.showToast({
  40. title: '请输入密码',
  41. icon: 'none',
  42. duration: 2000
  43. })
  44. return
  45. }
  46. let that = this;
  47. var data = {
  48. userName: this.data.userName,
  49. password: this.data.password,
  50. openid: this.data.openid,
  51. }
  52. http.post_token("/system/minapp/AppLoginController/bindWxUser", data, that.bindSuccess)
  53. },
  54. bindSuccess(res) {
  55. let that = this
  56. if (res.code != 200) {
  57. wx.showToast({
  58. title: res.msg,
  59. icon: "none"
  60. })
  61. // that.setData({
  62. // isShowAccoutDialog : true
  63. // })
  64. } else {
  65. // that.data.openid = res.openid
  66. app.globalToken = res.data.access_token,
  67. wx.setStorageSync('userName', that.data.userName),
  68. wx.setStorageSync('password', that.data.password),
  69. app.isLoginSuccess = true
  70. this.setData({
  71. isBindSuccess: true,
  72. })
  73. wx.reLaunch({
  74. url: '../index/index',
  75. })
  76. }
  77. },
  78. bindViewUserName(e) {
  79. this.data.userName = e.detail.value
  80. },
  81. bindViewPassword(e) {
  82. this.data.password = e.detail.value
  83. },
  84. getOpenIdBywxCode() {
  85. let that = this
  86. var data = {
  87. wxCode: that.data.wxCode,
  88. }
  89. http.post_token("/system/minapp/AppLoginController/getSessionKeyOropenid", data, this.openIdSuccess)
  90. },
  91. openIdSuccess(res) {
  92. let that = this
  93. if (res != null && res.openid != null) {
  94. that.data.openid = res.openid
  95. // wx.setStorageSync('openid', res.openid)
  96. }
  97. },
  98. /**
  99. * 生命周期函数--监听页面初次渲染完成
  100. */
  101. onReady() {
  102. },
  103. /**
  104. * 生命周期函数--监听页面显示
  105. */
  106. onShow() {
  107. },
  108. /**
  109. * 生命周期函数--监听页面隐藏
  110. */
  111. onHide() {
  112. },
  113. /**
  114. * 生命周期函数--监听页面卸载
  115. */
  116. onUnload() {
  117. },
  118. /**
  119. * 页面相关事件处理函数--监听用户下拉动作
  120. */
  121. onPullDownRefresh() {
  122. },
  123. /**
  124. * 页面上拉触底事件的处理函数
  125. */
  126. onReachBottom() {
  127. },
  128. /**
  129. * 用户点击右上角分享
  130. */
  131. onShareAppMessage() {
  132. }
  133. })