uni-app.d.ts 2.79 KB
declare module "@dcloudio/vite-plugin-uni";

declare type Theme = "light" | "dark";

declare interface Uni {
	rpx2px(px: number): number;
	// 兼容旧项目在 uni 上挂载的扩展对象,供 UTS 编译期识别
	$api?: any;
	// $logger?: any;
	$storage?: {
		get(key: string): any;
		set(key: string, value: any): void;
	};
	$signHttp?: any;
	signHttpConfig?: any;
}

declare interface JSON {
	parseObject<T>(text: string): T | null;
}

declare type UTSJSONObject = {
	[key: string]: any;
	parse?<T>(): T | null;
	get?(key: string): any | null;
	set?(key: string, value: any | null): void;
	getAny?(key: string): any | null;
	getAny?(key: string, def: any): any;
	getBoolean?(key: string): boolean | null;
	getBoolean?(key: string, def: any): boolean;
	getNumber?(key: string): number | null;
	getNumber?(key: string, def: any): number;
	getString?(key: string): string | null;
	getString?(key: string, def: any): string;
	getJSON?(key: string): UTSJSONObject | null;
	getJSON?(key: string, def: any): UTSJSONObject;
	getArray?<T>(key: string): T[] | null;
	getArray?<T>(key: string, def: T[]): T[];
	getArray?(key: string): any[] | null;
	getArray?(key: string, def: any[]): any[];
	toMap?(): Map<string, any>;
};

declare interface ChooseImageTempFile {
	path: string;
	size: number;
	name: string;
	type: string;
}

declare type RequestMethod =
	| "OPTIONS"
	| "GET"
	| "HEAD"
	| "POST"
	| "PUT"
	| "DELETE"
	| "TRACE"
	| "CONNECT";

declare interface DOMRect {
	x: number;
	y: number;
	width: number;
	height: number;
	left: number;
	top: number;
	right: number;
	bottom: number;
}

declare interface UniElement {
	$vm: ComponentPublicInstance;
	id: string;
	firstChild: UniElement;
	lastChild: UniElement;
	previousSibling: UniElement;
	parentElement: UniElement;
	children: UniElement[];
	attributes: Map<string, any>;
	dataset: Map<string, any>;
	style: CSSStyleDeclaration;
	classList: string[];
	takeSnapshot(options: {
		success?: (res: { tempFilePath: string }) => void;
		fail?: (err: { errCode: number; errMsg: string }) => void;
	}): void;
	getBoundingClientRectAsync(): Promise<DOMRect>;
	getDrawableContext(): DrawableContext;
	animate(
		keyframes: UniAnimationKeyframe | UniAnimationKeyframe[],
		options?:
			| {
					delay?: number;
					direction?: "normal" | "reverse" | "alternate" | "alternate-reverse";
					duration?: number;
					easing?:
						| "ease"
						| "ease-in"
						| "ease-out"
						| "ease-in-out"
						| "linear"
						| "cubic-bezier";
					fill?: "backwards" | "forwards" | "both" | "none";
					iterations?: number;
			  }
			| number
	): {
		id: string;
		playState: "running" | "paused" | "finished" | "idle";
	} | null;
}

declare interface CanvasContext extends HTMLCanvasElement {
	createImage(): HTMLImageElement;
	reset(): void;
}

declare type Image = HTMLImageElement;

declare type VueApp = any;