PhoneValidationSecondStep.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  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. console.log(this.Token)
  198. this.$store.commit('login/GET_TOKEN', this.Token)
  199. }
  200. }
  201. }
  202. }
  203. </script>
  204. <style lang="scss" scoped>
  205. .validation {
  206. margin: 0 auto;
  207. width: 100%;
  208. background: #eee;
  209. .container{
  210. padding-top: 50px;
  211. margin: 0 auto;
  212. width: 980px;
  213. text-align: center;
  214. .content{
  215. padding: 0 50px;
  216. margin: 50px auto 0;
  217. width: 100%;
  218. /*height: 540px;*/
  219. text-align: center;
  220. background: #fff;
  221. .content-top{
  222. height: 80px;
  223. line-height: 80px;
  224. h3{
  225. margin-bottom: 0;
  226. font-size: 24px;
  227. color: #000;
  228. border-bottom: 1px solid #dcdcdc;
  229. }
  230. .step{
  231. position: relative;
  232. margin-top: 10px;
  233. img{
  234. width: 315px;
  235. height: 46px;
  236. }
  237. .step-item{
  238. position: absolute;
  239. top: 45px;
  240. left: 265px;
  241. span{
  242. margin-right: 78px;
  243. font-size: 14px;
  244. color: #b4b4b4;
  245. }
  246. span.active {
  247. color: #0076ad;
  248. }
  249. }
  250. }
  251. }
  252. form {
  253. margin-top: 150px;
  254. padding-bottom: 44px;
  255. input{
  256. padding: 0 0 0 18px;
  257. width: 360px;
  258. height: 44px;
  259. line-height: 44px;
  260. font-size: 14px;
  261. color: #000;
  262. border-radius: 0;
  263. }
  264. input.answer {
  265. background: url("/images/all/more.png") no-repeat 325px center;
  266. cursor: pointer;
  267. }
  268. ul{
  269. display: none;
  270. position: absolute;
  271. top: 44px;
  272. left: 0;
  273. width: 360px;
  274. background: #fff;
  275. box-shadow: 0 0 5px rgba(0,0,0,.5);
  276. -moz-box-shadow: 0 0 5px rgba(0,0,0,.5);
  277. -o-box-shadow: 0 0 5px rgba(0,0,0,.5);
  278. -webkit-box-shadow: 0 0 5px rgba(0,0,0,.5);
  279. z-index: 10;
  280. li{
  281. padding-left: 18px;
  282. width: 100%;
  283. height: 30px;
  284. line-height: 30px;
  285. text-align: left;
  286. font-size: 14px;
  287. color: #000;
  288. cursor: pointer;
  289. &:hover{
  290. background: #0076ad;
  291. color: #fff;
  292. }
  293. }
  294. }
  295. span.tip{
  296. position: absolute;
  297. top: 0;
  298. right: -238px;
  299. font-size: 13px;
  300. color: #8c8c8c;
  301. a{
  302. font-size: 13px;
  303. color: #0076ad;
  304. }
  305. }
  306. span.tip.codeError-tip{
  307. position: absolute;
  308. top: 3px;
  309. left: 378px;
  310. width: 200px;
  311. text-align: left;
  312. color: #ff4949;
  313. font-size: 12px;
  314. }
  315. i{
  316. position: absolute;
  317. top: 13px;
  318. left: 20px;
  319. font-size: 20px;
  320. color: #a0a0a0;
  321. }
  322. .btn {
  323. margin: 34px 0 16px 0;
  324. width: 360px;
  325. height: 44px;
  326. line-height: 44px;
  327. font-size: 16px;
  328. color: #fff;
  329. background: #0076AD;
  330. border-radius: 3px;
  331. }
  332. }
  333. .content-bottom{
  334. margin: 155px auto 0;
  335. padding-bottom: 50px;
  336. width: 360px;
  337. div.warp{
  338. padding-bottom: 65px;
  339. }
  340. p{
  341. font-size: 24px;
  342. color: #323232;
  343. img{
  344. margin-right: 20px;
  345. width: 30px;
  346. height: 28px;
  347. }
  348. }
  349. p.pass{
  350. font-size: 24px;
  351. color: #e77405;
  352. img{
  353. height: 30px;
  354. }
  355. }
  356. p.passed {
  357. color: #2ab300;
  358. img{
  359. height: 30px;
  360. }
  361. }
  362. span{
  363. display: inline-block;
  364. font-size: 14px;
  365. color: #8b8b8b;
  366. }
  367. span.close-tip{
  368. margin: 15px 0 140px 0;
  369. }
  370. .close-btn{
  371. margin: 0 auto;
  372. width: 200px;
  373. height: 36px;
  374. line-height: 36px;
  375. font-size: 14px;
  376. text-align: center;
  377. color: #323232;
  378. border: 1px solid #d2d2d2;
  379. border-radius: 3px;
  380. cursor: pointer ;
  381. }
  382. span.use{
  383. display: inline-block;
  384. margin-bottom: 30px;
  385. width: 360px;
  386. font-size: 14px;
  387. color: #000;
  388. text-align: left;
  389. em{
  390. font-size: 14px;
  391. font-style: normal;
  392. color: #000;
  393. }
  394. }
  395. .form-group {
  396. margin: 0 auto 16px;
  397. position: relative;
  398. width: 360px;
  399. height: 44px;
  400. line-height: 44px;
  401. input{
  402. padding: 0 0 0 18px;
  403. width: 360px;
  404. height: 44px;
  405. line-height: 44px;
  406. font-size: 14px;
  407. color: #000;
  408. border-radius: 0;
  409. }
  410. input.msg{
  411. float: left;
  412. width: 210px;
  413. padding: 0 0 0 18px;
  414. height: 44px;
  415. line-height: 44px;
  416. font-size: 14px;
  417. color: #000;
  418. border-radius: 0;
  419. }
  420. span.msg{
  421. float: right;
  422. margin: 0;
  423. width: 130px;
  424. height: 44px;
  425. line-height: 44px;
  426. text-align: center ;
  427. font-size: 14px;
  428. color: #5a5a5a;
  429. background: #f4f4f4;
  430. border: 1px solid #dcdcdc;
  431. cursor: pointer;
  432. }
  433. span.msg.send{
  434. background: #d2d2d2;
  435. color: #fff;
  436. }
  437. }
  438. .btn {
  439. margin: 34px 0 10px 0;
  440. width: 360px;
  441. height: 44px;
  442. line-height: 44px;
  443. font-size: 16px;
  444. color: #fff;
  445. background: #0076AD;
  446. border-radius: 3px;
  447. }
  448. }
  449. .choose{
  450. margin: 155px auto 0;
  451. padding-bottom: 44px;
  452. div{
  453. padding: 0 15px;
  454. margin: 0 auto 16px;
  455. width: 360px;
  456. height: 60px;
  457. line-height: 60px;
  458. text-align: left;
  459. overflow: hidden;
  460. border: 1px solid #d2d2d2;
  461. cursor: pointer;
  462. &:hover,&.active{
  463. border-color: #0076ad;
  464. span{
  465. color: #0076ad;
  466. }
  467. i.second {
  468. color: #0076ad;
  469. }
  470. }
  471. img.first{
  472. float: left;
  473. margin: 24px 20px 0 0;
  474. font-size: 20px;
  475. color: #323232;
  476. }
  477. img.first.mob{
  478. margin: 22px 20px 0 5px;
  479. font-size: 28px;
  480. }
  481. i.second {
  482. float: right;
  483. margin: 20px 0 0 5px;
  484. font-size: 20px;
  485. color: #323232;
  486. }
  487. span{
  488. float: left;
  489. font-size: 14px;
  490. color: #323232;
  491. }
  492. }
  493. }
  494. a.return{
  495. position: absolute;
  496. left: 0;
  497. top: -15px;
  498. img{
  499. width: 34px !important;
  500. height: 34px !important;
  501. }
  502. }
  503. }
  504. }
  505. }
  506. </style>