EncryptedSetting.vue 16 KB

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