register.vue 6.3 KB

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