EncryptedSetting.vue 17 KB

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