@gulibs/react-autoroutes-client
Version:
Client-side utilities for React auto routes
330 lines • 8.57 kB
TypeScript
import type * as React from 'react';
import type { UIMatch } from "react-router";
/**
* 导航栏配置
*/
export interface NavbarConfig {
/** 是否固定在顶部 */
sticky?: boolean;
/** 背景透明度 */
transparent?: boolean;
/** 高度 */
height?: string;
}
/**
* 侧边栏配置
*/
export interface SidebarConfig {
/** 侧边栏宽度 */
width?: string;
/** 是否可折叠 */
collapsible?: boolean;
/** 默认是否折叠 */
defaultCollapsed?: boolean;
}
/**
* 页脚配置
*/
export interface FooterConfig {
/** 是否固定在底部 */
sticky?: boolean;
/** 高度 */
height?: string;
}
/**
* 主题配置
*/
export interface ThemeConfig {
/** 主题模式 */
mode?: 'light' | 'dark' | 'auto';
/** 主色调 */
primaryColor?: string;
}
/**
* 响应式配置
*/
export interface ResponsiveConfig {
/** 移动端是否隐藏侧边栏 */
hideSidebarOnMobile?: boolean;
/** 移动端断点 */
mobileBreakpoint?: string;
}
/**
* 布局设置 - 与 VGrove 布局配置兼容
*/
export interface LayoutSettings {
/** 是否显示侧边栏 */
sidebar?: boolean;
/** 是否显示导航栏/头部 */
header?: boolean;
/** 是否显示页脚 */
footer?: boolean;
/** 导航栏配置 */
navbar?: NavbarConfig;
/** 侧边栏配置 */
sidebarConfig?: SidebarConfig;
/** 页脚配置 */
footerConfig?: FooterConfig;
/** 主题相关配置 */
theme?: ThemeConfig;
/** 响应式配置 */
responsive?: ResponsiveConfig;
}
export interface LayoutFeatures {
hasSidebar: boolean;
hasHeader: boolean;
hasFooter: boolean;
isSidebarCollapsible: boolean;
isNavbarSticky: boolean;
isFooterSticky: boolean;
shouldHideSidebarOnMobile: boolean;
}
/**
* 本地化类型,可以是任何字符串
*/
export type LocalizedType<Keys extends string = string> = Keys | (string & {});
/**
* 本地化对象,包含本地化ID
*/
export type Localized<Keys extends string = string> = {
localizedId: LocalizedType<Keys>;
};
/**
* 本地化对象或React节点
*/
export type LocalizedOrNode<Keys extends string = string> = Localized<Keys> | React.ReactNode;
/**
* 页面元数据
*/
export type PageMeta<Keys extends string = string> = {
/** 页面标题 */
title?: LocalizedOrNode<Keys>;
/** 页面描述 */
description?: string;
};
export type PageHeaderMeta<Keys extends string = string> = {
/** 页面标题 */
title?: LocalizedOrNode<Keys>;
/** 页面描述 */
description?: LocalizedOrNode<Keys>;
};
/**
* 面包屑项属性
*/
export interface PageBreadcrumbItemProps {
/** 链接地址 */
href?: string;
/** 是否禁用 */
isDisabled?: boolean;
/** 是否为当前页 */
isCurrent?: boolean;
/** CSS 类名 */
className?: string;
/** 起始内容 */
startContent?: React.ReactNode;
/** 结尾内容 */
endContent?: React.ReactNode;
/** 子内容 */
children?: React.ReactNode;
}
/**
* 页面处理配置
*/
export type PageHandle<Keys extends string = string> = {
/** 元数据 */
meta?: PageMeta<Keys>;
/** 页面元数据 */
pageMeta?: PageHeaderMeta<Keys>;
/** 额外内容 */
extras?: React.ReactNode;
/** 布局设置 */
layoutSettings?: LayoutSettings;
/** 面包屑配置 */
breadcrumbs?: Omit<PageBreadcrumbItemProps, "children">;
/** 路由匹配 */
matches?: UIMatch[];
/** 其他自定义属性 */
[x: string]: any;
};
/**
* 守卫执行上下文
*/
export interface GuardContext {
/** 当前路由路径 */
path: string;
/** 路由参数 */
params: Record<string, string>;
/** 查询参数 */
query: Record<string, string>;
/** 用户信息 */
user?: any;
/** 用户权限 */
permissions?: string[];
/** 用户角色 */
roles?: string[];
/** 自定义数据 */
data: Record<string, any>;
}
/**
* 中间件上下文
*/
export interface MiddlewareContext {
/** 当前路由路径 */
path: string;
/** 路由参数 */
params: Record<string, string>;
/** 查询参数 */
query: Record<string, string>;
/** 请求头 */
headers?: Record<string, string>;
/** 用户数据 */
user?: any;
/** 自定义数据 */
data: Record<string, any>;
}
/**
* 认证上下文
*/
export interface AuthContext {
/** 当前路由路径 */
path: string;
/** 路由参数 */
params: Record<string, string>;
/** 查询参数 */
query: Record<string, string>;
/** 用户信息 */
user?: any;
/** 用户权限 */
permissions?: string[];
/** 用户角色 */
roles?: string[];
/** 自定义数据 */
data: Record<string, any>;
}
/**
* 认证状态
*/
export interface AuthState<TUser = any> {
user: TUser | null;
token: string | null;
refreshToken: string | null;
isAuthenticated: boolean;
isLoading: boolean;
error: string | null;
}
/**
* 认证操作
*/
export interface AuthActions<TUser = any, TCredentials = any> {
login: (credentials: TCredentials) => Promise<void>;
logout: () => void;
refreshUser: () => Promise<void>;
refreshTokenAction: () => Promise<void>;
updateUser: (userData: Partial<TUser>) => void;
setToken: (token: string) => void;
setRefreshToken: (refreshToken: string) => void;
clearError: () => void;
}
/**
* API 字段映射
*/
export interface FieldMapping {
/** 用户数据字段名,默认 'user' */
userField?: string;
/** Token字段名,默认 'token' */
tokenField?: string;
/** RefreshToken字段名,默认 'refreshToken' */
refreshTokenField?: string;
}
/**
* 数据转换器
*/
export interface DataTransformers<TUser = any, TCredentials = any> {
/** 登录前转换凭据 */
transformCredentials?: (credentials: TCredentials) => any;
/** 登录后转换用户数据 */
transformUser?: (userData: any) => TUser;
/** 存储前转换用户数据 */
beforeStore?: (userData: TUser) => any;
/** 读取后转换用户数据 */
afterRestore?: (userData: any) => TUser;
}
/**
* useUser 配置
*/
export interface UseUserOptions<TUser = any, TCredentials = any> {
/** 存储键前缀 */
storagePrefix?: string;
/** 是否使用 sessionStorage(默认使用 localStorage) */
useSessionStorage?: boolean;
/** 获取用户信息的函数 */
fetchUser?: (token: string) => Promise<TUser>;
/** 登录API */
loginApi?: (credentials: TCredentials) => Promise<{
user: TUser;
token: string;
refreshToken?: string;
}>;
/** 刷新Token API */
refreshTokenApi?: (refreshToken: string) => Promise<{
token: string;
refreshToken?: string;
user?: TUser;
}>;
/** 自动刷新间隔(毫秒,0表示禁用) */
autoRefreshInterval?: number;
/** Token过期检查函数 */
isTokenExpired?: (token: string) => boolean;
/** RefreshToken过期检查函数 */
isRefreshTokenExpired?: (refreshToken: string) => boolean;
/** API字段映射 */
fieldMapping?: FieldMapping;
/** 数据转换器 */
transformers?: DataTransformers<TUser, TCredentials>;
}
/**
* 中间件选项
*/
export interface MiddlewareOptions {
/** 中间件名称 */
name?: string;
/** 执行优先级(数字越小越先执行)*/
priority?: number;
/** 是否仅在开发环境执行 */
devOnly?: boolean;
/** 中间件处理函数 */
handler: (context: MiddlewareContext, next: () => Promise<void> | void) => Promise<void> | void;
}
/**
* 守卫选项
*/
export interface GuardOptions {
/** 守卫名称 */
name?: string;
/** 守卫类型 */
type?: 'auth' | 'role' | 'permission' | 'custom';
/** 访问被拒绝时的重定向路径 */
redirectTo?: string;
/** 错误信息 */
errorMessage?: string;
/** 守卫条件函数 */
condition: (context: GuardContext) => boolean | Promise<boolean>;
}
/**
* 认证选项
*/
export interface AuthOptions {
/** 认证名称 */
name?: string;
/** 认证失败时的重定向路径 */
redirectTo?: string;
/** 错误信息 */
errorMessage?: string;
/** 自定义认证检查函数 */
check?: (context: AuthContext) => boolean | Promise<boolean>;
/** 所需的角色 */
roles?: string[];
/** 所需的权限 */
permissions?: string[];
}
//# sourceMappingURL=types.d.ts.map