Browse Source

go home

master
fengdong777 2 years ago
parent
commit
54daa73367
  1. 3
      warehousing-system/project_web/src/components/Home.vue
  2. 174
      warehousing-system/project_web/src/components/Login.vue
  3. 2
      warehousing-system/project_web/src/main.js
  4. 6
      warehousing-system/project_web/src/router/index.js

3
warehousing-system/project_web/src/components/Home.vue

@ -121,7 +121,8 @@ export default {
},
mounted () {
this.user = window.sessionStorage.getItem('token').substr(32)
// this.user = window.sessionStorage.getItem('token').substr(32)
this.user = "9a3860f0f2af471982e919657099913dddd"
}
}
</script>

174
warehousing-system/project_web/src/components/Login.vue

@ -1,26 +1,47 @@
<template>
<div class='background'>
<div class="background">
<div class="login_box">
<div class="box_Central" >
<div><img></div>
<div class="box_Central">
<div><img /></div>
<el-form :rules="rules" :model="loginForm" ref="loginFormRef" label-width="80px">
<el-form-item label="用户名"prop="username">
<el-input v-model="loginForm.username" style="width: 200px" ></el-input>
<el-form
:rules="rules"
:model="loginForm"
ref="loginFormRef"
label-width="80px"
>
<el-form-item label="用户名" prop="username">
<el-input
v-model="loginForm.username"
style="width: 200px"
></el-input>
</el-form-item>
<el-form-item label="密码" prop="password">
<el-input v-model="loginForm.password" style="width: 200px" show-password ></el-input>
<el-input
v-model="loginForm.password"
style="width: 200px"
show-password
></el-input>
</el-form-item>
<div class="cl">
<div class="box_cn"> <el-row >
<div class="box_cn">
<el-row>
<el-button type="primary" @click="login">登录</el-button>
</el-row></div>
<div class="box_cv"> <el-row >
<el-button type="info" style="background-color: orange;border-color: orange;" @click="resetBtn">重置</el-button>
</el-row></div></div>
</el-row>
</div>
<div class="box_cv">
<el-row>
<el-button
type="info"
style="background-color: orange; border-color: orange"
@click="resetBtn"
>重置</el-button
>
</el-row>
</div>
</div>
</el-form>
</div >
</div>
<!-- 外层 -->
<div class="face face2">欢迎使用</div>
</div>
@ -29,85 +50,97 @@
<script>
export default {
data () {
data() {
return {
loginForm: {
username: '',
password: ''
username: "",
password: "",
},
rules: { // key:value
rules: {
// key:value
username: [
{ required: true, message: '请输入用户名', trigger: 'blur' },
{ min: 3, max: 30, message: '长度在 3 到 30 个字符', trigger: 'blur' }
{ required: true, message: "请输入用户名", trigger: "blur" },
{
min: 3,
max: 30,
message: "长度在 3 到 30 个字符",
trigger: "blur",
},
],
password: [
{ required: true, message: '请输入密码', trigger: 'blur' },
{ min: 3, max: 30, message: '长度在 3 到 30 个字符', trigger: 'blur' }
]
}
}
{ required: true, message: "请输入密码", trigger: "blur" },
{
min: 3,
max: 30,
message: "长度在 3 到 30 个字符",
trigger: "blur",
},
],
},
};
},
methods: {
resetBtn () {
resetBtn() {
//
this.$refs.loginFormRef.resetFields()
this.$refs.loginFormRef.resetFields();
},
login () {
this.$refs.loginFormRef.validate(async valid => {
if (!valid) return
login() {
this.$refs.loginFormRef.validate(async (valid) => {
if (!valid) return;
const { data: result } =
await this.$http.post('/user/login', this.loginForm)
if (result.status !== 200) return this.$message.error('用户名或密码错误!')
this.$message.success('用户登录成功!')
const token = result.data
console.log(token)
window.sessionStorage.setItem('token', token)
this.$router.push('/home')
})
}
}
}
const { data: result } = await this.$http.post(
"/user/login",
this.loginForm
);
if (result.status !== 200)
return this.$message.error("用户名或密码错误!");
this.$message.success("用户登录成功!");
const token = result.data;
console.log(token);
window.sessionStorage.setItem("token", token);
this.$router.push("/home");
});
},
},
};
</script>
<style>
.background{
.background {
/* 渐变背景 */
background: linear-gradient(90deg,#00aaff,#ffffff,#4eecec);
background: linear-gradient(90deg, #00aaff, #ffffff, #4eecec);
height: 100%;
width: 100%;
}
}
.box_Central{
.box_Central {
margin-top: 60px;
margin-left: 60px;
}
.box_cn{
float:left;
.box_cn {
float: left;
margin-left: 80px;
}
.box_cv{
.box_cv {
float: left;
margin-left: 50px;
}
.cl{
.cl {
clear: both;
}
.login_box{
.login_box {
width: 450px;
height: 330px;
background-color: #FFFFFF;
background-color: #ffffff;
border-radius: 10px;
position: absolute;
top: 50%;
left: 50%;
right: 50%;
transform: translate(-50%,-50%);
}
.face{
transform: translate(-50%, -50%);
}
.face {
width: 100%;
height: 100%;
position: absolute;
@ -118,40 +151,39 @@ float:left;
align-items: center;
color: white;
font-size: 50px;
}
}
.login_box .face2{
.login_box .face2 {
background: #111;
transition: .5s;
transition: 0.5s;
}
/* 经过外层高度变小 */
.login_box:hover .face2{
.login_box:hover .face2 {
height: 60px;
}
/* 经过字体变小 */
.login_box:hover .face2 h2{
.login_box:hover .face2 h2 {
font-size: 2em;
}
/* 三个卡片外层渐变色 */
.login_box:nth-child(1) .face2{
background: linear-gradient(45deg,#00aaff,#4eeaea);
.login_box:nth-child(1) .face2 {
background: linear-gradient(45deg, #00aaff, #4eeaea);
}
.login_box .face2::before{
content: '';
.login_box .face2::before {
content: "";
position: absolute;
top: 0;
left: 0;
width:50% ;
width: 50%;
height: 100%;
background: rgba(255, 255,255, .1);
background: rgba(255, 255, 255, 0.1);
}
.login_box .face2 h2{
margin:0;
.login_box .face2 h2 {
margin: 0;
padding: 0;
font-size: 10em;
color: #fff;
transition: 0.5s;
}
</style>

2
warehousing-system/project_web/src/main.js

@ -16,7 +16,7 @@ import 'quill/dist/quill.bubble.css' // for bubble theme
import axios from 'axios'
/* 设定axios的请求根目录 */
axios.defaults.baseURL = 'http://localhost:9050/'
axios.defaults.baseURL = 'http://192.168.3.183:9050/'
// axios.defaults.baseURL = 'http://manage.jt.com/'
// axios.defaults.baseURL = 'http://yichuwh.com/'

6
warehousing-system/project_web/src/router/index.js

@ -24,8 +24,8 @@ Vue.use(VueRouter)
const routes = [
{ path: '/login', component: Login },
{ path: '/', redirect: '/login' },
// {path: '/',redirect:'/home'},
// { path: '/', redirect: '/login' },
{ path: '/', redirect: '/home' },
{
path: '/home',
component: Home,
@ -61,7 +61,7 @@ export default router
router.beforeEach((to, from, next) => {
if (to.path === '/login') return next()
// 2.获取token信息
const token = window.sessionStorage.getItem('token')
const token = "9a3860f0f2af471982e919657099913dddd" // window.sessionStorage.getItem('token')
// 3.判断token是否有数据?? if(token) 如果token不为null
// 如果token为null 则跳转到登录页面
if (!token) return next('/login')

Loading…
Cancel
Save