feat(Materials): add new materials navigation and href functions
- 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:
@@ -6,6 +6,7 @@
|
||||
// 导出DTO类型作为主要类型
|
||||
export * from './dto';
|
||||
export * from './schedule';
|
||||
export * from './material';
|
||||
|
||||
// 兼容旧类型(用于内部组件)
|
||||
import type {
|
||||
|
||||
103
src/types/material.ts
Normal file
103
src/types/material.ts
Normal 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', // 深红
|
||||
];
|
||||
Reference in New Issue
Block a user