Browse Source

modify: 修改随机密码生成逻辑,增加密码生成数量

liuke01 6 tháng trước cách đây
mục cha
commit
28d355116f
3 tập tin đã thay đổi với 21 bổ sung13 xóa
  1. 2 1
      apps/password/index.css
  2. 3 0
      apps/password/index.html
  3. 16 12
      apps/password/index.js

+ 2 - 1
apps/password/index.css

@@ -2,8 +2,9 @@
 
 #rstCode {
     min-height: 80px;
+    max-height: 300px;
     width:530px;
-    resize: none;
+    resize: vertical;
     margin: 15px;
 }
 .row .checkbox {

+ 3 - 0
apps/password/index.html

@@ -39,6 +39,9 @@
                 <div class="checkbox">
                     <label>密码长度:<input class="form-control" type="number" min="0" v-model="length" @click="convert()"></label>
                 </div>
+                <div class="checkbox">
+                    <label>生成数量:<input class="form-control" type="number" min="1" v-model="count" @change="convert()"></label>
+                </div>
 
                 <div class="checkbox no-border">
                     <input id="btnCopy" class="btn btn-warning" type="button" value="复制" @click="copyResult()" v-show="resultContent.length > 0">

+ 16 - 12
apps/password/index.js

@@ -8,7 +8,8 @@ new Vue({
         lowerLetter: true,
         upperLetter: true,
         specialChar: false,
-        length: 16,
+        length: 20,
+        count: 1,
         chars: {
             number: '0123456789',
             lowerLetter: 'abcdefghijklmnopqrstuvwxyz',
@@ -23,19 +24,22 @@ new Vue({
             this.$nextTick(() => {
                 let exceptedChars = ['number', 'lowerLetter', 'upperLetter', 'specialChar'].filter(item => this[item]).map(item => this.chars[item]).join('');
 
-                let password = [], rands = [], rand = 0;
-                for (let index = 0; index < this.length; index++) {
+                // 生成指定数量的密码
+                let passwords = [];
+                for (let i = 0; i < this.count; i++) {
+                    let password = [], rands = [], rand = 0;
+                    for (let index = 0; index < this.length; index++) {
+                        // 尽可能不让字符重复
+                        do {
+                            rand = Math.floor(Math.random() * exceptedChars.length);
+                        } while (rands.includes(rand) && rands.length < exceptedChars.length);
 
-                    // 尽可能不让字符重复
-                    do {
-                        rand = Math.floor(Math.random() * exceptedChars.length);
-                    } while (rands.includes(rand) && rands.length < exceptedChars.length);
-
-                    rands.push(rand);
-                    password.push(exceptedChars[rand]);
+                        rands.push(rand);
+                        password.push(exceptedChars[rand]);
+                    }
+                    passwords.push(password.join(''));
                 }
-
-                this.resultContent = password.join('');
+                this.resultContent = passwords.join('\n');
             });
         },