中国算力平台算力登记系统2.0
yanzhaofeige
3 days ago 5cc82f45d73865489cc39e5ffbf521bf4279ec53
commit | author | age
43dc29 1 <template>
Y 2   <div class="login">
3     <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
4       <h3 class="title">中国算力平台算力登记系统</h3>
5       <el-form-item prop="username">
6         <el-input
7           v-model="loginForm.username"
8           type="text"
9           auto-complete="off"
10           placeholder="账号"
11         >
12           <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
13         </el-input>
14       </el-form-item>
15       <el-form-item prop="password">
16         <el-input
17           v-model="loginForm.password"
18           type="password"
19           auto-complete="off"
20           placeholder="密码"
21           @keyup.enter.native="handleLogin"
22         >
23           <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
24         </el-input>
25       </el-form-item>
26       <el-form-item prop="code" v-if="captchaEnabled">
27         <el-input
28           v-model="loginForm.code"
29           auto-complete="off"
30           placeholder="验证码"
31           style="width: 63%"
32           @keyup.enter.native="handleLogin"
33         >
34           <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
35         </el-input>
36         <div class="login-code">
37           <img :src="codeUrl" @click="getCode" class="login-code-img"/>
38         </div>
39       </el-form-item>
40       <el-checkbox v-model="loginForm.rememberMe" style="margin:0px 0px 25px 0px;">记住密码</el-checkbox>
41       <el-form-item style="width:100%;">
42         <el-button
43           :loading="loading"
44           size="medium"
45           type="primary"
46           style="width:100%;"
47           @click.native.prevent="handleLogin"
48         >
49           <span v-if="!loading">登 录</span>
50           <span v-else>登 录 中...</span>
51         </el-button>
52         <div style="float: right;" v-if="register">
53           <router-link class="link-type" :to="'/register'">立即注册</router-link>
54         </div>
55       </el-form-item>
56     </el-form>
57     <!--  底部  -->
58     <div class="el-login-footer">
59       <span>Copyright © 2018-2024 ruoyi.vip All Rights Reserved.</span>
60     </div>
61   </div>
62 </template>
63
64 <script>
65 import { getCodeImg } from "@/api/login";
66 import Cookies from "js-cookie";
67 import { encrypt, decrypt } from '@/utils/jsencrypt'
68
69 export default {
70   name: "Login",
71   data() {
72     return {
73       codeUrl: "",
74       loginForm: {
75         username: "admin",
3ef6ab 76         password: "dceco!",
43dc29 77         rememberMe: false,
Y 78         code: "",
79         uuid: ""
80       },
81       loginRules: {
82         username: [
83           { required: true, trigger: "blur", message: "请输入您的账号" }
84         ],
85         password: [
86           { required: true, trigger: "blur", message: "请输入您的密码" }
87         ],
88         code: [{ required: true, trigger: "change", message: "请输入验证码" }]
89       },
90       loading: false,
91       // 验证码开关
92       captchaEnabled: true,
93       // 注册开关
94       register: false,
95       redirect: undefined
96     };
97   },
98   watch: {
99     $route: {
100       handler: function(route) {
101         this.redirect = route.query && route.query.redirect;
102       },
103       immediate: true
104     }
105   },
106   created() {
107     this.getCode();
108     this.getCookie();
109   },
110   methods: {
111     getCode() {
112       getCodeImg().then(res => {
113         this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled;
114         if (this.captchaEnabled) {
115           this.codeUrl = "data:image/gif;base64," + res.img;
116           this.loginForm.uuid = res.uuid;
117         }
118       });
119     },
120     getCookie() {
121       const username = Cookies.get("username");
122       const password = Cookies.get("password");
123       const rememberMe = Cookies.get('rememberMe')
124       this.loginForm = {
125         username: username === undefined ? this.loginForm.username : username,
126         password: password === undefined ? this.loginForm.password : decrypt(password),
127         rememberMe: rememberMe === undefined ? false : Boolean(rememberMe)
128       };
129     },
130     handleLogin() {
131       this.$refs.loginForm.validate(valid => {
132         if (valid) {
133           this.loading = true;
134           if (this.loginForm.rememberMe) {
135             Cookies.set("username", this.loginForm.username, { expires: 30 });
136             Cookies.set("password", encrypt(this.loginForm.password), { expires: 30 });
137             Cookies.set('rememberMe', this.loginForm.rememberMe, { expires: 30 });
138           } else {
139             Cookies.remove("username");
140             Cookies.remove("password");
141             Cookies.remove('rememberMe');
142           }
143           this.$store.dispatch("Login", this.loginForm).then(() => {
144             this.$router.push({ path: this.redirect || "/" }).catch(()=>{});
145           }).catch(() => {
146             this.loading = false;
147             if (this.captchaEnabled) {
148               this.getCode();
149             }
150           });
151         }
152       });
153     }
154   }
155 };
156 </script>
157
158 <style rel="stylesheet/scss" lang="scss">
159 .login {
160   display: flex;
161   justify-content: center;
162   align-items: center;
163   height: 100%;
164   background-image: url("../assets/images/login-background.jpg");
165   background-size: cover;
166 }
167 .title {
168   margin: 0px auto 30px auto;
169   text-align: center;
170   color: #707070;
171 }
172
173 .login-form {
174   border-radius: 6px;
175   background: #ffffff;
176   width: 400px;
177   padding: 25px 25px 5px 25px;
178   .el-input {
179     height: 38px;
180     input {
181       height: 38px;
182     }
183   }
184   .input-icon {
185     height: 39px;
186     width: 14px;
187     margin-left: 2px;
188   }
189 }
190 .login-tip {
191   font-size: 13px;
192   text-align: center;
193   color: #bfbfbf;
194 }
195 .login-code {
196   width: 33%;
197   height: 38px;
198   float: right;
199   img {
200     cursor: pointer;
201     vertical-align: middle;
202   }
203 }
204 .el-login-footer {
205   height: 40px;
206   line-height: 40px;
207   position: fixed;
208   bottom: 0;
209   width: 100%;
210   text-align: center;
211   color: #fff;
212   font-family: Arial;
213   font-size: 12px;
214   letter-spacing: 1px;
215 }
216 .login-code-img {
217   height: 38px;
218 }
219 </style>