PersonalRegistration.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. <template>
  2. <div class="register">
  3. <div class="container">
  4. <div class="content">
  5. <div class="content-top">
  6. <h3>个人注册</h3>
  7. <a class="go" href="/register/enterpriseRegistration"><i class="fa fa-long-arrow-right"></i>企业注册</a>
  8. </div>
  9. <div>
  10. <el-form :model="item" :rules="rules2" ref="item" label-width="100px" class="demo-ruleForm">
  11. <el-form-item prop="vipName">
  12. <el-input type="text" v-model="item.vipName" auto-complete="off" placeholder="会员名"></el-input>
  13. </el-form-item>
  14. <el-form-item prop="password">
  15. <el-input type="password" v-model="item.password" auto-complete="off" placeholder="登录密码"></el-input>
  16. <div class="pwd sm" v-show="showMsgTip1">密码强度 <em></em><em></em><em></em><span>弱</span></div>
  17. <div class="pwd md" v-show="showMsgTip2">密码强度 <em></em><em></em><em></em><span>中</span></div>
  18. <div class="pwd lar" v-show="showMsgTip3">密码强度 <em></em><em></em><em></em><span>强</span></div>
  19. <div class="pwd low" v-show="showMsgTip4">密码强度 <em></em><em></em><em></em></div>
  20. </el-form-item>
  21. <el-form-item prop="confirm">
  22. <el-input type="password"
  23. v-model="item.confirm"
  24. v-bind:class="{active: showPasswordError}"
  25. auto-complete="off"
  26. placeholder="密码确认"></el-input>
  27. <span class="tip passwordError" v-show="showPasswordError">两次输入密码不一致</span>
  28. </el-form-item>
  29. <el-form-item prop="mobile">
  30. <el-input v-model="item.mobile"
  31. v-bind:class="{active: mobileRegister}"
  32. placeholder="手机号码"></el-input>
  33. <span class="tip" v-show="showMsgTip">单个手机号只能注册一个用户</span>
  34. <span class="tip tip-mobile" v-show="mobileRegister">该手机号已被注册</span>
  35. </el-form-item>
  36. <el-form-item prop="code">
  37. <el-input type="text" v-model="item.code"
  38. v-bind:class="{ active: codeErrorChecked }" auto-complete="off" class="msg" placeholder="短信验证码"></el-input>
  39. <el-button type="primary" class="code"
  40. v-show="sendPersonalCode"
  41. @click="getCheckCode"
  42. :disabled="this.checkMobile">获取验证码</el-button>
  43. <el-button type="primary" v-show="!sendPersonalCode" class="code code-send">已发送({{personal_time}}s)</el-button>
  44. <span v-show="codeErrorChecked" class="codeError-tip">{{codeErrorMsg}}</span>
  45. </el-form-item>
  46. <el-form-item>
  47. <!--<el-button type="primary" @click="submitForm('item')" :disabled="!this.item.vipName || !this.item.password || !this.item.confirm || !this.item.code || !this.checked" class="finish">完成注册</el-button>-->
  48. <a class="btn finish" @click="submit"
  49. :disabled="!this.vipNameChecked || !this.passwordChecked || !this.confirmChecked || !this.mobileChecked || !this.codeChecked || !this.checked">完成注册</a>
  50. </el-form-item>
  51. <el-form-item>
  52. <el-checkbox name="type" v-model="checked" @click="checkboxChecked"></el-checkbox>
  53. <span class="agree">我已阅读并同意 <a href="/common/agreement">《优软云服务条款》</a></span>
  54. </el-form-item>
  55. </el-form>
  56. </div>
  57. </div>
  58. <div class="login">已有账号?<a href="/">立即登录</a></div>
  59. <loading v-show="isShowLoading"/>
  60. </div>
  61. </div>
  62. </template>
  63. <script>
  64. import Loading from '~components/common/loading/Loading.vue'
  65. export default {
  66. name: 'PersonalRegistration',
  67. components: {
  68. Loading
  69. },
  70. data () {
  71. var validateName = (rule, value, callback) => {
  72. if (value === '') {
  73. callback(new Error('会员名不能为空'))
  74. this.vipNameChecked = false
  75. } else {
  76. if (this.item.vipName !== '') {
  77. if (value.length < 2 || value.length > 20) {
  78. callback(new Error('请填写合适的会员名称,2~20个字符'))
  79. this.vipNameChecked = false
  80. } else {
  81. this.vipNameChecked = true
  82. }
  83. }
  84. }
  85. callback()
  86. }
  87. var validatePass = (rule, value, callback) => {
  88. if (this.item.password !== '') {
  89. if (value.length <= 20 && value.length >= 8) {
  90. var reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  91. var reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  92. if (reg1.test(value)) {
  93. // callback(new Error('密码强度强'))
  94. this.showMsgTip3 = true
  95. this.showMsgTip2 = false
  96. this.showMsgTip1 = false
  97. this.showMsgTip4 = false
  98. this.passwordChecked = true
  99. } else if (reg2.test(value)) {
  100. // callback(new Error('密码强度中'))
  101. this.showMsgTip2 = true
  102. this.showMsgTip3 = false
  103. this.showMsgTip1 = false
  104. this.showMsgTip4 = false
  105. this.passwordChecked = true
  106. } else {
  107. this.showMsgTip1 = true
  108. this.showMsgTip3 = false
  109. this.showMsgTip2 = false
  110. this.showMsgTip4 = false
  111. this.passwordChecked = false
  112. }
  113. } else {
  114. this.showMsgTip3 = false
  115. this.showMsgTip2 = false
  116. this.showMsgTip1 = false
  117. this.showMsgTip4 = true
  118. this.passwordChecked = false
  119. }
  120. }
  121. callback()
  122. }
  123. var validatePassTip = (rule, value, callback) => {
  124. if (value === '') {
  125. callback(new Error('请输入密码'))
  126. this.passwordChecked = false
  127. } else {
  128. if (this.item.password !== '') {
  129. if (value.length <= 20 && value.length >= 8) {
  130. var reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  131. var reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  132. if (reg1.test(value)) {
  133. this.passwordChecked = true
  134. } else if (reg2.test(value)) {
  135. this.passwordChecked = true
  136. } else {
  137. callback(new Error('密码须为8-20字符的英文、数字混合'))
  138. this.passwordChecked = false
  139. }
  140. } else {
  141. callback(new Error('密码须为8-20字符的英文、数字混合'))
  142. this.passwordChecked = false
  143. }
  144. if (this.item.confirm !== '') {
  145. if (value !== this.item.confirm) {
  146. this.showPasswordError = true
  147. // callback(new Error('两次输入密码不一致!'))
  148. this.confirmChecked = false
  149. } else {
  150. this.confirmChecked = true
  151. this.showPasswordError = false
  152. callback()
  153. }
  154. }
  155. }
  156. callback()
  157. }
  158. }
  159. var validatePass2 = (rule, value, callback) => {
  160. if (value === '') {
  161. callback(new Error('请再次输入密码'))
  162. this.confirmChecked = false
  163. this.showPasswordError = false
  164. } else if (value !== this.item.password) {
  165. // callback(new Error('两次输入密码不一致!'))
  166. this.showPasswordError = true
  167. this.confirmChecked = false
  168. } else {
  169. this.confirmChecked = true
  170. this.showPasswordError = false
  171. callback()
  172. }
  173. }
  174. var validateMobile = (rule, value, callback) => {
  175. if (value === '') {
  176. callback(new Error('请填写正确的手机号'))
  177. this.showMsgTip = false
  178. this.checkMobile = true
  179. this.mobileRegister = false
  180. this.mobileChecked = false
  181. } else {
  182. if (this.item.mobile !== '') {
  183. var reg = /^1([0-9]{10})$/
  184. if (!reg.test(value)) {
  185. callback(new Error('请填写正确的手机号'))
  186. this.showMsgTip = false
  187. this.checkMobile = true
  188. this.mobileRegister = false
  189. this.mobileChecked = false
  190. } else {
  191. this.$http.get(`/api/user/checkMobile`, {params: {mobile: this.item.mobile, mobileArea: ''}})
  192. .then(response => {
  193. if (response.data.hasRegister) {
  194. this.mobileRegister = true
  195. this.showMsgTip = false
  196. this.checkMobile = true
  197. this.mobileChecked = false
  198. } else {
  199. this.showMsgTip = false
  200. this.checkMobile = false
  201. this.mobileRegister = false
  202. this.mobileChecked = true
  203. }
  204. })
  205. }
  206. }
  207. callback()
  208. }
  209. }
  210. var validateCode = (rule, value, callback) => {
  211. if (value === '') {
  212. callback(new Error('请填写正确的验证码'))
  213. this.codeErrorChecked = false
  214. this.codeChecked = false
  215. } else {
  216. if (this.item.code !== '') {
  217. if (this.item.mobile === '') {
  218. callback(new Error('请先填写正确的手机号'))
  219. } else {
  220. if (this.token) {
  221. let param = new FormData()
  222. param.append('mobile', this.item.mobile)
  223. param.append('code', this.item.code)
  224. param.append('token', this.token)
  225. let config = {
  226. headers: {'Content-Type': 'multipart/form-data'}
  227. }
  228. this.$http.post(`/sso/personal/register/checkCode`, param, config)
  229. .then(response => {
  230. if (response.data.success) {
  231. this.codeChecked = true
  232. this.codeErrorChecked = false
  233. } else {
  234. this.codeErrorChecked = true
  235. this.codeChecked = false
  236. // callback(new Error('验证码输入错误'))
  237. return Promise.reject(response.data)
  238. }
  239. }).catch(err => {
  240. this.codeErrorMsg = err.errMsg
  241. // this.$message.error(err.errMsg)
  242. })
  243. } else {
  244. callback(new Error('请先获取验证码'))
  245. this.codeChecked = false
  246. this.codeErrorChecked = false
  247. }
  248. }
  249. }
  250. callback()
  251. }
  252. }
  253. return {
  254. item: {
  255. vipName: '',
  256. password: '',
  257. confirm: '',
  258. mobile: '',
  259. code: ''
  260. },
  261. isShowLoading: false,
  262. showPasswordError: false,
  263. vipNameChecked: false,
  264. passwordChecked: false,
  265. confirmChecked: false,
  266. mobileChecked: false,
  267. codeChecked: false,
  268. codeErrorChecked: false,
  269. showMsgTip: true,
  270. showMsgTip1: false,
  271. showMsgTip2: false,
  272. showMsgTip3: false,
  273. showMsgTip4: false,
  274. checkMobile: true,
  275. checked: true,
  276. token: '',
  277. mobileRegister: false,
  278. sendPersonalCode: true,
  279. codeErrorMsg: '',
  280. personal_time: 0,
  281. rules2: {
  282. vipName: [
  283. { validator: validateName, trigger: 'blur' }
  284. ],
  285. password: [
  286. { validator: validatePassTip, trigger: 'blur' },
  287. { validator: validatePass, trigger: 'change' }
  288. ],
  289. confirm: [
  290. { required: true, validator: validatePass2, trigger: 'blur' }
  291. ],
  292. mobile: [
  293. { validator: validateMobile, trigger: 'blur' }
  294. ],
  295. code: [
  296. { validator: validateCode, trigger: 'blur' }
  297. ]
  298. }
  299. }
  300. },
  301. methods: {
  302. // 我同意是否被选中
  303. checkboxChecked () {
  304. this.checked = !this.checked
  305. },
  306. // 表单提交
  307. submit () {
  308. if (this.vipNameChecked && this.passwordChecked && this.confirmChecked && this.mobileChecked && this.codeChecked && this.checked) {
  309. this.isShowLoading = true
  310. var url = window.location.search
  311. var request = {}
  312. if (url.indexOf('?' !== -1)) {
  313. var str = url.substr(1)
  314. var strs = str.split('&')
  315. for (var i = 0; i < strs.length; i++) {
  316. request[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1])
  317. }
  318. }
  319. var appId = request['appId'] || ''
  320. let param = new FormData()
  321. param.append('vipName', this.item.vipName)
  322. param.append('password', this.item.password)
  323. param.append('mobile', this.item.mobile)
  324. // param.append('mobileArea', '')
  325. param.append('appId', appId)
  326. param.append('code', this.item.code)
  327. param.append('token', this.token)
  328. let config = {
  329. headers: {'Content-Type': 'multipart/form-data'}
  330. }
  331. this.$http.post('/sso/personal/register', param, config)
  332. .then(response => {
  333. this.isShowLoading = false
  334. if (response.data.success) {
  335. let userUU = response.data.content.userUU
  336. window.location.href = `/overRegister/${userUU}`
  337. } else {
  338. return Promise.reject(response.data)
  339. }
  340. }).catch(err => {
  341. this.$message.error(err.errMsg)
  342. this.isShowLoading = false
  343. // this.codeErrorChecked = true
  344. // this.codeChecked = false
  345. this.personal_time = 0
  346. })
  347. }
  348. },
  349. // 获取验证码
  350. // async getCode () {
  351. // let { data } = await this.$http.get(`/sso/personal/register/checkCode`, {params: {mobile: this.item.mobile}})
  352. // this.token = data.token
  353. // },
  354. getCheckCode () {
  355. this.isShowLoading = true
  356. // this.getCode()
  357. this.$http.get(`/sso/personal/register/checkCode`, {params: {mobile: this.item.mobile}})
  358. .then(response => {
  359. this.isShowLoading = false
  360. if (response.data) {
  361. this.token = response.data.token
  362. if (this.token !== '') {
  363. this.$message({
  364. message: '验证码已经发送到您的手机,请注意查收',
  365. type: 'success'
  366. })
  367. this.sendPersonalCode = false
  368. this.personal_time = 60
  369. var personalTime = setInterval(() => {
  370. this.personal_time--
  371. if (this.personal_time <= 0) {
  372. this.sendPersonalCode = true
  373. clearInterval(personalTime)
  374. }
  375. }, 1000)
  376. }
  377. } else {
  378. return Promise.reject(response.data)
  379. }
  380. }).catch(err => {
  381. this.isShowLoading = false
  382. this.$message.error(err.errMsg)
  383. })
  384. }
  385. }
  386. }
  387. </script>
  388. <style lang="scss" scoped>
  389. .register {
  390. margin: 0 auto;
  391. width: 100%;
  392. background: #eee;
  393. .container{
  394. padding-top: 50px;
  395. margin: 0 auto;
  396. width: 980px;
  397. text-align: center;
  398. .content{
  399. padding: 0 50px;
  400. margin: 50px auto 0;
  401. width: 100%;
  402. text-align: center;
  403. background: #fff;
  404. .content-top{
  405. position: relative;
  406. height: 80px;
  407. line-height: 80px;
  408. border-bottom: 1px solid #dcdcdc;
  409. h3{
  410. font-family: 'SimHei';
  411. font-size: 24px;
  412. color: #000;
  413. }
  414. a.go{
  415. position: absolute;
  416. top: 0;
  417. right: 0;
  418. font-size: 14px;
  419. i{
  420. margin-right: 3px;
  421. }
  422. }
  423. }
  424. form {
  425. padding-bottom: 44px;
  426. margin-top: 35px;
  427. input{
  428. padding: 0 0 0 18px;
  429. width: 360px;
  430. height: 44px;
  431. line-height: 44px;
  432. font-size: 14px;
  433. color: #000;
  434. border-radius: 0;
  435. }
  436. span.help{
  437. position: absolute;
  438. right: -230px;
  439. top:0;
  440. font-size: 12px;
  441. color: #f00;
  442. }
  443. i.fa{
  444. position: absolute;
  445. top: 10px;
  446. right: 18px;
  447. font-size: 24px;
  448. color: #a0a0a0;
  449. cursor: pointer;
  450. }
  451. .pwd {
  452. margin: 6px 0 -15px 0;
  453. text-align: left;
  454. font-size: 13px;
  455. em{
  456. display: inline-block;
  457. margin: 0 8px 2px 0;
  458. width: 24px;
  459. height: 6px;
  460. &:first-child{
  461. margin-left: 10px;
  462. }
  463. }
  464. span{
  465. margin-left: 10px;
  466. font-size: 13px;
  467. }
  468. }
  469. .pwd.sm{
  470. color: #8c8c8c;
  471. em {
  472. background: #bfbfbf;
  473. &:first-child{
  474. background: #ff4e00;
  475. }
  476. }
  477. span{
  478. color: #ff4e00;
  479. }
  480. }
  481. .pwd.md{
  482. color: #8c8c8c;
  483. em {
  484. background: #22ac38;
  485. &:nth-child(3){
  486. background: #bfbfbf;
  487. }
  488. }
  489. span{
  490. color: #22ac38;
  491. }
  492. }
  493. .pwd.lar{
  494. color: #8c8c8c;
  495. em {
  496. background: #00a0e9;
  497. }
  498. span{
  499. color: #00a0e9;
  500. }
  501. }
  502. .pwd.low{
  503. color: #8c8c8c;
  504. em{
  505. background: #bfbfbf;
  506. }
  507. }
  508. span.tip{
  509. position: absolute;
  510. top: 3px;
  511. right: -190px;
  512. font-size: 13px;
  513. color: #8c8c8c;
  514. }
  515. span.tip.tip-mobile{
  516. top: 3px;
  517. right: -118px;
  518. color: #ff4949;
  519. font-size: 12px;
  520. }
  521. span.codeError-tip{
  522. position: absolute;
  523. top: 3px;
  524. left: 378px;
  525. width: 200px;
  526. text-align: left;
  527. color: #ff4949;
  528. font-size: 12px;
  529. }
  530. span.tip.passwordError{
  531. position: absolute;
  532. top: 3px;
  533. left: 380px;
  534. width: 200px;
  535. text-align: left;
  536. color: #ff4949;
  537. font-size: 12px;
  538. }
  539. input.msg{
  540. float: left;
  541. width: 210px;
  542. }
  543. button.msg{
  544. float: right;
  545. width: 130px;
  546. height: 44px;
  547. font-size: 14px;
  548. color: #5a5a5a;
  549. background: #f4f4f4;
  550. border: 1px solid #dcdcdc;
  551. cursor: pointer;
  552. &:disabled{
  553. cursor: not-allowed ;
  554. opacity: .7;
  555. }
  556. }
  557. span.msg.send{
  558. float: right;
  559. width: 130px;
  560. height: 44px;
  561. line-height: 44px;
  562. font-size: 14px;
  563. background: #d2d2d2;
  564. color: #fff;
  565. border: 1px solid #dcdcdc;
  566. }
  567. input[type='checkbox']{
  568. margin: 0 14px 0 55px;
  569. float: left;
  570. width: 16px;
  571. height: 16px;
  572. }
  573. span.agree{
  574. float: left;
  575. margin: 1px 0 0 10px;
  576. font-size: 14px;
  577. color: #8b8b8b;
  578. a{
  579. color: #0076ad;
  580. }
  581. }
  582. .form-group.agree{
  583. margin: 20px auto 0 !important;
  584. }
  585. .submitBtn {
  586. display: inline-block;
  587. margin-top: 34px;
  588. width: 360px;
  589. height: 44px;
  590. line-height: 44px;
  591. font-size: 16px;
  592. color: #fff;
  593. background: #0076AD;
  594. border-radius: 3px;
  595. border: none;
  596. &:disabled{
  597. cursor: not-allowed ;
  598. opacity: .7;
  599. }
  600. }
  601. }
  602. }
  603. .login{
  604. margin-top: 20px;
  605. font-size: 14px;
  606. color: #8c8c8c;
  607. a{
  608. font-size: 14px;
  609. color: #0076ad;
  610. }
  611. }
  612. }
  613. }
  614. </style>