diff --git a/frontend/src/utils/StringUtils.js b/frontend/src/utils/StringUtils.js index 6124dc0dcc..6886395dc5 100644 --- a/frontend/src/utils/StringUtils.js +++ b/frontend/src/utils/StringUtils.js @@ -5,3 +5,14 @@ export function pdfTemplateReplaceAll(content, source, target) { return content } +export function randomRange(min, max) { + let returnStr = '' + const range = (max ? Math.round(Math.random() * (max - min)) + min : min) + const charStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' + + for (var i = 0; i < range; i++) { + var index = Math.round(Math.random() * (charStr.length - 1)) + returnStr += charStr.substring(index, index + 1) + } + return returnStr +} diff --git a/frontend/src/views/link/generate/index.vue b/frontend/src/views/link/generate/index.vue index d307a58eeb..864c26b205 100644 --- a/frontend/src/views/link/generate/index.vue +++ b/frontend/src/views/link/generate/index.vue @@ -77,6 +77,7 @@ import { shortUrl, setOverTime } from '@/api/link' +import { randomRange } from '@/utils/StringUtils' export default { name: 'LinkGenerate', @@ -171,14 +172,7 @@ export default { }, createPwd() { - const randomNum = () => { - return Math.floor(Math.random() * 10) + '' - } - let result = '' - for (let index = 0; index < this.pwdNums; index++) { - result += randomNum() - } - return result + return randomRange(this.pwdNums) }, resetPwd() {