Land.js 3.6 KB

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