xm
2024-06-14 722af26bc6fec32bb289b1df51a9016a4935610f
提交 | 用户 | 时间
722af2 1 <template>
X 2   <div class="register">
3     <el-form ref="registerForm" :model="registerForm" :rules="registerRules" class="register-form">
4       <h3 class="title">RuoYi-Vue-Plus后台管理系统</h3>
5       <el-form-item prop="username">
6         <el-input v-model="registerForm.username" type="text" auto-complete="off" placeholder="账号">
7           <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon" />
8         </el-input>
9       </el-form-item>
10       <el-form-item prop="password">
11         <el-input
12           v-model="registerForm.password"
13           type="password"
14           auto-complete="off"
15           placeholder="密码"
16           @keyup.enter.native="handleRegister"
17         >
18           <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
19         </el-input>
20       </el-form-item>
21       <el-form-item prop="confirmPassword">
22         <el-input
23           v-model="registerForm.confirmPassword"
24           type="password"
25           auto-complete="off"
26           placeholder="确认密码"
27           @keyup.enter.native="handleRegister"
28         >
29           <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon" />
30         </el-input>
31       </el-form-item>
32       <el-form-item prop="code" v-if="captchaEnabled">
33         <el-input
34           v-model="registerForm.code"
35           auto-complete="off"
36           placeholder="验证码"
37           style="width: 63%"
38           @keyup.enter.native="handleRegister"
39         >
40           <svg-icon slot="prefix" icon-class="validCode" class="el-input__icon input-icon" />
41         </el-input>
42         <div class="register-code">
43           <img :src="codeUrl" @click="getCode" class="register-code-img"/>
44         </div>
45       </el-form-item>
46       <el-form-item style="width:100%;">
47         <el-button
48           :loading="loading"
49           size="medium"
50           type="primary"
51           style="width:100%;"
52           @click.native.prevent="handleRegister"
53         >
54           <span v-if="!loading">注 册</span>
55           <span v-else>注 册 中...</span>
56         </el-button>
57         <div style="float: right;">
58           <router-link class="link-type" :to="'/login'">使用已有账户登录</router-link>
59         </div>
60       </el-form-item>
61     </el-form>
62     <!--  底部  -->
63     <div class="el-register-footer">
64       <span>Copyright © 2018-2023 KonBAI All Rights Reserved.</span>
65     </div>
66   </div>
67 </template>
68
69 <script>
70 import { getCodeImg, register } from "@/api/login";
71
72 export default {
73   name: "Register",
74   data() {
75     const equalToPassword = (rule, value, callback) => {
76       if (this.registerForm.password !== value) {
77         callback(new Error("两次输入的密码不一致"));
78       } else {
79         callback();
80       }
81     };
82     return {
83       codeUrl: "",
84       registerForm: {
85         username: "",
86         password: "",
87         confirmPassword: "",
88         code: "",
89         uuid: "",
90         userType: "sys_user"
91       },
92       registerRules: {
93         username: [
94           { required: true, trigger: "blur", message: "请输入您的账号" },
95           { min: 2, max: 20, message: '用户账号长度必须介于 2 和 20 之间', trigger: 'blur' }
96         ],
97         password: [
98           { required: true, trigger: "blur", message: "请输入您的密码" },
99           { min: 5, max: 20, message: '用户密码长度必须介于 5 和 20 之间', trigger: 'blur' }
100         ],
101         confirmPassword: [
102           { required: true, trigger: "blur", message: "请再次输入您的密码" },
103           { required: true, validator: equalToPassword, trigger: "blur" }
104         ],
105         code: [{ required: true, trigger: "change", message: "请输入验证码" }]
106       },
107       loading: false,
108       captchaEnabled: true
109     };
110   },
111   created() {
112     this.getCode();
113   },
114   methods: {
115     getCode() {
116       getCodeImg().then(res => {
117         this.captchaEnabled = res.data.captchaEnabled === undefined ? true : res.data.captchaEnabled;
118         if (this.captchaEnabled) {
119           this.codeUrl = "data:image/gif;base64," + res.data.img;
120           this.registerForm.uuid = res.data.uuid;
121         }
122       });
123     },
124     handleRegister() {
125       this.$refs.registerForm.validate(valid => {
126         if (valid) {
127           this.loading = true;
128           let registerForm = this.registerForm;
129           registerForm.userType = "sys_user"
130           register(registerForm).then(res => {
131             const username = this.registerForm.username;
132             this.$alert("<font color='red'>恭喜你,您的账号 " + username + " 注册成功!</font>", '系统提示', {
133               dangerouslyUseHTMLString: true,
134               type: 'success'
135             }).then(() => {
136               this.$router.push("/login");
137             }).catch(() => {});
138           }).catch(() => {
139             this.loading = false;
140             if (this.captchaEnabled) {
141               this.getCode();
142             }
143           })
144         }
145       });
146     }
147   }
148 };
149 </script>
150
151 <style rel="stylesheet/scss" lang="scss">
152 .register {
153   display: flex;
154   justify-content: center;
155   align-items: center;
156   height: 100%;
157   background-image: url("../assets/images/login-background.jpg");
158   background-size: cover;
159 }
160 .title {
161   margin: 0px auto 30px auto;
162   text-align: center;
163   color: #707070;
164 }
165
166 .register-form {
167   border-radius: 6px;
168   background: #ffffff;
169   width: 400px;
170   padding: 25px 25px 5px 25px;
171   .el-input {
172     height: 38px;
173     input {
174       height: 38px;
175     }
176   }
177   .input-icon {
178     height: 39px;
179     width: 14px;
180     margin-left: 2px;
181   }
182 }
183 .register-tip {
184   font-size: 13px;
185   text-align: center;
186   color: #bfbfbf;
187 }
188 .register-code {
189   width: 33%;
190   height: 38px;
191   float: right;
192   img {
193     cursor: pointer;
194     vertical-align: middle;
195   }
196 }
197 .el-register-footer {
198   height: 40px;
199   line-height: 40px;
200   position: fixed;
201   bottom: 0;
202   width: 100%;
203   text-align: center;
204   color: #fff;
205   font-family: Arial;
206   font-size: 12px;
207   letter-spacing: 1px;
208 }
209 .register-code-img {
210   height: 38px;
211 }
212 </style>