feat(Materials): add new materials navigation and href functions
All checks were successful
Frontend CI / build-and-push-web (push) Successful in 2m59s
Frontend CI / ota-android (push) Successful in 18m11s
Frontend CI / build-android-apk (push) Successful in 1h21m54s

- Introduced href functions for accessing materials, including hrefMaterials, hrefMaterialSubject, and hrefMaterialDetail.
- Updated AppsScreen to include a new entry for materials, enhancing the app's educational resources section.
- Exported material types in index.ts to support the new materials functionality.
This commit is contained in:
lafay
2026-03-25 21:17:17 +08:00
parent 619f08275c
commit 9529ea39c4
14 changed files with 2099 additions and 0 deletions

View File

@@ -6,6 +6,7 @@
// 导出DTO类型作为主要类型
export * from './dto';
export * from './schedule';
export * from './material';
// 兼容旧类型(用于内部组件)
import type {

103
src/types/material.ts Normal file
View File

@@ -0,0 +1,103 @@
/**
* 学习资料类型定义
*/
// 文件类型枚举
export type MaterialFileType = 'pdf' | 'word' | 'ppt';
// 学科分类
export interface MaterialSubject {
id: string;
name: string;
icon: string; // MaterialCommunityIcons name
color: string; // 主题色
description?: string;
sort_order: number;
is_active: boolean;
material_count: number;
created_at: string;
updated_at: string;
}
// 文件资料
export interface MaterialFile {
id: string;
subject_id: string;
title: string;
description?: string;
file_type: MaterialFileType;
file_size: number; // 字节数
file_url: string;
file_name: string;
download_count: number;
author_id?: string;
author_name?: string;
tags?: string[];
status: 'active' | 'inactive';
created_at: string;
updated_at: string;
subject?: MaterialSubject;
}
// 学科资料列表响应
export interface SubjectMaterialsResponse {
subject: MaterialSubject;
materials: MaterialFile[];
total: number;
page: number;
page_size: number;
}
// 搜索结果响应
export interface SearchMaterialsResponse {
materials: MaterialFile[];
total: number;
page: number;
page_size: number;
}
// 文件类型图标映射
export const MATERIAL_FILE_TYPE_ICONS: Record<MaterialFileType, string> = {
pdf: 'file-pdf-box',
word: 'file-word-box',
ppt: 'file-powerpoint-box',
};
// 文件类型颜色映射
export const MATERIAL_FILE_TYPE_COLORS: Record<MaterialFileType, string> = {
pdf: '#E53935',
word: '#1E88E5',
ppt: '#FF9800',
};
// 文件类型名称映射
export const MATERIAL_FILE_TYPE_NAMES: Record<MaterialFileType, string> = {
pdf: 'PDF',
word: 'Word',
ppt: 'PPT',
};
// 文件大小格式化
export function formatFileSize(bytes: number): string {
if (bytes === 0) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return `${parseFloat((bytes / Math.pow(k, i)).toFixed(1))} ${sizes[i]}`;
}
// 学科颜色预设
export const SUBJECT_COLORS = [
'#FF6B6B', // 红色
'#4ECDC4', // 青色
'#45B7D1', // 蓝色
'#96CEB4', // 绿色
'#FFEAA7', // 黄色
'#DDA0DD', // 紫色
'#F39C12', // 橙色
'#3498DB', // 深蓝
'#27AE60', // 深绿
'#9B59B6', // 深紫
'#1ABC9C', // 青绿
'#E74C3C', // 深红
];