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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
| <template>
| <div class="login" @click="$refs.verify.show = false">
| <Row @keydown.enter.native="submitLogin" class="flex">
| <Col style="width: 368px">
| <Header />
| <Row style="flex-direction: column">
| <Form
| ref="usernameLoginForm"
| :model="form"
| :rules="rules"
| class="form"
| >
| <FormItem prop="username">
| <Input
| v-model="form.username"
| prefix="ios-contact"
| size="large"
| clearable
| placeholder="请输入用户名"
| autocomplete="off"
| />
| </FormItem>
| <FormItem prop="password">
| <Input
| type="password"
| v-model="form.password"
| prefix="ios-lock"
| size="large"
| password
| placeholder="请输入密码"
| autocomplete="off"
| />
| </FormItem>
| </Form>
|
| <Row>
| <Button
| class="login-btn"
| type="primary"
| size="large"
| :loading="loading"
| @click="submitLogin"
| long
| >
| <span v-if="!loading">{{ $t("login") }}</span>
| <span v-else>{{ $t("logining") }}</span>
| </Button>
| </Row>
| </Row>
| <!-- 拼图验证码 -->
| <verify
| ref="verify"
| class="verify-con"
| verifyType="LOGIN"
| @change="verifyChange"
| ></verify>
| <Footer />
| </Col>
| <!-- <LangSwitch /> -->
| </Row>
| </div>
| </template>
|
| <script>
| import { login, userInfo } from "@/api/index";
| import Cookies from "js-cookie";
| import Header from "@/views/main-parts/header";
| import Footer from "@/views/main-parts/footer";
| import LangSwitch from "@/views/main-parts/lang-switch";
| import util from "@/libs/util.js";
| import verify from "@/components/verify";
|
| export default {
| components: {
| LangSwitch,
| Header,
| Footer,
| verify,
| },
| data() {
| return {
| loading: false, // 加载状态
| form: {
| // 表单数据
| username: "",
| password: "",
| mobile: "",
| code: "",
| },
| rules: {
| // 验证规则
| username: [
| {
| required: true,
| message: "账号不能为空",
| trigger: "blur",
| },
| ],
| password: [
| {
| required: true,
| message: "密码不能为空",
| trigger: "blur",
| },
| ],
| },
| };
| },
| methods: {
| afterLogin(res) {
| // 登录成功后处理
| let accessToken = res.result.accessToken;
| let refreshToken = res.result.refreshToken;
| this.setStore("accessToken", accessToken);
| this.setStore("refreshToken", refreshToken);
| // 获取用户信息
| userInfo().then((res) => {
| if (res.success) {
| // 加载菜单
| Cookies.set("userInfoManager", JSON.stringify(res.result));
| this.$store.commit("setAvatarPath", res.result.avatar);
| util.initRouter(this);
| this.$router.push({
| name: "home_index",
| });
| } else {
| this.loading = false;
| }
| });
| },
| submitLogin() {
| // 登录操作
| this.$refs.usernameLoginForm.validate((valid) => {
| if (valid) {
| this.$refs.verify.init();
| }
| });
| },
| verifyChange(con) {
| // 拼图验证码回显
| if (!con.status) return;
|
| this.loading = true;
|
| let fd = new FormData();
| fd.append("username", this.form.username);
| fd.append("password", this.md5(this.form.password));
| login(fd)
| .then((res) => {
| if (res && res.success) {
| this.afterLogin(res);
| } else {
| this.loading = false;
| }
| })
| .catch(() => {
| this.loading = false;
| });
| this.$refs.verify.show = false;
| },
| },
| };
| </script>
|
| <style lang="scss" scoped>
| .login {
| height: 100%;
| background: url("../assets/background.png") no-repeat;
| background-color: #f0f2f5;
| display: flex;
| background-size: cover;
| align-items: center;
| justify-content: center;
|
| .verify-con {
| position: absolute;
| top: 150px;
| z-index: 10;
| left: 20px;
| }
| .form {
| padding-top: 1vh;
| }
|
| .login-btn {
| background: linear-gradient(135deg, $theme_color 0%, $warning_color 100%);
| height: 40px;
| cursor: pointer;
| border-radius: 4px;
| display: flex;
| align-items: center;
| justify-content: center;
| font-size: 16px;
| color: #fff;
| width: 100%;
| text-align: center;
| transition: 0.35s;
| }
| .login-btn:hover {
| opacity: 0.9;
| border-radius: 10px;
| }
| }
| .flex {
| justify-content: center;
| }
| </style>
|
|