Land.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. usertext:'', //储存手机号码
  13. },
  14. /**
  15. * 生命周期函数--监听页面加载
  16. */
  17. onLoad: function (options) {
  18. var _this =this;
  19. setTimeout(function () {
  20. wx.hideLoading()
  21. // 记录登陆过的手机
  22. if (wx.getStorageSync('user')){
  23. _this.setData({
  24. inputValue1: wx.getStorageSync('user'),
  25. });
  26. }
  27. })
  28. wx.getSetting({
  29. success(res) {
  30. if (res.authSetting['scope.userInfo']) {
  31. // wx.reLaunch({
  32. // url: '/pages/Landpage/Land/Land'
  33. // });
  34. console.log('已经授权');
  35. } else {
  36. wx.reLaunch({
  37. url: '/pages/Jurisdiction/click_Jurisdiction/click_Jurisdiction' //未授权 进入授权页
  38. })
  39. console.log('没有授权');
  40. }
  41. }
  42. })
  43. },
  44. //获取账号
  45. Telephone: function (e) {
  46. var user = e.detail.value;
  47. // console.log(user);
  48. this.setData({
  49. user: user
  50. });
  51. },
  52. //获取密码
  53. password: function (e) {
  54. var password = e.detail.value;
  55. // console.log(password);
  56. this.setData({
  57. password: password
  58. });
  59. },
  60. //登陆事件
  61. Landbutton: function (e) {
  62. var that = this;
  63. // 登陆ajax
  64. let Land_url = 'public/login';
  65. let Land_data = {
  66. user: this.data.user, // 账号
  67. password: this.data.password, // 密码
  68. };
  69. app.postRequest(Land_url, Land_data, function (res) {
  70. if (res.code == 201) {
  71. console.log(res.data);
  72. // console.log(res.data.access_key);
  73. // console.log(res.data.access_token);
  74. wx.switchTab({ // 跳转首页
  75. url: '/pages/index/index'
  76. })
  77. // 全局同步传参
  78. try {
  79. wx.setStorageSync('access_key', res.data.access_key)
  80. wx.setStorageSync('access_token', res.data.access_token)
  81. wx.setStorageSync('access_user', res.data.access_user)
  82. wx.setStorageSync('user', that.data.user)
  83. } catch (e) {
  84. }
  85. return;
  86. }
  87. // console.log(res.data.user); //账号
  88. // console.log(res.data.password); //密码
  89. // console.log(that.data.user); //账号
  90. // console.log(that.data.password); //账号
  91. wx.showToast({
  92. title: '登陆失败',
  93. icon: 'none', // 不显示图标
  94. mask: true, // 是否显示透明蒙层,防止触摸穿透
  95. duration: 1500
  96. })
  97. if (res.data.user){
  98. that.setData({
  99. qtzh: res.data.user, //失败时返回账号提示
  100. color1: "color:red;font-size: 25rpx;", //字体变红色
  101. inputValue1: '', //清空input
  102. user: '', // 清空获取账号
  103. });
  104. }
  105. if (res.data.password){
  106. that.setData({
  107. qtPassword: res.data.password, //失败时返回密码提示
  108. color2: "color:red;font-size: 25rpx;", //字体变红色
  109. inputValue2: '', //清空input
  110. password: '', // 清空获取密码
  111. });
  112. }else{
  113. that.setData({
  114. qtPassword: '密码', //失败时返回密码提示
  115. inputValue2: '', //清空input
  116. color2:'',
  117. password: '', // 清空获取密码
  118. });
  119. }
  120. })
  121. },
  122. })