import { AppInfoPayload } from "./common"; export interface IframeMessage { type: string; data: T; } export interface PreviewReadyMessage extends IframeMessage> { type: 'PreviewReady'; } export interface ConsoleMessage extends IframeMessage> { method: string; type: 'Console'; } export interface ChildLocationChangeMessage extends IframeMessage { type: 'ChildLocationChange'; } export interface CreatePageMessage extends IframeMessage { type: 'CreatePage'; } export interface RenderErrorMessage extends IframeMessage { type: 'RenderError'; location?: any; } export interface RenderErrorRepairMessage extends IframeMessage { type: 'RenderErrorRepair'; } export interface PageScreenshotMessage extends IframeMessage { type: 'PageScreenshot'; } export interface UpdateRoutesMessage extends IframeMessage<{ routes: any[]; }> { type: 'UpdateRoutes'; } /** 热更新消息 */ export interface HmrMessage extends IframeMessage> { type: 'HmrMessage'; msg: { type: 'hot' | 'errors'; data?: any; }; } /** devServer相关消息 */ export interface DevServerMessage extends IframeMessage<{ type: 'devServer-status'; status: 'connected' | 'disconnected' | 'hmr-apply-success'; }> { type: 'DevServerMessage'; } export type OutgoingMessage = PreviewReadyMessage | HmrMessage | ConsoleMessage | ChildLocationChangeMessage | CreatePageMessage | RenderErrorMessage | RenderErrorRepairMessage | PageScreenshotMessage | DevServerMessage | UpdateRoutesMessage; export interface GetRoutesMessage extends IframeMessage> { type: 'GetRoutes'; } export type IncomingMessage = GetRoutesMessage; export interface ParentApi { } export interface ChildApi { getRoutes: () => Promise; getSourceMap: () => Promise; /** 更新应用信息 */ updateAppInfo: (appInfo: AppInfoPayload) => void; apiProxy: { api_get: (url: string, config?: any) => Promise; api_post: (url: string, data?: any, config?: any) => Promise; api_put: (url: string, data?: any, config?: any) => Promise; api_delete: (url: string, config?: any) => Promise; api_patch: (url: string, data?: any, config?: any) => Promise; api_head: (url: string, config?: any) => Promise; api_options: (url: string, config?: any) => Promise; }; }