wxml
<view class="usermotto">
<view>
账号:<input data-id="u_name" bindinput="setVals" />
</view>
<view>
密码:<input data-id=u_password" bindinput="setVals" type="password"/>
</view>
<view>
<button class="btn_login" bindtap="btn" data-indo="{{3}}" > 登录</button>
</view>
</view>
</view>
wxss
.userinfo {
display: flex;
flex-direction: column;
align-items: center;
color: #aaa;
}
.userinfo-avatar {
overflow: hidden;
width: 128rpx;
height: 128rpx;
margin: 20rpx;
border-radius: 50%;
}
.usermotto {
margin-top: 50px;
}
.usermotto >view{
display:flex;
margin-top: 12px;
}
.usermotto> view> input{
border-bottom: 1px rgb(15, 15, 15) solid;
border-color: rgb(15, 15, 15);
}
.btn_login{
margin-top: 30px;
background-color: rgb(75, 111, 209);
}
js
data: {
u_name: '',
u_password: ''
},
btn(e){
let name = this.data.u_name;
let password = this.data.u_password;
// if(name == null || name == "" || name == undefined || name == "undefined"){
if(this.isNull(name)){
wx.showToast({
title: '请输入账号!',
icon: 'error'
});
}else if(this.isNull(password)){
wx.showToast({
title: '请输入密码!',
icon: 'error'
});
}else{
wx.request({
url: 'http://114.116.32.26:8080/func/OPERATOR/LOGIN',
method: 'GET',
data: {
loginname: name,
pass: password
},
success: function (res) {
if(res.data.errorcode == 0){
app.globalData.userInfo = res.data.employee;
console.log(app.globalData.userInfo);
wx.navigateTo({
url:"../home/home"
})
}else{
wx.showToast({
title: res.data.message,
icon: 'error'
});
}
}
})
}
},
isNull(val){
console.log(val);
if(val == null || val == "" || val == undefined || val == "undefined" ){
return true
}else{
return false
}
}, setVals(e){
this.setData({
[e.currentTarget.dataset.id]:e.detail.value
})
console.log(this.data);
},