stepNew.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. data () {
  36. return {
  37. progress: '',
  38. state: {
  39. password: 'error',
  40. confirm: 'error'
  41. },
  42. news: {
  43. password: '',
  44. confirm: ''
  45. }
  46. }
  47. },
  48. methods: {
  49. // 弹窗处理
  50. downToast (type) {
  51. this.$toast({
  52. message: type,
  53. iconClass: 'el-icon-warning'
  54. })
  55. },
  56. // 验证密码强度
  57. validPassword () {
  58. let reg1 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z])(?=.*[A-Z]))|((?=.*[0-9])((?=.*[a-zA-Z]))(?=.*[^a-zA-Z0-9]))).*$/
  59. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  60. let count = this.news.password.length
  61. if (count >= 20) {
  62. this.downToast('密码须为8-20字符的英文、数字混合')
  63. } else {
  64. if (reg1.test(this.news.password)) {
  65. this.progress = '强'
  66. } else if (reg2.test(this.news.password)) {
  67. this.progress = '中'
  68. } else {
  69. this.progress = '弱'
  70. }
  71. }
  72. },
  73. // 验证新密码
  74. validPasswordTip () {
  75. let reg2 = /^(?=.{8,20})(((?=.*[0-9])(?=.*[a-z]))|((?=.*[0-9])(?=.*[A-Z]))).*$/
  76. if (!this.news.password) {
  77. this.downToast('请输入密码')
  78. this.state.password = 'error'
  79. } else {
  80. if (!reg2.test(this.news.password)) {
  81. this.downToast('密码须为8-20字符的英文、数字混合')
  82. this.state.password = 'warning'
  83. } else {
  84. this.state.password = 'success'
  85. if (this.news.confirm) {
  86. this.validConfirm()
  87. }
  88. }
  89. }
  90. },
  91. // 验证密码是否一致
  92. validConfirm () {
  93. if (!this.news.confirm) {
  94. this.downToast('请再次输入密码')
  95. this.state.confirm = 'error'
  96. } else {
  97. if (this.news.confirm === this.news.password) {
  98. this.state.confirm = 'success'
  99. } else {
  100. this.state.confirm = 'warning'
  101. this.downToast('两次输入密码不一致,请重新输入')
  102. }
  103. }
  104. },
  105. sureAccount (type) {
  106. if (this.state.password !== 'success' && this.state.confirm !== 'success') {
  107. this.downToast('请确认填写部分是否有误')
  108. } else {
  109. this.$indicator.open('验证中...')
  110. let param = new FormData()
  111. param.append('password', this.newPassword.password)
  112. param.append('token', this.firstStepToken)
  113. let config = {
  114. headers: {'Content-Type': 'multipart/form-data'}
  115. }
  116. this.$http.post(`/sso/resetPwd`, param, config)
  117. .then(response => {
  118. this.$indicator.close()
  119. if (response.data.success) {
  120. this.$emit('stepEvent', type)
  121. } else {
  122. this.downToast(response.data.errMsg)
  123. }
  124. }).catch(() => {
  125. this.$indicator.close()
  126. this.downToast('请检查网络是否正常或联系服务商')
  127. })
  128. }
  129. }
  130. }
  131. }
  132. </script>