public function index()
{
$user['username'] = input('username');
$user['password'] = input('password');
$username = \app\admin\model\User::where('username', $user['username'])->select()->toArray();
if ($username) {
if ($username[0]['password'] == $user['password']) {
return json(['code' => 1, 'msg' => '登录成功', 'result' => '']);
} else {
return json(['code' => 2, 'msg' => '账号密码错误', 'result' => '']);
}
}
}
const app = getApp()
Page({
/**
* 页面的初始数据
*/
data: {
username:'',
password:''
},
// 获取输入账号
usernameInput: function (e) {
// console.log(e)
this.setData({
username: e.detail.value
})
},
// 获取输入密码
passwordInput: function (e) {
this.setData({
password: e.detail.value
})
},
login:function(){
// console.log(e)
let username = this.data.username
let password = this.data.password
// var that = this;
if (this.data.username.length == 0 || this.data.password.length == 0) {
wx.showToast({
title: '账号或密码不能为空',
icon: 'none',
duration: 2000
})
} else {
wx.request({
url: 'http://www.week.com/index.php/admin/user/index', // 仅为示例,并非真实的接口地址
method: 'post',
data: {
username: username,
password: password
},
header: {
'content-type': 'application/x-www-form-urlencoded' // 默认值
},
success(res) {
// console.log(res)
if(res.data.code==2){
wx.showModal({
title:'登录失败',
icon:'none',
duration:1500,
showCancel:false
})
}else{
wx.showModal({
title:'登录成功',
icon:'success',
duration:1500
})
wx.redirectTo({
url: '/pages/home/home',
})
}
}
})
}
},
<view class="container">
<view class="login-from">
<!--账号-->
<view class="inputView">
<label class="loginLab">账号</label>
<input class="inputText" placeholder="请输入账号" bindinput="usernameInput" />
</view>
<view class="line"></view>
<!--密码-->
<view class="inputView">
<label class="loginLab">密码</label>
<input class="inputText" password="true" placeholder="请输入密码" bindinput="passwordInput" />
</view>
<!--按钮-->
<view class="loginBtnView">
<button class="loginBtn" type="primary" size="{{primarySize}}" loading="{{loading}}" plain="{{plain}}" disabled="{{disabled}}" bindtap="login">登录</button>
</view>
</view>
</view>
page{
height: 100%;
}
.container {
height: 100%;
display: flex;
flex-direction: column;
padding: 0;
box-sizing: border-box;
/* background-color: rgb(156, 23, 78) */
}
/*登录图片*/
.login-icon{
flex: none;
}
.login-img{
width: 750rpx;
}
/*表单内容*/
.login-from {
margin-top: 20px;
flex: auto;
height:100%;
}
.inputView {
/* background-color: #fff; */
line-height: 45px;
border-radius:20px;
border:1px solid #999999;
}
/*输入框*/
.nameImage, .keyImage {
margin-left: 22px;
width: 18px;
height: 16px
}
.loginLab {
margin: 15px 15px 15px 10px;
color: #545454;
font-size: 14px
}
.inputText {
flex: block;
float: right;
text-align: right;
margin-right: 22px;
margin-top: 11px;
color: #cccccc;
font-size: 14px
}
.line {
margin-top: 8px;
}
/* .line {
width: 100%;
height: 1px;
background-color: #cccccc;
margin-top: 1px;
} */
/*按钮*/
.loginBtnView {
width: 100%;
height: auto;
/* background-color:#DCDCDC; */
margin-top: 0px;
margin-bottom: 0px;
padding-bottom: 0px;
}
.loginBtn {
width: 90%;
margin-top: 40px;
border-radius:10px;
}