Files
ftb-project-management/apps/web/lib/members.ts
2026-06-26 11:18:00 +08:00

68 lines
1.6 KiB
TypeScript

export interface Department {
id: string;
name: string;
parentId?: string;
order: number;
createdAt: string;
}
export interface Member {
id: string;
name: string;
departmentId: string;
roleId: string;
phone: string;
email: string;
password: string;
createdAt: string;
isSystem?: boolean;
}
export interface RoleItem {
id: string;
name: string;
description?: string;
createdAt: string;
isSystem?: boolean;
permissions: string[];
}
export interface PasswordRule {
prefix: string;
length: number;
includeUppercase: boolean;
includeLowercase: boolean;
includeNumbers: boolean;
includeSpecial: boolean;
}
export const DEFAULT_PASSWORD_RULE: PasswordRule = {
prefix: 'Ftb',
length: 8,
includeUppercase: true,
includeLowercase: true,
includeNumbers: true,
includeSpecial: false,
};
export function generatePassword(rule: PasswordRule): string {
let chars = '';
if (rule.includeUppercase) chars += 'ABCDEFGHJKLMNPQRSTUVWXYZ';
if (rule.includeLowercase) chars += 'abcdefghjkmnpqrstuvwxyz';
if (rule.includeNumbers) chars += '23456789';
if (rule.includeSpecial) chars += '!@#$%&*';
if (!chars) chars = 'abcdefghjkmnpqrstuvwxyz23456789';
const randomLength = Math.max(rule.length - rule.prefix.length, 4);
let result = rule.prefix;
for (let i = 0; i < randomLength; i++) {
result += chars[Math.floor(Math.random() * chars.length)];
}
return result;
}
export function maskPhone(phone: string): string {
if (!phone || phone.length < 7) return phone;
return phone.slice(0, 3) + '****' + phone.slice(7);
}