123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- 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
- })
- }
- }
- }
- })
|