index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. const util = require('../../utils/util.js');
  2. const app = getApp()
  3. Page({
  4. data: {
  5. imgUrls: [
  6. "../../images/home/banner_1.png",
  7. "../../images/home/banner_2.png",
  8. "../../images/home/banner_3.png",
  9. ],
  10. routers: [
  11. {
  12. name: '填写日报',
  13. url: '../report/edit',
  14. img: '../../images/home/edit.png'
  15. },
  16. {
  17. name: '审核日报',
  18. url: '',
  19. img: '../../images/home/check.png'
  20. },
  21. {
  22. name: '我的信息',
  23. url: '',
  24. img: '../../images/home/my.png'
  25. },
  26. {
  27. name: '暂无更多',
  28. url: '',
  29. img: '../../images/home/more.png'
  30. }
  31. ],
  32. disabled: false, //按钮是否禁用
  33. click: true,
  34. },
  35. onLoad: function () {
  36. },
  37. // 获取输入的值
  38. getValue_username: function (e) {
  39. this.setData({
  40. username: e.detail.value
  41. })
  42. },
  43. getValue_password: function (e) {
  44. this.setData({
  45. password: e.detail.value
  46. })
  47. },
  48. // 登录
  49. formSubmitHandle: function (e) {
  50. if (this.data.username == "") {
  51. wx.showToast({
  52. title: '账号不能为空',
  53. icon: 'none',
  54. duration: 1000
  55. })
  56. return false;
  57. } else if (this.data.password == "") {
  58. wx.showToast({
  59. title: '密码不能为空',
  60. icon: 'none',
  61. duration: 1000
  62. })
  63. return false;
  64. } else {
  65. if (this.data.click) {
  66. var that = this;
  67. that.setData({ click: false });
  68. wx.login({
  69. success: res => {
  70. wx.request({
  71. url: app.globalData.serverUrl + "/user/loginAdmin",
  72. method: "POST",
  73. data: {
  74. username: that.data.username,
  75. password: that.data.password,
  76. },
  77. header: {
  78. "Content-Type": "application/x-www-form-urlencoded"
  79. },
  80. success: function (res) {
  81. if (res.data.code == "ok") {
  82. wx.showToast({
  83. title: '登录成功',
  84. icon: 'success',
  85. duration: 2000
  86. })
  87. wx.setStorageSync('userInfo', res.data.data);
  88. setTimeout(function () {
  89. wx.reLaunch({
  90. url: '../cloud/cloud'
  91. })
  92. }, 200)
  93. } else {
  94. that.setData({ click: true })
  95. wx.showToast({
  96. title: res.data.msg,
  97. icon: 'none',
  98. duration: 2000
  99. })
  100. }
  101. },
  102. fail: function (res) {
  103. that.setData({ click: true })
  104. wx.showToast({
  105. title: '登录失败!',
  106. icon: 'none',
  107. duration: 2000
  108. })
  109. }
  110. })
  111. }
  112. })
  113. } else {
  114. wx.showToast({
  115. title: '登录中,请勿重复点击',
  116. icon: 'none',
  117. duration: 1000
  118. })
  119. }
  120. }
  121. }
  122. })