PhoneValidationSecondStep.vue 16 KB

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