index.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. const util = require('../../utils/util.js');
  2. const { $Toast } = require('../../dist/base/index');
  3. const app = getApp()
  4. Page({
  5. data: {
  6. username: '',
  7. password: '',
  8. disabled: false, //按钮是否禁用
  9. click: true,
  10. },
  11. onLoad: function () {
  12. },
  13. // 获取输入的值
  14. getValue_username: function (e) {
  15. this.setData({
  16. username: e.detail.value
  17. })
  18. },
  19. getValue_password: function (e) {
  20. this.setData({
  21. password: e.detail.value
  22. })
  23. },
  24. // 登录
  25. formSubmitHandle: function (e) {
  26. if (this.data.username == "") {
  27. $Toast({
  28. content: '账号不能为空',
  29. type: 'warning',
  30. duration: 1
  31. })
  32. return false;
  33. } else if (this.data.password == "") {
  34. $Toast({
  35. content: '密码不能为空',
  36. type: 'warning',
  37. duration: 1
  38. })
  39. return false;
  40. } else {
  41. if (this.data.click) {
  42. var that = this;
  43. that.setData({ click: false });
  44. wx.request({
  45. url: app.globalData.serverUrl + "/user/loginAdmin",
  46. method: "POST",
  47. data: {
  48. username: that.data.username,
  49. password: that.data.password,
  50. },
  51. header: {
  52. "Content-Type": "application/x-www-form-urlencoded"
  53. },
  54. success: function (res) {
  55. if (res.data.code == "ok") {
  56. $Toast({
  57. content: '登录成功',
  58. type: 'success',
  59. duration: 2
  60. })
  61. wx.setStorageSync('userInfo', res.data.data);
  62. setTimeout(function () {
  63. wx.reLaunch({
  64. url: '../home/index'
  65. })
  66. }, 200)
  67. } else {
  68. that.setData({ click: true })
  69. $Toast({
  70. content: res.data.msg,
  71. type: 'error',
  72. duration: 2
  73. })
  74. }
  75. },
  76. fail: function (res) {
  77. that.setData({ click: true })
  78. $Toast({
  79. content: '登录失败!',
  80. type: 'error',
  81. duration: 2
  82. })
  83. }
  84. })
  85. } else {
  86. $Toast({
  87. content: '登录中,请勿重复点击',
  88. type: 'loading',
  89. duration: 1
  90. })
  91. }
  92. }
  93. }
  94. })