index.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. frameStyle: { useTop: false, name: '登录', leftArrow: false, useBar: false },
  10. // 主体高度
  11. infoHeight: '',
  12. from: {},
  13. },
  14. initValidate() {
  15. const rules = { phone: { required: true, tel: true }, password: { required: true, } }
  16. // 验证字段的提示信息,若不传则调用默认的信息
  17. const messages = { phone: { required: '请输入账号', }, password: { required: '请输入密码', } };
  18. this.WxValidate = new WxValidate(rules, messages)
  19. },
  20. // 提交登录
  21. onSubmit: function (e) {
  22. const params = e.detail.value;
  23. if (!this.WxValidate.checkForm(params)) {
  24. const error = this.WxValidate.errorList[0];
  25. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  26. return false
  27. } else {
  28. wx.request({
  29. url: `${app.globalData.publicUrl}/courtAdmin/api/user/login`, //接口地址
  30. method: 'post',
  31. data: params,
  32. success(res) {
  33. if (res.data.errcode == 0) {
  34. console.log('登录成功');
  35. app.globalData.userInfo = res.data.data;//存用户信息到app.js
  36. wx.setStorage({ key: "data", data: res.data.data })// 存用户信息到storage,以便之后判断用户是否登录
  37. wx.showToast({ title: `账号登录成功`, icon: 'success', duration: 2000 }) //登录成功提示
  38. wx.navigateTo({ url: '/pages/home/index' })// 跳转页面
  39. } else {
  40. wx.showToast({
  41. title: res.data.errmsg,
  42. icon: 'none',
  43. duration: 2000
  44. })
  45. }
  46. }
  47. })
  48. }
  49. },
  50. // 微信登录
  51. phoneLogin: function () {
  52. wx.showToast({ title: `暂未开放`, icon: 'error', duration: 2000 })
  53. },
  54. register: function () {
  55. wx.navigateTo({
  56. url: '/pages/register/index',
  57. })
  58. },
  59. /**
  60. * 生命周期函数--监听页面加载
  61. */
  62. onLoad: function (options) {
  63. //验证规则函数
  64. this.initValidate()
  65. // 计算高度
  66. this.searchHeight()
  67. },
  68. // 计算高度
  69. searchHeight: function () {
  70. let frameStyle = this.data.frameStyle;
  71. let client = app.globalData.client;
  72. let infoHeight = client.windowHeight;
  73. // 减去状态栏
  74. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2)
  75. // 是否减去底部菜单
  76. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  77. if (infoHeight) this.setData({ infoHeight: infoHeight })
  78. console.log(infoHeight);
  79. },
  80. /**
  81. * 生命周期函数--监听页面初次渲染完成
  82. */
  83. onReady: function () {
  84. },
  85. /**
  86. * 生命周期函数--监听页面显示
  87. */
  88. onShow: function () {
  89. },
  90. /**
  91. * 生命周期函数--监听页面隐藏
  92. */
  93. onHide: function () {
  94. },
  95. /**
  96. * 生命周期函数--监听页面卸载
  97. */
  98. onUnload: function () {
  99. },
  100. /**
  101. * 页面相关事件处理函数--监听用户下拉动作
  102. */
  103. onPullDownRefresh: function () {
  104. },
  105. /**
  106. * 页面上拉触底事件的处理函数
  107. */
  108. onReachBottom: function () {
  109. },
  110. /**
  111. * 用户点击右上角分享
  112. */
  113. onShareAppMessage: function () {
  114. }
  115. })