index.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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: async function (options) {
  45. this.initValidate(); //验证规则函数
  46. const res = await app.$get('/config');
  47. const logo = `${res.data.logo[0].url || ''}`;
  48. this.setData({ background: logo });
  49. // wx.request({
  50. // url: `${app.globalData.publicUrl}/api/st/system/tenant/getTenant/${app.globalData.tenant}`,
  51. // method: 'get',
  52. // data: {},
  53. // success: (res) => {
  54. // const { data } = res.data;
  55. // this.setData({ background: `${app.globalData.fileUrl}` + data.img.login });
  56. // },
  57. // error: (err) => {
  58. // wx.showToast({
  59. // title: err.msg,
  60. // icon: 'error',
  61. // });
  62. // },
  63. // });
  64. },
  65. /**
  66. * 生命周期函数--监听页面初次渲染完成
  67. */
  68. onReady: function () {},
  69. /**
  70. * 生命周期函数--监听页面显示
  71. */
  72. onShow: function () {},
  73. /**
  74. * 生命周期函数--监听页面隐藏
  75. */
  76. onHide: function () {},
  77. /**
  78. * 生命周期函数--监听页面卸载
  79. */
  80. onUnload: function () {},
  81. /**
  82. * 页面相关事件处理函数--监听用户下拉动作
  83. */
  84. onPullDownRefresh: function () {},
  85. /**
  86. * 页面上拉触底事件的处理函数
  87. */
  88. onReachBottom: function () {},
  89. /**
  90. * 用户点击右上角分享
  91. */
  92. onShareAppMessage: function () {},
  93. });