index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * FeHelper 密码随机生成工具
  3. */
  4. new Vue({
  5. el: '#pageContainer',
  6. data: {
  7. number: true,
  8. lowerLetter: true,
  9. upperLetter: true,
  10. specialChar: false,
  11. length: 16,
  12. chars: {
  13. number: '0123456789',
  14. lowerLetter: 'abcdefghijklmnopqrstuvwxyz',
  15. upperLetter: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
  16. specialChar: '~!@#$%^&*()[{]}-_=+\|;:\'\",<.>/?`'
  17. },
  18. resultContent: ''
  19. },
  20. methods: {
  21. convert: function () {
  22. this.$nextTick(() => {
  23. let exceptedChars = ['number', 'lowerLetter', 'upperLetter', 'specialChar'].filter(item => this[item]).map(item => this.chars[item]).join('');
  24. let password = [], rands = [], rand = 0;
  25. for (let index = 0; index < this.length; index++) {
  26. // 尽可能不让字符重复
  27. do {
  28. rand = Math.floor(Math.random() * exceptedChars.length);
  29. } while (rands.includes(rand) && rands.length < exceptedChars.length);
  30. rands.push(rand);
  31. password.push(exceptedChars[rand]);
  32. }
  33. this.resultContent = password.join('');
  34. });
  35. },
  36. getResult: function () {
  37. this.$refs.rstCode.select();
  38. }
  39. }
  40. });