index.js 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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: true, name: '登录', leftArrow: false, useBar: false },
  10. // 主体高度
  11. infoHeight: '',
  12. // 用户类别
  13. roleList: [
  14. { role: '1', name: '管理人员' },
  15. { role: '2', name: '区县人员' },
  16. { role: '3', name: '办案人员' },
  17. ]
  18. },
  19. initValidate() {
  20. const rules = { phone: { required: true, tel: true }, password: { required: true, }, role: { required: true, }, }
  21. // 验证字段的提示信息,若不传则调用默认的信息
  22. const messages = { phone: { required: '请输入账号', }, password: { required: '请输入密码', }, role: { required: '请输入用户类别', }, };
  23. this.WxValidate = new WxValidate(rules, messages)
  24. },
  25. // 选择用户类别
  26. roleChange: function (e) {
  27. let { value } = e.detail;
  28. let data = this.data.roleList[value];
  29. this.setData({ 'form.role': data.role })
  30. this.setData({ 'form.name': data.name })
  31. },
  32. // 提交登录
  33. onSubmit: function (e) {
  34. const params = e.detail.value;
  35. if (!this.WxValidate.checkForm(params)) {
  36. const error = this.WxValidate.errorList[0];
  37. wx.showToast({ title: `${error.msg}`, icon: 'error', duration: 2000 })
  38. return false
  39. } else {
  40. params.name = '办案人员';
  41. app.globalData.userInfo = params;
  42. wx.setStorage({ key: "token", data: 'token' })
  43. wx.setStorage({ key: "role", data: params.role })
  44. wx.showToast({ title: `账号登录成功`, icon: 'success', duration: 2000 })
  45. wx.navigateTo({ url: '/pages/home/index' })
  46. }
  47. },
  48. // 微信登录
  49. wxLogin: function () {
  50. wx.showToast({ title: `暂未开放`, icon: 'error', duration: 2000 })
  51. // wx.navigateTo({ url: '/pages/home/index' })
  52. },
  53. /**
  54. * 生命周期函数--监听页面加载
  55. */
  56. onLoad: function (options) {
  57. //验证规则函数
  58. this.initValidate()
  59. // 计算高度
  60. this.searchHeight()
  61. },
  62. // 计算高度
  63. searchHeight: function () {
  64. let frameStyle = this.data.frameStyle;
  65. let client = app.globalData.client;
  66. // 减去状态栏
  67. let infoHeight = client.windowHeight - (client.statusBarHeight + client.getMenu.height + (client.getMenu.top - client.statusBarHeight) * 2);
  68. // 是否减去底部菜单
  69. if (frameStyle.useBar) infoHeight = infoHeight - 50;
  70. if (infoHeight) this.setData({ infoHeight: infoHeight })
  71. },
  72. /**
  73. * 生命周期函数--监听页面初次渲染完成
  74. */
  75. onReady: function () {
  76. },
  77. /**
  78. * 生命周期函数--监听页面显示
  79. */
  80. onShow: function () {
  81. },
  82. /**
  83. * 生命周期函数--监听页面隐藏
  84. */
  85. onHide: function () {
  86. },
  87. /**
  88. * 生命周期函数--监听页面卸载
  89. */
  90. onUnload: function () {
  91. },
  92. /**
  93. * 页面相关事件处理函数--监听用户下拉动作
  94. */
  95. onPullDownRefresh: function () {
  96. },
  97. /**
  98. * 页面上拉触底事件的处理函数
  99. */
  100. onReachBottom: function () {
  101. },
  102. /**
  103. * 用户点击右上角分享
  104. */
  105. onShareAppMessage: function () {
  106. }
  107. })