EncryptedSetting.vue 17 KB

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