PhoneValidationSecondStep.vue 15 KB

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