// SSR 上下文与 cookie 管理(与业务无关的通用模块) export interface SSRContext { cache?: Map cookies?: Record setCookies?: string[] [key: string]: any } export function createSSRContext(): SSRContext { return { cache: new Map(), cookies: {}, setCookies: [] } } export function hydrateSSRContext(context: SSRContext): void { if (typeof window !== 'undefined') { if (context.cache && Array.isArray(context.cache)) { context.cache = new Map(context.cache) } ;(window as any).__SSR_CONTEXT__ = context } } export function clearSSRContext(): void { if (typeof window !== 'undefined') { delete (window as any).__SSR_CONTEXT__ } } // 通用获取 SSR 上下文(客户端从 window,服务端从 app 实例) export function resolveSSRContext(instance?: any): SSRContext | null { if (typeof window !== 'undefined') { return (window as any).__SSR_CONTEXT__ || null } return instance?.appContext?.config?.globalProperties?.$ssrContext || null }