PersonalRegistration.vue 20 KB

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