stepNew.vue 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div class="f-main">
  3. <div class="content-top">
  4. <p>密码重置</p>
  5. </div>
  6. <div class="f-form">
  7. <div class="page-part">
  8. <mt-field placeholder="新密码"
  9. :attr="{ maxlength: 20 }"
  10. :state="state.password"
  11. @blur.native.capture="validPasswordTip"
  12. @input.native="validPassword"
  13. v-model="news.password"></mt-field>
  14. <template v-if="news.password">
  15. <p class="pwd">密码强度 <em :class="{sm:progress === '弱', md: progress === '中', ld:progress === '强'}"></em> <em :class="{md: progress === '中', ld:progress === '强'}"></em> <em :class="{ld:progress === '强'}"></em> <span :class="{smstep:progress === '弱', mdstep: progress === '中', ldstep:progress === '强'}" v-text="progress">强</span></p>
  16. <p class="pwd">密码须为8-20字符的英文、数字混合</p>
  17. </template>
  18. </div>
  19. <div class="page-part">
  20. <mt-field placeholder="确认密码"
  21. :state="state.confirm"
  22. auto-complet="off"
  23. @blur.native.capture="validConfirm"
  24. v-model="news.confirm"></mt-field>
  25. </div>
  26. <div class="page-part">
  27. <mt-button size="large" type="primary" @click="sureAccount('last')">下一步</mt-button>
  28. </div>
  29. </div>
  30. </div>
  31. </template>
  32. <script>
  33. export default {
  34. name: 'step-new',
  35. props: ['tokenId'],
  36. data () {
  37. return {
  38. progress: '',
  39. state: {
  40. password: 'error',
  41. confirm: 'error'
  42. },
  43. news: {
  44. password: '',
  45. confirm: ''
  46. }
  47. }
  48. },
  49. methods: {
  50. // 弹窗处理
  51. downToast (type) {
  52. this.$toast({
  53. message: type,
  54. iconClass: 'el-icon-warning'
  55. })
  56. },
  57. // 验证密码强度
  58. validPassword () {
  59. let reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  60. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  61. let count = this.news.password.length
  62. if (count >= 20) {
  63. this.downToast('密码须为8-20字符的英文、数字混合')
  64. } else {
  65. if (reg1.test(this.news.password)) {
  66. this.progress = '强'
  67. } else if (reg2.test(this.news.password)) {
  68. this.progress = '中'
  69. } else {
  70. this.progress = '弱'
  71. }
  72. }
  73. },
  74. // 验证新密码
  75. validPasswordTip () {
  76. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  77. if (!this.news.password) {
  78. this.downToast('请输入密码')
  79. this.state.password = 'error'
  80. } else {
  81. if (!reg2.test(this.news.password)) {
  82. this.downToast('密码须为8-20字符的英文、数字混合')
  83. this.state.password = 'warning'
  84. } else {
  85. this.state.password = 'success'
  86. if (this.news.confirm) {
  87. this.validConfirm()
  88. }
  89. }
  90. }
  91. },
  92. // 验证密码是否一致
  93. validConfirm () {
  94. if (!this.news.confirm) {
  95. this.downToast('请再次输入密码')
  96. this.state.confirm = 'error'
  97. } else {
  98. if (this.news.confirm === this.news.password) {
  99. this.state.confirm = 'success'
  100. } else {
  101. this.state.confirm = 'warning'
  102. this.downToast('两次输入密码不一致,请重新输入')
  103. }
  104. }
  105. },
  106. sureAccount (type) {
  107. if (this.state.password !== 'success' && this.state.confirm !== 'success') {
  108. this.downToast('请确认填写部分是否有误')
  109. } else {
  110. this.$indicator.open('验证中...')
  111. let param = new FormData()
  112. param.append('password', this.news.password)
  113. param.append('token', this.$route.query.token ? this.$route.query.token : this.tokenId)
  114. let config = {
  115. headers: {'Content-Type': 'multipart/form-data'}
  116. }
  117. this.$http.post(`/sso/resetPwd`, param, config)
  118. .then(response => {
  119. this.$indicator.close()
  120. if (response.data.success) {
  121. this.$emit('stepEvent', type)
  122. this.$emit('lastEvent', 'new')
  123. } else {
  124. this.downToast(response.data.errMsg)
  125. }
  126. }).catch(() => {
  127. this.$indicator.close()
  128. this.downToast('请检查网络是否正常或联系服务商')
  129. })
  130. }
  131. }
  132. }
  133. }
  134. </script>