PasswordStrengthMeter.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <div class="password-meter">
  3. <div class="bar">
  4. <div :class="'level'+level"></div>
  5. </div>
  6. <span :class="'level'+level">密码强度 {{levelString}}</span>
  7. </div>
  8. </template>
  9. <script lang="ts">
  10. import { defineComponent } from 'vue'
  11. import { checkPassWordSecrityLevel } from '@/common/utils/CheckUtils'
  12. /**
  13. * 密码强度显示组件
  14. */
  15. export default defineComponent({
  16. props: {
  17. password: {
  18. type: String,
  19. default: '',
  20. }
  21. },
  22. data() {
  23. return {
  24. level: 0,
  25. levelString: '',
  26. }
  27. },
  28. watch: {
  29. password(v: string) {
  30. this.level = Math.floor((checkPassWordSecrityLevel(v) / 100) * 5);
  31. switch(this.level) {
  32. case 0: this.levelString = '非常弱'; break;
  33. case 1: this.levelString = '弱'; break;
  34. case 2: this.levelString = '中等'; break;
  35. case 3: this.levelString = '强'; break;
  36. case 4: this.levelString = '非常强'; break;
  37. }
  38. },
  39. }
  40. })
  41. </script>
  42. <style lang="scss">
  43. .password-meter {
  44. position: relative;
  45. height: 20px;
  46. margin: 10px 0;
  47. .bar {
  48. position: absolute;
  49. left: 0;
  50. top: 0;
  51. bottom: 0;
  52. right: 130px;
  53. background-color: #e7e7e7;
  54. border: 1px solid #a1a1a1;
  55. div {
  56. position: absolute;
  57. left: 0;
  58. top: 0;
  59. bottom: 0;
  60. &.level0 {
  61. width: 0;
  62. background-color: #000;
  63. }
  64. &.level1 {
  65. width: 25%;
  66. background-color: #ca410a;
  67. }
  68. &.level2 {
  69. width: 50%;
  70. background-color: #d8c40c;
  71. }
  72. &.level3 {
  73. width: 75%;
  74. background-color: #9ab814;
  75. }
  76. &.level4 {
  77. width: 100%;
  78. background-color: #2fbe0b;
  79. }
  80. }
  81. }
  82. > span {
  83. position: absolute;
  84. top: 0;
  85. bottom: 0;
  86. width: 100px;
  87. right: 0;
  88. font-size: 12px;
  89. &.level0 {
  90. color: #646464;
  91. }
  92. &.level1 {
  93. color: #a8380c;
  94. }
  95. &.level2 {
  96. color: #af9f0e;
  97. }
  98. &.level3 {
  99. color: #91ac18;
  100. }
  101. &.level4 {
  102. color: #26920b;
  103. }
  104. }
  105. }
  106. </style>