index.vue 10 KB

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