index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. // pages/login/login.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. src: '/image/s1.png',
  10. frameStyle: { useTop: false, name: '登录', leftArrow: false, useBar: false },
  11. // 主体高度
  12. infoHeight: '',
  13. },
  14. initValidate() {
  15. const rules = { phone: { required: false, tel: false }, 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. params.name = '办案人员';
  29. app.globalData.userInfo = params;
  30. wx.setStorage({ key: "token", data: 'token' })
  31. wx.showToast({ title: `账号登录成功`, icon: 'success', duration: 2000 })
  32. wx.navigateTo({ url: '/pages/home/index' })
  33. }
  34. },
  35. // 微信登录
  36. wxLogin: function () {
  37. wx.showToast({ title: `暂未开放`, icon: 'error', duration: 2000 })
  38. // wx.navigateTo({ url: '/pages/home/index' })
  39. },
  40. /**
  41. * 生命周期函数--监听页面加载
  42. */
  43. onLoad: function (options) {
  44. //验证规则函数
  45. this.initValidate()
  46. // 计算高度
  47. this.searchHeight()
  48. },
  49. // 计算高度
  50. searchHeight: function () {
  51. let frameStyle = this.data.frameStyle;
  52. let client = app.globalData.client;
  53. let infoHeight=client.windowHeight;
  54. // 减去状态栏
  55. if (frameStyle.useTop) infoHeight = infoHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2)
  56. // 是否减去底部菜单
  57. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  58. if (infoHeight) this.setData({ infoHeight: infoHeight })
  59. console.log(infoHeight);
  60. },
  61. /**
  62. * 生命周期函数--监听页面初次渲染完成
  63. */
  64. onReady: function () {
  65. },
  66. /**
  67. * 生命周期函数--监听页面显示
  68. */
  69. onShow: function () {
  70. },
  71. /**
  72. * 生命周期函数--监听页面隐藏
  73. */
  74. onHide: function () {
  75. },
  76. /**
  77. * 生命周期函数--监听页面卸载
  78. */
  79. onUnload: function () {
  80. },
  81. /**
  82. * 页面相关事件处理函数--监听用户下拉动作
  83. */
  84. onPullDownRefresh: function () {
  85. },
  86. /**
  87. * 页面上拉触底事件的处理函数
  88. */
  89. onReachBottom: function () {
  90. },
  91. /**
  92. * 用户点击右上角分享
  93. */
  94. onShareAppMessage: function () {
  95. }
  96. })