用户管理接口完成
This commit is contained in:
+46
-1
@@ -95,4 +95,49 @@ export function formatTimestamp(timestamp: number | string,format: string = 'yyy
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}`;
|
||||
}
|
||||
return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
||||
}
|
||||
}
|
||||
|
||||
// 辅助函数:Fisher-Yates 洗牌算法
|
||||
function shuffle(arr:any) {
|
||||
for (let i = arr.length - 1; i > 0; i--) {
|
||||
const j = Math.floor(Math.random() * (i + 1));
|
||||
[arr[i], arr[j]] = [arr[j], arr[i]];
|
||||
}
|
||||
return arr;
|
||||
}
|
||||
// 辅助函数:从字符串中随机获取字符
|
||||
function getRandomChar(str:any) {
|
||||
return str[Math.floor(Math.random() * str.length)];
|
||||
}
|
||||
// 生成至少12位,包含四类字符中的至少三种的随机密码
|
||||
export function generateSecurePassword(passwordLength:number) {
|
||||
// 定义字符池
|
||||
const charSets:any = {
|
||||
uppercase: 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
|
||||
lowercase: 'abcdefghijklmnopqrstuvwxyz',
|
||||
numbers: '0123456789',
|
||||
symbols: '!@#$%^&*()_+-=[]{}|;:,.<>?'
|
||||
};
|
||||
|
||||
// 随机选择三种字符类型(保证至少三类)
|
||||
const requiredTypes = shuffle(Object.keys(charSets)).slice(0, 3);
|
||||
|
||||
// 生成必选字符(每类至少1个)
|
||||
let password = requiredTypes
|
||||
.map((type:any) => getRandomChar(charSets[type]))
|
||||
.join('');
|
||||
|
||||
// 生成剩余字符(允许包含所有四类)
|
||||
const remainingLength = passwordLength - password.length;
|
||||
const allChars = Object.values(charSets).join('');
|
||||
for (let i = 0; i < remainingLength; i++) {
|
||||
password += getRandomChar(allChars);
|
||||
}
|
||||
|
||||
// 打乱字符顺序
|
||||
return shuffle(password.split('')).join('');
|
||||
}
|
||||
// 获取 token
|
||||
export const getToken = () => {
|
||||
return localStorage.getItem('token');
|
||||
};
|
||||
Reference in New Issue
Block a user