index.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // pages/login/index.js
  2. import WxValidate from '../../utils/wxValidate'
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. height: app.globalData.height * 2 + 25,
  10. background: '',
  11. form: {},
  12. },
  13. initValidate() {
  14. const rules = {
  15. phone: { required: false, tel: true },
  16. password: { required: false, },
  17. }
  18. // 验证字段的提示信息,若不传则调用默认的信息
  19. const messages = {
  20. phone: { required: '请输入账号', },
  21. password: { required: '请输入密码', },
  22. };
  23. this.WxValidate = new WxValidate(rules, messages)
  24. },
  25. formSubmit: function (e) {
  26. const params = e.detail.value;
  27. if (!this.WxValidate.checkForm(params)) {
  28. const error = this.WxValidate.errorList[0];
  29. wx.showToast({
  30. title: error.msg,
  31. icon: 'error',
  32. duration: 2000
  33. })
  34. return false
  35. } else {
  36. wx.switchTab({
  37. url: '/pages/home/index',
  38. })
  39. }
  40. },
  41. /**
  42. * 生命周期函数--监听页面加载
  43. */
  44. onLoad: function (options) {
  45. this.initValidate()//验证规则函数
  46. wx.request({
  47. url: `${app.globalData.publicUrl}/api/st/system/tenant/getTenant/${app.globalData.tenant}`,
  48. method: "get",
  49. header: { 'x-tenant': app.globalData.tenant },
  50. data: {},
  51. success: res => {
  52. const { data } = res.data;
  53. this.setData({ background: `${app.globalData.fileUrl}` + data.img.login })
  54. },
  55. error: err => {
  56. wx.showToast({
  57. title: err.msg,
  58. icon: 'error'
  59. })
  60. }
  61. })
  62. },
  63. /**
  64. * 生命周期函数--监听页面初次渲染完成
  65. */
  66. onReady: function () {
  67. },
  68. /**
  69. * 生命周期函数--监听页面显示
  70. */
  71. onShow: function () {
  72. },
  73. /**
  74. * 生命周期函数--监听页面隐藏
  75. */
  76. onHide: function () {
  77. },
  78. /**
  79. * 生命周期函数--监听页面卸载
  80. */
  81. onUnload: function () {
  82. },
  83. /**
  84. * 页面相关事件处理函数--监听用户下拉动作
  85. */
  86. onPullDownRefresh: function () {
  87. },
  88. /**
  89. * 页面上拉触底事件的处理函数
  90. */
  91. onReachBottom: function () {
  92. },
  93. /**
  94. * 用户点击右上角分享
  95. */
  96. onShareAppMessage: function () {
  97. }
  98. })