Migrate project from typing_practiceweb
This commit is contained in:
24
src/types/auth.ts
Normal file
24
src/types/auth.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// src/types/auth.ts
|
||||
export interface LoginFormValues {
|
||||
username: string;
|
||||
password: string;
|
||||
}
|
||||
export interface RegisterFormValues extends LoginFormValues {
|
||||
email?: string;
|
||||
fullname: string;
|
||||
confirmPassword: string;
|
||||
}
|
||||
export interface LoginResponse {
|
||||
token: string;
|
||||
user: {
|
||||
_id: string;
|
||||
username: string;
|
||||
email: string;
|
||||
fullname: string;
|
||||
isAdmin: boolean;
|
||||
};
|
||||
}
|
||||
export interface ErrorResponse {
|
||||
message: string;
|
||||
code?: string;
|
||||
}
|
||||
22
src/types/index.ts
Normal file
22
src/types/index.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// 练习类型接口
|
||||
export interface PracticeType {
|
||||
_id: string;
|
||||
title: string;
|
||||
description: string;
|
||||
level: PracticeLevel;
|
||||
}
|
||||
|
||||
// 代码示例接口
|
||||
export interface CodeExample {
|
||||
_id: string;
|
||||
title: string;
|
||||
content: string;
|
||||
description?: string;
|
||||
level: PracticeLevel;
|
||||
difficulty?: number;
|
||||
createdAt?: Date;
|
||||
updatedAt?: Date;
|
||||
}
|
||||
|
||||
// 练习级别类型
|
||||
export type PracticeLevel = 'keyword' | 'basic' | 'intermediate' | 'advanced';
|
||||
44
src/types/keywords.ts
Normal file
44
src/types/keywords.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
// 基础关键字数据接口
|
||||
export interface IKeywords {
|
||||
_id: string;
|
||||
content: string; // 所有关键字,用\n分隔
|
||||
updatedAt: Date;
|
||||
}
|
||||
|
||||
// API 响应数据接口
|
||||
export interface KeywordsResponse {
|
||||
content: string;
|
||||
error?: string; // 添加错误信息字段
|
||||
}
|
||||
|
||||
// 创建/更新关键字的请求数据接口
|
||||
export interface KeywordsUpdateRequest {
|
||||
content: string;
|
||||
}
|
||||
|
||||
// 单个关键字的类型
|
||||
export interface IKeyword {
|
||||
id: number;
|
||||
text: string;
|
||||
}
|
||||
|
||||
// API 错误类型
|
||||
export interface ApiError {
|
||||
message: string;
|
||||
status?: number;
|
||||
}
|
||||
|
||||
// 帮助函数:解析关键字字符串为数组
|
||||
export const parseKeywords = (content: string): string[] => {
|
||||
return content.split('\n').filter(keyword => keyword.trim() !== '');
|
||||
};
|
||||
|
||||
// 格式化函数:将关键字数组转为字符串
|
||||
export const formatKeywords = (keywords: string[]): string => {
|
||||
return keywords.join('\n');
|
||||
};
|
||||
|
||||
// 可选:验证关键字格式的函数
|
||||
export const isValidKeyword = (keyword: string): boolean => {
|
||||
return keyword.trim().length > 0;
|
||||
};
|
||||
20
src/types/practice.ts
Normal file
20
src/types/practice.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
export interface PracticeStats {
|
||||
totalWords: number;
|
||||
correctWords: number;
|
||||
accuracy: number;
|
||||
wordsPerMinute: number;
|
||||
duration: number;
|
||||
startTime: Date;
|
||||
endTime: Date;
|
||||
}
|
||||
|
||||
export interface PracticeRecord {
|
||||
_id: string;
|
||||
userId: string;
|
||||
username: string;
|
||||
fullname: string;
|
||||
type: 'keyword' | 'basic' | 'intermediate' | 'advanced';
|
||||
stats: PracticeStats;
|
||||
createdAt: Date;
|
||||
updatedAt: Date;
|
||||
}
|
||||
Reference in New Issue
Block a user