PhoneValidationSecondStep.vue 16 KB

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