|
<template>
<div class="wrapper">
<Header :isHideBackBtn="true" :isHideSettingBtn="true"/>
<div class="main">
<div class="login">
<p><input type="text" class="txt" v-model="username" placeholder="用户名" id="username" /></p>
<p><input type="password" class="txt" v-model="password" placeholder="密码" id="password"/></p>
<p><input type="button" value="登录" @click="login" class="btnlogin" /></p>
<p><input type="button" value="注册" @click="userreg" class="btnreg" /></p>
<p class="tipmsg">{{tipmsg}}</p>
</div>
</div>
<Footer/>
</div>
</template>
<script>
import Header from '@/components/Header'
import Footer from '@/components/Footer'
export default {
name: 'Login',
created(){
this.$store.commit('SET_APPTITLE',"快易乐点餐系统v1.0-登录");
},
data () {
return {
tipmsg:'',
username:'',
password:''
}
},
components:{
Header,
Footer
},
methods:{
userreg:function() {
this.$router.push({name: 'UserReg'});
},
login:function(){
var username=this.username;
var password=this.password;
var deskid=this.$route.query.id;
if(!(username.length>0))
{
this.tipmsg="请输入用户名";
document.getElementById("username").focus();
return;
}
if(!(password.length>0))
{
this.tipmsg="请输入密码";
document.getElementById("password").focus();
return;
}
if(!deskid)
{
deskid=1;
}
var webapiip=this.$store.getters.webapiip;
//向webapi发起一个ajax请求,验证用户名和密码
this.$ajax({
method: 'post',
url:webapiip+'/api/diancan/PostLogin',
data: {
LoginName:username,
PassWord:password
}
}).then(res=>{
if(res.data.data.ds.length>0)
{
//登录成功
this.tipmsg="";
var currentuser=res.data.data.ds[0];
localStorage.setItem("userid",currentuser.ID);
localStorage.setItem("TrueName",currentuser.TrueName);
localStorage.setItem("Tel",currentuser.Tel);
localStorage.setItem("deskid",deskid);
this.$router.push({
name: 'FoodList',
params: {
userId: currentuser.ID
}
});
}
else
{
//登录失败
this.tipmsg="错误:用户名或密码错误";
}
console.log(res.data.data.ds[0]);
}).catch(err=>{
console.log("错误:"+err);
this.tipmsg="错误:"+err;
});
}
}
}
</script>
<style scoped>
.wrapper{
width:100%;
height:100%;
}
.main{
width:100%;
height:calc(100% - 60px);
position:fixed;
top:30px;
left:0px;
overflow-y:scroll;
}
.login{
width:calc(100% - 100px);
height:200px;
position:absolute;
left:50px;
top:calc(50% - 100px);
}
.main input{
width:100%;
height:32px;
margin-top:5px;
border:solid 1px #eee;
border-radius:3px;
outline:none;
}
.main input.txt{
width:calc(100% - 5px);
height:30px;
margin-top:5px;
padding-left:3px;
}
.btnlogin{
background-color:#3CB371;
color:#fff;
cursor:pointer;
}
.tipmsg{
color:red;
}
</style>
后续模块陆续更新。
源码 |
所有评论(0)