Land.js 4.1 KB

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