PhoneValidationSecondStep.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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. this.$http.get(`/update/user/setMobile`, {params: {mobile: this.valid2.mobile, token: this.firstStepToken}})
  171. .then(response => {
  172. this.isShowLoading = false
  173. if (response.data.success) {
  174. this.secondToken = response.data.content.token
  175. if (this.secondToken !== '') {
  176. this.$message({
  177. message: '验证码已经发送到您的手机,请注意查收',
  178. type: 'success'
  179. })
  180. this.showSecondStepCode = false
  181. this.second_step_time = 60
  182. var secondStepTime = setInterval(() => {
  183. this.second_step_time--
  184. if (this.second_step_time <= 0) {
  185. this.showSecondStepCode = true
  186. clearInterval(secondStepTime)
  187. }
  188. }, 1000)
  189. }
  190. } else {
  191. return Promise.reject(response.data)
  192. }
  193. }).catch(err => {
  194. this.isShowLoading = false
  195. this.$message.error(err.errMsg)
  196. })
  197. },
  198. // 设置新手机号
  199. setNewMobile () {
  200. if (this.mobileSecondChecked && this.secondCodeChecked) {
  201. this.isShowLoading = true
  202. let param = new FormData()
  203. param.append('mobile', this.valid2.mobile)
  204. param.append('code', this.valid2.code)
  205. param.append('token', this.secondToken)
  206. let config = {
  207. headers: {'Content-Type': 'multipart/form-data'}
  208. }
  209. this.$http.post(`/update/user/setMobile`, param, config)
  210. .then(response => {
  211. this.isShowLoading = false
  212. if (response.data.success) {
  213. this.$router.push({ path: '/validation/phoneValidationThirdStep' })
  214. } else {
  215. return Promise.reject(response.data)
  216. }
  217. }).catch(err => {
  218. this.$message.error(err.errMsg)
  219. this.isShowLoading = false
  220. this.secondStepCodeErrorChecked = true
  221. this.secondCodeChecked = false
  222. this.second_step_time = 0
  223. })
  224. }
  225. },
  226. // 获得邮箱token
  227. getEmailLinkToken () {
  228. var url = window.location.search
  229. var request = {}
  230. if (url.indexOf('?' !== -1)) {
  231. var str = url.substr(1)
  232. var strs = str.split('&')
  233. for (var i = 0; i < strs.length; i++) {
  234. request[strs[i].split('=')[0]] = decodeURI(strs[i].split('=')[1])
  235. }
  236. }
  237. this.Token = request['token'] || ''
  238. if (this.Token) {
  239. this.$store.commit('login/GET_TOKEN', this.Token)
  240. }
  241. }
  242. }
  243. }
  244. </script>
  245. <style lang="scss" scoped>
  246. .validation {
  247. margin: 0 auto;
  248. width: 100%;
  249. background: #eee;
  250. .container{
  251. padding-top: 50px;
  252. margin: 0 auto;
  253. width: 980px;
  254. text-align: center;
  255. .content{
  256. padding: 0 50px;
  257. margin: 50px auto 0;
  258. width: 100%;
  259. /*height: 540px;*/
  260. text-align: center;
  261. background: #fff;
  262. .content-top{
  263. height: 80px;
  264. line-height: 80px;
  265. h3{
  266. margin-bottom: 0;
  267. font-size: 24px;
  268. color: #000;
  269. border-bottom: 1px solid #dcdcdc;
  270. }
  271. .step{
  272. position: relative;
  273. margin-top: 10px;
  274. img{
  275. width: 315px;
  276. height: 46px;
  277. }
  278. .step-item{
  279. position: absolute;
  280. top: 45px;
  281. left: 265px;
  282. span{
  283. margin-right: 78px;
  284. font-size: 14px;
  285. color: #b4b4b4;
  286. }
  287. span.active {
  288. color: #0076ad;
  289. }
  290. }
  291. }
  292. }
  293. form {
  294. margin-top: 150px;
  295. padding-bottom: 44px;
  296. input{
  297. padding: 0 0 0 18px;
  298. width: 360px;
  299. height: 44px;
  300. line-height: 44px;
  301. font-size: 14px;
  302. color: #000;
  303. border-radius: 0;
  304. }
  305. input.answer {
  306. background: url("/images/all/more.png") no-repeat 325px center;
  307. cursor: pointer;
  308. }
  309. ul{
  310. display: none;
  311. position: absolute;
  312. top: 44px;
  313. left: 0;
  314. width: 360px;
  315. background: #fff;
  316. box-shadow: 0 0 5px rgba(0,0,0,.5);
  317. -moz-box-shadow: 0 0 5px rgba(0,0,0,.5);
  318. -o-box-shadow: 0 0 5px rgba(0,0,0,.5);
  319. -webkit-box-shadow: 0 0 5px rgba(0,0,0,.5);
  320. z-index: 10;
  321. li{
  322. padding-left: 18px;
  323. width: 100%;
  324. height: 30px;
  325. line-height: 30px;
  326. text-align: left;
  327. font-size: 14px;
  328. color: #000;
  329. cursor: pointer;
  330. &:hover{
  331. background: #0076ad;
  332. color: #fff;
  333. }
  334. }
  335. }
  336. span.tip{
  337. position: absolute;
  338. top: 0;
  339. right: -238px;
  340. font-size: 13px;
  341. color: #8c8c8c;
  342. a{
  343. font-size: 13px;
  344. color: #0076ad;
  345. }
  346. }
  347. span.tip.tip-mobile{
  348. top: 3px;
  349. right: -105px;
  350. color: #ff4949;
  351. font-size: 12px;
  352. }
  353. span.tip.codeError-tip{
  354. position: absolute;
  355. top: 3px;
  356. left: 378px;
  357. width: 200px;
  358. text-align: left;
  359. color: #ff4949;
  360. font-size: 12px;
  361. }
  362. i{
  363. position: absolute;
  364. top: 13px;
  365. left: 20px;
  366. font-size: 20px;
  367. color: #a0a0a0;
  368. }
  369. .btn {
  370. margin: 34px 0 16px 0;
  371. width: 360px;
  372. height: 44px;
  373. line-height: 44px;
  374. font-size: 16px;
  375. color: #fff;
  376. background: #0076AD;
  377. border-radius: 3px;
  378. }
  379. }
  380. .content-bottom{
  381. margin: 155px auto 0;
  382. padding-bottom: 50px;
  383. width: 360px;
  384. div.warp{
  385. padding-bottom: 65px;
  386. }
  387. p{
  388. font-size: 24px;
  389. color: #323232;
  390. img{
  391. margin-right: 20px;
  392. width: 30px;
  393. height: 28px;
  394. }
  395. }
  396. p.pass{
  397. font-size: 24px;
  398. color: #e77405;
  399. img{
  400. height: 30px;
  401. }
  402. }
  403. p.passed {
  404. color: #2ab300;
  405. img{
  406. height: 30px;
  407. }
  408. }
  409. span{
  410. display: inline-block;
  411. font-size: 14px;
  412. color: #8b8b8b;
  413. }
  414. span.close-tip{
  415. margin: 15px 0 140px 0;
  416. }
  417. .close-btn{
  418. margin: 0 auto;
  419. width: 200px;
  420. height: 36px;
  421. line-height: 36px;
  422. font-size: 14px;
  423. text-align: center;
  424. color: #323232;
  425. border: 1px solid #d2d2d2;
  426. border-radius: 3px;
  427. cursor: pointer ;
  428. }
  429. span.use{
  430. display: inline-block;
  431. margin-bottom: 30px;
  432. width: 360px;
  433. font-size: 14px;
  434. color: #000;
  435. text-align: left;
  436. em{
  437. font-size: 14px;
  438. font-style: normal;
  439. color: #000;
  440. }
  441. }
  442. .form-group {
  443. margin: 0 auto 16px;
  444. position: relative;
  445. width: 360px;
  446. height: 44px;
  447. line-height: 44px;
  448. input{
  449. padding: 0 0 0 18px;
  450. width: 360px;
  451. height: 44px;
  452. line-height: 44px;
  453. font-size: 14px;
  454. color: #000;
  455. border-radius: 0;
  456. }
  457. input.msg{
  458. float: left;
  459. width: 210px;
  460. padding: 0 0 0 18px;
  461. height: 44px;
  462. line-height: 44px;
  463. font-size: 14px;
  464. color: #000;
  465. border-radius: 0;
  466. }
  467. span.msg{
  468. float: right;
  469. margin: 0;
  470. width: 130px;
  471. height: 44px;
  472. line-height: 44px;
  473. text-align: center ;
  474. font-size: 14px;
  475. color: #5a5a5a;
  476. background: #f4f4f4;
  477. border: 1px solid #dcdcdc;
  478. cursor: pointer;
  479. }
  480. span.msg.send{
  481. background: #d2d2d2;
  482. color: #fff;
  483. }
  484. }
  485. .btn {
  486. margin: 34px 0 10px 0;
  487. width: 360px;
  488. height: 44px;
  489. line-height: 44px;
  490. font-size: 16px;
  491. color: #fff;
  492. background: #0076AD;
  493. border-radius: 3px;
  494. }
  495. }
  496. .choose{
  497. margin: 155px auto 0;
  498. padding-bottom: 44px;
  499. div{
  500. padding: 0 15px;
  501. margin: 0 auto 16px;
  502. width: 360px;
  503. height: 60px;
  504. line-height: 60px;
  505. text-align: left;
  506. overflow: hidden;
  507. border: 1px solid #d2d2d2;
  508. cursor: pointer;
  509. &:hover,&.active{
  510. border-color: #0076ad;
  511. span{
  512. color: #0076ad;
  513. }
  514. i.second {
  515. color: #0076ad;
  516. }
  517. }
  518. img.first{
  519. float: left;
  520. margin: 24px 20px 0 0;
  521. font-size: 20px;
  522. color: #323232;
  523. }
  524. img.first.mob{
  525. margin: 22px 20px 0 5px;
  526. font-size: 28px;
  527. }
  528. i.second {
  529. float: right;
  530. margin: 20px 0 0 5px;
  531. font-size: 20px;
  532. color: #323232;
  533. }
  534. span{
  535. float: left;
  536. font-size: 14px;
  537. color: #323232;
  538. }
  539. }
  540. }
  541. a.return{
  542. position: absolute;
  543. left: 0;
  544. top: -15px;
  545. img{
  546. width: 34px !important;
  547. height: 34px !important;
  548. }
  549. }
  550. }
  551. }
  552. }
  553. </style>