docs: add comments to the src/routes & src/store & src/utils directory

This commit is contained in:
zhaoying
2026-02-02 16:37:32 +08:00
parent 6194222289
commit 9a38e8a4a0
13 changed files with 546 additions and 435 deletions

View File

@@ -1,14 +1,34 @@
/*
* @Author: ZhaoYing
* @Date: 2026-02-02 16:34:23
* @Last Modified by: ZhaoYing
* @Last Modified time: 2026-02-02 16:34:23
*/
/**
* Common Utility Functions
*
* Provides general-purpose utility functions.
*
* @module common
*/
/**
* Generate a random string with specified length and character types
* @param length - Length of the string (default: 12)
* @param isHasSpecialChars - Whether to include special characters (default: true)
* @returns Random string
*/
export const randomString = (length: number = 12, isHasSpecialChars: boolean = true) => {
// 定义字符集:大写字母、小写字母、数字和特殊字符
/** Define character sets: uppercase, lowercase, numbers, and special characters */
const uppercaseChars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const lowercaseChars = 'abcdefghijklmnopqrstuvwxyz';
const numberChars = '0123456789';
const specialChars = '!@#$%^&*_+-=|;:,.?';
// 合并所有字符集
/** Combine all character sets */
let allChars = uppercaseChars + lowercaseChars + numberChars;
// 确保至少包含每种类型的字符
/** Ensure at least one character of each type */
let str =
uppercaseChars[Math.floor(Math.random() * uppercaseChars.length)] +
lowercaseChars[Math.floor(Math.random() * lowercaseChars.length)] +
@@ -18,11 +38,11 @@ export const randomString = (length: number = 12, isHasSpecialChars: boolean = t
str+= specialChars[Math.floor(Math.random() * specialChars.length)];
}
// 填充剩余的字符使总长度为12
/** Fill remaining characters to reach desired length */
for (let i = 4; i < length; i++) {
str += allChars[Math.floor(Math.random() * allChars.length)];
}
// 打乱密码字符顺序
/** Shuffle the string characters */
return str.split('').sort(() => Math.random() - 0.5).join('');
}
}