PhoneValidationSecondStep.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555
  1. <template>
  2. <div class="validation">
  3. <div class="container">
  4. <div class="content">
  5. <div class="content-top">
  6. <h3>验证手机</h3>
  7. <div class="step">
  8. <img src="/images/all/step02.png" alt=""/>
  9. <div class="step-item"><span class="active">账号验证</span><span class="active">新手机号码</span><span>设置完成</span></div>
  10. </div>
  11. </div>
  12. <div class="content-bottom">
  13. <div>
  14. <el-form :model="valid2" :rules="rules2" ref="valid2" label-width="100px" class="demo-ruleForm">
  15. <el-form-item prop="mobile">
  16. <el-input v-model="valid2.mobile"
  17. v-bind:class="{active: mobileSecondExit}"
  18. placeholder="新手机号码"></el-input>
  19. <span class="tip tip-mobile" v-show="mobileSecondExit">该手机已被注册</span>
  20. </el-form-item>
  21. <el-form-item prop="code">
  22. <el-input type="text" v-model="valid2.code"
  23. v-bind:class="{ active: secondStepCodeErrorChecked }"
  24. auto-complete="off"
  25. class="msg"
  26. placeholder="短信验证码"></el-input>
  27. <el-button type="primary" class="code"
  28. v-show="showSecondStepCode"
  29. @click="getSecondCheckCode"
  30. :disabled="getCodeBtnIsDisabled">获取验证码</el-button>
  31. <el-button type="primary" v-show="!showSecondStepCode" class="code code-send">已发送({{second_step_time}}s)</el-button>
  32. <span v-show="secondStepCodeErrorChecked" class="tip codeError-tip">{{secondCodeErrorMsg}}</span>
  33. </el-form-item>
  34. <el-form-item>
  35. <a class="btn finish"
  36. :disabled="!mobileSecondChecked || !secondCodeChecked"
  37. @click="setNewMobile">确认</a>
  38. </el-form-item>
  39. </el-form>
  40. </div>
  41. </div>
  42. </div>
  43. <loading v-show="isShowLoading"/>
  44. </div>
  45. </div>
  46. </template>
  47. <script>
  48. import Loading from '~components/common/loading/Loading.vue'
  49. export default {
  50. name: 'validation',
  51. components: {
  52. Loading
  53. },
  54. middleware: 'authenticated',
  55. data () {
  56. // 第二步验证手机
  57. var validateSecondMobile = (rule, value, callback) => {
  58. if (value === '') {
  59. callback(new Error('请填写正确的手机号'))
  60. this.getCodeBtnIsDisabled = true
  61. this.mobileSecondChecked = false
  62. this.mobileSecondExit = false
  63. } else {
  64. if (this.valid2.mobile !== '') {
  65. var reg = /^1[0-9]{10}$/
  66. if (!reg.test(value)) {
  67. callback(new Error('请填写正确的手机号'))
  68. this.getCodeBtnIsDisabled = true
  69. this.mobileSecondChecked = false
  70. this.mobileSecondExit = false
  71. } else {
  72. this.$http.get(`/update/user/mobile/hasRegister`, {params: {mobile: this.valid2.mobile}})
  73. .then(response => {
  74. if (response.data.content.hasRegister) {
  75. this.getCodeBtnIsDisabled = true
  76. this.mobileSecondChecked = false
  77. this.mobileSecondExit = true
  78. } else {
  79. this.getCodeBtnIsDisabled = false
  80. this.mobileSecondChecked = true
  81. this.mobileSecondExit = false
  82. }
  83. })
  84. }
  85. }
  86. callback()
  87. }
  88. }
  89. var validateSecondCode = (rule, value, callback) => {
  90. if (value === '') {
  91. callback(new Error('请填写正确的验证码'))
  92. this.secondStepCodeErrorChecked = false
  93. this.secondCodeChecked = false
  94. } else {
  95. if (this.valid2.code !== '') {
  96. if (this.valid2.mobile === '') {
  97. callback(new Error('请先填写正确的手机号'))
  98. } else {
  99. if (this.secondToken) {
  100. let param = new FormData()
  101. param.append('mobile', this.valid2.mobile)
  102. param.append('code', this.valid2.code)
  103. param.append('token', this.secondToken)
  104. let config = {
  105. headers: {'Content-Type': 'multipart/form-data'}
  106. }
  107. this.$http.post(`/update/user/checkCode/mobile`, param, config)
  108. .then(response => {
  109. if (response.data.success) {
  110. this.secondCodeChecked = true
  111. this.secondStepCodeErrorChecked = false
  112. } else {
  113. this.secondStepCodeErrorChecked = true
  114. this.secondCodeChecked = false
  115. return Promise.reject(response.data)
  116. }
  117. }).catch(err => {
  118. this.secondCodeErrorMsg = err.errMsg
  119. })
  120. } else {
  121. callback(new Error('请先获取验证码'))
  122. this.codeChecked = false
  123. this.codeErrorChecked = false
  124. }
  125. }
  126. }
  127. callback()
  128. }
  129. }
  130. return {
  131. isShowLoading: false,
  132. second_step_time: 0,
  133. codeErrorChecked: false,
  134. secondStepCodeErrorChecked: false,
  135. secondCodeChecked: false,
  136. secondCodeErrorMsg: '',
  137. mobileSecondChecked: false,
  138. getCodeBtnIsDisabled: true,
  139. showSecondStepCode: true,
  140. mobileSecondExit: false,
  141. valid2: {
  142. mobile: '',
  143. code: ''
  144. },
  145. rules2: {
  146. mobile: [
  147. {validator: validateSecondMobile, trigger: 'blur'}
  148. ],
  149. code: [
  150. {validator: validateSecondCode, trigger: 'blur'}
  151. ]
  152. }
  153. }
  154. },
  155. computed: {
  156. firstStepToken () {
  157. return this.$store.state.login.token.data
  158. }
  159. },
  160. mounted () {
  161. // 获取邮箱token
  162. this.$nextTick(() => {
  163. this.getEmailLinkToken()
  164. })
  165. },
  166. methods: {
  167. // 获取第二步手机验证码
  168. getSecondCheckCode () {
  169. this.isShowLoading = true
  170. console.log(this.isShowLoading)
  171. this.$http.get(`/update/user/setMobile`, {params: {mobile: this.valid2.mobile, token: this.firstStepToken}})
  172. .then(response => {
  173. this.isShowLoading = false
  174. if (response.data.success) {
  175. this.secondToken = response.data.content.token
  176. if (this.secondToken !== '') {
  177. this.$message({
  178. message: '验证码已经发送到您的手机,请注意查收',
  179. type: 'success'
  180. })
  181. this.showSecondStepCode = false
  182. this.second_step_time = 60
  183. var secondStepTime = setInterval(() => {
  184. this.second_step_time--
  185. if (this.second_step_time <= 0) {
  186. this.showSecondStepCode = true
  187. clearInterval(secondStepTime)
  188. }
  189. }, 1000)
  190. }
  191. } else {
  192. return Promise.reject(response.data)
  193. }
  194. }).catch(err => {
  195. this.isShowLoading = false
  196. this.$message.error(err.errMsg)
  197. })
  198. },
  199. // 设置新手机号
  200. setNewMobile () {
  201. if (this.mobileSecondChecked && this.secondCodeChecked) {
  202. this.isShowLoading = true
  203. let param = new FormData()
  204. param.append('mobile', this.valid2.mobile)
  205. param.append('code', this.valid2.code)
  206. param.append('token', this.secondToken)
  207. let config = {
  208. headers: {'Content-Type': 'multipart/form-data'}
  209. }
  210. this.$http.post(`/update/user/setMobile`, param, config)
  211. .then(response => {
  212. this.isShowLoading = false
  213. if (response.data.success) {
  214. this.$router.push({ path: '/validation/phoneValidationThirdStep' })
  215. } else {
  216. return Promise.reject(response.data)
  217. }
  218. }).catch(err => {
  219. this.$message.error(err.errMsg)
  220. this.isShowLoading = false
  221. this.secondStepCodeErrorChecked = true
  222. this.secondCodeChecked = false
  223. this.second_step_time = 0
  224. })
  225. }
  226. },
  227. // 获得邮箱token
  228. getEmailLinkToken () {
  229. var url = window.location.search
  230. var request = {}
  231. if (url.indexOf('?' !== -1)) {
  232. var str = url.substr(1)
  233. var strs = str.split('&')
  234. for (var i = 0; i < strs.length; i++) {
  235. request[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1])
  236. }
  237. }
  238. this.Token = request['token'] || ''
  239. if (this.Token) {
  240. this.$store.commit('login/GET_TOKEN', this.Token)
  241. }
  242. }
  243. }
  244. }
  245. </script>
  246. <style lang="scss" scoped>
  247. .validation {
  248. margin: 0 auto;
  249. width: 100%;
  250. background: #eee;
  251. .container{
  252. padding-top: 50px;
  253. margin: 0 auto;
  254. width: 980px;
  255. text-align: center;
  256. .content{
  257. padding: 0 50px;
  258. margin: 50px auto 0;
  259. width: 100%;
  260. /*height: 540px;*/
  261. text-align: center;
  262. background: #fff;
  263. .content-top{
  264. height: 80px;
  265. line-height: 80px;
  266. h3{
  267. margin-bottom: 0;
  268. font-size: 24px;
  269. color: #000;
  270. border-bottom: 1px solid #dcdcdc;
  271. }
  272. .step{
  273. position: relative;
  274. margin-top: 10px;
  275. img{
  276. width: 315px;
  277. height: 46px;
  278. }
  279. .step-item{
  280. position: absolute;
  281. top: 45px;
  282. left: 265px;
  283. span{
  284. margin-right: 78px;
  285. font-size: 14px;
  286. color: #b4b4b4;
  287. }
  288. span.active {
  289. color: #0076ad;
  290. }
  291. }
  292. }
  293. }
  294. form {
  295. margin-top: 150px;
  296. padding-bottom: 44px;
  297. input{
  298. padding: 0 0 0 18px;
  299. width: 360px;
  300. height: 44px;
  301. line-height: 44px;
  302. font-size: 14px;
  303. color: #000;
  304. border-radius: 0;
  305. }
  306. input.answer {
  307. background: url("/images/all/more.png") no-repeat 325px center;
  308. cursor: pointer;
  309. }
  310. ul{
  311. display: none;
  312. position: absolute;
  313. top: 44px;
  314. left: 0;
  315. width: 360px;
  316. background: #fff;
  317. box-shadow: 0 0 5px rgba(0,0,0,.5);
  318. -moz-box-shadow: 0 0 5px rgba(0,0,0,.5);
  319. -o-box-shadow: 0 0 5px rgba(0,0,0,.5);
  320. -webkit-box-shadow: 0 0 5px rgba(0,0,0,.5);
  321. z-index: 10;
  322. li{
  323. padding-left: 18px;
  324. width: 100%;
  325. height: 30px;
  326. line-height: 30px;
  327. text-align: left;
  328. font-size: 14px;
  329. color: #000;
  330. cursor: pointer;
  331. &:hover{
  332. background: #0076ad;
  333. color: #fff;
  334. }
  335. }
  336. }
  337. span.tip{
  338. position: absolute;
  339. top: 0;
  340. right: -238px;
  341. font-size: 13px;
  342. color: #8c8c8c;
  343. a{
  344. font-size: 13px;
  345. color: #0076ad;
  346. }
  347. }
  348. span.tip.tip-mobile{
  349. top: 3px;
  350. right: -105px;
  351. color: #ff4949;
  352. font-size: 12px;
  353. }
  354. span.tip.codeError-tip{
  355. position: absolute;
  356. top: 3px;
  357. left: 378px;
  358. width: 200px;
  359. text-align: left;
  360. color: #ff4949;
  361. font-size: 12px;
  362. }
  363. i{
  364. position: absolute;
  365. top: 13px;
  366. left: 20px;
  367. font-size: 20px;
  368. color: #a0a0a0;
  369. }
  370. .btn {
  371. margin: 34px 0 16px 0;
  372. width: 360px;
  373. height: 44px;
  374. line-height: 44px;
  375. font-size: 16px;
  376. color: #fff;
  377. background: #0076AD;
  378. border-radius: 3px;
  379. }
  380. }
  381. .content-bottom{
  382. margin: 155px auto 0;
  383. padding-bottom: 50px;
  384. width: 360px;
  385. div.warp{
  386. padding-bottom: 65px;
  387. }
  388. p{
  389. font-size: 24px;
  390. color: #323232;
  391. img{
  392. margin-right: 20px;
  393. width: 30px;
  394. height: 28px;
  395. }
  396. }
  397. p.pass{
  398. font-size: 24px;
  399. color: #e77405;
  400. img{
  401. height: 30px;
  402. }
  403. }
  404. p.passed {
  405. color: #2ab300;
  406. img{
  407. height: 30px;
  408. }
  409. }
  410. span{
  411. display: inline-block;
  412. font-size: 14px;
  413. color: #8b8b8b;
  414. }
  415. span.close-tip{
  416. margin: 15px 0 140px 0;
  417. }
  418. .close-btn{
  419. margin: 0 auto;
  420. width: 200px;
  421. height: 36px;
  422. line-height: 36px;
  423. font-size: 14px;
  424. text-align: center;
  425. color: #323232;
  426. border: 1px solid #d2d2d2;
  427. border-radius: 3px;
  428. cursor: pointer ;
  429. }
  430. span.use{
  431. display: inline-block;
  432. margin-bottom: 30px;
  433. width: 360px;
  434. font-size: 14px;
  435. color: #000;
  436. text-align: left;
  437. em{
  438. font-size: 14px;
  439. font-style: normal;
  440. color: #000;
  441. }
  442. }
  443. .form-group {
  444. margin: 0 auto 16px;
  445. position: relative;
  446. width: 360px;
  447. height: 44px;
  448. line-height: 44px;
  449. input{
  450. padding: 0 0 0 18px;
  451. width: 360px;
  452. height: 44px;
  453. line-height: 44px;
  454. font-size: 14px;
  455. color: #000;
  456. border-radius: 0;
  457. }
  458. input.msg{
  459. float: left;
  460. width: 210px;
  461. padding: 0 0 0 18px;
  462. height: 44px;
  463. line-height: 44px;
  464. font-size: 14px;
  465. color: #000;
  466. border-radius: 0;
  467. }
  468. span.msg{
  469. float: right;
  470. margin: 0;
  471. width: 130px;
  472. height: 44px;
  473. line-height: 44px;
  474. text-align: center ;
  475. font-size: 14px;
  476. color: #5a5a5a;
  477. background: #f4f4f4;
  478. border: 1px solid #dcdcdc;
  479. cursor: pointer;
  480. }
  481. span.msg.send{
  482. background: #d2d2d2;
  483. color: #fff;
  484. }
  485. }
  486. .btn {
  487. margin: 34px 0 10px 0;
  488. width: 360px;
  489. height: 44px;
  490. line-height: 44px;
  491. font-size: 16px;
  492. color: #fff;
  493. background: #0076AD;
  494. border-radius: 3px;
  495. }
  496. }
  497. .choose{
  498. margin: 155px auto 0;
  499. padding-bottom: 44px;
  500. div{
  501. padding: 0 15px;
  502. margin: 0 auto 16px;
  503. width: 360px;
  504. height: 60px;
  505. line-height: 60px;
  506. text-align: left;
  507. overflow: hidden;
  508. border: 1px solid #d2d2d2;
  509. cursor: pointer;
  510. &:hover,&.active{
  511. border-color: #0076ad;
  512. span{
  513. color: #0076ad;
  514. }
  515. i.second {
  516. color: #0076ad;
  517. }
  518. }
  519. img.first{
  520. float: left;
  521. margin: 24px 20px 0 0;
  522. font-size: 20px;
  523. color: #323232;
  524. }
  525. img.first.mob{
  526. margin: 22px 20px 0 5px;
  527. font-size: 28px;
  528. }
  529. i.second {
  530. float: right;
  531. margin: 20px 0 0 5px;
  532. font-size: 20px;
  533. color: #323232;
  534. }
  535. span{
  536. float: left;
  537. font-size: 14px;
  538. color: #323232;
  539. }
  540. }
  541. }
  542. a.return{
  543. position: absolute;
  544. left: 0;
  545. top: -15px;
  546. img{
  547. width: 34px !important;
  548. height: 34px !important;
  549. }
  550. }
  551. }
  552. }
  553. }
  554. </style>