西藏巴青项目

register.vue 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. <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" :rules="registerPwdValidator">
  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>{{ footerContent }}</span>
  65. </div>
  66. </div>
  67. </template>
  68. <script>
  69. import { getCodeImg, register } from "@/api/login"
  70. import passwordRule from "@/utils/passwordRule"
  71. import defaultSettings from '@/settings'
  72. export default {
  73. mixins: [passwordRule],
  74. data() {
  75. return {
  76. title: process.env.VUE_APP_TITLE,
  77. footerContent: defaultSettings.footerContent,
  78. codeUrl: "",
  79. registerForm: {
  80. username: "",
  81. password: "",
  82. confirmPassword: "",
  83. code: "",
  84. uuid: ""
  85. },
  86. loading: false,
  87. captchaEnabled: true
  88. }
  89. },
  90. computed: {
  91. registerRules() {
  92. return {
  93. username: [
  94. { required: true, trigger: "blur", message: "请输入您的账号" },
  95. { min: 2, max: 20, message: '用户账号长度必须介于 2 和 20 之间', trigger: 'blur' }
  96. ],
  97. confirmPassword: [
  98. { required: true, message: "请再次输入您的密码", trigger: "blur" },
  99. {
  100. validator: (rule, value, callback) => {
  101. if (this.registerForm.password !== value) {
  102. callback(new Error("两次输入的密码不一致"))
  103. } else {
  104. callback()
  105. }
  106. }, trigger: "blur"
  107. }
  108. ],
  109. code: [{ required: true, trigger: "change", message: "请输入验证码" }]
  110. }
  111. }
  112. },
  113. created() {
  114. this.getCode()
  115. },
  116. methods: {
  117. getCode() {
  118. getCodeImg().then(res => {
  119. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  120. if (this.captchaEnabled) {
  121. this.codeUrl = "data:image/gif;base64," + res.img
  122. this.registerForm.uuid = res.uuid
  123. }
  124. })
  125. },
  126. handleRegister() {
  127. this.$refs.registerForm.validate(valid => {
  128. if (valid) {
  129. this.loading = true
  130. register(this.registerForm).then(() => {
  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. <style rel="stylesheet/scss" lang="scss" scoped>
  151. .register {
  152. display: flex;
  153. justify-content: center;
  154. align-items: center;
  155. height: 100%;
  156. background-image: url("../assets/images/login-background.jpg");
  157. background-size: cover;
  158. }
  159. .title {
  160. margin: 0px auto 30px auto;
  161. text-align: center;
  162. color: #707070;
  163. }
  164. .register-form {
  165. border-radius: 6px;
  166. background: #ffffff;
  167. width: 400px;
  168. padding: 25px 25px 5px 25px;
  169. .el-input {
  170. height: 38px;
  171. input {
  172. height: 38px;
  173. }
  174. }
  175. .input-icon {
  176. height: 39px;
  177. width: 14px;
  178. margin-left: 2px;
  179. }
  180. }
  181. .register-tip {
  182. font-size: 13px;
  183. text-align: center;
  184. color: #bfbfbf;
  185. }
  186. .register-code {
  187. width: 33%;
  188. height: 38px;
  189. float: right;
  190. img {
  191. cursor: pointer;
  192. vertical-align: middle;
  193. }
  194. }
  195. .el-register-footer {
  196. height: 40px;
  197. line-height: 40px;
  198. position: fixed;
  199. bottom: 0;
  200. width: 100%;
  201. text-align: center;
  202. color: #fff;
  203. font-family: Arial;
  204. font-size: 12px;
  205. letter-spacing: 1px;
  206. }
  207. .register-code-img {
  208. height: 38px;
  209. }
  210. </style>