index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292
  1. <template>
  2. <div class="f-main">
  3. <div class="content-top">
  4. <p>个人注册</p>
  5. <a class="go" href="/register/enterpriseRegistration"><i class="fa fa-long-arrow-right"></i>企业注册</a>
  6. </div>
  7. <div class="f-form">
  8. <div class="page-part">
  9. <mt-field :state="state.vipName"
  10. placeholder="会员名"
  11. v-model="vipName"
  12. @blur.native.capture="codeVipName" ></mt-field>
  13. </div>
  14. <div class="page-part">
  15. <mt-field :state="state.password"
  16. placeholder="密码"
  17. :attr="{ maxlength: 20 }"
  18. v-model="password"
  19. @input.native="codePwd"
  20. type="password"
  21. @blur.native.capture="codePwdBlur"></mt-field>
  22. <template v-if="password">
  23. <p class="pwd">密码强度 <em :class="{sm:step === '弱', md: step === '中', ld:step === '强'}"></em> <em :class="{md: step === '中', ld:step === '强'}"></em> <em :class="{ld:step === '强'}"></em> <span :class="{smstep:step === '弱', mdstep: step === '中', ldstep:step === '强'}" v-text="step">强</span></p>
  24. <p class="pwd">密码须为8-20字符的英文、数字混合</p>
  25. </template>
  26. </div>
  27. <div class="page-part">
  28. <mt-field :state="state.confirm"
  29. placeholder="确认密码"
  30. v-model="confirm"
  31. type="password"
  32. @blur.native.capture="codePassword"></mt-field>
  33. </div>
  34. <div class="page-part">
  35. <mt-field :state="state.mobile"
  36. placeholder="手机号码"
  37. v-model="mobile"
  38. type="tel"
  39. @blur.native.capture="codeMobile"></mt-field>
  40. </div>
  41. <div class="page-part">
  42. <mt-field :state="state.token"
  43. placeholder="短信验证码"
  44. v-model="token"
  45. @blur.native.capture="codeToken"
  46. auto-complete="off">
  47. <span class="token" v-text="tokenText" @click="getCheckCode">获取验证码</span>
  48. </mt-field>
  49. </div>
  50. </div>
  51. <div class="form-btn">
  52. <div class="page-part">
  53. <el-checkbox v-model="checked">我已阅读并同意 <a class="rgba" href="/common/agreement">《优软云服务条款》</a></el-checkbox>
  54. </div>
  55. <mt-button type="primary" size="large" @click.native="submit">完成注册</mt-button>
  56. </div>
  57. </div>
  58. </template>
  59. <script>
  60. export default {
  61. name: 'registerPerson',
  62. data () {
  63. return {
  64. step: 1,
  65. state: {
  66. vipName: 'error',
  67. password: 'error',
  68. confirm: 'error',
  69. mobile: 'error',
  70. token: 'error'
  71. },
  72. vipName: '',
  73. password: '',
  74. confirm: '',
  75. mobile: '',
  76. token: '',
  77. tokenCode: '',
  78. tokenText: '获取验证码',
  79. tokenTime: '60',
  80. checked: true
  81. }
  82. },
  83. methods: {
  84. // 验证弹窗
  85. downToast (type) {
  86. this.$toast({
  87. message: type,
  88. iconClass: 'el-icon-warning'
  89. })
  90. },
  91. // 验证会员名
  92. codeVipName () {
  93. let count = this.vipName.length
  94. if (count === 0) {
  95. this.downToast('会员名不能为空')
  96. this.state.vipName = 'error'
  97. } else if (count < 2 || count > 20) {
  98. this.downToast('请填写合适的会员名称,2~20个字符')
  99. this.state.vipName = 'warning'
  100. } else {
  101. this.state.vipName = 'success'
  102. }
  103. },
  104. // 验证密码强度
  105. codePwd () {
  106. let reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  107. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  108. let count = this.password.length
  109. if (count >= 20) {
  110. this.downToast('密码须为8-20字符的英文、数字混合')
  111. } else {
  112. if (reg1.test(this.password)) {
  113. this.step = '强'
  114. } else if (reg2.test(this.password)) {
  115. this.step = '中'
  116. } else {
  117. this.step = '弱'
  118. }
  119. }
  120. },
  121. // 验证密码格式
  122. codePwdBlur () {
  123. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  124. if (!this.password) {
  125. this.downToast('请输入密码')
  126. this.state.password = 'error'
  127. } else if (!reg2.test(this.password)) {
  128. this.downToast('密码须为8-20字符的英文、数字混合')
  129. this.state.password = 'warning'
  130. } else {
  131. this.state.password = 'success'
  132. if (this.confirm) {
  133. this.codePassword()
  134. }
  135. }
  136. },
  137. // 验证密码的确认信息
  138. codePassword () {
  139. if (!this.confirm) {
  140. this.downToast('请再次输入密码')
  141. this.state.confirm = 'error'
  142. } else if (this.confirm !== this.password) {
  143. this.downToast('两次输入密码不一致!')
  144. this.state.confirm = 'warning'
  145. } else {
  146. this.state.confirm = 'success'
  147. }
  148. },
  149. // 验证手机号
  150. codeMobile () {
  151. let reg = /^1([0-9]{10})$/
  152. if (!this.mobile) {
  153. this.downToast('请输入手机号')
  154. this.state.mobile = 'error'
  155. } else if (!reg.test(this.mobile)) {
  156. this.downToast('请填写正确的手机号码')
  157. this.state.mobile = 'warning'
  158. } else {
  159. this.$http.get(`/api/user/checkMobile`, {params: {mobile: this.mobile, mobileArea: ''}})
  160. .then(response => {
  161. if (response.data.hasRegister) {
  162. this.downToast('该手机号已被注册,可直接登录')
  163. this.state.mobile = 'warning'
  164. } else {
  165. this.state.mobile = 'success'
  166. }
  167. }).catch(() => {
  168. this.downToast('请检查网络是否正常或联系服务商')
  169. })
  170. }
  171. },
  172. // 验证-验证码信息
  173. codeToken () {
  174. if (!this.token) {
  175. this.downToast('请先填写验证码')
  176. this.state.token = 'error'
  177. } else {
  178. if (!this.mobile) {
  179. this.downToast('请先填写正确的手机号码')
  180. this.state.token = 'warning'
  181. } else {
  182. if (this.tokenCode) {
  183. let param = new FormData()
  184. param.append('mobile', this.mobile)
  185. param.append('token', this.tokenCode)
  186. param.append('code', this.token)
  187. let config = {
  188. headers: {'Content-Type': 'multipart/form-data'}
  189. }
  190. this.$http.post('/sso/personal/register/checkCode', param, config)
  191. .then(response => {
  192. if (response.data.success) {
  193. this.state.token = 'success'
  194. } else {
  195. this.$toast({
  196. message: response.data.errMsg,
  197. iconClass: 'el-icon-error'
  198. })
  199. }
  200. }).catch(() => {
  201. this.downToast('请检查网络是否正常或联系服务商')
  202. })
  203. } else {
  204. this.downToast('请点击先获取验证码信息')
  205. this.state.token = 'warning'
  206. }
  207. }
  208. }
  209. },
  210. // 获取验证码
  211. getCheckCode () {
  212. if (this.tokenTime > 0 && this.tokenTime < 60) {
  213. this.downToast('请稍后再点击,我在倒计时')
  214. } else {
  215. if (this.state.mobile !== 'success') {
  216. this.downToast('请先输入正确的手机号')
  217. } else {
  218. this.$indicator.open('获取中...')
  219. let _this = this
  220. this.$http.get('/sso/personal/register/checkCode', {params: {mobile: this.mobile}})
  221. .then(response => {
  222. this.$indicator.close()
  223. if (response.data) {
  224. this.tokenCode = response.data.token
  225. this.$toast({
  226. message: '验证码已经发送到您的手机,请注意查收',
  227. iconClass: 'el-icon-success'
  228. })
  229. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  230. let setTime = setInterval(() => {
  231. _this.tokenTime--
  232. this.tokenText = '已发送(' + this.tokenTime + 'S)'
  233. if (this.tokenTime <= 0) {
  234. clearInterval(setTime)
  235. _this.tokenText = '获取验证码'
  236. _this.tokenTime = 60
  237. }
  238. }, 1000)
  239. }
  240. }).catch(() => {
  241. this.$indicator.close()
  242. this.downToast('请检查网络是否正常或联系服务商')
  243. })
  244. }
  245. }
  246. },
  247. // 表单提交
  248. submit () {
  249. if (this.state.vipName !== 'success' &&
  250. this.state.password !== 'success' &&
  251. this.state.confirm !== 'success' &&
  252. this.state.mobile !== 'success' &&
  253. this.state.token !== 'success') {
  254. this.downToast('请确认填写部分是否有误')
  255. } else if (this.checked === false) {
  256. this.downToast('您对阅读条款未做勾选')
  257. } else {
  258. this.$indicator.open('注册中...')
  259. let param = new FormData()
  260. param.append('vipName', this.vipName)
  261. param.append('password', this.password)
  262. param.append('mobile', this.mobile)
  263. // param.append('mobileArea', '')
  264. param.append('appId', this.$store.state.option.appId)
  265. param.append('code', this.token)
  266. param.append('token', this.tokenCode)
  267. let config = {
  268. header: {'Content-Type': 'multipart/form-data'}
  269. }
  270. this.$http.post('/sso/personal/register', param, config)
  271. .then(response => {
  272. this.$indicator.close()
  273. if (response.data.success) {
  274. let userUU = response.data.content.userUU
  275. window.location.href = `/overRegister/${userUU}`
  276. } else if (response.data.error) {
  277. this.$toast({
  278. message: response.data.errMsg,
  279. iconClass: 'el-icon-error'
  280. })
  281. }
  282. }).catch(() => {
  283. this.$indicator.close()
  284. this.downToast('请检查网络是否正常或联系服务商')
  285. })
  286. }
  287. }
  288. }
  289. }
  290. </script>