register-form.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <div>
  3. <v-row justify="center">
  4. <v-col cols="10">
  5. <v-text-field
  6. v-model="userRegistry.username"
  7. placeholder="请输入用户名"
  8. label="用户名"
  9. :rules="[() => userRegistry.username != null || '用户名不能为空']"
  10. clearable
  11. @input="checkUsername"
  12. @blur="selectUsername"
  13. />
  14. </v-col>
  15. </v-row>
  16. <v-row justify="center">
  17. <v-col cols="10">
  18. <v-text-field
  19. v-model="userRegistry.email"
  20. placeholder="请输入邮箱"
  21. label="邮箱"
  22. :rules="[() => userRegistry.email != null || '邮箱不能为空']"
  23. type="email"
  24. clearable
  25. @blur="checkEmail"
  26. />
  27. </v-col>
  28. </v-row>
  29. <v-row justify="center">
  30. <v-col cols="10">
  31. <v-row justify="center">
  32. <v-col cols="5">
  33. <v-text-field
  34. v-model="userRegistry.regVerifyCode"
  35. placeholder="请输入邮件验证码"
  36. label="邮件验证码"
  37. :rules="[() => userRegistry.regVerifyCode != null || '邮件验证码不能为空']"
  38. type="email"
  39. clearable
  40. />
  41. </v-col>
  42. <v-col cols="5">
  43. <v-btn color="primary" @click="getVerifyCode">获取邮件验证码</v-btn>
  44. </v-col>
  45. </v-row>
  46. </v-col>
  47. </v-row>
  48. <v-row justify="center">
  49. <v-col cols="10">
  50. <v-text-field
  51. v-model="userRegistry.password"
  52. placeholder="请输入密码"
  53. label="密码"
  54. :rules="[() => userRegistry.password != null || '密码不能为空']"
  55. clearable
  56. type="password"
  57. />
  58. </v-col>
  59. </v-row>
  60. <v-row justify="center">
  61. <v-col cols="5">
  62. <img :src="captchaCode" alt="图形验证码" title="点击刷新" style="cursor:pointer;" @click="getCaptcha">
  63. </v-col>
  64. <v-col cols="5">
  65. <v-text-field
  66. v-model="userRegistry.captchaCode"
  67. placeholder="图形验证码"
  68. label="图形验证码"
  69. :rules="[() => userRegistry.captchaCode != null || '图形验证码不能为空']"
  70. clearable
  71. />
  72. </v-col>
  73. </v-row>
  74. <v-row justify="center">
  75. <v-btn color="primary" @click="submitRegister">注册</v-btn>
  76. </v-row>
  77. </div>
  78. </template>
  79. <script>
  80. import { getVerifyCode, isUsernameExist, selectUsername, isEmailExist, getCaptchaCode } from '@/api/user/account'
  81. export default {
  82. name: 'Register',
  83. data() {
  84. return {
  85. captchaCode: '',
  86. userRegistry: {
  87. regType: 1,
  88. email: '',
  89. password: '',
  90. regVerifyCode: '',
  91. captchaCode: '',
  92. r: ''
  93. }
  94. }
  95. },
  96. created() {
  97. this.getCaptcha()
  98. },
  99. methods: {
  100. checkUsername() {
  101. isUsernameExist(this.userRegistry.username)
  102. .then(res => {
  103. if (res.code === 0) {
  104. this.showMessage = true
  105. this.message = res.msg
  106. } else {
  107. this.showMessage = true
  108. this.message = res.data
  109. }
  110. })
  111. .catch(error => {
  112. this.showMessage = true
  113. this.message = error.message
  114. })
  115. },
  116. selectUsername() {
  117. selectUsername(this.userRegistry.username).then(res => {
  118. if (res.code === 0) {
  119. console.log(res.msg)
  120. } else {
  121. alert(res.data)
  122. }
  123. })
  124. .catch(error => {
  125. console.error(error.message)
  126. })
  127. },
  128. checkEmail() {
  129. const email = this.userRegistry.email
  130. if (email === null || email === '') {
  131. return
  132. }
  133. isEmailExist(this.userRegistry.email)
  134. .then(res => {
  135. if (res.code === 0) {
  136. console.log(res.msg)
  137. } else {
  138. alert(res.data)
  139. }
  140. })
  141. .catch(error => {
  142. console.error(error.message)
  143. })
  144. },
  145. submitRegister() {
  146. var re = /^(([^()[\]\\.,;:\s@\"]+(\.[^()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
  147. if (!re.test(this.userRegistry.email)) {
  148. console.log('email 字段不符合要求')
  149. return
  150. } else if (this.userRegistry.password === '' || this.userRegistry.password.length < 6) {
  151. console.log('password 字段不符合要求')
  152. return
  153. } else if (this.userRegistry.captchaCode === '') {
  154. alert('captchaCode 或 username 字段不符合要求')
  155. return
  156. }
  157. if (this.$store.state.webInfo.openInvitationRegister === 1 && this.userRegistry.invitationCode === '') {
  158. console.log('openInvitationRegister 或 invitationCode 字段不符合要求')
  159. return
  160. }
  161. // 返回到父组件
  162. this.$emit('register', this.userRegistry)
  163. },
  164. getCaptcha() {
  165. getCaptchaCode().then(res => {
  166. if (res.code === 0) {
  167. this.captchaCode = 'data:image/jpeg;base64,' + res.data
  168. } else {
  169. this.showMessage = true
  170. this.message = '获取图形验证码失败, 请重新刷新页面'
  171. }
  172. })
  173. },
  174. getVerifyCode() {
  175. const email = this.userRegistry.email
  176. if (email == null || email === '') {
  177. alert('请输入邮箱地址')
  178. return
  179. }
  180. const verifyCodeReq = {}
  181. verifyCodeReq.receiver = email
  182. verifyCodeReq.notifyType = 1
  183. getVerifyCode(verifyCodeReq).then(res => {
  184. if (res.code === 0) {
  185. alert(res.msg)
  186. } else {
  187. console.error(res.msg)
  188. }
  189. }).catch(error => {
  190. console.error(error.message)
  191. })
  192. }
  193. }
  194. }
  195. </script>
  196. <style>
  197. </style>