// pages/login/index.js import WxValidate from '../../utils/wxValidate'; const app = getApp(); Page({ /** * 页面的初始数据 */ data: { height: app.globalData.height * 2 + 25, background: '', form: {}, }, initValidate() { const rules = { phone: { required: false, tel: true }, password: { required: false }, }; // 验证字段的提示信息,若不传则调用默认的信息 const messages = { phone: { required: '请输入账号' }, password: { required: '请输入密码' }, }; this.WxValidate = new WxValidate(rules, messages); }, formSubmit: function (e) { const params = e.detail.value; if (!this.WxValidate.checkForm(params)) { const error = this.WxValidate.errorList[0]; wx.showToast({ title: error.msg, icon: 'error', duration: 2000, }); return false; } else { wx.switchTab({ url: '/pages/home/index', }); } }, /** * 生命周期函数--监听页面加载 */ onLoad: async function (options) { this.initValidate(); //验证规则函数 const res = await app.$get('/config'); const logo = `${res.data.logo[0].url || ''}`; this.setData({ background: logo }); // wx.request({ // url: `${app.globalData.publicUrl}/api/st/system/tenant/getTenant/${app.globalData.tenant}`, // method: 'get', // data: {}, // success: (res) => { // const { data } = res.data; // this.setData({ background: `${app.globalData.fileUrl}` + data.img.login }); // }, // error: (err) => { // wx.showToast({ // title: err.msg, // icon: 'error', // }); // }, // }); }, /** * 生命周期函数--监听页面初次渲染完成 */ onReady: function () {}, /** * 生命周期函数--监听页面显示 */ onShow: function () {}, /** * 生命周期函数--监听页面隐藏 */ onHide: function () {}, /** * 生命周期函数--监听页面卸载 */ onUnload: function () {}, /** * 页面相关事件处理函数--监听用户下拉动作 */ onPullDownRefresh: function () {}, /** * 页面上拉触底事件的处理函数 */ onReachBottom: function () {}, /** * 用户点击右上角分享 */ onShareAppMessage: function () {}, });