SpringBoot + Spring Cloud +Vue 管理系统前端搭建(六、完善登录流程)

这里我们简单做一个登录界面,界面如图:

话不多说直接上代码

首先我们修改登录界面

login.vue

<template>
  <el-form :model="loginForm" :rules="fieldRules" ref="loginForm" label-position="left" label-width="0px" class="demo-ruleForm login-container">
    <span class="tool-bar">
    </span>
    <h2 class="title" style="padding-left:22px;" >系统登录</h2>
    <el-form-item prop="account">
      <el-input type="text" v-model="loginForm.account" auto-complete="off" placeholder="账号"></el-input>
    </el-form-item>
    <el-form-item prop="password">
      <el-input type="password" v-model="loginForm.password" auto-complete="off" placeholder="密码"></el-input>
    </el-form-item>
    <el-form-item >
      <el-col :span="12">
        <el-form-item prop="captcha">
          <el-input type="test" v-model="loginForm.captcha" auto-complete="off" placeholder="验证码, 单击图片刷新"
            style="width: 100%;">
          </el-input>
        </el-form-item>
      </el-col>
      <el-col class="line" :span="1">&nbsp;</el-col>
      <el-col :span="11">
        <el-form-item>
            <img style="width: 100%;" class="pointer" :src="loginForm.src" @click="refreshCaptcha">
        </el-form-item>
      </el-col>
    </el-form-item>
    <el-form-item style="width:100%;">
      <el-button type="primary" style="width:48%;" @click.native.prevent="reset">重 置</el-button>
      <el-button type="primary" style="width:48%;" @click.native.prevent="login" :loading="loading">登 录</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import Cookies from "js-cookie"
export default {
  name: 'Login',
  data() {
    return {
      loading: false,
      loginForm: {
        account: 'admin',
        password: 'admin',
        captcha:'',
        src: ''
      },
      fieldRules: {
        account: [
          { required: true, message: '请输入账号', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入密码', trigger: 'blur' }
        ]
      },
      checked: true
    }
  },
  methods: {
    login() {
      this.loading = true
      let userInfo = { account:this.loginForm.account, password:this.loginForm.password,
        captcha:this.loginForm.captcha }
      this.$api.login.login(userInfo).then((res) => {  // 调用登录接口
          if(res.msg != null) {
            this.$message({ message: res.msg, type: 'error' })
          } else {
            Cookies.set('token', res.data.token) // 放置token到Cookie
            sessionStorage.setItem('user', userInfo.account) // 保存用户到本地会话
            this.$router.push('/')  // 登录成功,跳转到主页
          }
          this.loading = false
        }).catch((res) => {
          this.$message({ message: res.message, type: 'error' })
        })
    },
    refreshCaptcha: function(){
      this.loginForm.src = this.global.baseUrl + "/captcha.jpg?t=" + new Date().getTime();
    },
    reset() {
      this.$refs.loginForm.resetFields()
    }
  },
  mounted() {
    this.refreshCaptcha()
  }
}
</script>

<style lang="scss" scoped>
  .login-container {
    -webkit-border-radius: 5px;
    border-radius: 5px;
    -moz-border-radius: 5px;
    background-clip: padding-box;
    margin: 100px auto;
    width: 350px;
    padding: 35px 35px 15px 35px;
    background: #fff;
    border: 1px solid #eaeaea;
    box-shadow: 0 0 25px #cac6c6;
    .title {
      margin: 0px auto 30px auto;
      text-align: center;
      color: #505458;
    }
  }
</style>

修改主界面

Home.vue

<template>
  <div class="container">
      <!-- 导航菜单栏 -->
      <nav-bar></nav-bar>
      <!-- 头部区域 -->
      <head-bar></head-bar>
      <!-- 主内容区域 -->
      <main-content></main-content>
  </div>
</template>

<script>
import HeadBar from "./HeadBar"
import NavBar from "./NavBar"
import MainContent from "./MainContent"
export default {
  components:{
        HeadBar,
        NavBar,
        MainContent
  }
};
</script>

<style scoped lang="scss">
  .container {
    position:absolute;
    top: 0px;
    left: 0px;
    right: 0px;
    bottom: 0px;
    // background: rgba(224, 234, 235, 0.1);
  }
</style> 

在views下添加导航菜单栏、头部区域、内容区域

左测导航菜单栏

NavBar.vue

<template>
    <div class="menu-bar-container">
    <!-- logo -->
    <div class="logo" style="background:#14889A" :class="'menu-bar-width'"
        @click="$router.push('/')">
        <img src="@/assets/logo.png"/> <div>Mango</div>
    </div>
    </div>
</template>

<script>
export default {
  methods: {
  }
}
</script>

<style scoped lang="scss">
.menu-bar-container {
  position: fixed;
  top: 0px;
  left: 0;
  bottom: 0;
  z-index: 1020;
  .logo {
    position:absolute;
    top: 0px;
    height: 60px;   
    line-height: 60px;
    background: #545c64;
    cursor:pointer;
    img {
        width: 40px;
        height: 40px;
        border-radius: 0px;
        margin: 10px 10px 10px 10px;
        float: left;
    }
    div {
      font-size: 25px;
      color: white;
      text-align: left;
      padding-left: 20px;
    }
  }
  .menu-bar-width {
    width: 200px;
  }
}

</style>

头部区域:

HeadBar.vue

<template>

<div class="headbar" style="background:#14889A" :class="'position-left'">

<!-- 工具栏 -->

<span class="toolbar">

<el-menu class="el-menu-demo" background-color="#14889A" text-color="#14889A" active-text-color="#14889A" mode="horizontal">

<el-menu-item index="1">

<!-- 用户信息 -->

<span class="user-info"><img :src="user.avatar" />{{user.name}}</span>

</el-menu-item>

</el-menu>

</span>

</div>

</template>

 

<script>

import mock from "@/mock/index"

export default {

data() {

return {

user: {

name: "Louis",

avatar: "",

role: "超级管理员",

registeInfo: "注册时间:2018-12-20 "

},

activeIndex: '1',

langVisible: false

}

},

methods: {

selectNavBar(key, keyPath) {

console.log(key, keyPath)

}

},

mounted() {

var user = sessionStorage.getItem("user")

if (user) {

this.user.name = user

this.user.avatar = require("@/assets/user.png")

}

}

}

</script>

 

<style scoped lang="scss">

.headbar {

position: fixed;

top: 0;

right: 0;

z-index: 1030;

height: 60px;

line-height: 60px;

border-color: rgba(180, 190, 190, 0.8);

border-left-width: 1px;

border-left-style: solid;

}

.navbar {

float: left;

}

.toolbar {

float: right;

}

.user-info {

font-size: 20px;

color: #fff;

cursor: pointer;

img {

width: 40px;

height: 40px;

border-radius: 10px;

margin: 10px 0px 10px 10px;

float: right;

}

}

.position-left {

left: 200px;

}

</style>

主内容区域:

MainContent.vue

<template>
  <div id="main-container" class="main-container" :class="'position-left'">
    <!-- 标签页 -->
    <div class="tab-container"></div>
    <!-- 主内容区域 -->
    <div class="main-content">
      <keep-alive>
        <transition name="fade" mode="out-in">
            <router-view></router-view>
        </transition>
      </keep-alive>
    </div>
  </div>
</template>

<script>
export default {
  data () {
    return {
    }
  },
  methods: {
    
  }
}
</script>

<style scoped lang="scss">
.main-container {
  padding: 0 5px 5px;
  position: absolute;
  top: 60px;
  left: 1px;
  right: 1px;
  bottom: 0px;
  background: rgba(67, 69, 70, 0.1);
  .main-content {
    position: absolute;
    top: 45px;
    left: 5px;
    right: 5px;
    bottom: 5px;
    padding: 5px;
  }
}
.position-left {
  left: 200px;
}
</style>

修改App.vue

<template>

<div id="app">

<router-view/>

</div>

</template>

 

<script>

export default {

name: 'App'

}

</script>

 

<style>

#app {

font-family: 'Avenir', Helvetica, Arial, sans-serif;

-webkit-font-smoothing: antialiased;

-moz-osx-font-smoothing: grayscale;

text-align: center;

color: #2c3e50;

margin-top: 60px;

}

</style>

测试:

修改完代码后访问:http://localhost:8080/#/login

如下图,可以看到我们的登录界面已经出来了

然后我们点击登录,进入主界面

好啦,到此我们就完成了一个简单的登录流程,在实际开发过程中,在登录后可能会有一些操作要进行,我们这里就不细说了。

 

看完记得点赞哦!

 

  • 30
    点赞
  • 95
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值