EncryptedSetting.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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').then(response => {
  203. if (response.data.success) {
  204. if (!response.data.content.mobile) {
  205. this.goValidPhone = true
  206. } else {
  207. if (response.data.content.mobile) {
  208. this.hasValidPhoneWay = true
  209. this.showManualAppeal = true
  210. this.getMobile = response.data.content.mobile
  211. var reg = /^(\d{3})\d{6}(\d{2})$/
  212. this.secretMobile = this.getMobile.replace(reg, '$1******$2')
  213. }
  214. if (response.data.content.email) {
  215. this.hasValidEmailWay = true
  216. this.showManualAppeal = true
  217. this.getEmail = response.data.content.email
  218. let getEmailIndex = this.getEmail.indexOf('@')
  219. if (getEmailIndex > 3) {
  220. let len = this.getEmail.substring(3, getEmailIndex)
  221. this.secretEmail = this.getEmail.replace(len, '*')
  222. } else {
  223. this.getEmailArr = this.getEmail.split('')
  224. this.getEmailSplit = this.getEmailArr.splice(getEmailIndex, 0, '*')
  225. this.secretEmail = this.getEmailArr.join('')
  226. }
  227. }
  228. this.goValidPhone = false
  229. this.goFirstStep = true
  230. }
  231. }
  232. })
  233. },
  234. // 没验证手机将跳转到手机验证页面
  235. goVaildPhoneStep () {
  236. this.$router.push({ path: '/validation/phoneValidation' })
  237. },
  238. // 选择方式
  239. chooseWay (flag) {
  240. if (flag === 1) {
  241. this.showPhoneValid = true
  242. } else if (flag === 2) {
  243. this.showEmailValid = true
  244. }
  245. this.goFirstStep = false
  246. },
  247. // 返回上一步
  248. goPreviousStep () {
  249. this.goFirstStep = true
  250. this.showPhoneValid = false
  251. this.showEmailValid = false
  252. },
  253. // 获取第一步手机验证码
  254. getCheckCode () {
  255. this.isShowLoading = true
  256. this.$http.get(`/update/user/check/mobile`, {params: {mobile: this.getMobile}})
  257. .then(response => {
  258. this.isShowLoading = false
  259. this.token = response.data.content.token
  260. if (this.token !== '') {
  261. this.$message({
  262. message: '验证码已经发送到您的手机,请注意查收',
  263. type: 'success'
  264. })
  265. this.sendAccountCode = false
  266. this.account_time = 60
  267. var accountTime = setInterval(() => {
  268. this.account_time--
  269. if (this.account_time <= 0) {
  270. this.sendAccountCode = true
  271. clearInterval(accountTime)
  272. }
  273. }, 1000)
  274. }
  275. }).catch(err => {
  276. this.isShowLoading = false
  277. this.$message.error(err.errMsg)
  278. })
  279. },
  280. // 手机号验证下一步
  281. goNextStep () {
  282. if (this.codeChecked) {
  283. this.isShowLoading = true
  284. let param = new FormData()
  285. param.append('mobile', this.getMobile)
  286. param.append('code', this.valid.code)
  287. param.append('token', this.token)
  288. let config = {
  289. headers: {'Content-Type': 'multipart/form-data'}
  290. }
  291. this.$http.post(`/update/user/check/mobile`, param, config)
  292. .then(response => {
  293. if (response.data.success) {
  294. this.isShowLoading = false
  295. this.$store.commit('login/GET_TOKEN', response.data.content)
  296. this.showPhoneValid = false
  297. this.$router.push({ path: '/encrypted-setting/EncryptedSettingSecondStep' })
  298. } else {
  299. this.showPhoneValid = true
  300. return Promise.reject(response.data)
  301. }
  302. }).catch(err => {
  303. this.isShowLoading = false
  304. this.$message.error(err.errMsg)
  305. })
  306. }
  307. },
  308. // 第一步验证邮箱
  309. firstStepValidEmail () {
  310. this.isShowLoading = true
  311. this.$http.get(`/update/user/check/email`, {params: {email: this.getEmail, operate: 'question'}})
  312. .then(response => {
  313. if (response.data.success) {
  314. this.isShowLoading = false
  315. this.emailSendSuccess = true
  316. } else {
  317. this.emailSendSuccess = false
  318. return Promise.reject(response.data)
  319. }
  320. }).catch(err => {
  321. this.isShowLoading = false
  322. console.log(err)
  323. // this.$message.error(err.errMsg)
  324. })
  325. }
  326. }
  327. }
  328. </script>
  329. <style lang="scss" scoped>
  330. .validation {
  331. margin: 0 auto;
  332. width: 100%;
  333. background: #eee;
  334. .container{
  335. padding-top: 50px;
  336. margin: 0 auto;
  337. width: 980px;
  338. text-align: center;
  339. .content{
  340. padding: 0 50px;
  341. margin: 50px auto 0;
  342. width: 100%;
  343. /*height: 540px;*/
  344. text-align: center;
  345. background: #fff;
  346. .content-top{
  347. height: 80px;
  348. line-height: 80px;
  349. h3{
  350. margin-bottom: 0;
  351. font-size: 24px;
  352. color: #000;
  353. border-bottom: 1px solid #dcdcdc;
  354. }
  355. .step{
  356. position: relative;
  357. margin-top: 10px;
  358. img{
  359. width: 315px;
  360. height: 46px;
  361. }
  362. .step-item{
  363. position: absolute;
  364. top: 45px;
  365. left: 265px;
  366. span{
  367. margin-right: 78px;
  368. font-size: 14px;
  369. color: #b4b4b4;
  370. }
  371. span.active {
  372. color: #0076ad;
  373. }
  374. }
  375. }
  376. }
  377. form {
  378. margin-top: 150px;
  379. padding-bottom: 44px;
  380. input{
  381. padding: 0 0 0 18px;
  382. width: 360px;
  383. height: 44px;
  384. line-height: 44px;
  385. font-size: 14px;
  386. color: #000;
  387. border-radius: 0;
  388. }
  389. input.answer {
  390. background: url("/images/all/more.png") no-repeat 325px center;
  391. cursor: pointer;
  392. }
  393. ul{
  394. display: none;
  395. position: absolute;
  396. top: 44px;
  397. left: 0;
  398. width: 360px;
  399. background: #fff;
  400. box-shadow: 0 0 5px rgba(0,0,0,.5);
  401. -moz-box-shadow: 0 0 5px rgba(0,0,0,.5);
  402. -o-box-shadow: 0 0 5px rgba(0,0,0,.5);
  403. -webkit-box-shadow: 0 0 5px rgba(0,0,0,.5);
  404. z-index: 10;
  405. li{
  406. padding-left: 18px;
  407. width: 100%;
  408. height: 30px;
  409. line-height: 30px;
  410. text-align: left;
  411. font-size: 14px;
  412. color: #000;
  413. cursor: pointer;
  414. &:hover{
  415. background: #0076ad;
  416. color: #fff;
  417. }
  418. }
  419. }
  420. span.tip{
  421. position: absolute;
  422. top: 0;
  423. right: -238px;
  424. font-size: 13px;
  425. color: #8c8c8c;
  426. a{
  427. font-size: 13px;
  428. color: #0076ad;
  429. }
  430. }
  431. span.tip.codeError-tip{
  432. position: absolute;
  433. top: 3px;
  434. left: 378px;
  435. width: 200px;
  436. text-align: left;
  437. color: #ff4949;
  438. font-size: 12px;
  439. }
  440. i{
  441. position: absolute;
  442. top: 13px;
  443. left: 20px;
  444. font-size: 20px;
  445. color: #a0a0a0;
  446. }
  447. .btn {
  448. margin: 34px 0 16px 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. .content-bottom{
  459. margin: 155px auto 0;
  460. padding-bottom: 50px;
  461. width: 360px;
  462. div.warp{
  463. padding-bottom: 65px;
  464. }
  465. p{
  466. font-size: 24px;
  467. color: #323232;
  468. img{
  469. margin-right: 20px;
  470. width: 30px;
  471. height: 28px;
  472. }
  473. }
  474. p.pass{
  475. font-size: 24px;
  476. color: #e77405;
  477. img{
  478. height: 30px;
  479. }
  480. }
  481. p.passed {
  482. color: #2ab300;
  483. img{
  484. height: 30px;
  485. }
  486. }
  487. span{
  488. display: inline-block;
  489. font-size: 14px;
  490. color: #8b8b8b;
  491. }
  492. span.close-tip{
  493. margin: 15px 0 140px 0;
  494. }
  495. .close-btn{
  496. margin: 0 auto;
  497. width: 200px;
  498. height: 36px;
  499. line-height: 36px;
  500. font-size: 14px;
  501. text-align: center;
  502. color: #323232;
  503. border: 1px solid #d2d2d2;
  504. border-radius: 3px;
  505. cursor: pointer ;
  506. }
  507. span.use{
  508. display: inline-block;
  509. margin-bottom: 30px;
  510. width: 360px;
  511. font-size: 14px;
  512. color: #000;
  513. text-align: left;
  514. em{
  515. font-size: 14px;
  516. font-style: normal;
  517. color: #000;
  518. }
  519. }
  520. .form-group {
  521. margin: 0 auto 16px;
  522. position: relative;
  523. width: 360px;
  524. height: 44px;
  525. line-height: 44px;
  526. input{
  527. padding: 0 0 0 18px;
  528. width: 360px;
  529. height: 44px;
  530. line-height: 44px;
  531. font-size: 14px;
  532. color: #000;
  533. border-radius: 0;
  534. }
  535. input.msg{
  536. float: left;
  537. width: 210px;
  538. padding: 0 0 0 18px;
  539. height: 44px;
  540. line-height: 44px;
  541. font-size: 14px;
  542. color: #000;
  543. border-radius: 0;
  544. }
  545. span.msg{
  546. float: right;
  547. margin: 0;
  548. width: 130px;
  549. height: 44px;
  550. line-height: 44px;
  551. text-align: center ;
  552. font-size: 14px;
  553. color: #5a5a5a;
  554. background: #f4f4f4;
  555. border: 1px solid #dcdcdc;
  556. cursor: pointer;
  557. }
  558. span.msg.send{
  559. background: #d2d2d2;
  560. color: #fff;
  561. }
  562. }
  563. .btn {
  564. margin: 34px 0 10px 0;
  565. width: 360px;
  566. height: 44px;
  567. line-height: 44px;
  568. font-size: 16px;
  569. color: #fff;
  570. background: #0076AD;
  571. border-radius: 3px;
  572. }
  573. }
  574. .choose{
  575. margin: 155px auto 0;
  576. padding-bottom: 44px;
  577. div{
  578. padding: 0 15px;
  579. margin: 0 auto 16px;
  580. width: 360px;
  581. height: 60px;
  582. line-height: 60px;
  583. text-align: left;
  584. overflow: hidden;
  585. border: 1px solid #d2d2d2;
  586. cursor: pointer;
  587. &:hover,&.active{
  588. border-color: #0076ad;
  589. span{
  590. color: #0076ad;
  591. }
  592. i.second {
  593. color: #0076ad;
  594. }
  595. }
  596. img.first{
  597. float: left;
  598. margin: 24px 20px 0 0;
  599. font-size: 20px;
  600. color: #323232;
  601. }
  602. img.first.mob{
  603. margin: 22px 20px 0 5px;
  604. font-size: 28px;
  605. }
  606. i.second {
  607. float: right;
  608. margin: 20px 0 0 5px;
  609. font-size: 20px;
  610. color: #323232;
  611. }
  612. span{
  613. float: left;
  614. font-size: 14px;
  615. color: #323232;
  616. }
  617. }
  618. }
  619. a.return{
  620. position: absolute;
  621. left: 0;
  622. top: -15px;
  623. img{
  624. width: 34px !important;
  625. height: 34px !important;
  626. }
  627. }
  628. }
  629. }
  630. }
  631. </style>