user-form.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <el-form
  3. ref="loginForm"
  4. :rules="loginRules"
  5. :model="loginForm"
  6. class="login-form"
  7. status-icon
  8. label-width="0"
  9. >
  10. <el-form-item prop="fullName">
  11. <el-input
  12. v-model="loginForm.fullName"
  13. :placeholder="$t('login.fullName')"
  14. auto-complete="off"
  15. prefix-icon="iconfont ibps-icon-user"
  16. @keyup.enter.native="handleRegister"
  17. />
  18. </el-form-item>
  19. <el-form-item prop="gender">
  20. <el-radio-group v-model="loginForm.gender">
  21. <el-radio label="男">{{ $t('login.gender.male') }}</el-radio>
  22. <el-radio label="女">{{ $t('login.gender.female') }}</el-radio>
  23. </el-radio-group>
  24. </el-form-item>
  25. <el-form-item prop="company">
  26. <el-input
  27. v-model="loginForm.company"
  28. :placeholder="$t('login.company')"
  29. auto-complete="off"
  30. prefix-icon="iconfont ibps-icon-university"
  31. @keyup.enter.native="handleRegister"
  32. />
  33. </el-form-item>
  34. <el-form-item prop="area">
  35. <ibps-address-cascader v-model="area" :data="areaData" level="province" top-val="86" data-type="name" />
  36. </el-form-item>
  37. <el-form-item prop="mobile">
  38. <el-input v-model="loginForm.mobile" :placeholder="$t('login.mobile')" auto-complete="off" prefix-icon="iconfont ibps-icon-mobile" @keyup.enter.native="handleRegister" />
  39. </el-form-item>
  40. <el-form-item prop="passWd">
  41. <el-input v-model="loginForm.passWd" :type="passwordType" :placeholder="$t('login.password')" prefix-icon="ibps-icon-lock" auto-complete="off" @keyup.enter.native="handleRegister">
  42. <i slot="suffix" :class="passwordType=='password'?'ibps-icon-eye-slash':'ibps-icon-eye'" class=" el-input__icon" @click="showPassword" />
  43. </el-input>
  44. </el-form-item>
  45. <el-form-item prop="validCode">
  46. <el-input v-model="loginForm.validCode" :placeholder="$t('login.code')" auto-complete="off" prefix-icon="iconfont ibps-icon-qrcode" @keyup.enter.native="handleRegister">
  47. <template slot="append"><span :class="[{display:msgKey}]" class="msg-text" @click="handleSend">{{ $t(msgKey?'login.msgScuccess':'login.msgInit',{'time':msgTime}) }}</span></template>
  48. </el-input>
  49. </el-form-item>
  50. <el-form-item>
  51. <el-button type="primary" class="login-submit" @click.native.prevent="handleRegister">{{ $t('login.registration') }}</el-button>
  52. </el-form-item>
  53. <el-form-item>
  54. <el-button plain class="login-submit" @click.native.prevent="handleLogin">{{ $t('login.backLogin') }}</el-button>
  55. </el-form-item>
  56. </el-form>
  57. </template>
  58. <script>
  59. import { validateMobile } from '@/utils/validate'
  60. import { sendSms } from '@/api/oauth2/user'
  61. import { pca } from 'area-data'
  62. import IbpsAddressCascader from '@/components/ibps-address/cascader'
  63. const MSGTIME = 60 // 时间 60秒
  64. export default {
  65. name: 'codelogin',
  66. components: {
  67. IbpsAddressCascader
  68. },
  69. data() {
  70. const validatePhone = (rule, value, callback) => {
  71. const isMobile = validateMobile(value)
  72. if (!isMobile.result) {
  73. callback(new Error(this.$t('validate.mobile.' + isMobile.msg)))
  74. } else {
  75. callback()
  76. }
  77. }
  78. const validateCode = (rule, value, callback) => {
  79. if (value.length !== 6) {
  80. callback(new Error(this.$t('login.codeLength')))
  81. } else {
  82. callback()
  83. }
  84. }
  85. const validateSpecialCharacters = (rule, value, callback) => {
  86. const specialCharacters = /((?=[\x21-\x7e]+)[^A-Za-z0-9])/g
  87. if (specialCharacters.test(value)) {
  88. callback(new Error('请勿携带特殊字符'))
  89. } else {
  90. callback()
  91. }
  92. }
  93. return {
  94. msgTime: MSGTIME,
  95. msgKey: false,
  96. areaData: pca,
  97. passwordType: 'password',
  98. defaultArea: ['广东省', '广州市'],
  99. loginForm: {
  100. fullName: '',
  101. gender: '女',
  102. company: '',
  103. area: '',
  104. mobile: '',
  105. passWd: '',
  106. validCode: ''
  107. },
  108. loginRules: {
  109. fullName: [{ required: true, trigger: 'blur', validator: validateSpecialCharacters }],
  110. company: [{ required: true, trigger: 'blur', validator: validateSpecialCharacters }],
  111. address: [{ required: true, message: this.$t('validate.required') }],
  112. mobile: [{ required: true, trigger: 'blur', validator: validatePhone }],
  113. passWd: [{ required: true, message: this.$t('validate.required') }],
  114. validCode: [{ required: true, trigger: 'blur', validator: validateCode }]
  115. }
  116. }
  117. },
  118. computed: {
  119. area: {
  120. get() {
  121. if (this.loginForm.area === '') {
  122. return this.defaultArea
  123. } else {
  124. return this.loginForm.area.split('-')
  125. }
  126. },
  127. set(newValue) {
  128. this.loginForm.area = newValue.join('-')
  129. }
  130. }
  131. },
  132. methods: {
  133. showPassword() {
  134. this.passwordType === ''
  135. ? (this.passwordType = 'password')
  136. : (this.passwordType = '')
  137. },
  138. // 发送验证码
  139. handleSend() {
  140. const isMobile = validateMobile(this.loginForm.mobile)
  141. if (!isMobile.result) {
  142. this.$message.closeAll()
  143. this.$message.error(this.$t('login.mobileCorrect'))
  144. this.$el[5].focus()
  145. return
  146. }
  147. // 真正发送验证码
  148. sendSms({
  149. mobile: this.loginForm.mobile,
  150. forget: false
  151. }).then((data) => {
  152. if (this.msgKey) { return }
  153. this.msgKey = true
  154. const time = setInterval(() => {
  155. this.msgTime--
  156. if (this.msgTime === 0) {
  157. this.msgTime = MSGTIME
  158. this.msgKey = false
  159. clearInterval(time)
  160. }
  161. }, 1000)
  162. }).catch((e) => {
  163. })
  164. },
  165. handleRegister() {
  166. this.$refs.loginForm.validate(valid => {
  167. if (valid) {
  168. this.$store.dispatch('ibps/account/register', this.loginForm).then(res => {
  169. this.$confirm('注册账号成功', '提示', {
  170. confirmButtonText: '返回登录',
  171. cancelButtonText: '取消',
  172. type: 'success'
  173. }).then(() => {
  174. this.$router.push({ path: '/login' })
  175. }).catch(() => {
  176. })
  177. })
  178. }
  179. })
  180. },
  181. handleLogin() {
  182. this.$router.push({ path: '/login' })
  183. }
  184. }
  185. }
  186. </script>
  187. <style>
  188. .msg-text {
  189. display: block;
  190. width: 60px;
  191. font-size: 12px;
  192. text-align: center;
  193. cursor: pointer;
  194. }
  195. .msg-text.display {
  196. color: #ccc;
  197. }
  198. </style>