PhoneValidationSecondStep.vue 16 KB

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