login.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. // pages/login/login.js
  2. const app=getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. showEyes: false,
  9. form: {
  10. phone: "",
  11. password: ''
  12. },
  13. phone: ''
  14. },
  15. /**
  16. * 生命周期函数--监听页面加载
  17. */
  18. onLoad: function (options) {
  19. const token = wx.getStorageSync('token')
  20. console.log(token);
  21. if (!token || token == '') {
  22. wx.setNavigationBarTitle({
  23. title: '分拣系统',
  24. })
  25. }else{
  26. wx.switchTab({
  27. url: '/pages/tabber/home/index',
  28. })
  29. }
  30. },
  31. onReady(){
  32. },
  33. close() {
  34. this.data.form.phone = ''
  35. this.setData({
  36. phone: ''
  37. })
  38. console.log(this.data.phone);
  39. },
  40. inputValue1(e) {
  41. let { value } = e.detail
  42. this.data.form.phone = value
  43. this.setData({
  44. phone: value
  45. })
  46. console.log(this.data.phone);
  47. },
  48. inputValue2(e) {
  49. let { value } = e.detail
  50. this.data.form.password = value
  51. },
  52. changeEyes() {
  53. this.setData({
  54. showEyes: !this.data.showEyes
  55. })
  56. },
  57. login() {
  58. var that=this;
  59. var phone=this.data.form.phone
  60. var password=this.data.form.password
  61. if(!phone){
  62. wx.showLoading({
  63. title: '手机号必填',
  64. })
  65. setTimeout(function () {
  66. wx.hideLoading();
  67. }, 1000);
  68. return false;
  69. }
  70. if(!password){
  71. wx.showLoading({
  72. title: '密码必填',
  73. })
  74. setTimeout(function () {
  75. wx.hideLoading();
  76. }, 1000);
  77. return false;
  78. }
  79. app.api.useApi(app.globalData.baseAppUrl + "api/admin/login", {
  80. phone:this.data.form.phone,
  81. password: this.data.form.password,
  82. appid:wx.getAccountInfoSync().miniProgram.appId
  83. }, "post").then(function (res) {
  84. wx.showLoading({
  85. title: '登录中',
  86. })
  87. console.log(res);
  88. if (res.code != 200) {
  89. wx.showLoading({
  90. title: '登录失败',
  91. })
  92. setTimeout(function () {
  93. wx.hideLoading();
  94. }, 2000);
  95. } else {
  96. wx.hideLoading();
  97. wx.setStorageSync('token', res.message.data.access_token);
  98. wx.switchTab({
  99. url: '/pages/tabber/home/index',
  100. })
  101. }
  102. }).catch(function (err) {
  103. console.log(222);
  104. })
  105. }
  106. })