PhoneValidation.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. <template>
  2. <div class="validation">
  3. <div class="container">
  4. <div class="content" v-show="goFirstStep">
  5. <div class="content-top">
  6. <h3>验证手机</h3>
  7. <div class="step">
  8. <img src="/images/all/step01.png" alt=""/>
  9. <div class="step-item"><span class="active">账号验证</span><span>新手机号码</span><span>设置完成</span></div>
  10. </div>
  11. </div>
  12. <div class="choose">
  13. <div v-show="hasValidPhoneWay"
  14. @click="chooseWay(1)">
  15. <img src="/images/all/icon01.png" alt="" class="first mob"/>
  16. <span>通过验证手机</span><i class="fa fa-angle-right second"></i>
  17. </div>
  18. <div v-show="hasValidEmailWay"
  19. @click="chooseWay(2)">
  20. <img src="/images/all/icon02.png" alt="" class="first"/>
  21. <span>通过验证邮箱</span><i class="fa fa-angle-right second"></i>
  22. </div>
  23. <div v-show="hasValidQuestionsWay"
  24. @click="chooseWay(3)">
  25. <img src="/images/all/icon03.png" alt="" class="first"/>
  26. <span>通过验证密保</span><i class="fa fa-angle-right second"></i>
  27. </div>
  28. <div v-show="showManualAppeal"
  29. @click="goAccountAppeal()">
  30. <img src="/images/all/icon04.png" alt="" class="first"/>
  31. <span>通过人工申诉</span><i class="fa fa-angle-right second"></i>
  32. </div>
  33. </div>
  34. </div>
  35. <div class="content" v-show="showPhoneValid">
  36. <div class="content-top">
  37. <h3>验证手机</h3>
  38. <div class="step">
  39. <img src="/images/all/step01.png" alt=""/>
  40. <div class="step-item"><span class="active">账号验证</span><span>新手机号码</span><span>设置完成</span></div>
  41. <a @click="goPreviousStep" class="return"><img src="/images/all/return.png" alt=""/></a>
  42. </div>
  43. </div>
  44. <div class="content-bottom">
  45. <span class="use">使用手机号<em>{{secretMobile}}</em>接收验证码</span>
  46. <div>
  47. <el-form :model="valid" :rules="rules" ref="valid" label-width="100px" class="demo-ruleForm" style="margin-top: 0;">
  48. <el-form-item prop="code">
  49. <el-input type="text" v-model="valid.code"
  50. v-bind:class="{ active: codeErrorChecked }"
  51. auto-complete="off" class="msg"
  52. placeholder="短信验证码"></el-input>
  53. <el-button type="primary" class="code"
  54. v-show="sendAccountCode"
  55. @click="getCheckCode">获取验证码</el-button>
  56. <el-button type="primary" v-show="!sendAccountCode" class="code code-send">已发送({{account_time}}s)</el-button>
  57. <span v-show="codeErrorChecked" class="tip codeError-tip" >{{codeErrorMsg}}</span>
  58. </el-form-item>
  59. <el-form-item>
  60. <a class="btn finish"
  61. :disabled="!codeChecked"
  62. @click="goNextStep">下一步</a>
  63. </el-form-item>
  64. </el-form>
  65. </div>
  66. </div>
  67. </div>
  68. <div class="content" v-show="showEmailValid">
  69. <div class="content-top">
  70. <h3>验证手机</h3>
  71. <div class="step">
  72. <img src="/images/all/step01.png" alt=""/>
  73. <div class="step-item"><span class="active">账号验证</span><span>新手机号码</span><span>设置完成</span></div>
  74. <a href="" class="return"><img src="/images/all/return.png" alt=""/></a>
  75. </div>
  76. </div>
  77. <div class="content-bottom">
  78. <span class="use">使用电子邮箱<em>{{secretEmail}}</em>进行验证,有效期7天</span>
  79. <div class="warp"
  80. @click="firstStepValidEmail"
  81. v-show="!emailSendSuccess">
  82. <button class="btn">发送验证请求</button>
  83. </div>
  84. <div class="warp" v-show="emailSendSuccess">
  85. <button class="btn" :disabled="emailSendSuccess">已发送验证邮件,请查收</button>
  86. </div>
  87. </div>
  88. </div>
  89. <div class="content" v-show="showQuestionsValid">
  90. <div class="content-top">
  91. <h3>验证手机</h3>
  92. <div class="step">
  93. <img src="/images/all/step01.png" alt=""/>
  94. <div class="step-item"><span class="active">账号验证</span><span>新手机号码</span><span>设置完成</span></div>
  95. <a href="" class="return"><img src="/images/all/return.png" alt=""/></a>
  96. </div>
  97. </div>
  98. <div>
  99. <el-form :model="validQuestion" :rules="rulesQuestion" ref="valid" label-width="100px" class="demo-ruleForm">
  100. <el-form-item class="questions">
  101. <span class="question">问题:{{question1}}</span>
  102. </el-form-item>
  103. <el-form-item prop="answer1">
  104. <el-input type="text" v-model="validQuestion.answer1"
  105. auto-complete="off"
  106. placeholder="答案一"></el-input>
  107. </el-form-item>
  108. <el-form-item class="questions">
  109. <span class="question">问题:{{question2}}</span>
  110. </el-form-item>
  111. <el-form-item prop="answer2">
  112. <el-input type="text" v-model="validQuestion.answer2"
  113. auto-complete="off"
  114. placeholder="答案二"></el-input>
  115. </el-form-item>
  116. <el-form-item>
  117. <a class="btn finish"
  118. :disabled="!answer1SecondChecked || !answer2SecondChecked"
  119. @click="validQuestionSubmit">提交</a>
  120. </el-form-item>
  121. </el-form>
  122. </div>
  123. </div>
  124. </div>
  125. </div>
  126. </template>
  127. <script>
  128. export default {
  129. name: 'validation',
  130. data () {
  131. // 第一步校验验证码
  132. var validateFirstCode = (rule, value, callback) => {
  133. if (value === '') {
  134. callback(new Error('请填写正确的验证码'))
  135. this.codeErrorChecked = false
  136. this.codeChecked = false
  137. } else {
  138. if (this.valid.code !== '') {
  139. if (this.token !== '') {
  140. if (this.valid.code !== '' && this.getMobile !== '') {
  141. let param = new FormData()
  142. param.append('mobile', this.getMobile)
  143. param.append('code', this.valid.code)
  144. param.append('token', this.token)
  145. let config = {
  146. headers: {'Content-Type': 'multipart/form-data'}
  147. }
  148. this.$http.post(`/update/user/checkCode/mobile`, param, config)
  149. .then(response => {
  150. if (response.data.success) {
  151. this.codeChecked = true
  152. this.codeErrorChecked = false
  153. } else {
  154. this.codeErrorChecked = true
  155. this.codeChecked = false
  156. return Promise.reject(response.data)
  157. }
  158. }).catch(err => {
  159. this.codeErrorMsg = err.errMsg
  160. })
  161. }
  162. } else {}
  163. }
  164. callback()
  165. }
  166. }
  167. // 第二步验证密保
  168. var validateSecondAnswer1 = (rule, value, callback) => {
  169. if (value === '') {
  170. callback(new Error('请填写正确的答案'))
  171. this.answer1SecondChecked = false
  172. } else {
  173. if (this.validQuestion.answer1 !== '') {
  174. this.answer1SecondChecked = true
  175. }
  176. callback()
  177. }
  178. }
  179. var validateSecondAnswer2 = (rule, value, callback) => {
  180. if (value === '') {
  181. callback(new Error('请填写正确的答案'))
  182. this.answer2SecondChecked = false
  183. } else {
  184. if (this.validQuestion.answer2 !== '') {
  185. this.answer2SecondChecked = true
  186. }
  187. callback()
  188. }
  189. }
  190. return {
  191. goFirstStep: true,
  192. hasValidPhoneWay: false,
  193. hasValidQuestionsWay: false,
  194. hasValidEmailWay: false,
  195. showManualAppeal: false,
  196. showPhoneValid: false,
  197. showEmailValid: false,
  198. showQuestionsValid: false,
  199. sendAccountCode: true,
  200. account_time: 0,
  201. codeErrorChecked: false,
  202. codeChecked: false,
  203. secretMobile: '',
  204. secretEmail: '',
  205. getMobile: '',
  206. getEmail: '',
  207. getQuestions: '',
  208. question1: '',
  209. question2: '',
  210. sort1: '',
  211. sort2: '',
  212. codeErrorMsg: '',
  213. firstStepToken: '',
  214. answer1SecondChecked: false,
  215. answer2SecondChecked: false,
  216. emailSendSuccess: false,
  217. valid: {
  218. code: ''
  219. },
  220. validQuestion: {
  221. answer1: '',
  222. answer2: ''
  223. },
  224. rules: {
  225. code: [
  226. {validator: validateFirstCode, trigger: 'blur'}
  227. ]
  228. },
  229. rulesQuestion: {
  230. answer1: [
  231. {validator: validateSecondAnswer1, trigger: 'blur'}
  232. ],
  233. answer2: [
  234. {validator: validateSecondAnswer2, trigger: 'blur'}
  235. ]
  236. }
  237. }
  238. },
  239. computed: {
  240. logged () {
  241. // console.log(this.$store.state.option.isLogin.data.content)
  242. return this.$store.state.option.isLogin.data.content
  243. }
  244. },
  245. mounted () {
  246. // 验证是否登录
  247. this.$nextTick(() => {
  248. this.isLogin()
  249. // 刷新统计信息
  250. setInterval(() => {
  251. this.isLogin()
  252. }, 10000)
  253. })
  254. // 获取验证方式
  255. this.$nextTick(() => {
  256. this.getVerifyWay()
  257. })
  258. },
  259. methods: {
  260. // 判断用户是否登录
  261. isLogin () {
  262. if (!this.logged.isLogin) {
  263. // console.log(this.logged.isLogin)
  264. // 未登录跳到登录页面
  265. window.location.href = '/'
  266. }
  267. },
  268. // 获取验证方式
  269. getVerifyWay () {
  270. this.$http.get('/update/user/checkType').then(response => {
  271. if (response.data.success) {
  272. // console.log(response.data.content)
  273. if (!response.data.content) {
  274. this.$router.push({ path: '/validation/phoneValidationSecondStep' })
  275. } else {
  276. if (response.data.content.mobile) {
  277. this.hasValidPhoneWay = true
  278. this.showManualAppeal = true
  279. this.getMobile = response.data.content.mobile
  280. var reg = /^(\d{3})\d{6}(\d{2})$/
  281. this.secretMobile = this.getMobile.replace(reg, '$1******$2')
  282. }
  283. if (response.data.content.questions) {
  284. this.hasValidQuestionsWay = true
  285. this.showManualAppeal = true
  286. this.getQuestions = response.data.content.questions
  287. this.question1 = this.getQuestions[0].question || ''
  288. this.question2 = this.getQuestions[1].question || ''
  289. this.sort1 = this.getQuestions[0].sort || ''
  290. this.sort2 = this.getQuestions[1].sort || ''
  291. }
  292. if (response.data.content.email) {
  293. this.hasValidEmailWay = true
  294. this.showManualAppeal = true
  295. this.getEmail = response.data.content.email
  296. let getEmailIndex = this.getEmail.indexOf('@')
  297. if (getEmailIndex > 3) {
  298. let len = this.getEmail.substring(3, getEmailIndex)
  299. this.secretEmail = this.getEmail.replace(len, '*')
  300. } else {
  301. this.getEmailArr = this.getEmail.split('')
  302. this.getEmailSplit = this.getEmailArr.splice(getEmailIndex, 0, '*')
  303. this.secretEmail = this.getEmailArr.join('')
  304. }
  305. }
  306. this.goFirstStep = true
  307. }
  308. }
  309. })
  310. },
  311. // 选择方式
  312. chooseWay (flag) {
  313. if (flag === 1) {
  314. this.showPhoneValid = true
  315. } else if (flag === 2) {
  316. this.showEmailValid = true
  317. } else if (flag === 3) {
  318. this.showQuestionsValid = true
  319. }
  320. this.goFirstStep = false
  321. },
  322. // 跳转到人工申诉页面
  323. goAccountAppeal () {
  324. window.location.href = '/appeals/accountAppeal'
  325. },
  326. // 返回上一步
  327. goPreviousStep () {
  328. this.goFirstStep = true
  329. this.showPhoneValid = false
  330. this.showEmailValid = false
  331. this.showQuestionsValid = false
  332. },
  333. // 获取第一步手机验证码
  334. getCheckCode () {
  335. this.$http.get(`/update/user/check/mobile`, {params: {mobile: this.getMobile}})
  336. .then(response => {
  337. this.token = response.data.content.token
  338. if (this.token !== '') {
  339. this.$message({
  340. message: '验证码已经发送到您的手机,请注意查收',
  341. type: 'success'
  342. })
  343. this.sendAccountCode = false
  344. this.account_time = 60
  345. var accountTime = setInterval(() => {
  346. this.account_time--
  347. if (this.account_time <= 0) {
  348. this.sendAccountCode = true
  349. clearInterval(accountTime)
  350. }
  351. }, 1000)
  352. }
  353. }).catch(err => {
  354. this.$message.error(err.errMsg)
  355. })
  356. },
  357. // 手机号验证下一步
  358. goNextStep () {
  359. if (this.codeChecked) {
  360. let param = new FormData()
  361. param.append('mobile', this.getMobile)
  362. param.append('code', this.valid.code)
  363. param.append('token', this.token)
  364. let config = {
  365. headers: {'Content-Type': 'multipart/form-data'}
  366. }
  367. this.$http.post(`/update/user/check/mobile`, param, config)
  368. .then(response => {
  369. if (response.data.success) {
  370. this.$store.commit('login/GET_TOKEN', response.data.content)
  371. this.showPhoneValid = false
  372. this.$router.push({ path: '/validation/phoneValidationSecondStep' })
  373. } else {
  374. this.showPhoneValid = true
  375. return Promise.reject(response.data)
  376. }
  377. }).catch(err => {
  378. this.$message.error(err.errMsg)
  379. })
  380. }
  381. },
  382. // 第一步验证邮箱
  383. firstStepValidEmail () {
  384. this.$http.get(`/update/user/check/email`, {params: {email: this.getEmail, operate: 'mobile'}})
  385. .then(response => {
  386. if (response.data.success) {
  387. this.emailSendSuccess = true
  388. } else {
  389. this.emailSendSuccess = false
  390. return Promise.reject(response.data)
  391. }
  392. }).catch(err => {
  393. console.log(err)
  394. // this.$message.error(err.errMsg)
  395. })
  396. },
  397. // 第一步验证密保提交
  398. validQuestionSubmit () {
  399. if (this.answer1SecondChecked && this.answer2SecondChecked) {
  400. let param = new FormData()
  401. let answer = []
  402. answer.push({'answer': this.validQuestion.answer1, 'sort': this.sort1}, {'answer': this.validQuestion.answer2, 'sort': this.sort2})
  403. let answers = JSON.stringify(answer)
  404. param.append('answers', answers)
  405. let config = {
  406. headers: {'Content-Type': 'multipart/form-data'}
  407. }
  408. this.$http.post(`/update/user/check/question`, param, config)
  409. .then(response => {
  410. if (response.data.success) {
  411. this.$store.commit('login/GET_TOKEN', response.data.content.token)
  412. this.showQuestionsValid = false
  413. this.$router.push({ path: '/validation/phoneValidationSecondStep' })
  414. } else {
  415. this.showQuestionsValid = true
  416. return Promise.reject(response.data)
  417. }
  418. }).catch(err => {
  419. this.$message.error(err.errMsg)
  420. })
  421. }
  422. }
  423. }
  424. }
  425. </script>
  426. <style lang="scss" scoped>
  427. .validation {
  428. margin: 0 auto;
  429. width: 100%;
  430. background: #eee;
  431. .container{
  432. padding-top: 50px;
  433. margin: 0 auto;
  434. width: 980px;
  435. text-align: center;
  436. .content{
  437. padding: 0 50px;
  438. margin: 50px auto 0;
  439. width: 100%;
  440. /*height: 540px;*/
  441. text-align: center;
  442. background: #fff;
  443. .content-top{
  444. height: 80px;
  445. line-height: 80px;
  446. h3{
  447. margin-bottom: 0;
  448. font-size: 24px;
  449. color: #000;
  450. border-bottom: 1px solid #dcdcdc;
  451. }
  452. .step{
  453. position: relative;
  454. margin-top: 10px;
  455. img{
  456. width: 315px;
  457. height: 46px;
  458. }
  459. .step-item{
  460. position: absolute;
  461. top: 45px;
  462. left: 265px;
  463. span{
  464. margin-right: 78px;
  465. font-size: 14px;
  466. color: #b4b4b4;
  467. }
  468. span.active {
  469. color: #0076ad;
  470. }
  471. }
  472. }
  473. }
  474. form {
  475. margin-top: 150px;
  476. padding-bottom: 44px;
  477. input{
  478. padding: 0 0 0 18px;
  479. width: 360px;
  480. height: 44px;
  481. line-height: 44px;
  482. font-size: 14px;
  483. color: #000;
  484. border-radius: 0;
  485. }
  486. input.answer {
  487. background: url("/images/all/more.png") no-repeat 325px center;
  488. cursor: pointer;
  489. }
  490. ul{
  491. display: none;
  492. position: absolute;
  493. top: 44px;
  494. left: 0;
  495. width: 360px;
  496. background: #fff;
  497. box-shadow: 0 0 5px rgba(0,0,0,.5);
  498. -moz-box-shadow: 0 0 5px rgba(0,0,0,.5);
  499. -o-box-shadow: 0 0 5px rgba(0,0,0,.5);
  500. -webkit-box-shadow: 0 0 5px rgba(0,0,0,.5);
  501. z-index: 10;
  502. li{
  503. padding-left: 18px;
  504. width: 100%;
  505. height: 30px;
  506. line-height: 30px;
  507. text-align: left;
  508. font-size: 14px;
  509. color: #000;
  510. cursor: pointer;
  511. &:hover{
  512. background: #0076ad;
  513. color: #fff;
  514. }
  515. }
  516. }
  517. span.tip{
  518. position: absolute;
  519. top: 0;
  520. right: -238px;
  521. font-size: 13px;
  522. color: #8c8c8c;
  523. a{
  524. font-size: 13px;
  525. color: #0076ad;
  526. }
  527. }
  528. span.tip.codeError-tip{
  529. position: absolute;
  530. top: 3px;
  531. left: 378px;
  532. width: 200px;
  533. text-align: left;
  534. color: #ff4949;
  535. font-size: 12px;
  536. }
  537. i{
  538. position: absolute;
  539. top: 13px;
  540. left: 20px;
  541. font-size: 20px;
  542. color: #a0a0a0;
  543. }
  544. .btn {
  545. margin: 34px 0 16px 0;
  546. width: 360px;
  547. height: 44px;
  548. line-height: 44px;
  549. font-size: 16px;
  550. color: #fff;
  551. background: #0076AD;
  552. border-radius: 3px;
  553. }
  554. }
  555. .content-bottom{
  556. margin: 155px auto 0;
  557. padding-bottom: 50px;
  558. width: 360px;
  559. div.warp{
  560. padding-bottom: 65px;
  561. }
  562. p{
  563. font-size: 24px;
  564. color: #323232;
  565. img{
  566. margin-right: 20px;
  567. width: 30px;
  568. height: 28px;
  569. }
  570. }
  571. p.pass{
  572. font-size: 24px;
  573. color: #e77405;
  574. img{
  575. height: 30px;
  576. }
  577. }
  578. p.passed {
  579. color: #2ab300;
  580. img{
  581. height: 30px;
  582. }
  583. }
  584. span{
  585. display: inline-block;
  586. font-size: 14px;
  587. color: #8b8b8b;
  588. }
  589. span.close-tip{
  590. margin: 15px 0 140px 0;
  591. }
  592. .close-btn{
  593. margin: 0 auto;
  594. width: 200px;
  595. height: 36px;
  596. line-height: 36px;
  597. font-size: 14px;
  598. text-align: center;
  599. color: #323232;
  600. border: 1px solid #d2d2d2;
  601. border-radius: 3px;
  602. cursor: pointer ;
  603. }
  604. span.use{
  605. display: inline-block;
  606. margin-bottom: 30px;
  607. width: 360px;
  608. font-size: 14px;
  609. color: #000;
  610. text-align: left;
  611. em{
  612. font-size: 14px;
  613. font-style: normal;
  614. color: #000;
  615. }
  616. }
  617. .form-group {
  618. margin: 0 auto 16px;
  619. position: relative;
  620. width: 360px;
  621. height: 44px;
  622. line-height: 44px;
  623. input{
  624. padding: 0 0 0 18px;
  625. width: 360px;
  626. height: 44px;
  627. line-height: 44px;
  628. font-size: 14px;
  629. color: #000;
  630. border-radius: 0;
  631. }
  632. input.msg{
  633. float: left;
  634. width: 210px;
  635. padding: 0 0 0 18px;
  636. height: 44px;
  637. line-height: 44px;
  638. font-size: 14px;
  639. color: #000;
  640. border-radius: 0;
  641. }
  642. span.msg{
  643. float: right;
  644. margin: 0;
  645. width: 130px;
  646. height: 44px;
  647. line-height: 44px;
  648. text-align: center ;
  649. font-size: 14px;
  650. color: #5a5a5a;
  651. background: #f4f4f4;
  652. border: 1px solid #dcdcdc;
  653. cursor: pointer;
  654. }
  655. span.msg.send{
  656. background: #d2d2d2;
  657. color: #fff;
  658. }
  659. }
  660. .btn {
  661. margin: 34px 0 10px 0;
  662. width: 360px;
  663. height: 44px;
  664. line-height: 44px;
  665. font-size: 16px;
  666. color: #fff;
  667. background: #0076AD;
  668. border-radius: 3px;
  669. }
  670. }
  671. .choose{
  672. margin: 155px auto 0;
  673. padding-bottom: 44px;
  674. div{
  675. padding: 0 15px;
  676. margin: 0 auto 16px;
  677. width: 360px;
  678. height: 60px;
  679. line-height: 60px;
  680. text-align: left;
  681. overflow: hidden;
  682. border: 1px solid #d2d2d2;
  683. cursor: pointer;
  684. &:hover,&.active{
  685. border-color: #0076ad;
  686. span{
  687. color: #0076ad;
  688. }
  689. i.second {
  690. color: #0076ad;
  691. }
  692. }
  693. img.first{
  694. float: left;
  695. margin: 24px 20px 0 0;
  696. font-size: 20px;
  697. color: #323232;
  698. }
  699. img.first.mob{
  700. margin: 22px 20px 0 5px;
  701. font-size: 28px;
  702. }
  703. i.second {
  704. float: right;
  705. margin: 20px 0 0 5px;
  706. font-size: 20px;
  707. color: #323232;
  708. }
  709. span{
  710. float: left;
  711. font-size: 14px;
  712. color: #323232;
  713. }
  714. }
  715. }
  716. a.return{
  717. position: absolute;
  718. left: 0;
  719. top: -15px;
  720. img{
  721. width: 34px !important;
  722. height: 34px !important;
  723. }
  724. }
  725. }
  726. }
  727. }
  728. </style>