2021-07-14旅游后台管理系统之前端登录页面

该博客讨论了一种旅游后台管理系统的前端登录页面设计,包括用户名、密码和验证码输入字段。文章指出原本应该在后台进行的验证码验证因故在前端完成,并提供了相应的Vue.js代码实现。代码中包含了数据校验、表单提交、验证码获取和刷新等功能。当用户点击登录按钮时,会向后台发送POST请求验证用户信息和验证码。若验证码输入错误,前端会显示错误提示。
摘要由CSDN通过智能技术生成

旅游后台管理系统之前端登录页面

验证码验证时在前端验证,建议从后台验证,由于出了点小问题所以从前端验证了;

<template>
	<el-container class="login-img">
      <p class="login">
		<el-tabs v-model="activeName" @tab-click="handleClick">
			<el-tab-pane label="登录" name="first">
                        
				<el-form :model="loginForm" :rules="rules" ref="loginForm" label-width="100px" class="demo-ruleForm">
					
                              <el-form-item label="用户名" prop="username">
                                    <el-input v-model="loginForm.username"></el-input>
                              </el-form-item>
                              <!-- <i class="el-icon-user-solid"></i> -->
                              <!-- <i class="el-icon-lock"></i>    -->
					<el-form-item label="密码" prop="password">
                                    <label slot="label">&emsp;</label>
                                    <el-input type="password" v-model="loginForm.password" auto-complete="off"></el-input>
                              </el-form-item>
                              <el-form-item label="验证码" prop="code">
                                    <el-input size="normal" type="text" v-model="loginForm.code" auto-complete="off" style="width: 120px;height:30px;"></el-input>
                                    <img :src="src" @click="changegetImage" alt="" :key="key" class="ImageCode">
                              </el-form-item>
					<el-form-item>
						<el-button @click="handleLogin()" class="login-btn" type="primary">登录</el-button>
 
						<el-button @click="resetForm('loginForm')">重置</el-button>
					</el-form-item>
				</el-form>
			</el-tab-pane>
 
			<el-tab-pane label="注册" name="second" :key="'second'">
				<register></register>                       
			</el-tab-pane>
                  <el-tab-pane label="可视化" name="third" :key="'third'">
				<!-- <register></register> -->
                       <el-button @click="toShow()" class="" type="primary">点击查看大屏</el-button>                      
			</el-tab-pane>
		</el-tabs>
	</p>
     </el-container>
</template>
 
<script>
import WeChart from '@/components/communication/WeChat.vue';
import Register from '@/components/login/register.vue';
export default {
      components: {
		WeChart,
            Register
	},
	data() { 
		return {
			activeName: 'first',
			loginForm: {
                        username: '',
                        password: '',
                        code: ''
                  },
                  code: " ",
                  src: "",
                  key: "",
			rules: {
				username: [{ required: true, message: '请输入用户名', trigger: 'blur' }],
				password: [{ required: true, message: '请输入密码', trigger: 'blur' }],
                        code:[{required: true, message: '请输入验证码', trigger: 'blur'}]
			}
		};
	},
 
	methods: {
		//选项卡切换
		handleClick(tab, event) {},
            toShow(){
                  this.$router.push("/wechart");
            },
		//重置表单
		resetForm(loginForm) {
			this.$refs[loginForm].resetFields();
		},
		//提交表单
		handleLogin() {
                  let _this = this;
                  if(_this.loginForm.code==""){
                        _this.$message.error("请输入验证码!")
                  }
                  axios.post('http://localhost:8081/api/manager/login', this.loginForm).then(function (res) {
                        // console.log(res)
                        if(_this.code==_this.loginForm.code){
                              if (res.data.code == 1) {
                                    _this.$message.success(res.data.msg)
                                    _this.$router.push('/home')
                              } else {
                                    _this.$message.error(res.data.msg)
                              }
                        }else{
                              _this.$message.error("验证码错误!")
                        }
                        
                  })
            },
            getImage() {
                  const _this = this
                  axios.get('http://localhost:8081/api/manager/getImage').then((res) => {
                        //console.log(res)
                        this.src = "data:image/png;base64," + res.data.image;
                        // console.log(_this.src)
                        this.key = res.data.key;
                        // console.log(_this.key)
                        this.code=res.data.code;
                  });
            },
            changegetImage() {
                  this.getImage();
            }
	},
      created() {
            this.getImage(); //获取验证码
      },
};
</script>
 
<style>
.login-img {
      background: url("../../assets/images/Starry.jpg") no-repeat;
      height: 100%;
      width: 100%;
      /* background-size: cover; */
      /* position: fixed; */
}
.demo-ruleForm {
      width: 350px;
      background-color: rgb(13, 78, 104);
      border-radius: 5px;
      padding: 30px;
      margin-bottom: 80px;
}
.el-tabs__item{
      font-size: 20px;
}
.el-form-item__label{
      font-size: 18px;
      color:#020e1a;
}
.login {
	margin: 0 auto;
      margin-top: 130px;
}
 
.el-tabsitem {
	text-align: center;
	width: 60px;
}
.ImageCode {
      position: absolute;
      margin-bottom: 20px;
      height: 40px;
      width: 100px;
      border-radius: 5px;
      padding-left: 28px;
}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值