明梦爽
2022-10-11 ce7eaf97c37e476849c002ed8c720b4615965cda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<template>
  <div class="login">
    <el-form class="login-form" :model="loginForm">
      <h3 class="title">新闻管理平台</h3>
      <el-form-item>
        <el-input v-model="loginForm.username" prefix-icon="el-icon-user-solid" type="text" placeholder="账号"></el-input>
      </el-form-item>
      <el-form-item>
        <el-input v-model="loginForm.password" show-password prefix-icon="el-icon-lock" type="password" placeholder="密码"></el-input>
      </el-form-item>
      <el-checkbox style="margin: 0px 0px 25px 0px">记住密码</el-checkbox>
      <el-form-item>
        <el-button @click="Login" size="medium" type="primary">
          <span>登录</span>
        </el-button>
      </el-form-item>
    </el-form>
    <div class="el-login-fotter">
      <span>Copyright © mingms.</span>
    </div>
  </div>
</template>
 
<script>
import { login } from '../api/api'
export default {
  data() {
    return {
      // 这是登录表单的数据绑定对象
      loginForm: {
        username: 'rendong',
        password: '123456'
      }
    }
  },
  methods: {
    // 点击重置按钮,重置登录表单
    resetLoginForm() {
      this.$refs.loginFormRef.resetFields()
    },
    Login() {
      const data = {
        username: this.loginForm.username,
        password: this.loginForm.password
      }
      login(data).then(res => {
        console.log(res)
        if (res.code !== 200) {
          this.$message.error('登录失败!')
        } else if (res.data.role == '超级管理员') {
          this.$message.success('超管登录成功!')
          window.sessionStorage.setItem('token', res.cookie)
          this.$router.push('/administrator/admain')
        } else {
          this.$message.success('登录成功!')
          window.sessionStorage.setItem('token', res.cookie)
          this.$router.push('/administrator/main')
        }
      })
    }
  }
}
</script>
 
<style lang="less" scoped>
.login {
  background-image: url('../assets/bg2.png');
  background-size: 100% 100%;
  // background-size: auto;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  position: relative;
  .login-form {
    background-image: url('../assets/inputBg.png');
    border-radius: 6px;
    position: absolute;
    width: 490px;
    height: 444px;
    right: 250px;
    padding: 45px 50px 0 50px;
    .title {
      height: 40px;
      line-height: 40px;
      font-size: 28px;
      width: 100%;
      font-family: PingFang SC;
      color: #3360c2;
      text-align: center;
      margin-bottom: 35px;
    }
    .el-input {
      margin-bottom: 20px;
    }
    .el-button {
      width: 100%;
      margin: 35px 0;
      background-color: #3360c2;
    }
    .el-button:hover {
      background-color: #3360c2d5;
    }
  }
  .el-login-fotter {
    position: fixed;
    bottom: 0;
    height: 40px;
    line-height: 40px;
    color: #fff;
    font-size: 12px;
    font-family: Arial;
    letter-spacing: 1px;
  }
}
</style>