jesting0
2022-04-06 4a0fb138f5670809507c6483074622630e59eef3
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
<template>
  <div class="login-view">
    <div class="login-view-wrap">
      <div class="logo">
        <img src="../../assets/logo.png" alt="" />
      </div>
      <Form ref="form" :model="form" :rules="rules">
        <FormItem prop="login">
          <Input type="text" v-model="form.login" placeholder="登录名">
            <Icon type="ios-person-outline" slot="prepend"></Icon>
          </Input>
        </FormItem>
        <FormItem prop="password">
          <Input type="password" v-model="form.password" placeholder="口令" @on-enter="onClick">
            <Icon type="ios-lock-outline" slot="prepend"></Icon>
          </Input>
        </FormItem>
      </Form>
      <Button type="primary" @click="onClick">登录</Button>
      <Spin fix v-if="loading" />
    </div>
  </div>
</template>
 
<script>
import { webConfig, setSession } from "@/utils";
export default {
  name: "LoginView",
  data() {
    return {
      form: {
        login: "",
        password: "",
      },
      rules: {
        login: [{ required: true, message: "登录名不能为空", trigger: "blur" }],
        password: [
          { required: true, message: "口令不能为空", trigger: "blur" },
        ],
      },
      loading: false,
    };
  },
  methods: {
    onClick() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          // 登录验证
          if (!webConfig.admin || !webConfig.admin.id || !webConfig.admin.pwd) {
            return this.$Message.error("管理员信息配置不完整!");
          }
          if (this.form.login == webConfig.admin.id) {
            if (this.form.password == webConfig.admin.pwd) {
              // 管理员登录成功
              setSession({ id: this.form.login, admin: 1 });
            } else {
              // 管理员登录失败
              return this.$Message.error("管理员登录失败,密码不正确!");
            }
          } else {
            // 普通用户登录成功
            setSession({ id: this.form.login, admin: 0 });
          }
          this.$Message.success("登录成功!");
          setTimeout(() => this.$router.push("/"), 500);
        } else {
          this.$Message.error("登录失败!");
        }
      });
    },
  },
};
</script>
 
<style lang="less" scoped>
.login-view {
  background-color: #eeefff;
  font-size: 14px;
  display: flex;
  flex-direction: column;
  height: 100vh;
  .login-view-wrap {
    width: 280px;
    padding: 28px;
    text-align: center;
    margin: 100px auto 0;
    background-color: #fff;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.1);
    position: relative;
    .logo {
      margin-bottom: 20px;
      img {
        width: 150px;
      }
    }
  }
}
</style>