zrlibs
2025-03-21 cd24c776d772c7ad797891afd779b3b072293ec2
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
<template>
  <div class="login-view">
    <div class="login-wrap">
      <div class="login-account">
        <div class="account-logo">
          <img src="http://115.29.185.26:5101/userphoto?login=sa" />
        </div>
        <Form
          class="account-form"
          :model="form"
          :rules="rules"
          label-position="top"
          ref="refFormInline"
        >
          <div class="title">Vue仓库管理系统</div>
          <div class="ivu-login">
            <FormItem prop="user">
              <Input
                type="text"
                v-model="form.user"
                prefix="ios-person-outline"
              >
              </Input>
            </FormItem>
            <FormItem prop="password">
              <Input
                type="password"
                v-model="form.password"
                prefix="ios-lock-outline"
              >
              </Input>
            </FormItem>
            <FormItem>
              <Button type="primary" @click="onSignIn" long>登录</Button>
            </FormItem>
          </div>
        </Form>
      </div>
    </div>
  </div>
</template>
 
<script>
import { ref } from "vue";
import { login } from "@/api/test";
import { Base64 } from "js-base64";
import { showError, showSuccess, setToken } from "@/libs/util";
export default {
  name: "LoginView",
  data() {
    return {
      form: {
        user: "admin",
        password: "0000",
      },
      rules: {
        user: [
          {
            required: true,
            message: "Please fill in the user name",
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: "Please fill in the password.",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    onSignIn() {
      // 测试用户
      if (this.form.user == "admin" && this.form.password == "0000") {
        setToken("uid");
        this.showSuccess("登录成功");
        this.$router.push("/");
        return;
      }
      this.refFormInline.validate(async (valid) => {
        try {
          if (valid) {
            let res = await login({
              user_login: Base64.encode(this.form.user),
              user_psw: Base64.encode(this.form.password),
            });
            setToken(res.session_id);
            this.showSuccess("登录成功");
            this.$router.push("/");
          } else {
            this.showError("表单验证失败!");
          }
        } catch (ex) {
          this.showError(ex);
        }
      });
    },
    showError(ex) {
      showError(this, ex);
    },
    showSuccess(tip) {
      showSuccess(this, tip);
    },
  },
  setup() {
    const refFormInline = ref(null);
    return { refFormInline };
  },
};
</script>
 
<style lang="less">
.login-view {
  background-repeat: no-repeat;
  background-size: 100% 100%;
  background-position: right bottom;
  background-image: url("../../assets/login_bg.png");
  background-attachment: fixed;
  .login-wrap {
    height: 100vh;
    overflow: auto;
  }
  .login-account {
    width: 280px;
    padding: 16px 0 0;
    margin: 0 300px 0 auto;
    margin-top: 100px;
  }
  .account-logo {
    width: 80px;
    height: 80px;
    margin: 0 auto;
    border: 1px solid #eee;
    border-radius: 50%;
    background-color: #fafafc;
    img {
      width: 100%;
      border-style: none;
      border-radius: 100%;
    }
  }
  .account-form {
    margin-top: 32px;
  }
  .title {
    font-size: 30px;
    text-align: center;
    margin-bottom: 18px;
    letter-spacing: 3px;
 
    font-weight: bold;
    background: -webkit-linear-gradient(#009df4, #00e9cf);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    color: transparent;
  }
  .ivu-login {
    padding: 60px 30px 3px;
    background-image: url("../../assets/account_bg.png");
    background-repeat: no-repeat;
    background-size: 100% 100%;
    background-position: right bottom;
  }
  .ivu-form-item {
    margin-bottom: 24px;
    vertical-align: top;
    zoom: 1;
    .ivu-icon {
      color: #0ba1f8;
    }
    .ivu-input {
      border: 2px solid #0ba1f8;
      background-color: transparent;
      color: #fff;
    }
  }
  .ivu-form-item-content {
    position: relative;
    line-height: 32px;
    font-size: 14px;
  }
}
</style>