微信小程序--登录页

–wxml–

<!--pages/login/login.wxml-->
<view class='container'>
  <view class='header'>
    <text>学生评教系统</text>
  </view>
  <form bindsubmit="formSubmit">
    <view class='section'>
      <text>学号:</text>
      <input type='number' placeholder='请输入学号' name="no" value='1635050238'/>
    </view>
    <view class='section'>
      <text>密码:</text>
      <input password='true' placeholder='请输入密码' name="pwd" value='123456'/>
    </view>
    <view class='button'>
      <button type='primary' form-type='submit'>登录</button>
    </view>
  </form>
    <view class='fpwd' bindtap='findpwd'>
      <text>忘记密码</text>
    </view>
</view>

–wxss–

/* pages/login/login.wxss */
form{
  width: 310px;
  height: 240px;
  line-height: 40px;
  /* border: 1px solid red;  */
}
input{
  border: 1px solid #ccc;
  width: 310px;
  height: 40px;
}
.button{
  margin-top: 20px;
}
.header text{
  font-size: 25px;
  color: #666;
}
form text{
  font-size: 20px;
  color: #666;
}
.fpwd{
  margin-top: 200px;
}
.fpwd text{
  color: #ccc;
  font-size: 18px;
}

–js–

// pages/login/login.js
Page({
 
  /**
   * 页面的初始数据
   */
  data: {
  
  },
  formSubmit: function (e) {
    // console.log(e.detail.value);
    wx.request({
      // url: 'https://www.lishuming.top/pj/index.php/student/api/login', //仅为示例,并非真实的接口地址
      url: app.globalData.url.login,
      data: {
        username: e.detail.value.no,
        password: e.detail.value.pwd
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        console.log(res.data);
        if (res.statusCode == 200) {
          //访问正常
          if (res.data.error == true) {
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 2000,
            })
          } else {
            //缓存
            wx.setStorage({
              key: "student",
              data: res.data.student
            });
            wx.showToast({
              title: "登陆成功",
              icon: 'success',
              duration: 20000,
              success: function () {
                setTimeout(function () {
                  wx.switchTab({
                    url: '../teachers/teachers',
                  })
                }, 2000)
              }
            })
          }
        }
 
      }
    })
  }
})

猜你喜欢

转载自blog.csdn.net/weixin_44531304/article/details/88991705
今日推荐