Land.js 3.9 KB

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