const util = require('../../utils/util.js'); const { $Toast } = require('../../dist/base/index'); const app = getApp() Page({ data: { username: '', password: '', disabled: false, //按钮是否禁用 click: true, }, onLoad: function () { }, // 获取输入的值 getValue_username: function (e) { this.setData({ username: e.detail.value }) }, getValue_password: function (e) { this.setData({ password: e.detail.value }) }, // 登录 formSubmitHandle: function (e) { if (this.data.username == "") { $Toast({ content: '账号不能为空', type: 'warning', duration: 1 }) return false; } else if (this.data.password == "") { $Toast({ content: '密码不能为空', type: 'warning', duration: 1 }) return false; } else { if (this.data.click) { var that = this; that.setData({ click: false }); wx.request({ url: app.globalData.serverUrl + "/user/loginAdmin", method: "POST", data: { username: that.data.username, password: that.data.password, }, header: { "Content-Type": "application/x-www-form-urlencoded" }, success: function (res) { if (res.data.code == "ok") { $Toast({ content: '登录成功', type: 'success', duration: 2 }) wx.setStorageSync('userInfo', res.data.data); setTimeout(function () { wx.reLaunch({ url: '../home/index' }) }, 200) } else { that.setData({ click: true }) $Toast({ content: res.data.msg, type: 'error', duration: 2 }) } }, fail: function (res) { that.setData({ click: true }) $Toast({ content: '登录失败!', type: 'error', duration: 2 }) } }) } else { $Toast({ content: '登录中,请勿重复点击', type: 'loading', duration: 1 }) } } } })