Land.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. const app = getApp();
  2. Page({
  3. data: {
  4. user: '', // 账号
  5. password: '', // 密码
  6. qtzh:"手机号码",
  7. qtPassword:"密码",
  8. color1:"",
  9. color2:"",
  10. inputValue1: null,
  11. inputValue2: null,
  12. },
  13. /**
  14. * 生命周期函数--监听页面加载
  15. */
  16. onLoad: function (options) {
  17. setTimeout(function () {
  18. wx.hideLoading()
  19. })
  20. },
  21. //获取账号
  22. Telephone: function (e) {
  23. var user = e.detail.value;
  24. console.log(user);
  25. this.setData({
  26. user: user
  27. });
  28. },
  29. //获取密码
  30. password: function (e) {
  31. var password = e.detail.value;
  32. console.log(password);
  33. this.setData({
  34. password: password
  35. });
  36. },
  37. //登陆事件
  38. Landbutton: function (e) {
  39. var that = this;
  40. // 登陆ajax
  41. let Land_url = 'public/login';
  42. let Land_data = {
  43. user: this.data.user, // 账号
  44. password: this.data.password, // 密码
  45. };
  46. app.postRequest(Land_url, Land_data, function (res) {
  47. if (res.code == 201) {
  48. // console.log(res.data);
  49. // console.log(res.data.access_key);
  50. // console.log(res.data.access_token);
  51. wx.switchTab({ // 跳转首页
  52. url: '/pages/index/index'
  53. })
  54. // 全局同步传参
  55. try {
  56. wx.setStorageSync('access_key', res.data.access_key)
  57. } catch (e) {
  58. }
  59. // 全局同步传参
  60. try {
  61. wx.setStorageSync('access_token', res.data.access_token)
  62. } catch (e) {
  63. }
  64. return;
  65. }
  66. // console.log(res.data.user); //账号
  67. // console.log(res.data.password); //密码
  68. // console.log(that.data.user); //账号
  69. // console.log(that.data.password); //账号
  70. wx.showToast({
  71. title: '登陆失败',
  72. icon: 'none', // 不显示图标
  73. mask: true, // 是否显示透明蒙层,防止触摸穿透
  74. duration: 1500
  75. })
  76. if (res.data.user){
  77. that.setData({
  78. qtzh: res.data.user, //失败时返回账号提示
  79. color1: "color:red;font-size: 25rpx;", //字体变红色
  80. inputValue1: '', //清空input
  81. user: '', // 清空获取账号
  82. });
  83. }
  84. if (res.data.password){
  85. that.setData({
  86. qtPassword: res.data.password, //失败时返回密码提示
  87. color2: "color:red;font-size: 25rpx;", //字体变红色
  88. inputValue2: '', //清空input
  89. password: '', // 清空获取密码
  90. });
  91. }else{
  92. that.setData({
  93. qtPassword: '密码', //失败时返回密码提示
  94. inputValue2: '', //清空input
  95. color2:'',
  96. password: '', // 清空获取密码
  97. });
  98. }
  99. })
  100. },
  101. })