index.ts 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // 通用响应类型
  2. export interface ApiResponse<T = any> {
  3. success: boolean;
  4. data?: T;
  5. message?: string;
  6. error?: string;
  7. }
  8. // 分页类型
  9. export interface Pagination {
  10. page: number;
  11. pageSize: number;
  12. total: number;
  13. totalPages: number;
  14. }
  15. // 分页响应类型
  16. export interface PaginatedResponse<T = any> extends ApiResponse<T[]> {
  17. pagination: Pagination;
  18. }
  19. // 查询参数类型
  20. export interface QueryParams {
  21. page?: number;
  22. pageSize?: number;
  23. sortBy?: string;
  24. sortOrder?: 'ASC' | 'DESC';
  25. [key: string]: any;
  26. }
  27. // 启用/禁用状态枚举
  28. export enum EnableStatus {
  29. DISABLED = 0, // 禁用
  30. ENABLED = 1 // 启用
  31. }
  32. // 启用/禁用状态中文映射
  33. export const EnableStatusNameMap: Record<EnableStatus, string> = {
  34. [EnableStatus.DISABLED]: '禁用',
  35. [EnableStatus.ENABLED]: '启用'
  36. };
  37. // 删除状态枚举
  38. export enum DeleteStatus {
  39. NOT_DELETED = 0, // 未删除
  40. DELETED = 1 // 已删除
  41. }
  42. // 删除状态中文映射
  43. export const DeleteStatusNameMap: Record<DeleteStatus, string> = {
  44. [DeleteStatus.NOT_DELETED]: '未删除',
  45. [DeleteStatus.DELETED]: '已删除'
  46. };
  47. // 启用/禁用状态枚举(反向定义)
  48. export enum DisabledStatus {
  49. DISABLED = 1, // 禁用
  50. ENABLED = 0 // 启用
  51. }
  52. // 启用/禁用状态中文映射
  53. export const DisabledStatusNameMap: Record<DisabledStatus, string> = {
  54. [DisabledStatus.DISABLED]: '禁用',
  55. [DisabledStatus.ENABLED]: '启用'
  56. };
  57. // 认证上下文类型
  58. export interface AuthContextType<T> {
  59. user: T | null;
  60. token: string | null;
  61. login: (username: string, password: string, latitude?: number, longitude?: number) => Promise<void>;
  62. logout: () => Promise<void>;
  63. isAuthenticated: boolean;
  64. isLoading: boolean;
  65. }
  66. // 全局配置常量
  67. export interface GlobalConfig {
  68. OSS_BASE_URL: string;
  69. APP_NAME: string;
  70. }
  71. // JWT Payload 类型
  72. export interface JWTPayload {
  73. id: number;
  74. username: string;
  75. roles?: string[];
  76. openid?: string;
  77. }
  78. // Hono 认证上下文类型
  79. export type AuthContext = {
  80. Variables: {
  81. user: any; // 用户类型将在具体模块中定义
  82. token: string;
  83. }
  84. };