index.vue 11 KB

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