register-from.vue 5.9 KB

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