accountLogin.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. // pages/authorizedLogin/authorizedLogin.js
  2. var http = require('../../utils/http')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. principal: '',
  9. credentials: '',
  10. },
  11. /**
  12. * 输入框的值
  13. */
  14. getInputVal: function(e) {
  15. const type = e.currentTarget.dataset.type
  16. if (type == 'account') {
  17. this.setData({
  18. principal: e.detail.value
  19. })
  20. } else if (type == 'password') {
  21. this.setData({
  22. credentials: e.detail.value
  23. })
  24. }
  25. },
  26. /**
  27. * 登录
  28. */
  29. login() {
  30. if(!this.data.principal.trim()){
  31. wx.showToast({
  32. title: '请输入账号',
  33. icon: 'none'
  34. })
  35. return
  36. }if(!this.data.credentials.trim()){
  37. wx.showToast({
  38. title: '请输入密码',
  39. icon: 'none'
  40. })
  41. return
  42. }
  43. wx.login({
  44. success: (res) => {
  45. var params = {
  46. url: "/login",
  47. method: "post",
  48. data: {
  49. appType: 1,
  50. credentials: this.data.credentials,
  51. loginType: 0,
  52. principal: this.data.principal + ':' + res.code
  53. },
  54. callBack: result => {
  55. http.loginSuccess(result)
  56. wx.switchTab({
  57. url: '/pages/index/index'
  58. })
  59. },
  60. }
  61. http.request(params)
  62. },
  63. })
  64. },
  65. /**
  66. * 去注册
  67. */
  68. toRegitser: function() {
  69. console.log('去注册')
  70. wx.navigateTo({
  71. url: "/pages/register/register"
  72. })
  73. },
  74. /**
  75. * 生命周期函数--监听页面加载
  76. */
  77. onLoad: function(options) {
  78. },
  79. /**
  80. * 生命周期函数--监听页面初次渲染完成
  81. */
  82. onReady: function() {
  83. },
  84. /**
  85. * 生命周期函数--监听页面显示
  86. */
  87. onShow: function() {
  88. },
  89. /**
  90. * 生命周期函数--监听页面隐藏
  91. */
  92. onHide: function() {
  93. },
  94. /**
  95. * 生命周期函数--监听页面卸载
  96. */
  97. onUnload: function() {
  98. },
  99. /**
  100. * 页面相关事件处理函数--监听用户下拉动作
  101. */
  102. onPullDownRefresh: function() {
  103. },
  104. /**
  105. * 页面上拉触底事件的处理函数
  106. */
  107. onReachBottom: function() {
  108. },
  109. /**
  110. * 用户点击右上角分享
  111. */
  112. onShareAppMessage: function() {
  113. }
  114. })