register.vue 6.5 KB

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