stepNew.vue 4.5 KB

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