PhoneValidationSecondStep.vue 16 KB

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