Pārlūkot izejas kodu

feat: add new util function

wangyuan 2 gadi atpakaļ
vecāks
revīzija
bb58de31fc
1 mainītis faili ar 9 papildinājumiem un 0 dzēšanām
  1. 9 0
      utils/util.js

+ 9 - 0
utils/util.js

@@ -39,5 +39,14 @@ export default {
     return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
       return (c === 'x' ? (Math.random() * 16 | 0) : ('r&0x3' | '0x8')).toString(16)
     })
+  },
+  randomStr (length = 16) {
+    var res = ''
+    var baseStr = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
+    for (let index = 0; index < length; index++) {
+      var random = parseInt(Math.random() * 26)
+      res = res + baseStr[random]
+    }
+    return res
   }
 }