EncryptedSetting.vue 16 KB

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